Skip to content

Commit 06285ee

Browse files
committed
fix(info-collector): run TIS queries on main queue
1 parent 26eb019 commit 06285ee

3 files changed

Lines changed: 27 additions & 27 deletions

File tree

Packages/InfoCollector/Sources/InfoCollector/InfoCollector.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import Foundation
2525

2626
@objc
2727
public class InfoCollector: NSObject {
28-
@MainActor
2928
@available(iOS 13.0.0, macOS 10.15, *)
3029
public static func generate() async -> String {
3130
await withCheckedContinuation { (continuation: CheckedContinuation<String, Never>) in
@@ -35,7 +34,6 @@ public class InfoCollector: NSObject {
3534
}
3635
}
3736

38-
@MainActor
3937
public static func generate(callback: @escaping (String) -> Void) {
4038
let plugins: [InfoCollectorPlugin] = [
4139
MachineModelCollectorPlugin(),
@@ -44,7 +42,7 @@ public class InfoCollector: NSObject {
4442
KeyboardTypeCollectorPlugin(),
4543
ActiveInputSourceListCollectorPlugin(),
4644
DefaultWebBrowserCollectorPlugin(),
47-
SafaruVersionCollectorPlugin(),
45+
SafariVersionCollectorPlugin(),
4846
AppVersionCollectorPlugin(),
4947
]
5048

Packages/InfoCollector/Sources/InfoCollector/Plugins/ActiveInputSourceListCollectorPlugin.swift

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,37 @@ struct ActiveInputSourceListCollectorPlugin: InfoCollectorPlugin {
3737
return nil
3838
}
3939

40-
// Use HIToolbox TIS APIs to get current and enabled input sources
41-
// Build a query for enabled input sources
42-
let keys: [CFString: Any] = [
43-
kTISPropertyInputSourceIsEnabled: kCFBooleanTrue as CFBoolean,
44-
kTISPropertyInputSourceIsSelectCapable: kCFBooleanTrue as CFBoolean,
45-
kTISPropertyInputSourceCategory: kTISCategoryKeyboardInputSource as CFString,
46-
]
47-
let dict = keys as CFDictionary
48-
var lines: [String] = []
49-
// Enabled input sources
50-
if let list = TISCreateInputSourceList(dict, false)?.takeRetainedValue()
51-
as? [TISInputSource]
52-
{
53-
lines.append("- Enabled Input Sources:")
54-
for src in list {
55-
let name = getStringValue(src, kTISPropertyLocalizedName) ?? "<unknown>"
56-
let sid = getStringValue(src, kTISPropertyInputSourceID) ?? ""
57-
let category =
40+
DispatchQueue.main.async {
41+
// Use HIToolbox TIS APIs to get current and enabled input sources
42+
// Build a query for enabled input sources
43+
let keys: [CFString: Any] = [
44+
kTISPropertyInputSourceIsEnabled: kCFBooleanTrue as CFBoolean,
45+
kTISPropertyInputSourceIsSelectCapable: kCFBooleanTrue as CFBoolean,
46+
kTISPropertyInputSourceCategory: kTISCategoryKeyboardInputSource as CFString,
47+
]
48+
let dict = keys as CFDictionary
49+
var lines: [String] = []
50+
// Enabled input sources
51+
if let list = TISCreateInputSourceList(dict, false)?.takeRetainedValue()
52+
as? [TISInputSource]
53+
{
54+
lines.append("- Enabled Input Sources:")
55+
for src in list {
56+
let name = getStringValue(src, kTISPropertyLocalizedName) ?? "<unknown>"
57+
let sid = getStringValue(src, kTISPropertyInputSourceID) ?? ""
58+
let category =
5859
getStringValue(
5960
src,
6061
kTISPropertyInputSourceCategory
6162
) ?? ""
62-
lines.append(" - \(name) (\(sid)) [\(category)]")
63+
lines.append(" - \(name) (\(sid)) [\(category)]")
64+
}
6365
}
64-
}
6566

66-
if lines.isEmpty {
67-
lines.append("No input sources found")
67+
if lines.isEmpty {
68+
lines.append(" No input sources found")
69+
}
70+
callback(.success(lines.joined(separator: "\n")))
6871
}
69-
callback(.success(lines.joined(separator: "\n")))
7072
}
7173
}

Packages/InfoCollector/Sources/InfoCollector/Plugins/SafaruVersionCollectorPlugin.swift renamed to Packages/InfoCollector/Sources/InfoCollector/Plugins/SafariVersionCollectorPlugin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import AppKit
2525

26-
struct SafaruVersionCollectorPlugin: InfoCollectorPlugin {
26+
struct SafariVersionCollectorPlugin: InfoCollectorPlugin {
2727
var name: String { "Safari version collector" }
2828

2929
func collect(callback: @escaping (Result<String, Error>) -> Void) {

0 commit comments

Comments
 (0)