Skip to content

Commit 515f24d

Browse files
authored
Merge branch 'dev' into rename-file
2 parents 19c5cc3 + 4fcc12d commit 515f24d

File tree

4 files changed

+76
-20
lines changed

4 files changed

+76
-20
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ public static class PluginManager
2626
{
2727
private static readonly string ClassName = nameof(PluginManager);
2828

29-
private static IEnumerable<PluginPair> _contextMenuPlugins;
30-
private static IEnumerable<PluginPair> _homePlugins;
31-
private static IEnumerable<PluginPair> _resultUpdatePlugin;
32-
private static IEnumerable<PluginPair> _translationPlugins;
33-
private static IEnumerable<PluginPair> _hotkeyPlugins;
34-
3529
public static List<PluginPair> AllPlugins { get; private set; }
3630
public static readonly HashSet<PluginPair> GlobalPlugins = new();
3731
public static readonly Dictionary<string, PluginPair> NonGlobalPlugins = new();
@@ -43,8 +37,13 @@ public static class PluginManager
4337
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
4438

4539
private static PluginsSettings Settings;
46-
private static List<PluginMetadata> _metadatas;
47-
private static readonly List<string> _modifiedPlugins = new();
40+
private static readonly ConcurrentBag<string> ModifiedPlugins = new();
41+
42+
private static IEnumerable<PluginPair> _contextMenuPlugins;
43+
private static IEnumerable<PluginPair> _homePlugins;
44+
private static IEnumerable<PluginPair> _resultUpdatePlugin;
45+
private static IEnumerable<PluginPair> _translationPlugins;
46+
private static IEnumerable<PluginPair> _hotkeyPlugins;
4847

4948
private static readonly Dictionary<PluginPair, List<BasePluginHotkey>> _pluginHotkeyInfo = new();
5049
private static readonly Dictionary<HotkeyModel, List<(PluginMetadata, SearchWindowPluginHotkey)>> _windowPluginHotkeys = new();
@@ -183,12 +182,13 @@ static PluginManager()
183182
/// <param name="settings"></param>
184183
public static void LoadPlugins(PluginsSettings settings)
185184
{
186-
_metadatas = PluginConfig.Parse(Directories);
185+
var metadatas = PluginConfig.Parse(Directories);
187186
Settings = settings;
188-
Settings.UpdatePluginSettings(_metadatas);
189-
AllPlugins = PluginsLoader.Plugins(_metadatas, Settings);
187+
Settings.UpdatePluginSettings(metadatas);
188+
AllPlugins = PluginsLoader.Plugins(metadatas, Settings);
190189
// Since dotnet plugins need to get assembly name first, we should update plugin directory after loading plugins
191-
UpdatePluginDirectory(_metadatas);
190+
UpdatePluginDirectory(metadatas);
191+
192192
// Initialize plugin enumerable after all plugins are initialized
193193
_contextMenuPlugins = GetPluginsForInterface<IContextMenu>();
194194
_homePlugins = GetPluginsForInterface<IAsyncHomeQuery>();
@@ -432,10 +432,20 @@ private static IEnumerable<PluginPair> GetPluginsForInterface<T>() where T : IFe
432432
return AllPlugins?.Where(p => p.Plugin is T) ?? Array.Empty<PluginPair>();
433433
}
434434

435+
public static IList<PluginPair> GetResultUpdatePlugin()
436+
{
437+
return _resultUpdatePlugin.Where(p => !PluginModified(p.Metadata.ID)).ToList();
438+
}
439+
440+
public static IList<PluginPair> GetTranslationPlugins()
441+
{
442+
return _translationPlugins.Where(p => !PluginModified(p.Metadata.ID)).ToList();
443+
}
444+
435445
public static List<Result> GetContextMenusForPlugin(Result result)
436446
{
437447
var results = new List<Result>();
438-
var pluginPair = _contextMenuPlugins.FirstOrDefault(o => o.Metadata.ID == result.PluginID);
448+
var pluginPair = _contextMenuPlugins.Where(p => !PluginModified(p.Metadata.ID)).FirstOrDefault(o => o.Metadata.ID == result.PluginID);
439449
if (pluginPair != null)
440450
{
441451
var plugin = (IContextMenu)pluginPair.Plugin;
@@ -463,7 +473,7 @@ public static List<Result> GetContextMenusForPlugin(Result result)
463473

464474
public static bool IsHomePlugin(string id)
465475
{
466-
return _homePlugins.Any(p => p.Metadata.ID == id);
476+
return _homePlugins.Where(p => !PluginModified(p.Metadata.ID)).Any(p => p.Metadata.ID == id);
467477
}
468478

469479
public static IList<PluginPair> GetResultUpdatePlugin()
@@ -695,14 +705,14 @@ private static bool SameOrLesserPluginVersionExists(string metadataPath)
695705

696706
public static bool PluginModified(string id)
697707
{
698-
return _modifiedPlugins.Contains(id);
708+
return ModifiedPlugins.Contains(id);
699709
}
700710

701711
public static async Task UpdatePluginAsync(PluginMetadata existingVersion, UserPlugin newVersion, string zipFilePath)
702712
{
703-
InstallPlugin(newVersion, zipFilePath, checkModified:false);
704-
await UninstallPluginAsync(existingVersion, removePluginFromSettings:false, removePluginSettings:false, checkModified: false);
705-
_modifiedPlugins.Add(existingVersion.ID);
713+
InstallPlugin(newVersion, zipFilePath, checkModified: false);
714+
await UninstallPluginAsync(existingVersion, removePluginFromSettings: false, removePluginSettings: false, checkModified: false);
715+
ModifiedPlugins.Add(existingVersion.ID);
706716
}
707717

708718
public static void InstallPlugin(UserPlugin plugin, string zipFilePath)
@@ -789,7 +799,7 @@ internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool c
789799

790800
if (checkModified)
791801
{
792-
_modifiedPlugins.Add(plugin.ID);
802+
ModifiedPlugins.Add(plugin.ID);
793803
}
794804
}
795805

@@ -851,14 +861,20 @@ internal static async Task UninstallPluginAsync(PluginMetadata plugin, bool remo
851861
}
852862
Settings.RemovePluginSettings(plugin.ID);
853863
AllPlugins.RemoveAll(p => p.Metadata.ID == plugin.ID);
864+
GlobalPlugins.RemoveWhere(p => p.Metadata.ID == plugin.ID);
865+
var keysToRemove = NonGlobalPlugins.Where(p => p.Value.Metadata.ID == plugin.ID).Select(p => p.Key).ToList();
866+
foreach (var key in keysToRemove)
867+
{
868+
NonGlobalPlugins.Remove(key);
869+
}
854870
}
855871

856872
// Marked for deletion. Will be deleted on next start up
857873
using var _ = File.CreateText(Path.Combine(plugin.PluginDirectory, "NeedDelete.txt"));
858874

859875
if (checkModified)
860876
{
861-
_modifiedPlugins.Add(plugin.ID);
877+
ModifiedPlugins.Add(plugin.ID);
862878
}
863879
}
864880

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,5 +791,41 @@ public static unsafe void OpenFolderAndSelectFile(string filePath)
791791
}
792792

