From 54f61a28b142533aecc7362b104914dc7ab0d483 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Wed, 14 Feb 2024 03:32:48 +0800 Subject: [PATCH] Repo // Unify modal window calling methods. --- .../MainAssembly/ClientListMgr/VwrClientListMgr.swift | 6 +++--- .../Settings/SettingsCocoa/VwrSettingsCocoaPanes.swift | 2 +- .../SettingsCocoa/VwrSettingsPaneCocoaBehavior.swift | 2 +- .../SettingsCocoa/VwrSettingsPaneCocoaCandidates.swift | 4 ++-- .../SettingsCocoa/VwrSettingsPaneCocoaCassette.swift | 2 +- .../SettingsCocoa/VwrSettingsPaneCocoaDictionary.swift | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/ClientListMgr/VwrClientListMgr.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/ClientListMgr/VwrClientListMgr.swift index 731eb9d7..11bc2375 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/ClientListMgr/VwrClientListMgr.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/ClientListMgr/VwrClientListMgr.swift @@ -196,7 +196,7 @@ extension VwrClientListMgr { } @IBAction func btnAddClientClicked(_: Any) { - guard let window = NSApp.keyWindow else { return } + guard let window = CtlClientListMgr.shared?.window else { return } let alert = NSAlert() alert.messageText = NSLocalizedString( "Please enter the client app bundle identifier(s) you want to register.", comment: "" @@ -277,11 +277,11 @@ extension VwrClientListMgr { ) let text = url.path + "\n\n" + NSLocalizedString("Please try again.", comment: "") guard let bundle = Bundle(url: url) else { - NSApp.keyWindow?.callAlert(title: title, text: text) + CtlClientListMgr.shared?.window.callAlert(title: title, text: text) return } guard let identifier = bundle.bundleIdentifier else { - NSApp.keyWindow?.callAlert(title: title, text: text) + CtlClientListMgr.shared?.window.callAlert(title: title, text: text) return } let isIdentifierAlreadyRegistered = Self.clientsList.contains(identifier) diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsCocoaPanes.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsCocoaPanes.swift index d0f17b3d..8fb52679 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsCocoaPanes.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsCocoaPanes.swift @@ -38,7 +38,7 @@ public extension SettingsPanesCocoa { static func warnAboutComDlg32Inavailability() { let title = "Please drag the desired target from Finder to this place.".localized let message = "[Technical Reason] macOS releases earlier than 10.13 have an issue: If calling NSOpenPanel directly from an input method, both the input method and its current client app hang in a dead-loop. Furthermore, it makes other apps hang in the same way when you switch into another app. If you don't want to hard-reboot your computer, your last resort is to use SSH to connect to your current computer from another computer and kill the input method process by Terminal commands. That's why vChewing cannot offer access to NSOpenPanel for macOS 10.12 and earlier.".localized - NSApp.keyWindow.callAlert(title: title, text: message) + CtlSettingsCocoa.shared?.window.callAlert(title: title, text: message) } } diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsPaneCocoaBehavior.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsPaneCocoaBehavior.swift index 57f21f31..d1c260cb 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsPaneCocoaBehavior.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsPaneCocoaBehavior.swift @@ -118,7 +118,7 @@ public extension SettingsPanesCocoa { } } alert.addButton(withTitle: NSLocalizedString("Leave it checked", comment: "")) - let window = NSApp.keyWindow + let window = CtlSettingsCocoa.shared?.window if !PrefMgr.shared.shouldNotFartInLieuOfBeep { PrefMgr.shared.shouldNotFartInLieuOfBeep = true alert.beginSheetModal(at: window) { result in diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsPaneCocoaCandidates.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsPaneCocoaCandidates.swift index 7f43ee06..35879ffd 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsPaneCocoaCandidates.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsPaneCocoaCandidates.swift @@ -82,7 +82,7 @@ public extension SettingsPanesCocoa { } @IBAction func whereIsIMKCandidatesWindow(_: Any) { - let window = NSApp.keyWindow + let window = CtlSettingsCocoa.shared?.window let title = "The End of Support for IMK Candidate Window" let explanation = "1) Only macOS has IMKCandidates. Since it relies on a dedicated ObjC Bridging Header to expose necessary internal APIs to work, it hinders vChewing from completely modularized for multi-platform support.\n\n2) IMKCandidates is buggy. It is not likely to be completely fixed by Apple, and its devs are not allowed to talk about it to non-Apple individuals. That's why we have had enough with IMKCandidates. It is likely the reason why Apple had never used IMKCandidates in their official InputMethodKit sample projects (as of August 2023)." window.callAlert(title: title.localized, text: explanation.localized) @@ -105,7 +105,7 @@ public extension SettingsPanesCocoa { let alert = NSAlert(error: NSLocalizedString("Invalid Selection Keys.", comment: "")) alert.informativeText = errorResult IMEApp.buzz() - if let window = NSApp.keyWindow { + if let window = CtlSettingsCocoa.shared?.window { alert.beginSheetModal(for: window) { _ in sender.stringValue = CandidateKey.defaultKeys } diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsPaneCocoaCassette.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsPaneCocoaCassette.swift index 6c45491c..7411e4ee 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsPaneCocoaCassette.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsPaneCocoaCassette.swift @@ -139,7 +139,7 @@ extension SettingsPanesCocoa.Cassette: NSPathControlDelegate { let bolPreviousPathValidity = LMMgr.checkCassettePathValidity( PrefMgr.shared.cassettePath.expandingTildeInPath) - let window = NSApp.keyWindow + let window = CtlSettingsCocoa.shared?.window dlgOpenFile.beginSheetModal(at: window) { result in if result == NSApplication.ModalResponse.OK { guard let url = dlgOpenFile.url else { return } diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsPaneCocoaDictionary.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsPaneCocoaDictionary.swift index 6af06b36..98142737 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsPaneCocoaDictionary.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/Settings/SettingsCocoa/VwrSettingsPaneCocoaDictionary.swift @@ -138,7 +138,7 @@ public extension SettingsPanesCocoa { dlgOpenFile.allowedContentTypes = [.init(filenameExtension: "txt")].compactMap { $0 } } - let window = NSApp.keyWindow + let window = CtlSettingsCocoa.shared?.window dlgOpenFile.beginSheetModal(at: window) { result in if result == NSApplication.ModalResponse.OK { guard let url = dlgOpenFile.url else { return } @@ -209,7 +209,7 @@ extension SettingsPanesCocoa.Dictionary: NSPathControlDelegate { let bolPreviousFolderValidity = LMMgr.checkIfSpecifiedUserDataFolderValid( PrefMgr.shared.userDataFolderSpecified.expandingTildeInPath) - let window = NSApp.keyWindow + let window = CtlSettingsCocoa.shared?.window dlgOpenPath.beginSheetModal(at: window) { result in if result == NSApplication.ModalResponse.OK { guard let url = dlgOpenPath.url else { return }