Skip to content

Commit 79f3bfa

Browse files
committed
merge back v2.1.1 from master to dev
2 parents 0d9cc7e + 0ddcc5c commit 79f3bfa

21 files changed

Lines changed: 695 additions & 214 deletions

File tree

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
33
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
4-
<!-- Work around https://github.com/dotnet/runtime/issues/109682 -->
4+
<!-- Workaround https://github.com/dotnet/runtime/issues/109682 -->
55
<CETCompat>false</CETCompat>
66
</PropertyGroup>
77
</Project>

Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Threading;
44
using System.Threading.Tasks;
55
using Flow.Launcher.Plugin;
6-
using Flow.Launcher.Infrastructure;
6+
using Flow.Launcher.Core.Plugin;
77

88
namespace Flow.Launcher.Core.ExternalPlugins
99
{
@@ -41,11 +41,10 @@ public static async Task<bool> UpdateManifestAsync(bool usePrimaryUrlOnly = fals
4141
return false;
4242

4343
var updatedPluginResults = new List<UserPlugin>();
44-
var appVersion = SemanticVersioning.Version.Parse(Constant.Version);
4544

4645
for (int i = 0; i < results.Count; i++)
4746
{
48-
if (IsMinimumAppVersionSatisfied(results[i], appVersion))
47+
if (PluginManager.IsMinimumAppVersionSatisfied(results[i].Name, results[i].MinimumAppVersion))
4948
updatedPluginResults.Add(results[i]);
5049
}
5150

@@ -72,28 +71,5 @@ public static async Task<bool> UpdateManifestAsync(bool usePrimaryUrlOnly = fals
7271

7372
return false;
7473
}
75-
76-
private static bool IsMinimumAppVersionSatisfied(UserPlugin plugin, SemanticVersioning.Version appVersion)
77-
{
78-
if (string.IsNullOrEmpty(plugin.MinimumAppVersion))
79-
return true;
80-
81-
try
82-
{
83-
if (appVersion >= SemanticVersioning.Version.Parse(plugin.MinimumAppVersion))
84-
return true;
85-
}
86-
catch (Exception e)
87-
{
88-
PublicApi.Instance.LogException(ClassName, $"Failed to parse the minimum app version {plugin.MinimumAppVersion} for plugin {plugin.Name}. "
89-
+ "Plugin excluded from manifest", e);
90-
return false;
91-
}
92-
93-
PublicApi.Instance.LogInfo(ClassName, $"Plugin {plugin.Name} requires minimum Flow Launcher version {plugin.MinimumAppVersion}, "
94-
+ $"but current version is {Constant.Version}. Plugin excluded from manifest.");
95-
96-
return false;
97-
}
9874
}
9975
}

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 121 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Text.Json;
77
using System.Threading;
88
using System.Threading.Tasks;
9+
using System.Windows;
910
using Flow.Launcher.Core.ExternalPlugins;
1011
using Flow.Launcher.Core.Resource;
1112
using Flow.Launcher.Infrastructure;
@@ -813,15 +814,13 @@ private static string GetContainingFolderPathAfterUnzip(string unzippedParentFol
813814
return string.Empty;
814815
}
815816

