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,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()
}
} }
/// ///