UpdateSputnik // Also show the GitHub download page in notification.

This commit is contained in:
ShikiSuen 2023-03-01 19:25:16 +08:00
parent 2fc8dbe541
commit ff468a94a1
3 changed files with 27 additions and 9 deletions

View File

@ -11,6 +11,7 @@ import Cocoa
public class UpdateSputnik {
public static let shared: UpdateSputnik = .init()
public let kUpdateInfoPageURLKey: String = "UpdateInfoSite"
public let kUpdateInfoPageURLGitHubKey: String = "UpdateInfoSiteGitHub"
public let kUpdateCheckDateKeyPrevious: String = "PreviousUpdateCheckDate"
public let kUpdateCheckDateKeyNext: String = "NextUpdateCheckDate"
public let kUpdateCheckInterval: TimeInterval = 114_514
@ -127,20 +128,33 @@ public class UpdateSputnik {
intRemoteVersion.description
)
let alert = NSAlert()
alert.messageText = NSLocalizedString("New Version Available", comment: "")
alert.informativeText = content
alert.addButton(withTitle: NSLocalizedString("Visit Website", comment: ""))
alert.messageText = NSLocalizedString("New Version Available", comment: "")
let strVisitWebsite = NSLocalizedString("Visit Website", comment: "")
alert.addButton(withTitle: "\(strVisitWebsite) (Gitee)")
alert.addButton(withTitle: "\(strVisitWebsite) (GitHub)")
alert.addButton(withTitle: NSLocalizedString("Not Now", comment: ""))
guard let siteInfoURLString = plist["\(kUpdateInfoPageURLKey)"] as? String,
let siteURL = URL(string: siteInfoURLString),
let siteInfoURLStringGitHub = plist["\(kUpdateInfoPageURLGitHubKey)"] as? String,
let siteURLGitHub = URL(string: siteInfoURLStringGitHub)
else {
return
}
let result = alert.runModal()
NSApp.activate(ignoringOtherApps: true)
if result == NSApplication.ModalResponse.alertFirstButtonReturn {
if let siteInfoURLString = plist[kUpdateInfoPageURLKey] as? String,
let siteURL = URL(string: siteInfoURLString)
{
switch result {
case .alertFirstButtonReturn:
DispatchQueue.main.async {
NSWorkspace.shared.open(siteURL)
}
case .alertSecondButtonReturn:
DispatchQueue.main.async {
NSWorkspace.shared.open(siteURLGitHub)
}
default: break
}
}

View File

@ -157,6 +157,8 @@ SOFTWARE.
<string>https://gitee.com/vchewing/vChewing-macOS/raw/main/Update-Info.plist</string>
<key>UpdateInfoSite</key>
<string>https://gitee.com/vChewing/vChewing-macOS/releases</string>
<key>UpdateInfoSiteGitHub</key>
<string>https://gitee.com/vChewing/vChewing-macOS/releases</string>
<key>tsInputMethodCharacterRepertoireKey</key>
<array>
<string>Hans</string>

View File

@ -10,5 +10,7 @@
<string>https://gitee.com/vchewing/vChewing-macOS/raw/main/Update-Info.plist</string>
<key>UpdateInfoSite</key>
<string>https://gitee.com/vChewing/vChewing-macOS/releases</string>
<key>UpdateInfoSiteGitHub</key>
<string>https://gitee.com/vChewing/vChewing-macOS/releases</string>
</dict>
</plist>