Skip to content

Commit b6fc9dd

Browse files
committed
Adjust layout and auto-close Installer when done
This ports the following PRs from McBopomofo: - openvanilla/McBopomofo#740 - openvanilla/McBopomofo#746 - openvanilla/McBopomofo#749
1 parent 2eccdf5 commit b6fc9dd

12 files changed

Lines changed: 398 additions & 187 deletions

File tree

OpenVanilla.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
6ABBAF2C15CD61BE0080EE7D /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6ABBAF2B15CD61BE0080EE7D /* Carbon.framework */; };
3737
6ACB49C315E49EA700380B82 /* OVInputMethodController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6ACB49C215E49EA700380B82 /* OVInputMethodController.mm */; };
3838
6ACD128823688A32005046C7 /* NotarizedArchives in Resources */ = {isa = PBXBuildFile; fileRef = 6ACD128723688A32005046C7 /* NotarizedArchives */; };
39+
6AD29A4D2ED4CA6000384421 /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = 6AD29A4B2ED4CA6000384421 /* Localizable.stringsdict */; };
3940
6AECB188253A6314008EB6E4 /* OpenVanilla.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6AECB187253A6314008EB6E4 /* OpenVanilla.xcassets */; };
4041
6AECB189253A6314008EB6E4 /* OpenVanilla.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6AECB187253A6314008EB6E4 /* OpenVanilla.xcassets */; };
4142
D40E28FF2B31D17D00EBD97C /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = D40E28FE2B31D17D00EBD97C /* main.swift */; };
@@ -165,6 +166,9 @@
165166
6AC9E19421AB554000AF6B69 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
166167
6ACB49C215E49EA700380B82 /* OVInputMethodController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = OVInputMethodController.mm; sourceTree = "<group>"; };
167168
6ACD128723688A32005046C7 /* NotarizedArchives */ = {isa = PBXFileReference; lastKnownFileType = folder; path = NotarizedArchives; sourceTree = "<group>"; };
169+
6AD29A4C2ED4CA6000384421 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = en; path = en.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
170+
6AD29A4E2ED4CA7100384421 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.stringsdict"; sourceTree = "<group>"; };
171+
6AD29A4F2ED4CA7300384421 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.stringsdict"; sourceTree = "<group>"; };
168172
6AD4989E163396FA005D5382 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
169173
6AD4989F163396FA005D5382 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "zh-Hans"; path = "zh-Hans.lproj/MainMenu.xib"; sourceTree = "<group>"; };
170174
6AD498A0163396FA005D5382 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/InfoPlist.strings"; sourceTree = "<group>"; };
@@ -257,6 +261,7 @@
257261
6A0E0ABF1623EDF5004FED10 /* InfoPlist.strings */,
258262
6A0E0AC11623EDF5004FED10 /* License.rtf */,
259263
6A0E0AC31623EDF5004FED10 /* Localizable.strings */,
264+
6AD29A4B2ED4CA6000384421 /* Localizable.stringsdict */,
260265
6A0E0AC51623EDF5004FED10 /* MainMenu.xib */,
261266
6A0E0AC71623EDF5004FED10 /* OpenVanillaInstaller-Info.plist */,
262267
6A0E0AC81623EDF5004FED10 /* OpenVanillaInstaller-Prefix.pch */,
@@ -531,6 +536,7 @@
531536
6A0E0AD01623EDF5004FED10 /* License.rtf in Resources */,
532537
6ACD128823688A32005046C7 /* NotarizedArchives in Resources */,
533538
6A0E0AD11623EDF5004FED10 /* Localizable.strings in Resources */,
539+
6AD29A4D2ED4CA6000384421 /* Localizable.stringsdict in Resources */,
534540
6A0E0AD21623EDF5004FED10 /* MainMenu.xib in Resources */,
535541
6A0E0AD61623EEDB004FED10 /* OpenVanilla.app in Resources */,
536542
);
@@ -702,6 +708,16 @@
702708
name = MainMenu.xib;
703709
sourceTree = "<group>";
704710
};
711+
6AD29A4B2ED4CA6000384421 /* Localizable.stringsdict */ = {
712+
isa = PBXVariantGroup;
713+
children = (
714+
6AD29A4C2ED4CA6000384421 /* en */,
715+
6AD29A4E2ED4CA7100384421 /* zh-Hans */,
716+
6AD29A4F2ED4CA7300384421 /* zh-Hant */,
717+
);
718+
name = Localizable.stringsdict;
719+
sourceTree = "<group>";
720+
};
705721
/* End PBXVariantGroup section */
706722

707723
/* Begin XCBuildConfiguration section */

Source/Mac/Installer/AppDelegate.swift

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private let kTranslocationRemovalDeadline: TimeInterval = 60.0
3737
@NSApplicationMain
3838
@objc(AppDelegate)
3939
class 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

Comments
 (0)