@@ -37,7 +37,7 @@ private let kTranslocationRemovalDeadline: TimeInterval = 60.0
3737@NSApplicationMain
3838@objc ( AppDelegate)
3939class AppDelegate : NSWindowController , NSApplicationDelegate {
40- @IBOutlet weak private var installButton : NSButton !
40+ @IBOutlet weak private var actionButton : NSButton !
4141 @IBOutlet weak private var cancelButton : NSButton !
4242 @IBOutlet private var textView : NSTextView !
4343 @IBOutlet weak private var progressSheet : NSWindow !
@@ -51,6 +51,8 @@ class AppDelegate: NSWindowController, NSApplicationDelegate {
5151 private var translocationRemovalStartTime : Date ?
5252 private var currentVersionNumber : Int = 0
5353
54+ private var installed = false
55+
5456 func runAlertPanel( title: String , message: String , buttonTitle: String ) {
5557 let alert = NSAlert ( )
5658 alert. alertStyle = . informational
@@ -69,9 +71,9 @@ class AppDelegate: NSWindowController, NSApplicationDelegate {
6971 self . archiveUtil = ArchiveUtil ( appName: kTargetBin, targetAppBundleName: kTargetBundle)
7072 _ = archiveUtil? . validateIfNotarizedArchiveExists ( )
7173
72- cancelButton. nextKeyView = installButton
73- installButton . nextKeyView = cancelButton
74- if let cell = installButton . cell as? NSButtonCell {
74+ cancelButton. nextKeyView = actionButton
75+ actionButton . nextKeyView = cancelButton
76+ if let cell = actionButton . cell as? NSButtonCell {
7577 window? . defaultButtonCell = cell
7678 }
7779
@@ -99,7 +101,7 @@ class AppDelegate: NSWindowController, NSApplicationDelegate {
99101 }
100102
101103 if upgrading {
102- installButton . title = NSLocalizedString ( " Agree and Upgrade " , comment: " " )
104+ actionButton . title = NSLocalizedString ( " Agree and Upgrade " , comment: " " )
103105 }
104106
105107 window? . center ( )
@@ -108,13 +110,13 @@ class AppDelegate: NSWindowController, NSApplicationDelegate {
108110 }
109111
110112 @IBAction func agreeAndInstallAction( _ sender: AnyObject ) {
111- if !agreeText . isHidden {
113+ if !installed {
112114 // user agreed to terms for install
113115 cancelButton. isEnabled = false
114- installButton . isEnabled = false
116+ actionButton . isEnabled = false
115117 removeThenInstallInputMethod ( )
116118 } else {
117- // installation was successful, user clicked [Ok]
119+ // installation was successful, user clicked the "Close Installer" button
118120 endAppWithDelay ( )
119121 }
120122 }
@@ -270,12 +272,16 @@ class AppDelegate: NSWindowController, NSApplicationDelegate {
270272 message. append ( NSAttributedString ( string: " \n \n " ) )
271273 message. append ( details)
272274 textView. textStorage? . setAttributedString ( message)
273-
275+
276+ installed = true
277+
274278 welcomeText. isHidden = true
275- agreeText. isHidden = true
276279 cancelButton. isHidden = true
277- installButton. title = NSLocalizedString ( " OK " , comment: " " )
278- installButton. isEnabled = true
280+ actionButton. title = NSLocalizedString ( " Close Installer " , comment: " " )
281+ actionButton. isEnabled = true
282+
283+ // System Settings now asks the user whether to activate the IME; auto-close the installer
284+ scheduleAutoClose ( )
279285 }
280286 }
281287 }
@@ -294,5 +300,24 @@ class AppDelegate: NSWindowController, NSApplicationDelegate {
294300 NSApp . terminate ( self )
295301 }
296302
303+ func updateAutoClosingMessage( seconds: Int ) {
304+ agreeText. stringValue = String . localizedStringWithFormat (
305+ NSLocalizedString ( " The installer will close itself in %d second(s). " , comment: " " ) ,
306+ seconds)
307+ }
308+
309+ func scheduleAutoClose( ) {
310+ var counter = 60
311+ updateAutoClosingMessage ( seconds: counter)
297312
313+ Timer . scheduledTimer ( withTimeInterval: 1.0 , repeats: true ) { [ weak self] timer in
314+ counter -= 1
315+ if counter == 0 {
316+ timer. invalidate ( )
317+ self ? . endAppWithDelay ( )
318+ } else {
319+ self ? . updateAutoClosingMessage ( seconds: counter)
320+ }
321+ }
322+ }
298323}
0 commit comments