793793
#endregion
794+
795+
#region Win32 Dark Mode
796+
797+
/*
798+
* Inspired by https://github.com/ysc3839/win32-darkmode
799+
*/
800+
801+
[DllImport("uxtheme.dll", EntryPoint = "#135", SetLastError = true)]
802+
private static extern int SetPreferredAppMode(int appMode);
803+
804+
public static void EnableWin32DarkMode(string colorScheme)
805+
{
806+
try
807+
{
808+
// Undocumented API from Windows 10 1809
809+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
810+
Environment.OSVersion.Version.Build >= 17763)
811+
{
812+
var flag = colorScheme switch
813+
{
814+
Constant.Light => 3, // ForceLight
815+
Constant.Dark => 2, // ForceDark
816+
Constant.System => 1, // AllowDark
817+
_ => 0 // Default
818+
};
819+
_ = SetPreferredAppMode(flag);
820+
}
821+
822+
}
823+
catch
824+
{
825+
// Ignore errors on unsupported OS
826+
}
827+
}
828+
829+
#endregion
794830
}
795831
}

Flow.Launcher/App.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>
188188

189189
Notification.Install();
190190

191+
// Enable Win32 dark mode if the system is in dark mode before creating all windows
192+
Win32Helper.EnableWin32DarkMode(_settings.ColorScheme);
193+
191194
Ioc.Default.GetRequiredService<Portable>().PreStartCleanUpAfterPortabilityUpdate();
192195

193196
API.LogInfo(ClassName, "Begin Flow Launcher startup ----------------------------------------------------");

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public string ColorScheme
136136
};
137137
Settings.ColorScheme = value;
138138
_ = _theme.RefreshFrameAsync();
139+
Win32Helper.EnableWin32DarkMode(value);
139140
}
140141
}
141142

0 commit comments

Comments
 (0)