Skip to content

Commit 736837e

Browse files
committed
Add function for switch and button
1 parent 5c09598 commit 736837e

File tree

3 files changed

+131
-55
lines changed

3 files changed

+131
-55
lines changed

Flow.Launcher/Languages/en.xaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@
125125
and enable "Use previous version of Microsoft IME".


126126
You can open the relevant menu using the option below, or change the setting directly without manually opening the settings page.
127127
</system:String>
128-
<system:String x:Key="KoreanImeRegistry">Very short</system:String>
128+
<system:String x:Key="KoreanImeOpenLink">Open Language and Region System Settings</system:String>
129+
<system:String x:Key="KoreanImeOpenLinkToolTIp">Opens the Korean IME setting locationKorean &gt; Language Options &gt; Keyboard - Microsoft IME &gt; Compatibility</system:String>
130+
<system:String x:Key="KoreanImeOpenLinkButton">Open</system:String>
131+
<system:String x:Key="KoreanImeRegistry">Use Legacy Korean IME</system:String>
132+
<system:String x:Key="KoreanImeRegistryTooltip">You can change the IME settings directly from here without opening a separate settings window</system:String>
129133

130134
<!-- Setting Plugin -->
131135
<system:String x:Key="searchplugin">Search Plugin</system:String>

Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs

Lines changed: 98 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
using Flow.Launcher.Plugin.SharedModels;
1414
using Microsoft.Win32;
1515
using OpenFileDialog = System.Windows.Forms.OpenFileDialog;
16+
using System.Windows.Input;
17+
1618

1719
namespace Flow.Launcher.SettingPages.ViewModels;
1820

@@ -21,14 +23,16 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
2123
public Settings Settings { get; }
2224
private readonly Updater _updater;
2325
private readonly IPortable _portable;
24-
26+
public ICommand OpenImeSettingsCommand { get; }
27+
2528
public SettingsPaneGeneralViewModel(Settings settings, Updater updater, IPortable portable)
2629
{
2730
Settings = settings;
2831
_updater = updater;
2932
_portable = portable;
3033
UpdateEnumDropdownLocalizations();
3134
IsLegacyKoreanIMEEnabled();
35+
OpenImeSettingsCommand = new RelayCommand(OpenImeSettings);
3236
}
3337

3438
public class SearchWindowScreenData : DropdownDataGeneric<SearchWindowScreens> { }
@@ -190,37 +194,100 @@ public string Language
190194
UpdateEnumDropdownLocalizations();
191195
}
192196
}
197+
198+
public bool LegacyKoreanIMEEnabled
199+
{
200+
get => IsLegacyKoreanIMEEnabled();
201+
set
202+
{
203+
SetLegacyKoreanIMEEnabled(value);
204+
OnPropertyChanged(nameof(LegacyKoreanIMEEnabled));
205+
OnPropertyChanged(nameof(KoreanIMERegistryValueIsZero));
206+
}
207+
}
208+
209+
public bool KoreanIMERegistryKeyExists => IsKoreanIMEExist();
210+
211+
public bool KoreanIMERegistryValueIsZero
212+
{
213+
get
214+
{
215+
object value = GetLegacyKoreanIMERegistryValue();
216+
if (value is int intValue)
217+
{
218+
return intValue == 0;
219+
}
220+
else if (value != null && int.TryParse(value.ToString(), out int parsedValue))
221+
{
222+
return parsedValue == 0;
223+
}
224+
225+
return false;
226+
}
227+
}
228+
229+
bool IsKoreanIMEExist()
230+
{
231+
return GetLegacyKoreanIMERegistryValue() != null;
232+
}
193233

194234
bool IsLegacyKoreanIMEEnabled()
235+
{
236+
object value = GetLegacyKoreanIMERegistryValue();
237+
238+
if (value is int intValue)
239+
{
240+
return intValue == 1;
241+
}
242+
else if (value != null && int.TryParse(value.ToString(), out int parsedValue))
243+
{
244+
return parsedValue == 1;
245+
}
246+
247+
return false;
248+
}
249+
250+
bool SetLegacyKoreanIMEEnabled(bool enable)
195251
{
196252
const string subKeyPath = @"Software\Microsoft\input\tsf\tsf3override\{A028AE76-01B1-46C2-99C4-ACD9858AE02F}";
197253
const string valueName = "NoTsf3Override5";
198254

199255
try
200256
{
201-
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(subKeyPath))
257+
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(subKeyPath))
202258
{
203259
if (key != null)
204260
{
205-
object value = key.GetValue(valueName);
206-
if (value != null)
207-
{
208-
Debug.WriteLine($"[IME DEBUG] '{valueName}' 값: {value} (타입: {value.GetType()})");
209-
210-
if (value is int intValue)
211-
return intValue == 1;
212-
213-
if (int.TryParse(value.ToString(), out int parsed))
214-
return parsed == 1;
215-
}
216-
else
217-
{
218-
Debug.WriteLine($"[IME DEBUG] '{valueName}' 값이 존재하지 않습니다.");
219-
}
261+
int value = enable ? 1 : 0;
262+
key.SetValue(valueName, value, RegistryValueKind.DWord);
263+
return true;
220264
}
221265
else
222266
{
223-
Debug.WriteLine($"[IME DEBUG] 레지스트리 키를 찾을 수 없습니다: {subKeyPath}");
267+
Debug.WriteLine($"[IME DEBUG] 레지스트리 키 생성 또는 열기 실패: {subKeyPath}");
268+
}
269+
}
270+
}
271+
catch (Exception ex)
272+
{
273+
Debug.WriteLine($"[IME DEBUG] 레지스트리 설정 중 예외 발생: {ex.Message}");
274+
}
275+
276+
return false;
277+
}
278+
279+
private object GetLegacyKoreanIMERegistryValue()
280+
{
281+
const string subKeyPath = @"Software\Microsoft\input\tsf\tsf3override\{A028AE76-01B1-46C2-99C4-ACD9858AE02F}";
282+
const string valueName = "NoTsf3Override5";
283+
284+
try
285+
{
286+
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(subKeyPath))
287+
{
288+
if (key != null)
289+
{
290+
return key.GetValue(valueName);
224291
}
225292
}
226293
}
@@ -229,10 +296,21 @@ bool IsLegacyKoreanIMEEnabled()
229296
Debug.WriteLine($"[IME DEBUG] 예외 발생: {ex.Message}");
230297
}
231298

