@@ -19,17 +19,17 @@ struct InputMethodsSectionHeaderView: View {
1919 }
2020}
2121
22- private class ViewModel : ObservableObject {
23- @Published var inputMethods = [ InputMethod] ( )
22+ func availableInputMethods( ) -> [ InputMethod ] {
23+ let allInputMethods = try ! JSONDecoder ( ) . decode (
24+ [ InputMethod ] . self, from: String ( getAllInputMethods ( ) ) . data ( using: . utf8) !)
25+ let enabledInputMethods = try ! JSONDecoder ( ) . decode (
26+ [ InputMethod ] . self, from: String ( getInputMethods ( ) ) . data ( using: . utf8) !
27+ ) . map { $0. name }
28+ return allInputMethods. filter { !enabledInputMethods. contains ( $0. name) }
29+ }
2430
25- func refresh( ) {
26- let allInputMethods = try ! JSONDecoder ( ) . decode (
27- [ InputMethod ] . self, from: String ( getAllInputMethods ( ) ) . data ( using: . utf8) !)
28- let enabledInputMethods = try ! JSONDecoder ( ) . decode (
29- [ InputMethod ] . self, from: String ( getInputMethods ( ) ) . data ( using: . utf8) !
30- ) . map { $0. name }
31- inputMethods = allInputMethods. filter { !enabledInputMethods. contains ( $0. name) }
32- }
31+ private class ViewModel : ObservableObject {
32+ @Published var inputMethods = availableInputMethods ( )
3333}
3434
3535struct AddInputMethodsView : View {
@@ -54,7 +54,8 @@ struct AddInputMethodsView: View {
5454 enabledInputMethods. append ( inputMethod)
5555 setInputMethods (
5656 String (
57- data: try ! JSONEncoder ( ) . encode ( enabledInputMethods. map { $0. name } ) ,
57+ data: try ! JSONEncoder ( ) . encode (
58+ enabledInputMethods. map { $0. name } + [ inputMethod. name] ) ,
5859 encoding: . utf8) !)
5960 requestReload ( )
6061 message = " Added \( inputMethod. displayName) "
@@ -78,8 +79,5 @@ struct AddInputMethodsView: View {
7879 }
7980 . navigationTitle ( " Add input methods " )
8081 . navigationBarTitleDisplayMode ( . inline)
81- . onAppear {
82- viewModel. refresh ( )
83- }
8482 }
8583}
0 commit comments