816-
private static bool SameOrLesserPluginVersionExists(string metadataPath)
817+
private static bool SameOrLesserPluginVersionExists(PluginMetadata metadata)
817818
{
818-
var newMetadata = JsonSerializer.Deserialize<PluginMetadata>(File.ReadAllText(metadataPath));
819-
820-
if (!Version.TryParse(newMetadata.Version, out var newVersion))
819+
if (!Version.TryParse(metadata.Version, out var newVersion))
821820
return true; // If version is not valid, we assume it is lesser than any existing version
822821

823822
// Get all plugins even if initialization failed so that we can check if the plugin with the same ID exists
824-
return GetAllInitializedPlugins(includeFailed: true).Any(x => x.Metadata.ID == newMetadata.ID
823+
return GetAllInitializedPlugins(includeFailed: true).Any(x => x.Metadata.ID == metadata.ID
825824
&& Version.TryParse(x.Metadata.Version, out var version)
826825
&& newVersion <= version);
827826
}
@@ -881,84 +880,116 @@ internal static bool InstallPlugin(UserPlugin plugin, string zipFilePath, bool c
881880
var tempFolderPluginPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
882881
System.IO.Compression.ZipFile.ExtractToDirectory(zipFilePath, tempFolderPluginPath);
883882

884-
if(!plugin.IsFromLocalInstallPath)
885-
File.Delete(zipFilePath);
883+
try
884+
{
885+
if (!plugin.IsFromLocalInstallPath)
886+
File.Delete(zipFilePath);
886887

887-
var pluginFolderPath = GetContainingFolderPathAfterUnzip(tempFolderPluginPath);
888+
var pluginFolderPath = GetContainingFolderPathAfterUnzip(tempFolderPluginPath);
888889

889-
var metadataJsonFilePath = string.Empty;
890-
if (File.Exists(Path.Combine(pluginFolderPath, Constant.PluginMetadataFileName)))
891-
metadataJsonFilePath = Path.Combine(pluginFolderPath, Constant.PluginMetadataFileName);
890+
var metadataJsonFilePath = string.Empty;
891+
if (File.Exists(Path.Combine(pluginFolderPath, Constant.PluginMetadataFileName)))
892+
metadataJsonFilePath = Path.Combine(pluginFolderPath, Constant.PluginMetadataFileName);
892893

893-
if (string.IsNullOrEmpty(metadataJsonFilePath) || string.IsNullOrEmpty(pluginFolderPath))
894-
{
895-
PublicApi.Instance.ShowMsgError(Localize.failedToInstallPluginTitle(plugin.Name),
896-
Localize.fileNotFoundMessage(pluginFolderPath));
897-
return false;
898-
}
899-
900-
if (SameOrLesserPluginVersionExists(metadataJsonFilePath))
901-
{
902-
PublicApi.Instance.ShowMsgError(Localize.failedToInstallPluginTitle(plugin.Name),
903-
Localize.pluginExistAlreadyMessage());
904-
return false;
905-
}
894+
if (string.IsNullOrEmpty(metadataJsonFilePath) || string.IsNullOrEmpty(pluginFolderPath))
895+
{
896+
PublicApi.Instance.ShowMsgError(Localize.failedToInstallPluginTitle(plugin.Name),
897+
Localize.fileNotFoundMessage(pluginFolderPath));
898+
return false;
899+
}
906900

907-
var folderName = string.IsNullOrEmpty(plugin.Version) ? $"{plugin.Name}-{Guid.NewGuid()}" : $"{plugin.Name}-{plugin.Version}";
901+
PluginMetadata newMetadata;
902+
try
903+
{
904+
newMetadata = JsonSerializer.Deserialize<PluginMetadata>(File.ReadAllText(metadataJsonFilePath)) ??
905+
throw new JsonException("Deserialized metadata is null");
906+
}
907+
catch (Exception ex)
908+
{
909+
PublicApi.Instance.ShowMsgError(Localize.failedToInstallPluginTitle(plugin.Name),
910+
Localize.pluginJsonInvalidOrCorrupted());
911+
PublicApi.Instance.LogException(ClassName,
912+
$"Failed to deserialize plugin metadata for plugin {plugin.Name} from file {metadataJsonFilePath}", ex);
913+
return false;
914+
}
908915

909-
var defaultPluginIDs = new List<string>
916+
if (SameOrLesserPluginVersionExists(newMetadata))
910917
{
911-
"0ECADE17459B49F587BF81DC3A125110", // BrowserBookmark
912-
"CEA0FDFC6D3B4085823D60DC76F28855", // Calculator
913-
"572be03c74c642baae319fc283e561a8", // Explorer
914-
"6A122269676E40EB86EB543B945932B9", // PluginIndicator
915-
"9f8f9b14-2518-4907-b211-35ab6290dee7", // PluginsManager
916-
"b64d0a79-329a-48b0-b53f-d658318a1bf6", // ProcessKiller
917-
"791FC278BA414111B8D1886DFE447410", // Program
918-
"D409510CD0D2481F853690A07E6DC426", // Shell
919-
"CEA08895D2544B019B2E9C5009600DF4", // Sys
920-
"0308FD86DE0A4DEE8D62B9B535370992", // URL
921-
"565B73353DBF4806919830B9202EE3BF", // WebSearch
922-
"5043CETYU6A748679OPA02D27D99677A" // WindowsSettings
923-
};
918+
PublicApi.Instance.ShowMsgError(Localize.failedToInstallPluginTitle(plugin.Name),
919+
Localize.pluginExistAlreadyMessage());
920+
return false;
921+
}
924922

925-
// Treat default plugin differently, it needs to be removable along with each flow release
926-
var installDirectory = !defaultPluginIDs.Any(x => x == plugin.ID)
927-
? DataLocation.PluginsDirectory
928-
: Constant.PreinstalledDirectory;
923+
if (!IsMinimumAppVersionSatisfied(newMetadata.Name, newMetadata.MinimumAppVersion))
924+
{
925+
// Ask users if they want to install the plugin that doesn't satisfy the minimum app version requirement
926+
if (PublicApi.Instance.ShowMsgBox(
927+
Localize.pluginMinimumAppVersionUnsatisfiedMessage(newMetadata.Name, Environment.NewLine),
928+
Localize.pluginMinimumAppVersionUnsatisfiedTitle(newMetadata.Name, newMetadata.MinimumAppVersion),
929+
MessageBoxButton.YesNo) == MessageBoxResult.No)
930+
{
931+
return false;
932+
}
933+
}
929934

930-
var newPluginPath = Path.Combine(installDirectory, folderName);
935+
var folderName = string.IsNullOrEmpty(plugin.Version) ? $"{plugin.Name}-{Guid.NewGuid()}" : $"{plugin.Name}-{plugin.Version}";
931936

932-
FilesFolders.CopyAll(pluginFolderPath, newPluginPath, (s) => PublicApi.Instance.ShowMsgBox(s));
937+
var defaultPluginIDs = new List<string>
938+
{
939+
"0ECADE17459B49F587BF81DC3A125110", // BrowserBookmark
940+
"CEA0FDFC6D3B4085823D60DC76F28855", // Calculator
941+
"572be03c74c642baae319fc283e561a8", // Explorer
942+
"6A122269676E40EB86EB543B945932B9", // PluginIndicator
943+
"9f8f9b14-2518-4907-b211-35ab6290dee7", // PluginsManager
944+
"b64d0a79-329a-48b0-b53f-d658318a1bf6", // ProcessKiller
945+
"791FC278BA414111B8D1886DFE447410", // Program
946+
"D409510CD0D2481F853690A07E6DC426", // Shell
947+
"CEA08895D2544B019B2E9C5009600DF4", // Sys
948+
"0308FD86DE0A4DEE8D62B9B535370992", // URL
949+
"565B73353DBF4806919830B9202EE3BF", // WebSearch
950+
"5043CETYU6A748679OPA02D27D99677A" // WindowsSettings
951+
};
952+
953+
// Treat default plugin differently, it needs to be removable along with each flow release
954+
var installDirectory = !defaultPluginIDs.Any(x => x == plugin.ID)
955+
? DataLocation.PluginsDirectory
956+
: Constant.PreinstalledDirectory;
957+
958+
var newPluginPath = Path.Combine(installDirectory, folderName);
959+
960+
FilesFolders.CopyAll(pluginFolderPath, newPluginPath, (s) => PublicApi.Instance.ShowMsgBox(s));
961+
962+
// Check if marker file exists and delete it
963+
try
964+
{
965+
var markerFilePath = Path.Combine(newPluginPath, DataLocation.PluginDeleteFile);
966+
if (File.Exists(markerFilePath))
967+
File.Delete(markerFilePath);
968+
}
969+
catch (Exception e)
970+
{
971+
PublicApi.Instance.LogException(ClassName, $"Failed to delete plugin marker file in {newPluginPath}", e);
972+
}
933973

934-
// Check if marker file exists and delete it
935-
try
936-
{
937-
var markerFilePath = Path.Combine(newPluginPath, DataLocation.PluginDeleteFile);
938-
if (File.Exists(markerFilePath))
939-
File.Delete(markerFilePath);
940-
}
941-
catch (Exception e)
942-
{
943-
PublicApi.Instance.LogException(ClassName, $"Failed to delete plugin marker file in {newPluginPath}", e);
944-
}
974+
if (checkModified)
975+
{
976+
ModifiedPlugins.Add(plugin.ID);
977+
}
945978

946-
try
947-
{
948-
if (Directory.Exists(tempFolderPluginPath))
949-
Directory.Delete(tempFolderPluginPath, true);
950-
}
951-
catch (Exception e)
952-
{
953-
PublicApi.Instance.LogException(ClassName, $"Failed to delete temp folder {tempFolderPluginPath}", e);
979+
return true;
954980
}
955-
956-
if (checkModified)
981+
finally
957982
{
958-
ModifiedPlugins.Add(plugin.ID);
983+
try
984+
{
985+
if (Directory.Exists(tempFolderPluginPath))
986+
Directory.Delete(tempFolderPluginPath, true);
987+
}
988+
catch (Exception e)
989+
{
990+
PublicApi.Instance.LogException(ClassName, $"Failed to delete temp folder {tempFolderPluginPath}", e);
991+
}
959992
}
960-
961-
return true;
962993
}
963994

964995
internal static async Task<bool> UninstallPluginAsync(PluginMetadata plugin, bool removePluginFromSettings, bool removePluginSettings, bool checkModified)
@@ -1050,6 +1081,27 @@ internal static async Task<bool> UninstallPluginAsync(PluginMetadata plugin, boo
10501081
return true;
10511082
}
10521083

1084+
internal static bool IsMinimumAppVersionSatisfied(string pluginName, string minimumAppVersion)
1085+
{
1086+
// If the minimum app version is not specified in plugin.json, this plugin is compatible with all app versions
1087+
if (string.IsNullOrEmpty(minimumAppVersion))
1088+
return true;
1089+
1090+
var appVersion = Version.Parse(Constant.Version);
1091+
1092+
if (!Version.TryParse(minimumAppVersion, out var minimumVersion))
1093+
{
1094+
PublicApi.Instance.LogError(ClassName,
1095+
$"Failed to parse the minimum app version {minimumAppVersion} for plugin {pluginName}.");
1096+
return false; // If the minimum app version specified in plugin.json is invalid, we assume it is not satisfied
1097+
}
1098+
1099+
if (appVersion >= minimumVersion)
1100+
return true;
1101+
1102+
return false;
1103+
}
1104+
10531105
#endregion
10541106

10551107
#endregion

Flow.Launcher.Core/Resource/Theme.cs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -673,13 +673,13 @@ private void SetBlurForWindow(string theme, BackdropTypes backdropType)
673673
// If the BackdropType is Mica or MicaAlt, set the windowborderstyle's background to transparent
674674
if (backdropType == BackdropTypes.Mica || backdropType == BackdropTypes.MicaAlt)
675675
{
676-
windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property.Name == "Background"));
677-
windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(Color.FromArgb(1, 0, 0, 0))));
676+
windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property == Control.BackgroundProperty));
677+
windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, ThemeHelper.GetFrozenSolidColorBrush(Color.FromArgb(1, 0, 0, 0))));
678678
}
679679
else if (backdropType == BackdropTypes.Acrylic)
680680
{
681-
windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property.Name == "Background"));
682-
windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(Colors.Transparent)));
681+
windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property == Control.BackgroundProperty));
682+
windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, Brushes.Transparent));
683683
}
684684

