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
private static var thePool: CandidatePool = .init(candidates: [])
private static var currentView: NSView = .init()
public static var currentMenu: NSMenu?
public static var currentMenu: NSMenu? {
willSet {
currentMenu?.cancelTracking()
}
}
public static var currentWindow: NSWindow? {
willSet {
currentWindow?.orderOut(nil)

View File

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