Skip to content

Commit ca06734

Browse files
authored
Merge branch 'dev' into l10n_dev
2 parents d0e9a90 + 352c0f8 commit ca06734

File tree

35 files changed

+569
-335
lines changed

35 files changed

+569
-335
lines changed

.github/actions/spelling/expect.txt

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# This file should contain names of products, companies, or individuals that aren't in a standard dictionary (e.g., GitHub, Keptn, VSCode).
2+
13
crowdin
24
DWM
35
workflows
@@ -34,7 +36,6 @@ mscorlib
3436
pythonw
3537
dotnet
3638
winget
37-
jjw24
3839
wolframalpha
3940
gmail
4041
duckduckgo
@@ -49,15 +50,13 @@ srchadmin
4950
EWX
5051
dlgtext
5152
CMD
52-
appref-ms
5353
appref
5454
TSource
5555
runas
5656
dpi
5757
popup
5858
ptr
5959
pluginindicator
60-
TobiasSekan
6160
img
6261
resx
6362
bak
@@ -68,9 +67,6 @@ dlg
6867
ddd
6968
dddd
7069
clearlogfolder
71-
ACCENT_ENABLE_TRANSPARENTGRADIENT
72-
ACCENT_ENABLE_BLURBEHIND
73-
WCA_ACCENT_POLICY
7470
HGlobal
7571
dopusrt
7672
firefox
@@ -91,22 +87,15 @@ keyevent
9187
KListener
9288
requery
9389
vkcode
94-
čeština
9590
Polski
9691
Srpski
97-
Português
98-
Português (Brasil)
9992
Italiano
100-
Slovenský
10193
quicklook
102-
Tiếng Việt
10394
Droplex
10495
Preinstalled
10596
errormetadatafile
10697
noresult
10798
pluginsmanager
10899
alreadyexists
109-
JsonRPC
110-
JsonRPCV2
111100
Softpedia
112101
img

.github/actions/spelling/patterns.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# See https://github.com/check-spelling/check-spelling/wiki/Configuration-Examples:-patterns
2+
# This file should contain strings that contain a mix of letters and numbers, or specific symbols
3+
24

35
# Questionably acceptable forms of `in to`
46
# Personally, I prefer `log into`, but people object
@@ -121,3 +123,13 @@
121123

122124
# version suffix <word>v#
123125
(?:(?<=[A-Z]{2})V|(?<=[a-z]{2}|[A-Z]{2})v)\d+(?:\b|(?=[a-zA-Z_]))
126+
127+
\bjjw24\b
128+
\bappref-ms\b
129+
\bTobiasSekan\b
130+
\bJsonRPC\b
131+
\bJsonRPCV2\b
132+
\bTiếng Việt\b
133+
\bPortuguês (Brasil)\b
134+
\bčeština\b
135+
\bPortuguês\b

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,14 @@ public static ICollection<PluginPair> ValidPluginsForQuery(Query query)
290290
return Array.Empty<PluginPair>();
291291

292292
if (!NonGlobalPlugins.TryGetValue(query.ActionKeyword, out var plugin))
293-
return GlobalPlugins;
293+
{
294+
return GlobalPlugins.Where(p => !PluginModified(p.Metadata.ID)).ToList();
295+
}
296+
297+
if (API.PluginModified(plugin.Metadata.ID))
298+
{
299+
return Array.Empty<PluginPair>();
300+
}
294301

295302
return new List<PluginPair>
296303
{
@@ -300,7 +307,7 @@ public static ICollection<PluginPair> ValidPluginsForQuery(Query query)
300307

301308
public static ICollection<PluginPair> ValidPluginsForHomeQuery()
302309
{
303-
return _homePlugins.ToList();
310+
return _homePlugins.Where(p => !PluginModified(p.Metadata.ID)).ToList();
304311
}
305312

306313
public static async Task<List<Result>> QueryForPluginAsync(PluginPair pair, Query query, CancellationToken token)
@@ -552,9 +559,9 @@ public static void InstallPlugin(UserPlugin plugin, string zipFilePath)
552559
InstallPlugin(plugin, zipFilePath, checkModified: true);
553560
}
554561

555-
public static async Task UninstallPluginAsync(PluginMetadata plugin, bool removePluginFromSettings = true, bool removePluginSettings = false)
562+
public static async Task UninstallPluginAsync(PluginMetadata plugin, bool removePluginSettings = false)
556563
{
557-
await UninstallPluginAsync(plugin, removePluginFromSettings, removePluginSettings, true);
564+
await UninstallPluginAsync(plugin, removePluginFromSettings: true, removePluginSettings: removePluginSettings, checkModified: true);
558565
}
559566

560567
#endregion

Flow.Launcher.Core/Resource/Internationalization.cs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.IO;
45
using System.Linq;
56
using System.Reflection;
7+
using System.Threading;
8+
using System.Threading.Tasks;
69
using System.Windows;
10+
using CommunityToolkit.Mvvm.DependencyInjection;
711
using Flow.Launcher.Core.Plugin;
812
using Flow.Launcher.Infrastructure;
913
using Flow.Launcher.Infrastructure.UserSettings;
1014
using Flow.Launcher.Plugin;
11-
using System.Globalization;
12-
using System.Threading.Tasks;
13-
using CommunityToolkit.Mvvm.DependencyInjection;
1415

