SessionCtl // Use GCD for certain state tasks.

This commit is contained in:
ShikiSuen 2023-03-20 14:38:44 +08:00
parent 0f44861440
commit 852eed07e2
2 changed files with 24 additions and 10 deletions

View File

@ -43,6 +43,9 @@ public class SessionCtl: IMKInputController {
///
public var isServingIMEItself: Bool = false
///
public var stateQueueSet = [String]()
/// bundleIdentifier
///
public var clientBundleIdentifier: String = "" {

View File

@ -12,6 +12,20 @@ import Shared
// MARK: - 調 (State Handling)
public extension SessionCtl {
private func performStateTask(_ doTask: @escaping () -> Void) {
let queueID = UUID().uuidString
DispatchQueue.main.async { [self] in
stateQueueSet.append(queueID)
while stateQueueSet.first != queueID {
Thread.sleep(forTimeInterval: 0.001)
}
doTask()
if stateQueueSet.first == queueID {
stateQueueSet.removeFirst()
}
}
}
/// 調
///
///
@ -43,11 +57,8 @@ public extension SessionCtl {
switch newState.type {
case .ofDeactivated:
// commitComposition()
// clearInlineDisplay()
// IMK inputMode.didSet()
candidateUI?.visible = false
popupCompositionBuffer.hide()
tooltipInstance.hide()
hidePalettes()
inputHandler?.clear()
if ![.ofAbortion, .ofEmpty].contains(previous.type), !previous.displayedText.isEmpty {
clearInlineDisplay()
@ -68,23 +79,23 @@ public extension SessionCtl {
commit(text: previous.displayedText)
}
//
showTooltip(newState.tooltip, duration: newState.tooltipDuration)
performStateTask { self.showTooltip(newState.tooltip, duration: newState.tooltipDuration) }
clearInlineDisplay()
inputHandler?.clear()
case .ofInputting:
candidateUI?.visible = false
if !newState.textToCommit.isEmpty { commit(text: newState.textToCommit) }
setInlineDisplayWithCursor()
//
showTooltip(newState.tooltip, duration: newState.tooltipDuration)
performStateTask { self.showTooltip(newState.tooltip, duration: newState.tooltipDuration) }
setInlineDisplayWithCursor()
case .ofMarking:
candidateUI?.visible = false
performStateTask { self.showTooltip(newState.tooltip) }
setInlineDisplayWithCursor()
showTooltip(newState.tooltip)
case .ofCandidates, .ofAssociates, .ofSymbolTable:
tooltipInstance.hide()
performStateTask { self.showCandidates() }
setInlineDisplayWithCursor()
showCandidates()
tooltipInstance.hide()
}
//
updatePopupDisplayWithCursor()