SessionCtl // Revamp setKeyLayout().
This commit is contained in:
parent
9fc54412cc
commit
f57238f380
|
@ -121,7 +121,6 @@ public class SessionCtl: IMKInputController {
|
||||||
syncBaseLMPrefs()
|
syncBaseLMPrefs()
|
||||||
// ----------------------------
|
// ----------------------------
|
||||||
Self.isVerticalTyping = isVerticalTyping
|
Self.isVerticalTyping = isVerticalTyping
|
||||||
// 強制重設當前鍵盤佈局、使其與偏好設定同步。這裡的這一步也不能省略。
|
|
||||||
switchState(IMEState.ofEmpty())
|
switchState(IMEState.ofEmpty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,30 +141,25 @@ public class SessionCtl: IMKInputController {
|
||||||
// 下述部分很有必要,否則輸入法會在手動重啟之後無法立刻生效。
|
// 下述部分很有必要,否則輸入法會在手動重啟之後無法立刻生效。
|
||||||
activateServer(inputClient)
|
activateServer(inputClient)
|
||||||
if PrefMgr.shared.onlyLoadFactoryLangModelsIfNeeded { LMMgr.loadDataModel(IMEApp.currentInputMode) }
|
if PrefMgr.shared.onlyLoadFactoryLangModelsIfNeeded { LMMgr.loadDataModel(IMEApp.currentInputMode) }
|
||||||
if let myID = Bundle.main.bundleIdentifier, !myID.isEmpty, !clientBundleIdentifier.contains(myID) {
|
|
||||||
setKeyLayout()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - 工具函式
|
// MARK: - 工具函式
|
||||||
|
|
||||||
extension SessionCtl {
|
extension SessionCtl {
|
||||||
/// 指定鍵盤佈局。
|
/// 強制重設當前鍵盤佈局、使其與偏好設定同步。
|
||||||
public func setKeyLayout() {
|
public func setKeyLayout() {
|
||||||
guard let client = client() else { return }
|
guard let client = client(), let myID = Bundle.main.bundleIdentifier, !myID.isEmpty,
|
||||||
|
clientBundleIdentifier != myID
|
||||||
|
else { return }
|
||||||
|
|
||||||
func doSetKeyLayout() {
|
DispatchQueue.main.async { [self] in
|
||||||
if isASCIIMode, IMKHelper.isDynamicBasicKeyboardLayoutEnabled {
|
if isASCIIMode, IMKHelper.isDynamicBasicKeyboardLayoutEnabled {
|
||||||
client.overrideKeyboard(withKeyboardNamed: PrefMgr.shared.alphanumericalKeyboardLayout)
|
client.overrideKeyboard(withKeyboardNamed: PrefMgr.shared.alphanumericalKeyboardLayout)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
client.overrideKeyboard(withKeyboardNamed: PrefMgr.shared.basicKeyboardLayout)
|
client.overrideKeyboard(withKeyboardNamed: PrefMgr.shared.basicKeyboardLayout)
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
doSetKeyLayout()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 重設輸入調度模組,會將當前尚未遞交的內容遞交出去。
|
/// 重設輸入調度模組,會將當前尚未遞交的內容遞交出去。
|
||||||
|
@ -212,6 +206,7 @@ extension SessionCtl {
|
||||||
switchState(IMEState.ofEmpty())
|
switchState(IMEState.ofEmpty())
|
||||||
isActivated = true // 登記啟用狀態。
|
isActivated = true // 登記啟用狀態。
|
||||||
Self.allInstances.insert(self)
|
Self.allInstances.insert(self)
|
||||||
|
setKeyLayout()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 停用輸入法時,會觸發該函式。
|
/// 停用輸入法時,會觸發該函式。
|
||||||
|
@ -235,11 +230,6 @@ extension SessionCtl {
|
||||||
let newInputMode: Shared.InputMode = .init(rawValue: value as? String ?? "") ?? .imeModeNULL
|
let newInputMode: Shared.InputMode = .init(rawValue: value as? String ?? "") ?? .imeModeNULL
|
||||||
if PrefMgr.shared.onlyLoadFactoryLangModelsIfNeeded { LMMgr.loadDataModel(newInputMode) }
|
if PrefMgr.shared.onlyLoadFactoryLangModelsIfNeeded { LMMgr.loadDataModel(newInputMode) }
|
||||||
inputMode = newInputMode
|
inputMode = newInputMode
|
||||||
if let rawValString = value as? String, let bundleID = Bundle.main.bundleIdentifier,
|
|
||||||
!bundleID.isEmpty, !rawValString.contains(bundleID)
|
|
||||||
{
|
|
||||||
setKeyLayout()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 將輸入法偏好設定同步至語言模組內。
|
/// 將輸入法偏好設定同步至語言模組內。
|
||||||
|
|
Loading…
Reference in New Issue