Skip to content

Commit 368a908

Browse files
authored
Merge pull request #740 from lukhnos/installer-ux
Installer UX: auto-close the installer after activation
2 parents 6f75d36 + a21ba98 commit 368a908

File tree

8 files changed

+189
-76
lines changed

8 files changed

+189
-76
lines changed

McBopomofo.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
6A38BC1515FC117A00A8A51F /* data.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A38BBF615FC117A00A8A51F /* data.txt */; };
1919
6A4F5F982879E838008C4307 /* reading_grid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6A4F5F932879E838008C4307 /* reading_grid.cpp */; };
2020
6A660A702EAF371000D53D7B /* ByteBlockBackedDictionary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6A660A6F2EAF371000D53D7B /* ByteBlockBackedDictionary.cpp */; };
21+
6A68C1C32EC7F2C0005284A0 /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = 6A68C1C12EC7F2C0005284A0 /* Localizable.stringsdict */; };
2122
6A6ED16B2797650A0012872E /* template-phrases-replacement.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A6ED1632797650A0012872E /* template-phrases-replacement.txt */; };
2223
6A6ED16C2797650A0012872E /* template-data.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A6ED1652797650A0012872E /* template-data.txt */; };
2324
6A6ED16D2797650A0012872E /* template-exclude-phrases-plain-bpmf.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A6ED1672797650A0012872E /* template-exclude-phrases-plain-bpmf.txt */; };
@@ -140,6 +141,8 @@
140141
6A4F5F932879E838008C4307 /* reading_grid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = reading_grid.cpp; sourceTree = "<group>"; };
141142
6A660A6E2EAF371000D53D7B /* ByteBlockBackedDictionary.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ByteBlockBackedDictionary.h; sourceTree = "<group>"; };
142143
6A660A6F2EAF371000D53D7B /* ByteBlockBackedDictionary.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ByteBlockBackedDictionary.cpp; sourceTree = "<group>"; };
144+
6A68C1C22EC7F2C0005284A0 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = en; path = en.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
145+
6A68C1C42EC7F6B7005284A0 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.stringsdict"; sourceTree = "<group>"; };
143146
6A6ED1642797650A0012872E /* Base */ = {isa = PBXFileReference; lastKnownFileType = text; name = Base; path = "Base.lproj/template-phrases-replacement.txt"; sourceTree = "<group>"; };
144147
6A6ED1662797650A0012872E /* Base */ = {isa = PBXFileReference; lastKnownFileType = text; name = Base; path = "Base.lproj/template-data.txt"; sourceTree = "<group>"; };
145148
6A6ED1682797650A0012872E /* Base */ = {isa = PBXFileReference; lastKnownFileType = text; name = Base; path = "Base.lproj/template-exclude-phrases-plain-bpmf.txt"; sourceTree = "<group>"; };
@@ -455,6 +458,7 @@
455458
6A93050C279877FF00D370DA /* McBopomofoInstaller-Bridging-Header.h */,
456459
D4F0BBE2279B08900071253C /* BundleTranslocate.h */,
457460
D4F0BBE3279B08900071253C /* BundleTranslocate.m */,
461+
6A68C1C12EC7F2C0005284A0 /* Localizable.stringsdict */,
458462
);
459463
path = Installer;
460464
sourceTree = "<group>";
@@ -680,6 +684,7 @@
680684
6ACA41FA15FC1D9000935EF6 /* InfoPlist.strings in Resources */,
681685
6A225A1F23679F2600F685C6 /* NotarizedArchives in Resources */,
682686
6ACA41FB15FC1D9000935EF6 /* License.rtf in Resources */,
687+
6A68C1C32EC7F2C0005284A0 /* Localizable.stringsdict in Resources */,
683688
6ACA41FC15FC1D9000935EF6 /* Localizable.strings in Resources */,
684689
6ACA41FD15FC1D9000935EF6 /* MainMenu.xib in Resources */,
685690
);
@@ -821,6 +826,15 @@
821826
name = MainMenu.xib;
822827
sourceTree = "<group>";
823828
};
829+
6A68C1C12EC7F2C0005284A0 /* Localizable.stringsdict */ = {
830+
isa = PBXVariantGroup;
831+
children = (
832+
6A68C1C22EC7F2C0005284A0 /* en */,
833+
6A68C1C42EC7F6B7005284A0 /* zh-Hant */,
834+
);
835+
name = Localizable.stringsdict;
836+
sourceTree = "<group>";
837+
};
824838
6A6ED1632797650A0012872E /* template-phrases-replacement.txt */ = {
825839
isa = PBXVariantGroup;
826840
children = (

Source/Installer/AppDelegate.swift

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -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
114116
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-
actionButton.title = NSLocalizedString("OK", comment: "")
280+
actionButton.title = NSLocalizedString("Close Installer", comment: "")
278281
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

Comments
 (0)