AppDelegate // Define alert types.
This commit is contained in:
parent
a07709fd4f
commit
e4f907b37d
|
@ -162,6 +162,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega
|
||||||
private var checkTask: URLSessionTask?
|
private var checkTask: URLSessionTask?
|
||||||
private var updateNextStepURL: URL?
|
private var updateNextStepURL: URL?
|
||||||
private var fsStreamHelper = FSEventStreamHelper(path: mgrLangModel.dataFolderPath(isDefaultFolder: false), queue: DispatchQueue(label: "vChewing User Phrases"))
|
private var fsStreamHelper = FSEventStreamHelper(path: mgrLangModel.dataFolderPath(isDefaultFolder: false), queue: DispatchQueue(label: "vChewing User Phrases"))
|
||||||
|
private var currentAlertType: String = ""
|
||||||
|
|
||||||
// 補上 dealloc
|
// 補上 dealloc
|
||||||
deinit {
|
deinit {
|
||||||
|
@ -236,7 +237,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega
|
||||||
let nextUpdateDate = Date(timeInterval: kNextCheckInterval, since: Date())
|
let nextUpdateDate = Date(timeInterval: kNextCheckInterval, since: Date())
|
||||||
UserDefaults.standard.set(nextUpdateDate, forKey: kNextUpdateCheckDateKey)
|
UserDefaults.standard.set(nextUpdateDate, forKey: kNextUpdateCheckDateKey)
|
||||||
|
|
||||||
checkTask = VersionUpdateApi.check(forced: forced) { result in
|
checkTask = VersionUpdateApi.check(forced: forced) { [self] result in
|
||||||
defer {
|
defer {
|
||||||
self.checkTask = nil
|
self.checkTask = nil
|
||||||
}
|
}
|
||||||
|
@ -252,6 +253,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega
|
||||||
report.remoteVersion,
|
report.remoteVersion,
|
||||||
report.versionDescription)
|
report.versionDescription)
|
||||||
IME.prtDebugIntel("vChewingDebug: \(content)")
|
IME.prtDebugIntel("vChewingDebug: \(content)")
|
||||||
|
self.currentAlertType = "Update"
|
||||||
ctlNonModalAlertWindow.shared.show(title: NSLocalizedString("New Version Available", comment: ""), content: content, confirmButtonTitle: NSLocalizedString("Visit Website", comment: ""), cancelButtonTitle: NSLocalizedString("Not Now", comment: ""), cancelAsDefault: false, delegate: self)
|
ctlNonModalAlertWindow.shared.show(title: NSLocalizedString("New Version Available", comment: ""), content: content, confirmButtonTitle: NSLocalizedString("Visit Website", comment: ""), cancelButtonTitle: NSLocalizedString("Not Now", comment: ""), cancelAsDefault: false, delegate: self)
|
||||||
NSApp.setActivationPolicy(.accessory)
|
NSApp.setActivationPolicy(.accessory)
|
||||||
case .noNeedToUpdate, .ignored:
|
case .noNeedToUpdate, .ignored:
|
||||||
|
@ -264,6 +266,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega
|
||||||
let content = String(format: NSLocalizedString("There may be no internet connection or the server failed to respond.\n\nError message: %@", comment: ""), message)
|
let content = String(format: NSLocalizedString("There may be no internet connection or the server failed to respond.\n\nError message: %@", comment: ""), message)
|
||||||
let buttonTitle = NSLocalizedString("Dismiss", comment: "")
|
let buttonTitle = NSLocalizedString("Dismiss", comment: "")
|
||||||
IME.prtDebugIntel("vChewingDebug: \(content)")
|
IME.prtDebugIntel("vChewingDebug: \(content)")
|
||||||
|
self.currentAlertType = "Update"
|
||||||
ctlNonModalAlertWindow.shared.show(title: title, content: content, confirmButtonTitle: buttonTitle, cancelButtonTitle: nil, cancelAsDefault: false, delegate: nil)
|
ctlNonModalAlertWindow.shared.show(title: title, content: content, confirmButtonTitle: buttonTitle, cancelButtonTitle: nil, cancelAsDefault: false, delegate: nil)
|
||||||
NSApp.setActivationPolicy(.accessory)
|
NSApp.setActivationPolicy(.accessory)
|
||||||
default:
|
default:
|
||||||
|
@ -274,14 +277,24 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega
|
||||||
}
|
}
|
||||||
|
|
||||||
func ctlNonModalAlertWindowDidConfirm(_ controller: ctlNonModalAlertWindow) {
|
func ctlNonModalAlertWindowDidConfirm(_ controller: ctlNonModalAlertWindow) {
|
||||||
if let updateNextStepURL = updateNextStepURL {
|
switch self.currentAlertType {
|
||||||
|
case "Update":
|
||||||
|
if let updateNextStepURL = self.updateNextStepURL {
|
||||||
NSWorkspace.shared.open(updateNextStepURL)
|
NSWorkspace.shared.open(updateNextStepURL)
|
||||||
}
|
}
|
||||||
updateNextStepURL = nil
|
self.updateNextStepURL = nil
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ctlNonModalAlertWindowDidCancel(_ controller: ctlNonModalAlertWindow) {
|
func ctlNonModalAlertWindowDidCancel(_ controller: ctlNonModalAlertWindow) {
|
||||||
updateNextStepURL = nil
|
switch self.currentAlertType {
|
||||||
|
case "Update":
|
||||||
|
self.updateNextStepURL = nil
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// New About Window
|
// New About Window
|
||||||
|
|
Loading…
Reference in New Issue