232-
return false; // 기본적으로 새 IME 사용 중으로 간주
299+
return null;
300+
}
301+
302+
private void OpenImeSettings()
303+
{
304+
try
305+
{
306+
Process.Start(new ProcessStartInfo("ms-settings:regionlanguage") { UseShellExecute = true });
307+
}
308+
catch (Exception e)
309+
{
310+
Debug.WriteLine($"Error opening IME settings: {e.Message}");
311+
}
233312
}
234313

235-
236314
public bool ShouldUsePinyin
237315
{
238316
get => Settings.ShouldUsePinyin;

Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
99
xmlns:settingsViewModels="clr-namespace:Flow.Launcher.SettingPages.ViewModels"
1010
xmlns:ui="http://schemas.modernwpf.com/2019"
11+
xmlns:converters="clr-namespace:Flow.Launcher.Converters"
1112
xmlns:userSettings="clr-namespace:Flow.Launcher.Infrastructure.UserSettings;assembly=Flow.Launcher.Infrastructure"
1213
Title="General"
1314
d:DataContext="{d:DesignInstance settingsViewModels:SettingsPaneGeneralViewModel}"
1415
d:DesignHeight="450"
1516
d:DesignWidth="800"
1617
mc:Ignorable="d">
18+
<ui:Page.Resources>
19+
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
20+
</ui:Page.Resources>
1721
<ScrollViewer
1822
Margin="0"
1923
CanContentScroll="False"
@@ -28,40 +32,7 @@
2832
Style="{StaticResource PageTitle}"
2933
Text="{DynamicResource general}"
3034
TextAlignment="left" />
31-
<cc:InfoBar
32-
Title="Test"
33-
Closable="False"
34-
IsIconVisible="True"
35-
Length="Short"
36-
Message="This is a success message."
37-
Type="Info" />
38-
<cc:InfoBar
39-
Closable="True"
40-
IsIconVisible="True"
41-
Length="Short"
42-
Message="This is a success message."
43-
Type="Success" />
44-
<cc:InfoBar
45-
Title="Test"
46-
Closable="False"
47-
IsIconVisible="True"
48-
Length="Long"
49-
Message="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Curabitur pretium"
50-
Type="Warning" />
51-
<cc:InfoBar
52-
Title="Test"
53-
Closable="False"
54-
IsIconVisible="True"
55-
Length="Short"
56-
Message="This is a success message."
57-
Type="Error" />
58-
<cc:InfoBar
59-
Title="{DynamicResource KoreanImeTitle}"
60-
Closable="False"
61-
IsIconVisible="True"
62-
Length="Long"
63-
Message="{DynamicResource KoreanImeGuide}"
64-
Type="Warning" />
35+
6536
<cc:ExCard
6637
Title="{DynamicResource startFlowLauncherOnSystemStartup}"
6738
Margin="0 8 0 0"
@@ -317,6 +288,29 @@
317288
SelectedValue="{Binding Language}"
318289
SelectedValuePath="LanguageCode" />
319290
</cc:Card>
291+
<cc:InfoBar Margin="0 12 0 0"
292+
Title="{DynamicResource KoreanImeTitle}"
293+
Closable="False"
294+
IsIconVisible="True"
295+
Length="Long"
296+
Message="{DynamicResource KoreanImeGuide}"
297+
Type="Warning" />
298+
<cc:CardGroup Margin="0 4 0 0">
299+
<cc:Card
300+
Title="{DynamicResource KoreanImeRegistry}"
301+
Icon="&#xe88b;" Sub="{DynamicResource KoreanImeRegistryTooltip}">
302+
<ui:ToggleSwitch
303+
IsOn="{Binding LegacyKoreanIMEEnabled}"
304+
OffContent="{DynamicResource disable}"
305+
OnContent="{DynamicResource enable}" />
306+
</cc:Card>
307+
<cc:Card
308+
Title="{DynamicResource KoreanImeOpenLink}"
309+
Sub="{DynamicResource KoreanImeOpenLinkTooltip}"
310+
Icon="&#xf7b9;">
311+
<Button Content="{DynamicResource KoreanImeOpenLinkButton}" Command="{Binding OpenImeSettingsCommand}"/>
312+
</cc:Card>
313+
</cc:CardGroup>
320314
</VirtualizingStackPanel>
321315
</ScrollViewer>
322316
</ui:Page>

0 commit comments

Comments
 (0)