685685
// For themes with blur enabled, the window border is rendered by the system, so it's treated as a simple rectangle regardless of thickness.
@@ -798,12 +798,12 @@ private void ApplyPreviewBackground(Color? bgColor = null)
798798
Application.Current.Resources["WindowBorderStyle"] is Style originalStyle)
799799
{
800800
// Copy the original style, including the base style if it exists
801-
CopyStyle(originalStyle, previewStyle);
801+
ThemeHelper.CopyStyle(originalStyle, previewStyle);
802802
}
803803

804804
// Apply background color (remove transparency in color)
805-
Color backgroundColor = Color.FromRgb(bgColor.Value.R, bgColor.Value.G, bgColor.Value.B);
806-
previewStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(backgroundColor)));
805+
var backgroundColor = Color.FromRgb(bgColor.Value.R, bgColor.Value.G, bgColor.Value.B);
806+
previewStyle.Setters.Add(new Setter(Border.BackgroundProperty, ThemeHelper.GetFrozenSolidColorBrush(backgroundColor)));
807807

808808
// The blur theme keeps the corner round fixed (applying DWM code to modify it causes rendering issues).
809809
// The non-blur theme retains the previously set WindowBorderStyle.
@@ -817,21 +817,6 @@ private void ApplyPreviewBackground(Color? bgColor = null)
817817
Application.Current.Resources["PreviewWindowBorderStyle"] = previewStyle;
818818
}
819819

