SessionCtl // GCD the init() and IMK-related methods.

This commit is contained in:
ShikiSuen 2022-11-05 08:11:49 +08:00
parent bd0fe1bacc
commit 8f7d452a1d
1 changed files with 41 additions and 33 deletions

View File

@ -136,11 +136,14 @@ public class SessionCtl: IMKInputController {
/// - inputClient:
override public init!(server: IMKServer!, delegate: Any!, client inputClient: Any!) {
super.init(server: server, delegate: delegate, client: inputClient)
inputHandler.delegate = self
syncBaseLMPrefs()
//
activateServer(inputClient)
inputMode = .init(rawValue: PrefMgr.shared.mostRecentInputMode) ?? .imeModeNULL
DispatchQueue.main.async { [self] in
inputHandler.delegate = self
syncBaseLMPrefs()
//
activateServer(inputClient)
// GCD didSet
inputMode = .init(rawValue: PrefMgr.shared.mostRecentInputMode) ?? .imeModeNULL
}
}
}
@ -148,7 +151,6 @@ public class SessionCtl: IMKInputController {
extension SessionCtl {
/// 使
/// - Remark:
public func setKeyLayout() {
guard let client = client(), let myID = Bundle.main.bundleIdentifier, !myID.isEmpty,
clientBundleIdentifier != myID
@ -184,40 +186,44 @@ extension SessionCtl {
/// - Parameter sender: 使
public override func activateServer(_ sender: Any!) {
_ = sender //
UserDefaults.standard.synchronize()
if Self.allInstances.contains(self) { return }
DispatchQueue.main.async { [self] in
UserDefaults.standard.synchronize()
if Self.allInstances.contains(self) { return }
// activateServer nil
//
if inputHandler.delegate == nil { inputHandler.delegate = self }
// setValue() IMK activateServer() setValue()
inputHandler.clear() // handle State.Empty()
inputHandler.ensureKeyboardParser()
// activateServer nil
//
if inputHandler.delegate == nil { inputHandler.delegate = self }
// setValue() IMK activateServer() setValue()
inputHandler.clear() // handle State.Empty()
inputHandler.ensureKeyboardParser()
Self.theShiftKeyDetector.alsoToggleWithLShift = PrefMgr.shared.togglingAlphanumericalModeWithLShift
Self.theShiftKeyDetector.alsoToggleWithLShift = PrefMgr.shared.togglingAlphanumericalModeWithLShift
if #available(macOS 10.15, *) {
if isASCIIMode, PrefMgr.shared.disableShiftTogglingAlphanumericalMode { isASCIIMode = false }
if #available(macOS 10.15, *) {
if isASCIIMode, PrefMgr.shared.disableShiftTogglingAlphanumericalMode { isASCIIMode = false }
}
DispatchQueue.main.async {
UpdateSputnik.shared.checkForUpdate(forced: false, url: kUpdateInfoSourceURL)
}
state = IMEState.ofEmpty()
isActivated = true //
Self.allInstances.insert(self)
setKeyLayout()
}
DispatchQueue.main.async {
UpdateSputnik.shared.checkForUpdate(forced: false, url: kUpdateInfoSourceURL)
}
state = IMEState.ofEmpty()
isActivated = true //
Self.allInstances.insert(self)
setKeyLayout()
}
///
/// - Parameter sender: 使
public override func deactivateServer(_ sender: Any!) {
_ = sender //
isActivated = false
resetInputHandler() // Empty
switchState(IMEState.ofDeactivated())
Self.allInstances.remove(self)
DispatchQueue.main.async { [self] in
isActivated = false
resetInputHandler() // Empty
switchState(IMEState.ofDeactivated())
Self.allInstances.remove(self)
}
}
///
@ -230,9 +236,11 @@ extension SessionCtl {
public override func setValue(_ value: Any!, forTag tag: Int, client sender: Any!) {
_ = tag //
_ = sender //
let mostRecentInputMode = PrefMgr.shared.mostRecentInputMode
inputMode = .init(rawValue: value as? String ?? mostRecentInputMode) ?? .imeModeNULL
Self.isVerticalTyping = isVerticalTyping
DispatchQueue.main.async { [self] in
let mostRecentInputMode = PrefMgr.shared.mostRecentInputMode
inputMode = .init(rawValue: value as? String ?? mostRecentInputMode) ?? .imeModeNULL
Self.isVerticalTyping = isVerticalTyping
}
}
///