From fad4e213bcc241064eb43436cc8ab90a903b9883 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Mon, 15 Aug 2022 12:29:15 +0800 Subject: [PATCH] Repo // Disable DevZone for macOS 10.11 and 10.12. - IMKCandidates can crash on macOS 10.11 El Capitan. --- .../ControllerModules/ctlInputMethod_Core.swift | 10 +++++++--- Source/WindowControllers/ctlPrefWindow.swift | 13 ++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Source/Modules/ControllerModules/ctlInputMethod_Core.swift b/Source/Modules/ControllerModules/ctlInputMethod_Core.swift index 5251356a..f050521a 100644 --- a/Source/Modules/ControllerModules/ctlInputMethod_Core.swift +++ b/Source/Modules/ControllerModules/ctlInputMethod_Core.swift @@ -107,11 +107,15 @@ class ctlInputMethod: IMKInputController { // 因為偶爾會收到與 activateServer 有關的以「強制拆 nil」為理由的報錯, // 所以這裡添加這句、來試圖應對這種情況。 if keyHandler.delegate == nil { keyHandler.delegate = self } - guard let client = client() else { return } - setValue(IME.currentInputMode.rawValue, forTag: 114_514, client: client) + setValue(IME.currentInputMode.rawValue, forTag: 114_514, client: client()) keyHandler.clear() // 這句不要砍,因為後面 handle State.Empty() 不一定執行。 keyHandler.ensureParser() + if #available(macOS 10.13, *) { + } else { + mgrPrefs.useIMKCandidateWindow = false // 防呆。macOS 10.11 用 IMK 選字窗會崩潰。 + } + if isASCIIMode { if mgrPrefs.disableShiftTogglingAlphanumericalMode { isASCIIMode = false @@ -128,7 +132,7 @@ class ctlInputMethod: IMKInputController { /// 必須加上下述條件,否則會在每次切換至輸入法本體的視窗(比如偏好設定視窗)時會卡死。 /// 這是很多 macOS 副廠輸入法的常見失誤之處。 - if client.bundleIdentifier() != Bundle.main.bundleIdentifier { + if let client = client(), client.bundleIdentifier() != Bundle.main.bundleIdentifier { // 強制重設當前鍵盤佈局、使其與偏好設定同步。 setKeyLayout() handle(state: InputState.Empty()) diff --git a/Source/WindowControllers/ctlPrefWindow.swift b/Source/WindowControllers/ctlPrefWindow.swift index 01d01f3a..be3000e3 100644 --- a/Source/WindowControllers/ctlPrefWindow.swift +++ b/Source/WindowControllers/ctlPrefWindow.swift @@ -335,16 +335,23 @@ extension ctlPrefWindow: NSToolbarDelegate { window.contentView?.addSubview(view) } + var toolbarIdentifiers: [NSToolbarItem.Identifier] { + if #available(macOS 10.13, *) { + return [.ofGeneral, .ofExperience, .ofDictionary, .ofKeyboard, .ofDevZone] + } + return [.ofGeneral, .ofExperience, .ofDictionary, .ofKeyboard] + } + func toolbarDefaultItemIdentifiers(_: NSToolbar) -> [NSToolbarItem.Identifier] { - [.ofGeneral, .ofExperience, .ofDictionary, .ofKeyboard, .ofDevZone] + toolbarIdentifiers } func toolbarAllowedItemIdentifiers(_: NSToolbar) -> [NSToolbarItem.Identifier] { - [.ofGeneral, .ofExperience, .ofDictionary, .ofKeyboard, .ofDevZone] + toolbarIdentifiers } func toolbarSelectableItemIdentifiers(_: NSToolbar) -> [NSToolbarItem.Identifier] { - [.ofGeneral, .ofExperience, .ofDictionary, .ofKeyboard, .ofDevZone] + toolbarIdentifiers } @objc func showGeneralView(_: Any?) {