1516
namespace Flow.Launcher.Core.Resource
1617
{
@@ -29,13 +30,12 @@ public class Internationalization
2930
private readonly Settings _settings;
3031
private readonly List<string> _languageDirectories = new();
3132
private readonly List<ResourceDictionary> _oldResources = new();
32-
private readonly string SystemLanguageCode;
33+
private static string SystemLanguageCode;
3334

3435
public Internationalization(Settings settings)
3536
{
3637
_settings = settings;
3738
AddFlowLauncherLanguageDirectory();
38-
SystemLanguageCode = GetSystemLanguageCodeAtStartup();
3939
}
4040

4141
private void AddFlowLauncherLanguageDirectory()
@@ -44,7 +44,7 @@ private void AddFlowLauncherLanguageDirectory()
4444
_languageDirectories.Add(directory);
4545
}
4646

47-
private static string GetSystemLanguageCodeAtStartup()
47+
public static void InitSystemLanguageCode()
4848
{
4949
var availableLanguages = AvailableLanguages.GetAvailableLanguages();
5050

@@ -65,11 +65,11 @@ private static string GetSystemLanguageCodeAtStartup()
6565
string.Equals(languageCode, threeLetterCode, StringComparison.OrdinalIgnoreCase) ||
6666
string.Equals(languageCode, fullName, StringComparison.OrdinalIgnoreCase))
6767
{
68-
return languageCode;
68+
SystemLanguageCode = languageCode;
6969
}
7070
}
7171

72-
return DefaultLanguageCode;
72+
SystemLanguageCode = DefaultLanguageCode;
7373
}
7474

7575
private void AddPluginLanguageDirectories()
@@ -173,15 +173,33 @@ private async Task ChangeLanguageAsync(Language language)
173173
LoadLanguage(language);
174174
}
175175

176-
// Culture of main thread
177-
// Use CreateSpecificCulture to preserve possible user-override settings in Windows, if Flow's language culture is the same as Windows's
178-
CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture(language.LanguageCode);
179-
CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture;
176+
// Change culture info
177+
ChangeCultureInfo(language.LanguageCode);
180178

181179
// Raise event for plugins after culture is set
182180
await Task.Run(UpdatePluginMetadataTranslations);
183181
}
184182

183+
public static void ChangeCultureInfo(string languageCode)
184+
{
185+
// Culture of main thread
186+
// Use CreateSpecificCulture to preserve possible user-override settings in Windows, if Flow's language culture is the same as Windows's
187+
CultureInfo currentCulture;
188+
try
189+
{
190+
currentCulture = CultureInfo.CreateSpecificCulture(languageCode);
191+
}
192+
catch (CultureNotFoundException)
193+
{
194+
currentCulture = CultureInfo.CreateSpecificCulture(SystemLanguageCode);
195+
}
196+
CultureInfo.CurrentCulture = currentCulture;
197+
CultureInfo.CurrentUICulture = currentCulture;
198+
var thread = Thread.CurrentThread;
199+
thread.CurrentCulture = currentCulture;
200+
thread.CurrentUICulture = currentCulture;
201+
}
202+
185203
public bool PromptShouldUsePinyin(string languageCodeToSet)
186204
{
187205
var languageToSet = GetLanguageByLanguageCode(languageCodeToSet);

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ public void SetStorage(FlowLauncherJsonStorage<Settings> storage)
2525

2626
public void Initialize()
2727
{
28+
// Initialize dependency injection instances after Ioc.Default is created
2829
_stringMatcher = Ioc.Default.GetRequiredService<StringMatcher>();
30+
31+
// Initialize application resources after application is created
32+
var settingWindowFont = new FontFamily(SettingWindowFont);
33+
Application.Current.Resources["SettingWindowFont"] = settingWindowFont;
34+
Application.Current.Resources["ContentControlThemeFontFamily"] = settingWindowFont;
2935
}
3036

3137
public void Save()
@@ -119,8 +125,11 @@ public string SettingWindowFont
119125
{
120126
_settingWindowFont = value;
121127
OnPropertyChanged();
122-
Application.Current.Resources["SettingWindowFont"] = new FontFamily(value);
123-
Application.Current.Resources["ContentControlThemeFontFamily"] = new FontFamily(value);
128+
if (Application.Current != null)
129+
{
130+
Application.Current.Resources["SettingWindowFont"] = new FontFamily(value);
131+
Application.Current.Resources["ContentControlThemeFontFamily"] = new FontFamily(value);
132+
}
124133
}
125134
}
126135
}
@@ -383,7 +392,7 @@ public bool HideNotifyIcon
383392
public bool LeaveCmdOpen { get; set; }
384393
public bool HideWhenDeactivated { get; set; } = true;
385394

