mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Compare commits
No commits in common. "cce80ac5aacfe726c8af17fbd31cd307fecfa3a8" and "dca90916fe41ef290baffc37616430c4cd7febae" have entirely different histories.
cce80ac5aa
...
dca90916fe
1 changed files with 103 additions and 105 deletions
|
|
@ -880,116 +880,111 @@ namespace Flow.Launcher.Core.Plugin
|
|||
var tempFolderPluginPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
|
||||
System.IO.Compression.ZipFile.ExtractToDirectory(zipFilePath, tempFolderPluginPath);
|
||||
|
||||
if(!plugin.IsFromLocalInstallPath)
|
||||
File.Delete(zipFilePath);
|
||||
|
||||
var pluginFolderPath = GetContainingFolderPathAfterUnzip(tempFolderPluginPath);
|
||||
|
||||
var metadataJsonFilePath = string.Empty;
|
||||
if (File.Exists(Path.Combine(pluginFolderPath, Constant.PluginMetadataFileName)))
|
||||
metadataJsonFilePath = Path.Combine(pluginFolderPath, Constant.PluginMetadataFileName);
|
||||
|
||||
if (string.IsNullOrEmpty(metadataJsonFilePath) || string.IsNullOrEmpty(pluginFolderPath))
|
||||
{
|
||||
PublicApi.Instance.ShowMsgError(Localize.failedToInstallPluginTitle(plugin.Name),
|
||||
Localize.fileNotFoundMessage(pluginFolderPath));
|
||||
return false;
|
||||
}
|
||||
|
||||
PluginMetadata newMetadata;
|
||||
try
|
||||
{
|
||||
if (!plugin.IsFromLocalInstallPath)
|
||||
File.Delete(zipFilePath);
|
||||
|
||||
var pluginFolderPath = GetContainingFolderPathAfterUnzip(tempFolderPluginPath);
|
||||
|
||||
var metadataJsonFilePath = string.Empty;
|
||||
if (File.Exists(Path.Combine(pluginFolderPath, Constant.PluginMetadataFileName)))
|
||||
metadataJsonFilePath = Path.Combine(pluginFolderPath, Constant.PluginMetadataFileName);
|
||||
|
||||
if (string.IsNullOrEmpty(metadataJsonFilePath) || string.IsNullOrEmpty(pluginFolderPath))
|
||||
{
|
||||
PublicApi.Instance.ShowMsgError(Localize.failedToInstallPluginTitle(plugin.Name),
|
||||
Localize.fileNotFoundMessage(pluginFolderPath));
|
||||
return false;
|
||||
}
|
||||
|
||||
PluginMetadata newMetadata;
|
||||
try
|
||||
{
|
||||
newMetadata = JsonSerializer.Deserialize<PluginMetadata>(File.ReadAllText(metadataJsonFilePath)) ??
|
||||
throw new JsonException("Deserialized metadata is null");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
PublicApi.Instance.ShowMsgError(Localize.failedToInstallPluginTitle(plugin.Name),
|
||||
Localize.pluginJsonInvalidOrCorrupted());
|
||||
PublicApi.Instance.LogException(ClassName,
|
||||
$"Failed to deserialize plugin metadata for plugin {plugin.Name} from file {metadataJsonFilePath}", ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (SameOrLesserPluginVersionExists(newMetadata))
|
||||
{
|
||||
PublicApi.Instance.ShowMsgError(Localize.failedToInstallPluginTitle(plugin.Name),
|
||||
Localize.pluginExistAlreadyMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsMinimumAppVersionSatisfied(newMetadata.Name, newMetadata.MinimumAppVersion))
|
||||
{
|
||||
// Ask users if they want to install the plugin that doesn't satisfy the minimum app version requirement
|
||||
if (PublicApi.Instance.ShowMsgBox(
|
||||
Localize.pluginMinimumAppVersionUnsatisfiedMessage(newMetadata.Name, Environment.NewLine),
|
||||
Localize.pluginMinimumAppVersionUnsatisfiedTitle(newMetadata.Name, newMetadata.MinimumAppVersion),
|
||||
MessageBoxButton.YesNo) == MessageBoxResult.No)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var folderName = string.IsNullOrEmpty(plugin.Version) ? $"{plugin.Name}-{Guid.NewGuid()}" : $"{plugin.Name}-{plugin.Version}";
|
||||
|
||||
var defaultPluginIDs = new List<string>
|
||||
{
|
||||
"0ECADE17459B49F587BF81DC3A125110", // BrowserBookmark
|
||||
"CEA0FDFC6D3B4085823D60DC76F28855", // Calculator
|
||||
"572be03c74c642baae319fc283e561a8", // Explorer
|
||||
"6A122269676E40EB86EB543B945932B9", // PluginIndicator
|
||||
"9f8f9b14-2518-4907-b211-35ab6290dee7", // PluginsManager
|
||||
"b64d0a79-329a-48b0-b53f-d658318a1bf6", // ProcessKiller
|
||||
"791FC278BA414111B8D1886DFE447410", // Program
|
||||
"D409510CD0D2481F853690A07E6DC426", // Shell
|
||||
"CEA08895D2544B019B2E9C5009600DF4", // Sys
|
||||
"0308FD86DE0A4DEE8D62B9B535370992", // URL
|
||||
"565B73353DBF4806919830B9202EE3BF", // WebSearch
|
||||
"5043CETYU6A748679OPA02D27D99677A" // WindowsSettings
|
||||
};
|
||||
|
||||
// Treat default plugin differently, it needs to be removable along with each flow release
|
||||
var installDirectory = !defaultPluginIDs.Any(x => x == plugin.ID)
|
||||
? DataLocation.PluginsDirectory
|
||||
: Constant.PreinstalledDirectory;
|
||||
|
||||
var newPluginPath = Path.Combine(installDirectory, folderName);
|
||||
|
||||
FilesFolders.CopyAll(pluginFolderPath, newPluginPath, (s) => PublicApi.Instance.ShowMsgBox(s));
|
||||
|
||||
// Check if marker file exists and delete it
|
||||
try
|
||||
{
|
||||
var markerFilePath = Path.Combine(newPluginPath, DataLocation.PluginDeleteFile);
|
||||
if (File.Exists(markerFilePath))
|
||||
File.Delete(markerFilePath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
PublicApi.Instance.LogException(ClassName, $"Failed to delete plugin marker file in {newPluginPath}", e);
|
||||
}
|
||||
|
||||
if (checkModified)
|
||||
{
|
||||
ModifiedPlugins.Add(plugin.ID);
|
||||
}
|
||||
|
||||
return true;
|
||||
newMetadata = JsonSerializer.Deserialize<PluginMetadata>(File.ReadAllText(metadataJsonFilePath)) ??
|
||||
throw new JsonException("Deserialized metadata is null");
|
||||
}
|
||||
finally
|
||||
catch (Exception ex)
|
||||
{
|
||||
try
|
||||
PublicApi.Instance.ShowMsgError(Localize.failedToInstallPluginTitle(plugin.Name),
|
||||
Localize.pluginJsonInvalidOrCorrupted());
|
||||
PublicApi.Instance.LogException(ClassName,
|
||||
$"Failed to deserialize plugin metadata for plugin {plugin.Name} from file {metadataJsonFilePath}", ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (SameOrLesserPluginVersionExists(newMetadata))
|
||||
{
|
||||
PublicApi.Instance.ShowMsgError(Localize.failedToInstallPluginTitle(plugin.Name),
|
||||
Localize.pluginExistAlreadyMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsMinimumAppVersionSatisfied(newMetadata.Name, newMetadata.MinimumAppVersion))
|
||||
{
|
||||
// Ask users if they want to install the plugin that doesn't satisfy the minimum app version requirement
|
||||
if (PublicApi.Instance.ShowMsgBox(
|
||||
Localize.pluginMinimumAppVersionUnsatisfiedMessage(newMetadata.Name, Environment.NewLine),
|
||||
Localize.pluginMinimumAppVersionUnsatisfiedTitle(newMetadata.Name, newMetadata.MinimumAppVersion),
|
||||
MessageBoxButton.YesNo) == MessageBoxResult.No)
|
||||
{
|
||||
if (Directory.Exists(tempFolderPluginPath))
|
||||
Directory.Delete(tempFolderPluginPath, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
PublicApi.Instance.LogException(ClassName, $"Failed to delete temp folder {tempFolderPluginPath}", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var folderName = string.IsNullOrEmpty(plugin.Version) ? $"{plugin.Name}-{Guid.NewGuid()}" : $"{plugin.Name}-{plugin.Version}";
|
||||
|
||||
var defaultPluginIDs = new List<string>
|
||||
{
|
||||
"0ECADE17459B49F587BF81DC3A125110", // BrowserBookmark
|
||||
"CEA0FDFC6D3B4085823D60DC76F28855", // Calculator
|
||||
"572be03c74c642baae319fc283e561a8", // Explorer
|
||||
"6A122269676E40EB86EB543B945932B9", // PluginIndicator
|
||||
"9f8f9b14-2518-4907-b211-35ab6290dee7", // PluginsManager
|
||||
"b64d0a79-329a-48b0-b53f-d658318a1bf6", // ProcessKiller
|
||||
"791FC278BA414111B8D1886DFE447410", // Program
|
||||
"D409510CD0D2481F853690A07E6DC426", // Shell
|
||||
"CEA08895D2544B019B2E9C5009600DF4", // Sys
|
||||
"0308FD86DE0A4DEE8D62B9B535370992", // URL
|
||||
"565B73353DBF4806919830B9202EE3BF", // WebSearch
|
||||
"5043CETYU6A748679OPA02D27D99677A" // WindowsSettings
|
||||
};
|
||||
|
||||
// Treat default plugin differently, it needs to be removable along with each flow release
|
||||
var installDirectory = !defaultPluginIDs.Any(x => x == plugin.ID)
|
||||
? DataLocation.PluginsDirectory
|
||||
: Constant.PreinstalledDirectory;
|
||||
|
||||
var newPluginPath = Path.Combine(installDirectory, folderName);
|
||||
|
||||
FilesFolders.CopyAll(pluginFolderPath, newPluginPath, (s) => PublicApi.Instance.ShowMsgBox(s));
|
||||
|
||||
// Check if marker file exists and delete it
|
||||
try
|
||||
{
|
||||
var markerFilePath = Path.Combine(newPluginPath, DataLocation.PluginDeleteFile);
|
||||
if (File.Exists(markerFilePath))
|
||||
File.Delete(markerFilePath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
PublicApi.Instance.LogException(ClassName, $"Failed to delete plugin marker file in {newPluginPath}", e);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(tempFolderPluginPath))
|
||||
Directory.Delete(tempFolderPluginPath, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
PublicApi.Instance.LogException(ClassName, $"Failed to delete temp folder {tempFolderPluginPath}", e);
|
||||
}
|
||||
|
||||
if (checkModified)
|
||||
{
|
||||
ModifiedPlugins.Add(plugin.ID);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static async Task<bool> UninstallPluginAsync(PluginMetadata plugin, bool removePluginFromSettings, bool removePluginSettings, bool checkModified)
|
||||
|
|
@ -1083,7 +1078,6 @@ namespace Flow.Launcher.Core.Plugin
|
|||
|
||||
internal static bool IsMinimumAppVersionSatisfied(string pluginName, string minimumAppVersion)
|
||||
{
|
||||
// If the minimum app version is not specified in plugin.json, this plugin is compatible with all app versions
|
||||
if (string.IsNullOrEmpty(minimumAppVersion))
|
||||
return true;
|
||||
|
||||
|
|
@ -1092,13 +1086,17 @@ namespace Flow.Launcher.Core.Plugin
|
|||
if (!Version.TryParse(minimumAppVersion, out var minimumVersion))
|
||||
{
|
||||
PublicApi.Instance.LogError(ClassName,
|
||||
$"Failed to parse the minimum app version {minimumAppVersion} for plugin {pluginName}.");
|
||||
$"Failed to parse the minimum app version {minimumAppVersion} for plugin {pluginName}. "
|
||||
+ "Plugin excluded from manifest");
|
||||
return false; // If the minimum app version specified in plugin.json is invalid, we assume it is not satisfied
|
||||
}
|
||||
|
||||
if (appVersion >= minimumVersion)
|
||||
return true;
|
||||
|
||||
PublicApi.Instance.LogInfo(ClassName, $"Plugin {pluginName} requires minimum Flow Launcher version {minimumAppVersion}, "
|
||||
+ $"but current version is {Constant.Version}. Plugin excluded from manifest.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue