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

View File

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