Skip to content

Commit

Permalink
feat: add inner version check
Browse files Browse the repository at this point in the history
  • Loading branch information
boybeak committed Dec 18, 2024
1 parent da099b0 commit 3f79803
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 5 deletions.
25 changes: 21 additions & 4 deletions DeskNote.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
84358E852D130238003F382A /* GithubReleaseChecker in Frameworks */ = {isa = PBXBuildFile; productRef = 84358E842D130238003F382A /* GithubReleaseChecker */; };
8450C9D02C9D36200028DDA1 /* NoLaunchWin in Frameworks */ = {isa = PBXBuildFile; productRef = 8450C9CF2C9D36200028DDA1 /* NoLaunchWin */; };
845A30892C1B269400834D65 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 845A30872C1B269400834D65 /* Localizable.strings */; };
845A308C2C1B26D000834D65 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 845A308A2C1B26D000834D65 /* Localizable.strings */; };
Expand Down Expand Up @@ -66,6 +67,7 @@
buildActionMask = 2147483647;
files = (
848F2B792C343BED0007A19D /* WinToEdge in Frameworks */,
84358E852D130238003F382A /* GithubReleaseChecker in Frameworks */,
848F2B612C33CA1E0007A19D /* WinDragger in Frameworks */,
8450C9D02C9D36200028DDA1 /* NoLaunchWin in Frameworks */,
848F2B802C3E7EED0007A19D /* LaunchAtLogin in Frameworks */,
Expand Down Expand Up @@ -191,6 +193,7 @@
848F2B782C343BED0007A19D /* WinToEdge */,
848F2B7F2C3E7EED0007A19D /* LaunchAtLogin */,
8450C9CF2C9D36200028DDA1 /* NoLaunchWin */,
84358E842D130238003F382A /* GithubReleaseChecker */,
);
productName = DeskNote;
productReference = 84F83DEF2C10A4D80094346C /* DeskNote.app */;
Expand Down Expand Up @@ -227,6 +230,7 @@
848F2B772C343BED0007A19D /* XCLocalSwiftPackageReference "../WinToEdge" */,
848F2B7E2C3E7EED0007A19D /* XCRemoteSwiftPackageReference "LaunchAtLogin-Modern" */,
8450C9CE2C9D36200028DDA1 /* XCRemoteSwiftPackageReference "NoLaunchWin" */,
84358E832D130238003F382A /* XCRemoteSwiftPackageReference "GithubReleaseChecker" */,
);
productRefGroup = 84F83DF02C10A4D80094346C /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -423,7 +427,7 @@
CODE_SIGN_ENTITLEMENTS = DeskNote/DeskNote.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1302;
CURRENT_PROJECT_VERSION = 1400;
DEVELOPMENT_ASSET_PATHS = "\"DeskNote/Preview Content\"";
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -436,7 +440,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 1.3.10;
MARKETING_VERSION = 1.4.00;
PRODUCT_BUNDLE_IDENTIFIER = com.github.boybeak.DeskNote;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -452,7 +456,7 @@
CODE_SIGN_ENTITLEMENTS = DeskNote/DeskNote.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1302;
CURRENT_PROJECT_VERSION = 1400;
DEVELOPMENT_ASSET_PATHS = "\"DeskNote/Preview Content\"";
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -465,7 +469,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 1.3.10;
MARKETING_VERSION = 1.4.00;
PRODUCT_BUNDLE_IDENTIFIER = com.github.boybeak.DeskNote;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -512,6 +516,14 @@
/* End XCLocalSwiftPackageReference section */

