From 860dd685583da78f8e39d612a637e923b1783d5e Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Wed, 12 Oct 2022 10:09:10 +0800 Subject: [PATCH] AppInstaller // Reorganize applicationDidFinishLaunching(). --- Installer/AppDelegate.swift | 48 +++++++++++++------------------------ 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/Installer/AppDelegate.swift b/Installer/AppDelegate.swift index 7db90297..6f7a18dd 100644 --- a/Installer/AppDelegate.swift +++ b/Installer/AppDelegate.swift @@ -44,7 +44,6 @@ class AppDelegate: NSWindowController, NSApplicationDelegate { @IBOutlet var appEULAContent: NSTextView! var installingVersion = "" - var upgrading = false var translocationRemovalStartTime: Date? var currentVersionNumber: Int = 0 @@ -70,59 +69,44 @@ class AppDelegate: NSWindowController, NSApplicationDelegate { func applicationDidFinishLaunching(_: Notification) { guard - let installingVersion = Bundle.main.infoDictionary?[kCFBundleVersionKey as String] - as? String, let window = window, - let versionString = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String + let cell = installButton.cell as? NSButtonCell, + let installingVersion = Bundle.main.infoDictionary?[kCFBundleVersionKey as String] as? String, + let versionString = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String, + let copyrightLabel = Bundle.main.localizedInfoDictionary?["NSHumanReadableCopyright"] as? String, + let eulaContent = Bundle.main.localizedInfoDictionary?["CFEULAContent"] as? String, + let eulaContentUpstream = Bundle.main.infoDictionary?["CFUpstreamEULAContent"] as? String else { + NSSound.beep() + NSLog("The vChewing App Installer failed its initial guard-let process on appDidFinishLaunching().") return } self.installingVersion = installingVersion - cancelButton.nextKeyView = installButton installButton.nextKeyView = cancelButton - if let cell = installButton.cell as? NSButtonCell { - window.defaultButtonCell = cell - } - - if let copyrightLabel = Bundle.main.localizedInfoDictionary?["NSHumanReadableCopyright"] - as? String - { - appCopyrightLabel.stringValue = copyrightLabel - } - if let eulaContent = Bundle.main.localizedInfoDictionary?["CFEULAContent"] as? String, - let eulaContentUpstream = Bundle.main.infoDictionary?["CFUpstreamEULAContent"] as? String - { - appEULAContent.string = eulaContent + "\n" + eulaContentUpstream - } + window.defaultButtonCell = cell + appCopyrightLabel.stringValue = copyrightLabel + appEULAContent.string = eulaContent + "\n" + eulaContentUpstream appVersionLabel.stringValue = "\(versionString) Build \(installingVersion)" - window.title = "\(window.title) (v\(versionString), Build \(installingVersion))" window.standardWindowButton(.closeButton)?.isHidden = true window.standardWindowButton(.miniaturizeButton)?.isHidden = true window.standardWindowButton(.zoomButton)?.isHidden = true window.titlebarAppearsTransparent = true - if FileManager.default.fileExists( - atPath: kTargetPartialPath) - { + if FileManager.default.fileExists(atPath: kTargetPartialPath) { let currentBundle = Bundle(path: kTargetPartialPath) - let shortVersion = - currentBundle?.infoDictionary?["CFBundleShortVersionString"] as? String - let currentVersion = - currentBundle?.infoDictionary?[kCFBundleVersionKey as String] as? String + let shortVersion = currentBundle?.infoDictionary?["CFBundleShortVersionString"] as? String + let currentVersion = currentBundle?.infoDictionary?[kCFBundleVersionKey as String] as? String currentVersionNumber = (currentVersion as NSString?)?.integerValue ?? 0 if shortVersion != nil, let currentVersion = currentVersion, currentVersion.compare(installingVersion, options: .numeric) == .orderedAscending { - upgrading = true + // Upgrading confirmed. + installButton.title = NSLocalizedString("Upgrade", comment: "") } } - if upgrading { - installButton.title = NSLocalizedString("Upgrade", comment: "") - } - window.center() window.orderFront(self) NSApp.activate(ignoringOtherApps: true)