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,14 +261,20 @@ 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
guard let self = self else { return }
if let senderBundleID: String = (sender as? IMKTextInput)?.bundleIdentifier() {
vCLog("activateServer(\(senderBundleID))") vCLog("activateServer(\(senderBundleID))")
self.isServingIMEItself = Bundle.main.bundleIdentifier == senderBundleID isServingIMEItself = Bundle.main.bundleIdentifier == senderBundleID
self.clientBundleIdentifier = senderBundleID clientBundleIdentifier = senderBundleID
// 使 // 使
if PrefMgr.shared.checkUpdateAutomatically { if PrefMgr.shared.checkUpdateAutomatically {
AppDelegate.shared.checkUpdate(forced: false) { AppDelegate.shared.checkUpdate(forced: false) {
@ -297,50 +282,41 @@ 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 self.candidateUI is CtlCandidateTDK { if candidateUI is CtlCandidateTDK {
self.candidateUI = nil candidateUI = nil
} }
CtlCandidateTDK.currentMenu?.cancelTracking()
CtlCandidateTDK.currentMenu = nil CtlCandidateTDK.currentMenu = nil
CtlCandidateTDK.currentWindow?.orderOut(nil)
CtlCandidateTDK.currentWindow = nil CtlCandidateTDK.currentWindow = nil
}
DispatchQueue.main.async { [weak self] in // MARK:
guard let self = self else { return }
if self.isActivated { return } if isActivated { return }
// setValue() IMK activateServer() setValue() // setValue() IMK activateServer() setValue()
self.inputHandler = InputHandler( inputHandler = InputHandler(
lm: LMMgr.currentLM, uom: LMMgr.currentUOM, pref: PrefMgr.shared lm: LMMgr.currentLM, uom: LMMgr.currentUOM, pref: PrefMgr.shared
) )
self.inputHandler?.delegate = self inputHandler?.delegate = self
self.syncBaseLMPrefs() 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 self.isASCIIMode, !IMEApp.isKeyboardJIS { if 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 {
self.isASCIIMode = false isASCIIMode = false
} }
} }
@ -348,10 +324,9 @@ public extension SessionCtl {
AppDelegate.shared.checkMemoryUsage() AppDelegate.shared.checkMemoryUsage()
} }
self.state = IMEState.ofEmpty() state = IMEState.ofEmpty()
self.isActivated = true // isActivated = true //
self.setKeyLayout() 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()