Add function for switch and button

This commit is contained in:
DB p 2025-04-08 15:23:23 +09:00
parent 5c09598f21
commit 736837ebe8
3 changed files with 133 additions and 57 deletions

View file

@ -125,7 +125,11 @@
and enable "Use previous version of Microsoft IME".


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

View file

@ -13,6 +13,8 @@ using Flow.Launcher.Plugin;
using Flow.Launcher.Plugin.SharedModels;
using Microsoft.Win32;
using OpenFileDialog = System.Windows.Forms.OpenFileDialog;
using System.Windows.Input;
namespace Flow.Launcher.SettingPages.ViewModels;
@ -21,7 +23,8 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
public Settings Settings { get; }
private readonly Updater _updater;
private readonly IPortable _portable;
public ICommand OpenImeSettingsCommand { get; }
public SettingsPaneGeneralViewModel(Settings settings, Updater updater, IPortable portable)
{
Settings = settings;
@ -29,6 +32,7 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
_portable = portable;
UpdateEnumDropdownLocalizations();
IsLegacyKoreanIMEEnabled();
OpenImeSettingsCommand = new RelayCommand(OpenImeSettings);
}
public class SearchWindowScreenData : DropdownDataGeneric<SearchWindowScreens> { }
@ -190,8 +194,89 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
UpdateEnumDropdownLocalizations();
}
}
public bool LegacyKoreanIMEEnabled
{
get => IsLegacyKoreanIMEEnabled();
set
{
SetLegacyKoreanIMEEnabled(value);
OnPropertyChanged(nameof(LegacyKoreanIMEEnabled));
OnPropertyChanged(nameof(KoreanIMERegistryValueIsZero));
}
}
public bool KoreanIMERegistryKeyExists => IsKoreanIMEExist();
public bool KoreanIMERegistryValueIsZero
{
get
{
object value = GetLegacyKoreanIMERegistryValue();
if (value is int intValue)
{
return intValue == 0;
}
else if (value != null && int.TryParse(value.ToString(), out int parsedValue))
{
return parsedValue == 0;
}
return false;
}
}
bool IsKoreanIMEExist()
{
return GetLegacyKoreanIMERegistryValue() != null;
}
bool IsLegacyKoreanIMEEnabled()
{
object value = GetLegacyKoreanIMERegistryValue();
if (value is int intValue)
{
return intValue == 1;
}
else if (value != null && int.TryParse(value.ToString(), out int parsedValue))
{
return parsedValue == 1;
}
return false;
}
bool SetLegacyKoreanIMEEnabled(bool enable)
{
const string subKeyPath = @"Software\Microsoft\input\tsf\tsf3override\{A028AE76-01B1-46C2-99C4-ACD9858AE02F}";
const string valueName = "NoTsf3Override5";
try
{
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(subKeyPath))
{
if (key != null)
{
int value = enable ? 1 : 0;
key.SetValue(valueName, value, RegistryValueKind.DWord);
return true;
}
else
{
Debug.WriteLine($"[IME DEBUG] 레지스트리 키 생성 또는 열기 실패: {subKeyPath}");
}
}
}
catch (Exception ex)
{
Debug.WriteLine($"[IME DEBUG] 레지스트리 설정 중 예외 발생: {ex.Message}");
}
return false;
}
private object GetLegacyKoreanIMERegistryValue()
{
const string subKeyPath = @"Software\Microsoft\input\tsf\tsf3override\{A028AE76-01B1-46C2-99C4-ACD9858AE02F}";
const string valueName = "NoTsf3Override5";
@ -202,25 +287,7 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
{
if (key != null)
{
object value = key.GetValue(valueName);
if (value != null)
{
Debug.WriteLine($"[IME DEBUG] '{valueName}' 값: {value} (타입: {value.GetType()})");
if (value is int intValue)
return intValue == 1;
if (int.TryParse(value.ToString(), out int parsed))
return parsed == 1;
}
else
{
Debug.WriteLine($"[IME DEBUG] '{valueName}' 값이 존재하지 않습니다.");
}
}
else
{
Debug.WriteLine($"[IME DEBUG] 레지스트리 키를 찾을 수 없습니다: {subKeyPath}");
return key.GetValue(valueName);
}
}
}
@ -229,10 +296,21 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
Debug.WriteLine($"[IME DEBUG] 예외 발생: {ex.Message}");
}
return false; // 기본적으로 새 IME 사용 중으로 간주
return null;
}
private void OpenImeSettings()
{
try
{
Process.Start(new ProcessStartInfo("ms-settings:regionlanguage") { UseShellExecute = true });
}
catch (Exception e)
{
Debug.WriteLine($"Error opening IME settings: {e.Message}");
}
}
public bool ShouldUsePinyin
{
get => Settings.ShouldUsePinyin;

View file

@ -8,12 +8,16 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:settingsViewModels="clr-namespace:Flow.Launcher.SettingPages.ViewModels"
xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:converters="clr-namespace:Flow.Launcher.Converters"
xmlns:userSettings="clr-namespace:Flow.Launcher.Infrastructure.UserSettings;assembly=Flow.Launcher.Infrastructure"
Title="General"
d:DataContext="{d:DesignInstance settingsViewModels:SettingsPaneGeneralViewModel}"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<ui:Page.Resources>
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
</ui:Page.Resources>
<ScrollViewer
Margin="0"
CanContentScroll="False"
@ -28,40 +32,7 @@
Style="{StaticResource PageTitle}"
Text="{DynamicResource general}"
TextAlignment="left" />
<cc:InfoBar
Title="Test"
Closable="False"
IsIconVisible="True"
Length="Short"
Message="This is a success message."
Type="Info" />
<cc:InfoBar
Closable="True"
IsIconVisible="True"
Length="Short"
Message="This is a success message."
Type="Success" />
<cc:InfoBar
Title="Test"
Closable="False"
IsIconVisible="True"
Length="Long"
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"
Type="Warning" />
<cc:InfoBar
Title="Test"
Closable="False"
IsIconVisible="True"
Length="Short"
Message="This is a success message."
Type="Error" />
<cc:InfoBar
Title="{DynamicResource KoreanImeTitle}"
Closable="False"
IsIconVisible="True"
Length="Long"
Message="{DynamicResource KoreanImeGuide}"
Type="Warning" />
<cc:ExCard
Title="{DynamicResource startFlowLauncherOnSystemStartup}"
Margin="0 8 0 0"
@ -317,6 +288,29 @@
SelectedValue="{Binding Language}"
SelectedValuePath="LanguageCode" />
</cc:Card>
<cc:InfoBar Margin="0 12 0 0"
Title="{DynamicResource KoreanImeTitle}"
Closable="False"
IsIconVisible="True"
Length="Long"
Message="{DynamicResource KoreanImeGuide}"
Type="Warning" />
<cc:CardGroup Margin="0 4 0 0">
<cc:Card
Title="{DynamicResource KoreanImeRegistry}"
Icon="&#xe88b;" Sub="{DynamicResource KoreanImeRegistryTooltip}">
<ui:ToggleSwitch
IsOn="{Binding LegacyKoreanIMEEnabled}"
OffContent="{DynamicResource disable}"
OnContent="{DynamicResource enable}" />
</cc:Card>
<cc:Card
Title="{DynamicResource KoreanImeOpenLink}"
Sub="{DynamicResource KoreanImeOpenLinkTooltip}"
Icon="&#xf7b9;">
<Button Content="{DynamicResource KoreanImeOpenLinkButton}" Command="{Binding OpenImeSettingsCommand}"/>
</cc:Card>
</cc:CardGroup>
</VirtualizingStackPanel>
</ScrollViewer>
</ui:Page>