SessionCtl // Revert some buggy refactors.

This commit is contained in:
ShikiSuen 2024-01-01 01:56:56 +08:00
parent b449edc2a8
commit 8a5d2a5f6f
1 changed files with 69 additions and 56 deletions

View File

@ -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,20 +271,13 @@ 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
guard let self = self else { return }
if let senderBundleID: String = (sender as? IMKTextInput)?.bundleIdentifier() {
vCLog("activateServer(\(senderBundleID))") vCLog("activateServer(\(senderBundleID))")
isServingIMEItself = Bundle.main.bundleIdentifier == senderBundleID self.isServingIMEItself = Bundle.main.bundleIdentifier == senderBundleID
clientBundleIdentifier = senderBundleID self.clientBundleIdentifier = senderBundleID
// 使 // 使
if PrefMgr.shared.checkUpdateAutomatically { if PrefMgr.shared.checkUpdateAutomatically {
AppDelegate.shared.checkUpdate(forced: false) { AppDelegate.shared.checkUpdate(forced: false) {
@ -282,41 +285,50 @@ public extension SessionCtl {
} }
} }
} }
}
DispatchQueue.main.async {
// //
if !Date.isTodayTheDate(from: 0401), !PrefMgr.shared.shouldNotFartInLieuOfBeep { if !Date.isTodayTheDate(from: 0401), !PrefMgr.shared.shouldNotFartInLieuOfBeep {
PrefMgr.shared.shouldNotFartInLieuOfBeep = true PrefMgr.shared.shouldNotFartInLieuOfBeep = true
} }
if inputMode != IMEApp.currentInputMode {
inputMode = IMEApp.currentInputMode
} }
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
if self.inputMode != IMEApp.currentInputMode {
self.inputMode = IMEApp.currentInputMode
}
}
DispatchQueue.main.async {
// //
if candidateUI is CtlCandidateTDK { if self.candidateUI is CtlCandidateTDK {
candidateUI = nil self.candidateUI = nil
} }
CtlCandidateTDK.currentMenu?.cancelTracking()
CtlCandidateTDK.currentMenu = nil CtlCandidateTDK.currentMenu = nil
CtlCandidateTDK.currentWindow?.orderOut(nil)
CtlCandidateTDK.currentWindow = nil CtlCandidateTDK.currentWindow = nil
}
// MARK: DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
if isActivated { return } if self.isActivated { return }
// setValue() IMK activateServer() setValue() // setValue() IMK activateServer() setValue()
inputHandler = InputHandler( self.inputHandler = InputHandler(
lm: LMMgr.currentLM, uom: LMMgr.currentUOM, pref: PrefMgr.shared lm: LMMgr.currentLM, uom: LMMgr.currentUOM, pref: PrefMgr.shared
) )
inputHandler?.delegate = self self.inputHandler?.delegate = self
syncBaseLMPrefs() self.syncBaseLMPrefs()
Self.theShiftKeyDetector.toggleWithLShift = PrefMgr.shared.togglingAlphanumericalModeWithLShift Self.theShiftKeyDetector.toggleWithLShift = PrefMgr.shared.togglingAlphanumericalModeWithLShift
Self.theShiftKeyDetector.toggleWithRShift = PrefMgr.shared.togglingAlphanumericalModeWithRShift Self.theShiftKeyDetector.toggleWithRShift = PrefMgr.shared.togglingAlphanumericalModeWithRShift
if isASCIIMode, !IMEApp.isKeyboardJIS { if self.isASCIIMode, !IMEApp.isKeyboardJIS {
if #available(macOS 10.15, *) { if #available(macOS 10.15, *) {
if !Self.theShiftKeyDetector.enabled { if !Self.theShiftKeyDetector.enabled {
self.isASCIIMode = false self.isASCIIMode = false
} }
} else { } else {
isASCIIMode = false self.isASCIIMode = false
} }
} }
@ -324,9 +336,10 @@ public extension SessionCtl {
AppDelegate.shared.checkMemoryUsage() AppDelegate.shared.checkMemoryUsage()
} }
state = IMEState.ofEmpty() self.state = IMEState.ofEmpty()
isActivated = true // self.isActivated = true //
setKeyLayout() self.setKeyLayout()
}
} }
/// ///