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()
private func construct(client theClient: (IMKTextInput & NSObjectProtocol)? = nil) {
activate(server: theClient ?? client())
// defer didSet
defer {
inputMode = .init(rawValue: PrefMgr.shared.mostRecentInputMode) ?? .imeModeNULL
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
//
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:
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)
if let senderBundleID: String = sender.bundleIdentifier() {
vCLog("activateServer(\(senderBundleID))")
isServingIMEItself = Bundle.main.bundleIdentifier == senderBundleID
clientBundleIdentifier = senderBundleID
// 使
if PrefMgr.shared.checkUpdateAutomatically {
AppDelegate.shared.checkUpdate(forced: false) {
senderBundleID == "com.apple.SecurityAgent"
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
if let senderBundleID: String = (sender as? IMKTextInput)?.bundleIdentifier() {
vCLog("activateServer(\(senderBundleID))")
self.isServingIMEItself = Bundle.main.bundleIdentifier == senderBundleID
self.clientBundleIdentifier = senderBundleID
// 使
if PrefMgr.shared.checkUpdateAutomatically {
AppDelegate.shared.checkUpdate(forced: false) {
senderBundleID == "com.apple.SecurityAgent"
}
}
}
}
//
if !Date.isTodayTheDate(from: 0401), !PrefMgr.shared.shouldNotFartInLieuOfBeep {
PrefMgr.shared.shouldNotFartInLieuOfBeep = true
DispatchQueue.main.async {
//
if !Date.isTodayTheDate(from: 0401), !PrefMgr.shared.shouldNotFartInLieuOfBeep {
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
}
}
//
if candidateUI is CtlCandidateTDK {
candidateUI = nil
DispatchQueue.main.async {
//
if self.candidateUI is CtlCandidateTDK {
self.candidateUI = nil
}
CtlCandidateTDK.currentMenu?.cancelTracking()
CtlCandidateTDK.currentMenu = nil
CtlCandidateTDK.currentWindow?.orderOut(nil)
CtlCandidateTDK.currentWindow = nil
}
CtlCandidateTDK.currentMenu = nil
CtlCandidateTDK.currentWindow = nil
DispatchQueue.main.async { [weak self] in
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()
inputHandler = InputHandler(
lm: LMMgr.currentLM, uom: LMMgr.currentUOM, pref: PrefMgr.shared
)
inputHandler?.delegate = self
syncBaseLMPrefs()
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 {
if self.isASCIIMode, !IMEApp.isKeyboardJIS {
if #available(macOS 10.15, *) {
if !Self.theShiftKeyDetector.enabled {
self.isASCIIMode = false
}
} else {
self.isASCIIMode = false
}
} else {
isASCIIMode = false
}
}
DispatchQueue.main.async {
AppDelegate.shared.checkMemoryUsage()
}
DispatchQueue.main.async {
AppDelegate.shared.checkMemoryUsage()
}
state = IMEState.ofEmpty()
isActivated = true //
setKeyLayout()
self.state = IMEState.ofEmpty()
self.isActivated = true //
self.setKeyLayout()
}
}
///