Repo // Stop previous session from interfering current palettes.

This commit is contained in:
ShikiSuen 2023-12-31 19:10:09 +08:00
parent 1c92ab8edf
commit 73b0da3eb4
3 changed files with 66 additions and 85 deletions

View File

@ -30,7 +30,13 @@ public class CtlCandidateTDK: CtlCandidate, NSWindowDelegate {
public var useMouseScrolling: Bool = true public var useMouseScrolling: Bool = true
private static var thePool: CandidatePool = .init(candidates: []) private static var thePool: CandidatePool = .init(candidates: [])
private static var currentView: NSView = .init() private static var currentView: NSView = .init()
public static var currentMenu: NSMenu?
public static var currentMenu: NSMenu? {
willSet {
currentMenu?.cancelTracking()
}
}
public static var currentWindow: NSWindow? { public static var currentWindow: NSWindow? {
willSet { willSet {
currentWindow?.orderOut(nil) currentWindow?.orderOut(nil)

View File

@ -46,16 +46,6 @@ public class SessionCtl: IMKInputController {
/// ///
public var isActivated = false public var isActivated = false
/// activateServer 0.1
public private(set) var isBootingUp: Bool = true {
didSet {
guard isBootingUp else { return }
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.isBootingUp = false
}
}
}
/// ///
public var isServingIMEItself: Bool = false public var isServingIMEItself: Bool = false
@ -219,22 +209,12 @@ public class SessionCtl: IMKInputController {
/// super.init() /// super.init()
private func construct(client theClient: (IMKTextInput & NSObjectProtocol)? = nil) { private func construct(client theClient: (IMKTextInput & NSObjectProtocol)? = nil) {
DispatchQueue.main.async { [weak self] in activate(server: theClient ?? client())
guard let self = self else { return } // defer didSet
// defer {
Self.current?.hidePalettes() inputMode = .init(rawValue: PrefMgr.shared.mostRecentInputMode) ?? .imeModeNULL
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.")
} }
} }
@ -243,10 +223,9 @@ public class SessionCtl: IMKInputController {
public extension SessionCtl { public extension SessionCtl {
/// 使 /// 使
func setKeyLayout() { func setKeyLayout() {
guard let client = client(), !isServingIMEItself else { return }
DispatchQueue.main.async { [weak self] in DispatchQueue.main.async { [weak self] in
guard let self = self else { return } guard let self = self else { return }
guard let client = self.client(), !self.isServingIMEItself else { return }
if self.isASCIIMode, IMKHelper.isDynamicBasicKeyboardLayoutEnabled { if self.isASCIIMode, IMKHelper.isDynamicBasicKeyboardLayoutEnabled {
client.overrideKeyboard(withKeyboardNamed: PrefMgr.shared.alphanumericalKeyboardLayout) client.overrideKeyboard(withKeyboardNamed: PrefMgr.shared.alphanumericalKeyboardLayout)
return return
@ -282,76 +261,72 @@ 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)
isBootingUp = true 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 {
if !Date.isTodayTheDate(from: 0401), !PrefMgr.shared.shouldNotFartInLieuOfBeep { PrefMgr.shared.shouldNotFartInLieuOfBeep = true
PrefMgr.shared.shouldNotFartInLieuOfBeep = true
}
} }
DispatchQueue.main.async { [weak self] in if inputMode != IMEApp.currentInputMode {
guard let self = self else { return } inputMode = IMEApp.currentInputMode
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.currentWindow?.orderOut(nil)
CtlCandidateTDK.currentWindow = nil
} }
DispatchQueue.main.async { [weak self] in CtlCandidateTDK.currentMenu = nil
guard let self = self else { return } CtlCandidateTDK.currentWindow = nil
if self.isActivated { return }
// setValue() IMK activateServer() setValue() // MARK:
self.inputHandler = InputHandler(
lm: LMMgr.currentLM, uom: LMMgr.currentUOM, pref: PrefMgr.shared
)
self.inputHandler?.delegate = self
self.syncBaseLMPrefs()
Self.theShiftKeyDetector.toggleWithLShift = PrefMgr.shared.togglingAlphanumericalModeWithLShift if isActivated { return }
Self.theShiftKeyDetector.toggleWithRShift = PrefMgr.shared.togglingAlphanumericalModeWithRShift
if self.isASCIIMode, !IMEApp.isKeyboardJIS { // setValue() IMK activateServer() setValue()
if #available(macOS 10.15, *) { inputHandler = InputHandler(
if !Self.theShiftKeyDetector.enabled { lm: LMMgr.currentLM, uom: LMMgr.currentUOM, pref: PrefMgr.shared
self.isASCIIMode = false )
} inputHandler?.delegate = self
} else { 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 {
self.isASCIIMode = false self.isASCIIMode = false
} }
} else {
isASCIIMode = false
} }
DispatchQueue.main.async {
AppDelegate.shared.checkMemoryUsage()
}
self.state = IMEState.ofEmpty()
self.isActivated = true //
self.setKeyLayout()
} }
DispatchQueue.main.async {
AppDelegate.shared.checkMemoryUsage()
}
state = IMEState.ofEmpty()
isActivated = true //
setKeyLayout()
} }
/// ///

View File

@ -46,7 +46,7 @@ public extension SessionCtl {
// commitComposition() // commitComposition()
// clearInlineDisplay() // clearInlineDisplay()
// IMK inputMode.didSet() // IMK inputMode.didSet()
hidePalettes() // hidePalettes() Session Session
inputHandler?.clear() inputHandler?.clear()
if ![.ofAbortion, .ofEmpty].contains(previous.type), !previous.displayedText.isEmpty { if ![.ofAbortion, .ofEmpty].contains(previous.type), !previous.displayedText.isEmpty {
clearInlineDisplay() clearInlineDisplay()