Skip to content

Commit 2314f09

Browse files
spinachomesrunjuu
authored andcommitted
fix: preserve input mode identifiers for app-specific keyboard switching
1 parent e888d3d commit 2314f09

14 files changed

Lines changed: 112 additions & 29 deletions

Input Source Pro/Models/IndicatorVM+Triggers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ extension IndicatorVM {
8787
}
8888
}
8989

90-
if previous?.inputSource.id != current.inputSource.id {
90+
if previous?.inputSource.persistentIdentifier != current.inputSource.persistentIdentifier {
9191
switch current.inputSourceChangeReason {
9292
case .noChanges:
9393
return .justHide

Input Source Pro/Models/IndicatorVM.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ extension IndicatorVM {
172172
guard appKind1.isSameAppOrWebsite(with: appKind2, detectAddressBar: true)
173173
else { return false }
174174

175-
guard lhs.inputSource.id == rhs.inputSource.id
175+
guard lhs.inputSource.persistentIdentifier == rhs.inputSource.persistentIdentifier
176176
else { return false }
177177

178178
return true
@@ -249,7 +249,7 @@ extension IndicatorVM {
249249
)
250250
}
251251
case let .inputSourceChanged(inputSource):
252-
guard inputSource.id != state.inputSource.id else { return state }
252+
guard inputSource.persistentIdentifier != state.inputSource.persistentIdentifier else { return state }
253253

254254
return updateState(appKind: state.appKind, inputSource: inputSource, inputSourceChangeReason: .system)
255255
case let .switchInputSourceByShortcut(inputSource):

Input Source Pro/Models/PreferencesVM+AppKeyboardCache.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extension PreferencesVM {
3434
let defaultKeyboard = getAppDefaultKeyboard(appKind)
3535

3636
if appNeedCacheKeyboard(appKind),
37-
defaultKeyboard?.id != keyboard.id
37+
defaultKeyboard?.persistentIdentifier != keyboard.persistentIdentifier
3838
{
3939
appKeyboardCache.save(appKind, keyboard: keyboard)
4040
} else {

Input Source Pro/Models/PreferencesVM.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,11 @@ extension Preferences {
537537

538538
extension PreferencesVM {
539539
var systemWideDefaultKeyboard: InputSource? {
540-
return InputSource.sources.first { $0.id == preferences.systemWideDefaultKeyboardId }
540+
return InputSource.resolvePersistedIdentifier(preferences.systemWideDefaultKeyboardId)
541541
}
542542

543543
var browserAddressDefaultKeyboard: InputSource? {
544-
return InputSource.sources.first { $0.id == preferences.browserAddressDefaultKeyboardId }
544+
return InputSource.resolvePersistedIdentifier(preferences.browserAddressDefaultKeyboardId)
545545
}
546546
}
547547

Input Source Pro/Persistence/AppRule.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ extension AppRule {
1111
extension AppRule {
1212
@MainActor
1313
var forcedKeyboard: InputSource? {
14-
guard let inputSourceId = inputSourceId else { return nil }
15-
16-
return InputSource.sources.first { $0.id == inputSourceId }
14+
return InputSource.resolvePersistedIdentifier(inputSourceId)
1715
}
1816

1917
var functionKeyMode: FKeyMode? {

Input Source Pro/Persistence/BrowserRule.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ enum BrowserRuleType: Int32, CaseIterable {
2424
extension BrowserRule {
2525
@MainActor
2626
var forcedKeyboard: InputSource? {
27-
guard let inputSourceId = inputSourceId else { return nil }
28-
29-
return InputSource.sources.first { $0.id == inputSourceId }
27+
return InputSource.resolvePersistedIdentifier(inputSourceId)
3028
}
3129

3230
var type: BrowserRuleType {

Input Source Pro/UI/Components/BrowserRuleEditView.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ struct BrowserRuleEditView: View {
2424

2525
var inputSourceItems: [PickerItem] {
2626
[PickerItem.empty]
27-
+ InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }
27+
+ InputSource.sources.map {
28+
PickerItem(id: $0.persistentIdentifier, title: $0.name, toolTip: $0.persistentIdentifier)
29+
}
2830
}
2931

3032
var restoreStrategyItems: [PickerItem] {
@@ -199,7 +201,11 @@ struct BrowserRuleEditView: View {
199201
hideIndicator = rule?.hideIndicator ?? false
200202

201203
if let inputSource = rule?.forcedKeyboard {
202-
inputSourceItem = PickerItem(id: inputSource.id, title: inputSource.name, toolTip: inputSource.id)
204+
inputSourceItem = PickerItem(
205+
id: inputSource.persistentIdentifier,
206+
title: inputSource.name,
207+
toolTip: inputSource.persistentIdentifier
208+
)
203209
}
204210

205211
if let keyboardRestoreStrategy = rule?.keyboardRestoreStrategy {

Input Source Pro/UI/Components/RulesApplicationDetail.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct ApplicationDetail: View {
2727
@State var functionKeyModeItem: PickerItem?
2828

2929
var mixed: Bool {
30-
Set(selectedApp.map { $0.forcedKeyboard?.id }).count > 1
30+
Set(selectedApp.map { $0.forcedKeyboard?.persistentIdentifier }).count > 1
3131
}
3232

3333
var isFunctionKeyModeMixed: Bool {
@@ -36,7 +36,9 @@ struct ApplicationDetail: View {
3636

3737
var items: [PickerItem] {
3838
[mixed ? PickerItem.mixed : nil, PickerItem.empty].compactMap { $0 }
39-
+ InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }
39+
+ InputSource.sources.map {
40+
PickerItem(id: $0.persistentIdentifier, title: $0.name, toolTip: $0.persistentIdentifier)
41+
}
4042
}
4143

4244
var functionKeyItems: [PickerItem] {
@@ -208,7 +210,11 @@ struct ApplicationDetail: View {
208210
if mixed {
209211
forceKeyboard = PickerItem.mixed
210212
} else if let keyboard = selectedApp.first?.forcedKeyboard {
211-
forceKeyboard = PickerItem(id: keyboard.id, title: keyboard.name, toolTip: keyboard.id)
213+
forceKeyboard = PickerItem(
214+
id: keyboard.persistentIdentifier,
215+
title: keyboard.name,
216+
toolTip: keyboard.persistentIdentifier
217+
)
212218
} else {
213219
forceKeyboard = PickerItem.empty
214220
}

Input Source Pro/UI/Screens/BrowserRulesSettingsView.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ struct BrowserRulesSettingsView: View {
1818

1919
var inputSourceItems: [PickerItem] {
2020
[PickerItem.empty]
21-
+ InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }
21+
+ InputSource.sources.map {
22+
PickerItem(id: $0.persistentIdentifier, title: $0.name, toolTip: $0.persistentIdentifier)
23+
}
2224
}
2325

2426
var body: some View {
@@ -39,7 +41,9 @@ struct BrowserRulesSettingsView: View {
3941
PopUpButtonPicker<PickerItem?>(
4042
items: inputSourceItems,
4143
width: 150,
42-
isItemSelected: { $0?.id == preferencesVM.preferences.browserAddressDefaultKeyboardId },
44+
isItemSelected: {
45+
$0?.id == (preferencesVM.browserAddressDefaultKeyboard?.persistentIdentifier ?? PickerItem.empty.id)
46+
},
4347
getTitle: { $0?.title ?? "" },
4448
getToolTip: { $0?.toolTip },
4549
onSelect: handleBrowserAddressDefaultKeyboardSelect

Input Source Pro/UI/Screens/GeneralSettingsView.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ struct GeneralSettingsView: View {
88

99
var items: [PickerItem] {
1010
[PickerItem.empty]
11-
+ InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }
11+
+ InputSource.sources.map {
12+
PickerItem(id: $0.persistentIdentifier, title: $0.name, toolTip: $0.persistentIdentifier)
13+
}
1214
}
1315

1416
var body: some View {
@@ -41,7 +43,9 @@ struct GeneralSettingsView: View {
4143

4244
PopUpButtonPicker<PickerItem?>(
4345
items: items,
44-
isItemSelected: { $0?.id == preferencesVM.preferences.systemWideDefaultKeyboardId },
46+
isItemSelected: {
47+
$0?.id == (preferencesVM.systemWideDefaultKeyboard?.persistentIdentifier ?? PickerItem.empty.id)
48+
},
4549
getTitle: { $0?.title ?? "" },
4650
getToolTip: { $0?.toolTip },
4751
onSelect: handleSystemWideDefaultKeyboardSelect

0 commit comments

Comments
 (0)