Skip to content

Commit 0ddaea3

Browse files
authored
Merge branch 'dev' into processkiller_orderby_windowtitle
2 parents aa6c9d9 + 350276d commit 0ddaea3

File tree

230 files changed

+7014
-4500
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+7014
-4500
lines changed

Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

Lines changed: 331 additions & 289 deletions
Large diffs are not rendered by default.

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,6 @@ public static async Task InitializePluginsAsync()
205205
}
206206
}
207207

208-
InternationalizationManager.Instance.AddPluginLanguageDirectories(GetPluginsForInterface<IPluginI18n>());
209-
InternationalizationManager.Instance.ChangeLanguage(Ioc.Default.GetRequiredService<Settings>().Language);
210-
211208
if (failedPlugins.Any())
212209
{
213210
var failed = string.Join(",", failedPlugins.Select(x => x.Metadata.Name));
@@ -231,7 +228,6 @@ public static ICollection<PluginPair> ValidPluginsForQuery(Query query)
231228
if (!NonGlobalPlugins.ContainsKey(query.ActionKeyword))
232229
return GlobalPlugins;
233230

234-
235231
var plugin = NonGlobalPlugins[query.ActionKeyword];
236232
return new List<PluginPair>
237233
{
@@ -367,7 +363,16 @@ public static void AddActionKeyword(string id, string newActionKeyword)
367363
NonGlobalPlugins[newActionKeyword] = plugin;
368364
}
369365

366+
// Update action keywords and action keyword in plugin metadata
370367
plugin.Metadata.ActionKeywords.Add(newActionKeyword);
368+
if (plugin.Metadata.ActionKeywords.Count > 0)
369+
{
370+
plugin.Metadata.ActionKeyword = plugin.Metadata.ActionKeywords[0];
371+
}
372+
else
373+
{
374+
plugin.Metadata.ActionKeyword = string.Empty;
375+
}
371376
}
372377

373378
/// <summary>
@@ -388,16 +393,15 @@ public static void RemoveActionKeyword(string id, string oldActionkeyword)
388393
if (oldActionkeyword != Query.GlobalPluginWildcardSign)
389394
NonGlobalPlugins.Remove(oldActionkeyword);
390395

391-
396+
// Update action keywords and action keyword in plugin metadata
392397
plugin.Metadata.ActionKeywords.Remove(oldActionkeyword);
393-
}
394-
395-
public static void ReplaceActionKeyword(string id, string oldActionKeyword, string newActionKeyword)
396-
{
397-
if (oldActionKeyword != newActionKeyword)
398+
if (plugin.Metadata.ActionKeywords.Count > 0)
399+
{
400+
plugin.Metadata.ActionKeyword = plugin.Metadata.ActionKeywords[0];
401+
}
402+
else
398403
{
399-
AddActionKeyword(id, newActionKeyword);
400-
RemoveActionKeyword(id, oldActionKeyword);
404+
plugin.Metadata.ActionKeyword = string.Empty;
401405
}
402406
}
403407

Flow.Launcher.Core/Resource/Internationalization.cs

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ private static string GetSystemLanguageCodeAtStartup()
6767
return DefaultLanguageCode;
6868
}
6969

70-
internal void AddPluginLanguageDirectories(IEnumerable<PluginPair> plugins)
70+
private void AddPluginLanguageDirectories()
7171
{
72-
foreach (var plugin in plugins)
72+
foreach (var plugin in PluginManager.GetPluginsForInterface<IPluginI18n>())
7373
{
7474
var location = Assembly.GetAssembly(plugin.Plugin.GetType()).Location;
7575
var dir = Path.GetDirectoryName(location);
@@ -96,6 +96,32 @@ private void LoadDefaultLanguage()
9696
_oldResources.Clear();
9797
}
9898

99+
/// <summary>
100+
/// Initialize language. Will change app language and plugin language based on settings.
101+
/// </summary>
102+
public async Task InitializeLanguageAsync()
103+
{
104+
// Get actual language
105+
var languageCode = _settings.Language;
106+
if (languageCode == Constant.SystemLanguageCode)
107+
{
108+
languageCode = SystemLanguageCode;
109+
}
110+
111+
// Get language by language code and change language
112+
var language = GetLanguageByLanguageCode(languageCode);
113+
114+
// Add plugin language directories first so that we can load language files from plugins
115+
AddPluginLanguageDirectories();
116+
117+
// Change language
118+
await ChangeLanguageAsync(language);
119+
}
120+
121+
/// <summary>
122+
/// Change language during runtime. Will change app language and plugin language & save settings.
123+
/// </summary>
124+
/// <param name="languageCode"></param>
99125
public void ChangeLanguage(string languageCode)
100126
{
101127
languageCode = languageCode.NonNull();
@@ -110,7 +136,12 @@ public void ChangeLanguage(string languageCode)
110136

111137
// Get language by language code and change language
112138
var language = GetLanguageByLanguageCode(languageCode);
113-
ChangeLanguage(language, isSystem);
139+
140+
// Change language
141+
_ = ChangeLanguageAsync(language);
142+
143+
// Save settings
144+
_settings.Language = isSystem ? Constant.SystemLanguageCode : language.LanguageCode;
114145
}
115146

116147
private Language GetLanguageByLanguageCode(string languageCode)
@@ -128,26 +159,22 @@ private Language GetLanguageByLanguageCode(string languageCode)
128159
}
129160
}
130161

131-
private void ChangeLanguage(Language language, bool isSystem)
162+
private async Task ChangeLanguageAsync(Language language)
132163
{
133-
language = language.NonNull();
134-
164+
// Remove old language files and load language
135165
RemoveOldLanguageFiles();
136166
if (language != AvailableLanguages.English)
137167
{
138168
LoadLanguage(language);
139169
}
170+
140171
// Culture of main thread
141172
// Use CreateSpecificCulture to preserve possible user-override settings in Windows, if Flow's language culture is the same as Windows's
142173
CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture(language.LanguageCode);
143174
CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture;
144175

145-
// Raise event after culture is set
146-
_settings.Language = isSystem ? Constant.SystemLanguageCode : language.LanguageCode;
147-
_ = Task.Run(() =>
148-
{
149-
UpdatePluginMetadataTranslations();
150-
});
176+
// Raise event for plugins after culture is set
177+
await Task.Run(UpdatePluginMetadataTranslations);
151178
}
152179

153180
public bool PromptShouldUsePinyin(string languageCodeToSet)

0 commit comments

Comments
 (0)