diff --git a/Sources/Sst/AppModel.swift b/Sources/Sst/AppModel.swift index ddd406e..0197c8e 100644 --- a/Sources/Sst/AppModel.swift +++ b/Sources/Sst/AppModel.swift @@ -12,12 +12,11 @@ import SwiftUI final class InsertionPolicy { var windowSession = false + @MainActor func route() -> InsertionRoute { - MainActor.assumeIsolated { - let sstInFront = NSWorkspace.shared.frontmostApplication?.bundleIdentifier == Bundle.main.bundleIdentifier - if sstInFront { return NoteEditorRegistry.shared.active != nil ? .editor : .none } - return windowSession ? .none : .system - } + let sstInFront = NSWorkspace.shared.frontmostApplication?.bundleIdentifier == Bundle.main.bundleIdentifier + if sstInFront { return NoteEditorRegistry.shared.active != nil ? .editor : .none } + return windowSession ? .none : .system } } @@ -103,7 +102,7 @@ final class AppModel: ObservableObject { inserter: RoutingInserter( system: TextInserter(pasteboard: SystemPasteboard(), paster: CGEventPaster()), editor: EditorInserter(), - route: { policy.route() }), + route: { await policy.route() }), corrector: corrector, vocabularyProvider: { settings.usePriming ? VocabularyBuilder.build(from: dictionary.entries) : [] }) diff --git a/Sources/SstCore/AppGlue.swift b/Sources/SstCore/AppGlue.swift index 218afdd..5f9c331 100644 --- a/Sources/SstCore/AppGlue.swift +++ b/Sources/SstCore/AppGlue.swift @@ -14,16 +14,16 @@ public enum InsertionRoute: Equatable, Sendable { public struct RoutingInserter: TextInserting { private let system: TextInserting private let editor: TextInserting - private let route: () -> InsertionRoute + private let route: () async -> InsertionRoute - public init(system: TextInserting, editor: TextInserting, route: @escaping () -> InsertionRoute) { + public init(system: TextInserting, editor: TextInserting, route: @escaping () async -> InsertionRoute) { self.system = system self.editor = editor self.route = route } public func insert(_ text: String) async throws { - switch route() { + switch await route() { case .system: try await system.insert(text) case .editor: try await editor.insert(text) case .none: break