11using System ;
22using System . Collections . Generic ;
3- using System . Diagnostics ;
4- using System . Linq ;
53using System . Windows . Forms ;
64using CommunityToolkit . Mvvm . Input ;
75using Flow . Launcher . Core ;
86using Flow . Launcher . Core . Configuration ;
97using Flow . Launcher . Core . Resource ;
108using Flow . Launcher . Helper ;
9+ using Flow . Launcher . Infrastructure ;
1110using Flow . Launcher . Infrastructure . UserSettings ;
1211using Flow . Launcher . Plugin ;
1312using Flow . Launcher . Plugin . SharedModels ;
14- using Microsoft . Win32 ;
1513using OpenFileDialog = System . Windows . Forms . OpenFileDialog ;
16- using System . Windows . Input ;
17-
1814
1915namespace Flow . Launcher . SettingPages . ViewModels ;
2016
@@ -25,16 +21,13 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
2521 private readonly IPortable _portable ;
2622 private readonly Internationalization _translater ;
2723
28- public ICommand OpenImeSettingsCommand { get ; }
29-
3024 public SettingsPaneGeneralViewModel ( Settings settings , Updater updater , IPortable portable , Internationalization translater )
3125 {
3226 Settings = settings ;
3327 _updater = updater ;
3428 _portable = portable ;
3529 _translater = translater ;
3630 UpdateEnumDropdownLocalizations ( ) ;
37- OpenImeSettingsCommand = new RelayCommand ( OpenImeSettings ) ;
3831 }
3932
4033 public class SearchWindowScreenData : DropdownDataGeneric < SearchWindowScreens > { }
@@ -187,21 +180,22 @@ public string Language
187180 UpdateEnumDropdownLocalizations ( ) ;
188181 }
189182 }
190-
183+
184+ #region Korean IME
185+
191186 // The new Korean IME used in Windows 11 has compatibility issues with WPF. This issue is difficult to resolve within
192187 // WPF itself, but it can be avoided by having the user switch to the legacy IME at the system level. Therefore,
193188 // we provide guidance and a direct button for users to make this change themselves. If the relevant registry key does
194189 // not exist (i.e., the Korean IME is not installed), this setting will not be shown at all.
195- #region Korean IME
190+
196191 public bool LegacyKoreanIMEEnabled
197192 {
198- get => IsLegacyKoreanIMEEnabled ( ) ;
193+ get => Win32Helper . IsLegacyKoreanIMEEnabled ( ) ;
199194 set
200195 {
201- Debug . WriteLine ( $ "[DEBUG] LegacyKoreanIMEEnabled changed: { value } ") ;
202- if ( SetLegacyKoreanIMEEnabled ( value ) )
196+ if ( Win32Helper . SetLegacyKoreanIMEEnabled ( value ) )
203197 {
204- OnPropertyChanged ( nameof ( LegacyKoreanIMEEnabled ) ) ;
198+ OnPropertyChanged ( ) ;
205199 OnPropertyChanged ( nameof ( KoreanIMERegistryValueIsZero ) ) ;
206200 }
207201 else
@@ -212,13 +206,13 @@ public bool LegacyKoreanIMEEnabled
212206 }
213207 }
214208
215- public bool KoreanIMERegistryKeyExists => IsKoreanIMEExist ( ) ;
209+ public bool KoreanIMERegistryKeyExists => Win32Helper . IsKoreanIMEExist ( ) ;
216210
217211 public bool KoreanIMERegistryValueIsZero
218212 {
219213 get
220214 {
221- object value = GetLegacyKoreanIMERegistryValue ( ) ;
215+ object value = Win32Helper . GetLegacyKoreanIMERegistryValue ( ) ;
222216 if ( value is int intValue )
223217 {
224218 return intValue == 0 ;
@@ -232,90 +226,12 @@ public bool KoreanIMERegistryValueIsZero
232226 }
233227 }
234228
235- bool IsKoreanIMEExist ( )
236- {
237- return GetLegacyKoreanIMERegistryValue ( ) != null ;
238- }
239-
240- bool IsLegacyKoreanIMEEnabled ( )
241- {
242- object value = GetLegacyKoreanIMERegistryValue ( ) ;
243-
244- if ( value is int intValue )
245- {
246- return intValue == 1 ;
247- }
248- else if ( value != null && int . TryParse ( value . ToString ( ) , out int parsedValue ) )
249- {
250- return parsedValue == 1 ;
251- }
252-
253- return false ;
254- }
255-
256- bool SetLegacyKoreanIMEEnabled ( bool enable )
257- {
258- const string subKeyPath = @"Software\Microsoft\input\tsf\tsf3override\{A028AE76-01B1-46C2-99C4-ACD9858AE02F}" ;
259- const string valueName = "NoTsf3Override5" ;
260-
261- try
262- {
263- using ( RegistryKey key = Registry . CurrentUser . CreateSubKey ( subKeyPath ) )
264- {
265- if ( key != null )
266- {
267- int value = enable ? 1 : 0 ;
268- key . SetValue ( valueName , value , RegistryValueKind . DWord ) ;
269- return true ;
270- }
271- else
272- {
273- Debug . WriteLine ( $ "[IME DEBUG] Failed to create or open registry key: { subKeyPath } ") ;
274- }
275- }
276- }
277- catch ( Exception ex )
278- {
279- Debug . WriteLine ( $ "[IME DEBUG] Exception occurred while setting registry: { ex . Message } ") ;
280- }
281-
282- return false ;
283- }
284-
285- private object GetLegacyKoreanIMERegistryValue ( )
286- {
287- const string subKeyPath = @"Software\Microsoft\input\tsf\tsf3override\{A028AE76-01B1-46C2-99C4-ACD9858AE02F}" ;
288- const string valueName = "NoTsf3Override5" ;
289-
290- try
291- {
292- using ( RegistryKey key = Registry . CurrentUser . OpenSubKey ( subKeyPath ) )
293- {
294- if ( key != null )
295- {
296- return key . GetValue ( valueName ) ;
297- }
298- }
299- }
300- catch ( Exception ex )
301- {
302- Debug . WriteLine ( $ "[IME DEBUG] Exception occurred: { ex . Message } ") ;
303- }
304-
305- return null ;
306- }
307-
229+ [ RelayCommand ]
308230 private void OpenImeSettings ( )
309231 {
310- try
311- {
312- Process . Start ( new ProcessStartInfo ( "ms-settings:regionlanguage" ) { UseShellExecute = true } ) ;
313- }
314- catch ( Exception e )
315- {
316- Debug . WriteLine ( $ "Error opening IME settings: { e . Message } ") ;
317- }
232+ Win32Helper . OpenImeSettings ( ) ;
318233 }
234+
319235 #endregion
320236
321237 public bool ShouldUsePinyin
0 commit comments