820-
private void CopyStyle(Style originalStyle, Style targetStyle)
821-
{
822-
// If the style is based on another style, copy the base style first
823-
if (originalStyle.BasedOn != null)
824-
{
825-
CopyStyle(originalStyle.BasedOn, targetStyle);
826-
}
827-
828-
// Copy the setters from the original style
829-
foreach (var setter in originalStyle.Setters.OfType<Setter>())
830-
{
831-
targetStyle.Setters.Add(new Setter(setter.Property, setter.Value));
832-
}
833-
}
834-
835820
private void ColorizeWindow(string theme, BackdropTypes backdropType)
836821
{
837822
var dict = GetThemeResourceDictionary(theme);
@@ -917,11 +902,11 @@ private void ColorizeWindow(string theme, BackdropTypes backdropType)
917902
// Only set the background to transparent if the theme supports blur
918903
if (backdropType == BackdropTypes.Mica || backdropType == BackdropTypes.MicaAlt)
919904
{
920-
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0));
905+
mainWindow.Background = ThemeHelper.GetFrozenSolidColorBrush(Color.FromArgb(1, 0, 0, 0));
921906
}
922907
else
923908
{
924-
mainWindow.Background = new SolidColorBrush(selectedBG);
909+
mainWindow.Background = ThemeHelper.GetFrozenSolidColorBrush(selectedBG);
925910
}
926911
}
927912
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Linq;
2+
using System.Windows;
3+
using System.Windows.Media;
4+
5+
namespace Flow.Launcher.Core.Resource;
6+
7+
public static class ThemeHelper
8+
{
9+
public static void CopyStyle(Style originalStyle, Style targetStyle)
10+
{
11+
// If the style is based on another style, copy the base style first
12+
if (originalStyle.BasedOn != null)
13+
{
14+
CopyStyle(originalStyle.BasedOn, targetStyle);
15+
}
16+
17+
// Copy the setters from the original style
18+
foreach (var setter in originalStyle.Setters.OfType<Setter>())
19+
{
20+
targetStyle.Setters.Add(new Setter(setter.Property, setter.Value));
21+
}
22+
}
23+
24+
public static SolidColorBrush GetFrozenSolidColorBrush(Color color)
25+
{
26+
var brush = new SolidColorBrush(color);
27+
brush.Freeze();
28+
return brush;
29+
}
30+
}

0 commit comments

Comments
 (0)