diff --git a/src/color.swift b/src/color.swift index 9901e76..3779d1c 100644 --- a/src/color.swift +++ b/src/color.swift @@ -11,8 +11,10 @@ public func nsColorToString(_ color: NSColor) -> String? { return String(format: "#%02X%02X%02X%02X", red, green, blue, alpha) } +@MainActor private var colorMap = [String: String]() +@MainActor func getAccentColor(_ id: String) -> String { if let cachedColor = colorMap[id] { return cachedColor diff --git a/src/config/menu.swift b/src/config/menu.swift index 21e89f6..74fb8a6 100644 --- a/src/config/menu.swift +++ b/src/config/menu.swift @@ -1,6 +1,7 @@ import Cocoa import Fcitx +@MainActor func restartAndReconnect(_ actionBetween: (() -> Void)? = nil) { stop_fcitx_thread() actionBetween?() diff --git a/src/controller.swift b/src/controller.swift index 324140b..9cd262e 100644 --- a/src/controller.swift +++ b/src/controller.swift @@ -16,6 +16,7 @@ struct SyncResponse: Codable { let capsLock = 65536 let shift = 131072 +@MainActor class FcitxInputController: IMKInputController { var uuid: ICUUID var appId: String @@ -29,12 +30,13 @@ class FcitxInputController: IMKInputController { // A registry of live FcitxInputController objects. // Use NSHashTable to store weak references. - static var registry = NSHashTable.weakObjects() + nonisolated(unsafe) static var registry = NSHashTable.weakObjects() // A new InputController is created for each server-client // connection. We use the finest granularity here (one InputContext // for one IMKTextInput), and pass the bundle identifier to let // libfcitx handle the heavylifting. + @MainActor override init(server: IMKServer!, delegate: Any!, client: Any!) { if let client = client as? IMKTextInput { appId = client.bundleIdentifier() ?? "" diff --git a/tests/testcolor.swift b/tests/testcolor.swift index abc9045..6595805 100644 --- a/tests/testcolor.swift +++ b/tests/testcolor.swift @@ -17,11 +17,13 @@ func testGrayScale() { assert(nsColorToString(grayColor) == "#808080FF") } +@MainActor func testGetAccentColor() { let accentColor = getAccentColor("com.apple.Notes") assert(accentColor == "#FCB827FF") } +@MainActor @_cdecl("main") func main() -> Int { testGrayScale()