SessionCtl // Add isServingIMEItself().

- Also monitoring activateServer() in console.
This commit is contained in:
ShikiSuen 2022-11-29 09:30:32 +08:00
parent 5db19f854e
commit 0e98eb0d2c
2 changed files with 9 additions and 7 deletions

View File

@ -40,6 +40,9 @@ public class SessionCtl: IMKInputController {
/// ///
public var isActivated = false public var isActivated = false
///
public var isServingIMEItself: Bool = false
// MARK: - // MARK: -
/// Caps Lock /// Caps Lock
@ -165,9 +168,7 @@ public class SessionCtl: IMKInputController {
extension SessionCtl { extension SessionCtl {
/// 使 /// 使
public func setKeyLayout() { public func setKeyLayout() {
guard let client = client(), let myID = Bundle.main.bundleIdentifier, !myID.isEmpty, guard let client = client(), !isServingIMEItself else { return }
clientBundleIdentifier != myID
else { return }
DispatchQueue.main.async { [self] in DispatchQueue.main.async { [self] in
if isASCIIMode, IMKHelper.isDynamicBasicKeyboardLayoutEnabled { if isASCIIMode, IMKHelper.isDynamicBasicKeyboardLayoutEnabled {
@ -198,12 +199,13 @@ extension SessionCtl {
extension SessionCtl { extension SessionCtl {
/// ///
/// - Parameter sender: 使 /// - Parameter sender:
public override func activateServer(_ sender: Any!) { public override func activateServer(_ sender: Any!) {
_ = sender // _ = sender //
DispatchQueue.main.async { DispatchQueue.main.async { [self] in
if let senderBundleID: String = (sender as? IMKTextInput)?.bundleIdentifier() { if let senderBundleID: String = (sender as? IMKTextInput)?.bundleIdentifier() {
vCLog("activateServer(\(senderBundleID))") vCLog("activateServer(\(senderBundleID))")
isServingIMEItself = Bundle.main.bundleIdentifier == senderBundleID
} }
} }
DispatchQueue.main.async { [self] in DispatchQueue.main.async { [self] in

View File

@ -121,7 +121,7 @@ extension SessionCtl {
if buffer.isEmpty { if buffer.isEmpty {
return return
} }
if let myID = Bundle.main.bundleIdentifier, let clientID = client.bundleIdentifier(), myID == clientID { if isServingIMEItself {
DispatchQueue.main.async { DispatchQueue.main.async {
client.insertText( client.insertText(
buffer, replacementRange: NSRange(location: NSNotFound, length: NSNotFound) buffer, replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
@ -137,7 +137,7 @@ extension SessionCtl {
/// setMarkedText GCD /// setMarkedText GCD
public func doSetMarkedText(_ string: Any!, selectionRange: NSRange, replacementRange: NSRange) { public func doSetMarkedText(_ string: Any!, selectionRange: NSRange, replacementRange: NSRange) {
guard isActivated, let client = client() else { return } guard isActivated, let client = client() else { return }
if let myID = Bundle.main.bundleIdentifier, let clientID = client.bundleIdentifier(), myID == clientID { if isServingIMEItself {
DispatchQueue.main.async { DispatchQueue.main.async {
client.setMarkedText(string, selectionRange: selectionRange, replacementRange: replacementRange) client.setMarkedText(string, selectionRange: selectionRange, replacementRange: replacementRange)
} }