386-
private bool _showAtTopmost = true;
395+
private bool _showAtTopmost = false;
387396
public bool ShowAtTopmost
388397
{
389398
get => _showAtTopmost;

Flow.Launcher/App.xaml.cs

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public partial class App : IDisposable, ISingleInstanceApp
4141
private static readonly string ClassName = nameof(App);
4242

4343
private static bool _disposed;
44+
private static Settings _settings;
4445
private static MainWindow _mainWindow;
4546
private readonly MainViewModel _mainVM;
46-
private readonly Settings _settings;
4747

4848
// To prevent two disposals running at the same time.
4949
private static readonly object _disposingLock = new();
@@ -55,18 +55,7 @@ public partial class App : IDisposable, ISingleInstanceApp
5555
public App()
5656
{
5757
// Initialize settings
58-
try
59-
{
60-
var storage = new FlowLauncherJsonStorage<Settings>();
61-
_settings = storage.Load();
62-
_settings.SetStorage(storage);
63-
_settings.WMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled();
64-
}
65-
catch (Exception e)
66-
{
67-
ShowErrorMsgBoxAndFailFast("Cannot load setting storage, please check local data directory", e);
68-
return;
69-
}
58+
_settings.WMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled();
7059

7160
// Configure the dependency injection container
7261
try
@@ -123,16 +112,6 @@ public App()
123112
ShowErrorMsgBoxAndFailFast("Cannot initialize api and settings, please open new issue in Flow.Launcher", e);
124113
return;
125114
}
126-
127-
// Local function
128-
static void ShowErrorMsgBoxAndFailFast(string message, Exception e)
129-
{
130-
// Firstly show users the message
131-
MessageBox.Show(e.ToString(), message, MessageBoxButton.OK, MessageBoxImage.Error);
132-
133-
// Flow cannot construct its App instance, so ensure Flow crashes w/ the exception info.
134-
Environment.FailFast(message, e);
135-
}
136115
}
137116

138117
#endregion
@@ -142,6 +121,29 @@ static void ShowErrorMsgBoxAndFailFast(string message, Exception e)
142121
[STAThread]
143122
public static void Main()
144123
{
124+
// Initialize settings so that we can get language code
125+
try
126+
{
127+
var storage = new FlowLauncherJsonStorage<Settings>();
128+
_settings = storage.Load();
129+
_settings.SetStorage(storage);
130+
}
131+
catch (Exception e)
132+
{
133+
ShowErrorMsgBoxAndFailFast("Cannot load setting storage, please check local data directory", e);
134+
return;
135+
}
136+
137+
// Initialize system language before changing culture info
138+
Internationalization.InitSystemLanguageCode();
139+
140+
// Change culture info before application creation to localize WinForm windows
141+
if (_settings.Language != Constant.SystemLanguageCode)
142+
{
143+
Internationalization.ChangeCultureInfo(_settings.Language);
144+
}
145+
146+
// Start the application as a single instance
145147
if (SingleInstance<App>.InitializeAsFirstInstance())
146148
{
147149
using var application = new App();
@@ -152,6 +154,19 @@ public static void Main()
152154

153155
#endregion
154156

157+
#region Fail Fast
158+
159+
private static void ShowErrorMsgBoxAndFailFast(string message, Exception e)
160+
{
161+
// Firstly show users the message
162+
MessageBox.Show(e.ToString(), message, MessageBoxButton.OK, MessageBoxImage.Error);
163+
164+
// Flow cannot construct its App instance, so ensure Flow crashes w/ the exception info.
165+
Environment.FailFast(message, e);
166+
}
167+
168+
#endregion
169+
155170
#region App Events
156171

157172
#pragma warning disable VSTHRD100 // Avoid async void methods

Flow.Launcher/CustomShortcutSetting.xaml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,26 @@
118118
FontSize="14"
119119
Text="{DynamicResource customShortcutExpansion}" />
120120

121-
<DockPanel
122-
Grid.Row="1"
123-
Grid.Column="1"
124-
LastChildFill="True">
125-
<Button
126-
x:Name="btnTestShortcut"
127-
Margin="0 0 10 0"
128-
Padding="10 5 10 5"
129-
Click="BtnTestShortcut_OnClick"
130-
Content="{DynamicResource preview}"
131-
DockPanel.Dock="Right" />
121+
<Grid Grid.Row="1" Grid.Column="1">
122+
<Grid.ColumnDefinitions>
123+
<ColumnDefinition Width="*" />
124+
<ColumnDefinition Width="Auto" />
125+
</Grid.ColumnDefinitions>
132126
<TextBox
133127
x:Name="tbExpand"
128+
Grid.Column="0"
134129
Margin="10 0 10 0"
135130
HorizontalAlignment="Stretch"
136131
VerticalAlignment="Center"
137132
Text="{Binding Value}" />
138-
</DockPanel>
133+
<Button
134+
x:Name="btnTestShortcut"
135+
Grid.Column="1"
136+
Margin="0 0 10 0"
137+
Padding="10 5 10 5"
138+
Click="BtnTestShortcut_OnClick"
139+
Content="{DynamicResource preview}" />
140+
</Grid>
139141
</Grid>
140142
</StackPanel>
141143
</StackPanel>

0 commit comments

Comments
 (0)