Skip to content

Commit f56d038

Browse files
committed
Remove debug codes & Improve code quality
1 parent ebff80c commit f56d038

File tree

2 files changed

+95
-97
lines changed

2 files changed

+95
-97
lines changed

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.ComponentModel;
3+
using System.Diagnostics;
34
using System.Globalization;
45
using System.Runtime.InteropServices;
56
using System.Windows;
@@ -517,5 +518,86 @@ public static bool IsNotificationSupported()
517518
}
518519

519520
#endregion
521+
522+
#region Korean IME
523+
524+
public static bool IsKoreanIMEExist()
525+
{
526+
return GetLegacyKoreanIMERegistryValue() != null;
527+
}
528+
529+
public static bool IsLegacyKoreanIMEEnabled()
530+
{
531+
object value = GetLegacyKoreanIMERegistryValue();
532+
533+
if (value is int intValue)
534+
{
535+
return intValue == 1;
536+
}
537+
else if (value != null && int.TryParse(value.ToString(), out int parsedValue))
538+
{
539+
return parsedValue == 1;
540+
}
541+
542+
return false;
543+
}
544+
545+
public static bool SetLegacyKoreanIMEEnabled(bool enable)
546+
{
547+
const string subKeyPath = @"Software\Microsoft\input\tsf\tsf3override\{A028AE76-01B1-46C2-99C4-ACD9858AE02F}";
548+
const string valueName = "NoTsf3Override5";
549+
550+
try
551+
{
552+
using RegistryKey key = Registry.CurrentUser.CreateSubKey(subKeyPath);
553+
if (key != null)
554+
{
555+
int value = enable ? 1 : 0;
556+
key.SetValue(valueName, value, RegistryValueKind.DWord);
557+
return true;
558+
}
559+
}
560+
catch (System.Exception)
561+
{
562+
// Ignored
563+
}
564+
565+
return false;
566+
}
567+
568+
public static object GetLegacyKoreanIMERegistryValue()
569+
{
570+
const string subKeyPath = @"Software\Microsoft\input\tsf\tsf3override\{A028AE76-01B1-46C2-99C4-ACD9858AE02F}";
571+
const string valueName = "NoTsf3Override5";
572+
573+
try
574+
{
575+
using RegistryKey key = Registry.CurrentUser.OpenSubKey(subKeyPath);
576+
if (key != null)
577+
{
578+
return key.GetValue(valueName);
579+
}
580+
}
581+
catch (System.Exception)
582+
{
583+
// Ignored
584+
}
585+
586+
return null;
587+
}
588+
589+
public static void OpenImeSettings()
590+
{
591+
try
592+
{
593+
Process.Start(new ProcessStartInfo("ms-settings:regionlanguage") { UseShellExecute = true });
594+
}
595+
catch (System.Exception)
596+
{
597+
// Ignored
598+
}
599+
}
600+
601+
#endregion
520602
}
521603
}

Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs

Lines changed: 13 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics;
4-
using System.Linq;
53
using System.Windows.Forms;
64
using CommunityToolkit.Mvvm.Input;
75
using Flow.Launcher.Core;
86
using Flow.Launcher.Core.Configuration;
97
using Flow.Launcher.Core.Resource;
108
using Flow.Launcher.Helper;
9+
using Flow.Launcher.Infrastructure;
1110
using Flow.Launcher.Infrastructure.UserSettings;
1211
using Flow.Launcher.Plugin;
1312
using Flow.Launcher.Plugin.SharedModels;
14-
using Microsoft.Win32;
1513
using OpenFileDialog = System.Windows.Forms.OpenFileDialog;
16-
using System.Windows.Input;
17-
1814

1915
namespace 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

Comments
 (0)