SessionCtl // Revert some buggy refactors.
This commit is contained in:
parent
b449edc2a8
commit
8a5d2a5f6f
|
@ -209,12 +209,22 @@ public class SessionCtl: IMKInputController {
|
||||||
|
|
||||||
/// 所有建構子都會執行的共用部分,在 super.init() 之後執行。
|
/// 所有建構子都會執行的共用部分,在 super.init() 之後執行。
|
||||||
private func construct(client theClient: (IMKTextInput & NSObjectProtocol)? = nil) {
|
private func construct(client theClient: (IMKTextInput & NSObjectProtocol)? = nil) {
|
||||||
activate(server: theClient ?? client())
|
DispatchQueue.main.async { [weak self] in
|
||||||
// defer 會觸發 didSet,所以不用擔心。
|
guard let self = self else { return }
|
||||||
defer {
|
// 關掉所有之前的副本的視窗。
|
||||||
inputMode = .init(rawValue: PrefMgr.shared.mostRecentInputMode) ?? .imeModeNULL
|
Self.current?.hidePalettes()
|
||||||
|
Self.current = self
|
||||||
|
self.inputHandler = InputHandler(
|
||||||
|
lm: LMMgr.currentLM, uom: LMMgr.currentUOM, pref: PrefMgr.shared
|
||||||
|
)
|
||||||
|
self.inputHandler?.delegate = self
|
||||||
|
self.syncBaseLMPrefs()
|
||||||
|
// 下述兩行很有必要,否則輸入法會在手動重啟之後無法立刻生效。
|
||||||
|
let maybeClient = theClient ?? self.client()
|
||||||
|
self.activateServer(maybeClient)
|
||||||
|
// GCD 會觸發 didSet,所以不用擔心。
|
||||||
|
self.inputMode = .init(rawValue: PrefMgr.shared.mostRecentInputMode) ?? .imeModeNULL
|
||||||
}
|
}
|
||||||
vCLog("constuct() executed.")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,72 +271,75 @@ public extension SessionCtl {
|
||||||
/// 啟用輸入法時,會觸發該函式。
|
/// 啟用輸入法時,會觸發該函式。
|
||||||
/// - Parameter sender: 呼叫了該函式的客體。
|
/// - Parameter sender: 呼叫了該函式的客體。
|
||||||
override func activateServer(_ sender: Any!) {
|
override func activateServer(_ sender: Any!) {
|
||||||
activate(server: sender as? IMKTextInput ?? client())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 啟用輸入法時,會觸發該函式。
|
|
||||||
/// - Parameter sender: 呼叫了該函式的客體。
|
|
||||||
func activate(server sender: IMKTextInput) {
|
|
||||||
// 關掉所有之前的副本的視窗。
|
|
||||||
Self.current?.hidePalettes()
|
|
||||||
Self.current = self
|
|
||||||
super.activateServer(sender)
|
super.activateServer(sender)
|
||||||
if let senderBundleID: String = sender.bundleIdentifier() {
|
DispatchQueue.main.async { [weak self] in
|
||||||
vCLog("activateServer(\(senderBundleID))")
|
guard let self = self else { return }
|
||||||
isServingIMEItself = Bundle.main.bundleIdentifier == senderBundleID
|
if let senderBundleID: String = (sender as? IMKTextInput)?.bundleIdentifier() {
|
||||||
clientBundleIdentifier = senderBundleID
|
vCLog("activateServer(\(senderBundleID))")
|
||||||
// 只要使用者沒有勾選檢查更新、沒有主動做出要檢查更新的操作,就不要檢查更新。
|
self.isServingIMEItself = Bundle.main.bundleIdentifier == senderBundleID
|
||||||
if PrefMgr.shared.checkUpdateAutomatically {
|
self.clientBundleIdentifier = senderBundleID
|
||||||
AppDelegate.shared.checkUpdate(forced: false) {
|
// 只要使用者沒有勾選檢查更新、沒有主動做出要檢查更新的操作,就不要檢查更新。
|
||||||
senderBundleID == "com.apple.SecurityAgent"
|
if PrefMgr.shared.checkUpdateAutomatically {
|
||||||
|
AppDelegate.shared.checkUpdate(forced: false) {
|
||||||
|
senderBundleID == "com.apple.SecurityAgent"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 自動啟用肛塞(廉恥模式),除非這一天是愚人節。
|
DispatchQueue.main.async {
|
||||||
if !Date.isTodayTheDate(from: 0401), !PrefMgr.shared.shouldNotFartInLieuOfBeep {
|
// 自動啟用肛塞(廉恥模式),除非這一天是愚人節。
|
||||||
PrefMgr.shared.shouldNotFartInLieuOfBeep = true
|
if !Date.isTodayTheDate(from: 0401), !PrefMgr.shared.shouldNotFartInLieuOfBeep {
|
||||||
|
PrefMgr.shared.shouldNotFartInLieuOfBeep = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if inputMode != IMEApp.currentInputMode {
|
DispatchQueue.main.async { [weak self] in
|
||||||
inputMode = IMEApp.currentInputMode
|
guard let self = self else { return }
|
||||||
|
if self.inputMode != IMEApp.currentInputMode {
|
||||||
|
self.inputMode = IMEApp.currentInputMode
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 清理掉上一個會話的選字窗及其選單。
|
DispatchQueue.main.async {
|
||||||
if candidateUI is CtlCandidateTDK {
|
// 清理掉上一個會話的選字窗及其選單。
|
||||||
candidateUI = nil
|
if self.candidateUI is CtlCandidateTDK {
|
||||||
|
self.candidateUI = nil
|
||||||
|
}
|
||||||
|
CtlCandidateTDK.currentMenu?.cancelTracking()
|
||||||
|
CtlCandidateTDK.currentMenu = nil
|
||||||
|
CtlCandidateTDK.currentWindow?.orderOut(nil)
|
||||||
|
CtlCandidateTDK.currentWindow = nil
|
||||||
}
|
}
|
||||||
CtlCandidateTDK.currentMenu = nil
|
DispatchQueue.main.async { [weak self] in
|
||||||
CtlCandidateTDK.currentWindow = nil
|
guard let self = self else { return }
|
||||||
|
if self.isActivated { return }
|
||||||
|
|
||||||
// MARK: 正式過程
|
// 這裡不需要 setValue(),因為 IMK 會在自動呼叫 activateServer() 之後自動執行 setValue()。
|
||||||
|
self.inputHandler = InputHandler(
|
||||||
|
lm: LMMgr.currentLM, uom: LMMgr.currentUOM, pref: PrefMgr.shared
|
||||||
|
)
|
||||||
|
self.inputHandler?.delegate = self
|
||||||
|
self.syncBaseLMPrefs()
|
||||||
|
|
||||||
if isActivated { return }
|
Self.theShiftKeyDetector.toggleWithLShift = PrefMgr.shared.togglingAlphanumericalModeWithLShift
|
||||||
|
Self.theShiftKeyDetector.toggleWithRShift = PrefMgr.shared.togglingAlphanumericalModeWithRShift
|
||||||
|
|
||||||
// 這裡不需要 setValue(),因為 IMK 會在自動呼叫 activateServer() 之後自動執行 setValue()。
|
if self.isASCIIMode, !IMEApp.isKeyboardJIS {
|
||||||
inputHandler = InputHandler(
|
if #available(macOS 10.15, *) {
|
||||||
lm: LMMgr.currentLM, uom: LMMgr.currentUOM, pref: PrefMgr.shared
|
if !Self.theShiftKeyDetector.enabled {
|
||||||
)
|
self.isASCIIMode = false
|
||||||
inputHandler?.delegate = self
|
}
|
||||||
syncBaseLMPrefs()
|
} else {
|
||||||
|
|
||||||
Self.theShiftKeyDetector.toggleWithLShift = PrefMgr.shared.togglingAlphanumericalModeWithLShift
|
|
||||||
Self.theShiftKeyDetector.toggleWithRShift = PrefMgr.shared.togglingAlphanumericalModeWithRShift
|
|
||||||
|
|
||||||
if isASCIIMode, !IMEApp.isKeyboardJIS {
|
|
||||||
if #available(macOS 10.15, *) {
|
|
||||||
if !Self.theShiftKeyDetector.enabled {
|
|
||||||
self.isASCIIMode = false
|
self.isASCIIMode = false
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
isASCIIMode = false
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
AppDelegate.shared.checkMemoryUsage()
|
AppDelegate.shared.checkMemoryUsage()
|
||||||
}
|
}
|
||||||
|
|
||||||
state = IMEState.ofEmpty()
|
self.state = IMEState.ofEmpty()
|
||||||
isActivated = true // 登記啟用狀態。
|
self.isActivated = true // 登記啟用狀態。
|
||||||
setKeyLayout()
|
self.setKeyLayout()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 停用輸入法時,會觸發該函式。
|
/// 停用輸入法時,會觸發該函式。
|
||||||
|
|
Loading…
Reference in New Issue