@@ -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}
0 commit comments