/* Begin XCRemoteSwiftPackageReference section */
84358E832D130238003F382A /* XCRemoteSwiftPackageReference "GithubReleaseChecker" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/boybeak/GithubReleaseChecker.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.0.1;
};
};
8450C9CE2C9D36200028DDA1 /* XCRemoteSwiftPackageReference "NoLaunchWin" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/boybeak/NoLaunchWin.git";
Expand All @@ -531,6 +543,11 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
84358E842D130238003F382A /* GithubReleaseChecker */ = {
isa = XCSwiftPackageProductDependency;
package = 84358E832D130238003F382A /* XCRemoteSwiftPackageReference "GithubReleaseChecker" */;
productName = GithubReleaseChecker;
};
8450C9CF2C9D36200028DDA1 /* NoLaunchWin */ = {
isa = XCSwiftPackageProductDependency;
package = 8450C9CE2C9D36200028DDA1 /* XCRemoteSwiftPackageReference "NoLaunchWin" */;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"originHash" : "df31889941f022babd7e42db6e4aa3f0832ef9d3688dded1828079be4373cf5e",
"originHash" : "5adb9c6026b21b2b556a659809614368c2cf089d1d7e90e34e37b071db74d397",
"pins" : [
{
"identity" : "githubreleasechecker",
"kind" : "remoteSourceControl",
"location" : "https://github.com/boybeak/GithubReleaseChecker.git",
"state" : {
"revision" : "bf654544f74588f7e80bfda198b5400b746d54c9",
"version" : "0.0.2"
}
},
{
"identity" : "launchatlogin-modern",
"kind" : "remoteSourceControl",
Expand All @@ -18,6 +27,15 @@
"revision" : "8114836b96375ffe24740bd9c503ca1b0a57324d",
"version" : "0.0.1"
}
},
{
"identity" : "swiftuiwindow",
"kind" : "remoteSourceControl",
"location" : "https://github.com/boybeak/SwiftUIWindow.git",
"state" : {
"revision" : "e7d0d194a06b3de48bafda630864c80d8fe6df08",
"version" : "0.0.1"
}
}
],
"version" : 3
Expand Down
Binary file not shown.
29 changes: 29 additions & 0 deletions DeskNote/DeskNoteApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftData
import Tray
import LaunchAtLogin
import NoLaunchWin
import GithubReleaseChecker

@main
struct DeskNoteApp: App {
Expand All @@ -26,6 +27,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {

private var tray: Tray!

private let checker = GithubReleaseChecker()
private let versionCheckItem = NSMenuItem(title: NSLocalizedString("Menu_item_version_check", comment: ""), action: #selector(checkVersion), keyEquivalent: "")
private var newVersion: ReleaseInfo? = nil

func applicationDidFinishLaunching(_ notification: Notification) {

tray = Tray.install(named: "TrayIcon") { tray in
Expand All @@ -42,6 +47,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let launchAtLoginMenuItem = NSMenuItem(title: NSLocalizedString("Menu_item_launch_at_login", comment: ""), action: #selector(onLaunchAtLoginToggle), keyEquivalent: "")
launchAtLoginMenuItem.state = LaunchAtLogin.isEnabled ? .on : .off


versionCheckItem.isHidden = true

let quitMenuItem = NSMenuItem(title: NSLocalizedString("Menu_item_quit", comment: ""), action: #selector(onQuitAction), keyEquivalent: "")

menu.addItem(newNoteMenuItem)
Expand All @@ -57,11 +65,26 @@ class AppDelegate: NSObject, NSApplicationDelegate {

menu.addItem(.separator())

menu.addItem(versionCheckItem)
menu.addItem(quitMenuItem)

tray.setMenu(menu: menu)

showHistoryNotes(notes: NoteManager.shared.fetchAllNotes())

checker.checkUpdate(for: .userRepo("boybeak/DeskNote")) { (res: Result<(newVersion: ReleaseInfo, hasUpdate: Bool), any Error>) in
switch(res) {
case .success((let newVersion, let hasUpdate)):
self.versionCheckItem.isHidden = !hasUpdate
self.versionCheckItem.title = String(format: NSLocalizedString("Menu_item_version_check", comment: ""), newVersion.tagName)
if hasUpdate {
self.newVersion = newVersion
}
case .failure(_):
self.versionCheckItem.isHidden = true
self.newVersion = nil
}
}
}

@objc func onNewNoteAction() {
Expand Down Expand Up @@ -105,6 +128,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

@objc func checkVersion() {
if let newVersion = self.newVersion, let url = URL(string: newVersion.htmlUrl) {
NSWorkspace.shared.open(url)
}
}

@objc func onQuitAction() {
NSApplication.shared.terminate(nil)
}
Expand Down
1 change: 1 addition & 0 deletions en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
"Menu_item_legacy_medium" = "Medium";
"Menu_item_legacy_large" = "Large";

"Menu_item_version_check" = "New version: %@";
"Menu_item_quit" = "Quit";
1 change: 1 addition & 0 deletions zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
"Menu_item_legacy_medium" = "中";
"Menu_item_legacy_large" = "大";

"Menu_item_version_check" = "新版本: %@";
"Menu_item_quit" = "退出";

0 comments on commit 3f79803

Please sign in to comment.