Skip to content

Commit 3106b02

Browse files
committed
Support plugin directory update & validate
1 parent 126153b commit 3106b02

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ private IEnumerable<PluginPair> SetPathForPluginPairs(string filePath, string la
116116
if (metadata.Language.Equals(languageToSet, StringComparison.OrdinalIgnoreCase))
117117
{
118118
metadata.AssemblyName = string.Empty;
119-
metadata.PluginSettingsDirectoryPath = Path.Combine(DataLocation.PluginSettingsDirectory, metadata.Name);
120-
metadata.PluginCacheDirectoryPath = Path.Combine(DataLocation.PluginCacheDirectory, metadata.Name);
121-
122119
pluginPairs.Add(CreatePluginPair(filePath, metadata));
123120
}
124121
}

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static class PluginManager
3232

3333
private static PluginsSettings Settings;
3434
private static List<PluginMetadata> _metadatas;
35-
private static List<string> _modifiedPlugins = new List<string>();
35+
private static List<string> _modifiedPlugins = new();
3636

3737
/// <summary>
3838
/// Directories that will hold Flow Launcher plugin directory
@@ -152,6 +152,27 @@ public static void LoadPlugins(PluginsSettings settings)
152152
Settings = settings;
153153
Settings.UpdatePluginSettings(_metadatas);
154154
AllPlugins = PluginsLoader.Plugins(_metadatas, Settings);
155+
UpdateAndValidatePluginDirectory(_metadatas);
156+
}
157+
158+
private static void UpdateAndValidatePluginDirectory(List<PluginMetadata> metadatas)
159+
{
160+
foreach (var metadata in metadatas)
161+
{
162+
if (AllowedLanguage.IsDotNet(metadata.Language))
163+
{
164+
metadata.PluginSettingsDirectoryPath = Path.Combine(DataLocation.PluginSettingsDirectory, metadata.AssemblyName);
165+
metadata.PluginCacheDirectoryPath = Path.Combine(DataLocation.PluginCacheDirectory, metadata.AssemblyName);
166+
}
167+
else
168+
{
169+
metadata.PluginSettingsDirectoryPath = Path.Combine(DataLocation.PluginSettingsDirectory, metadata.Name);
170+
metadata.PluginCacheDirectoryPath = Path.Combine(DataLocation.PluginCacheDirectory, metadata.Name);
171+
}
172+
173+
Helper.ValidateDirectory(metadata.PluginSettingsDirectoryPath);
174+
Helper.ValidateDirectory(metadata.PluginCacheDirectoryPath);
175+
}
155176
}
156177

157178
/// <summary>
@@ -226,11 +247,9 @@ public static ICollection<PluginPair> ValidPluginsForQuery(Query query)
226247
if (query is null)
227248
return Array.Empty<PluginPair>();
228249

229-
if (!NonGlobalPlugins.ContainsKey(query.ActionKeyword))
250+
if (!NonGlobalPlugins.TryGetValue(query.ActionKeyword, out var plugin))
230251
return GlobalPlugins;
231252

232-
233-
var plugin = NonGlobalPlugins[query.ActionKeyword];
234253
return new List<PluginPair>
235254
{
236255
plugin

Flow.Launcher.Core/Plugin/PluginsLoader.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,7 @@ public static IEnumerable<PluginPair> DotNetPlugins(List<PluginMetadata> source)
7575

7676
plugin = Activator.CreateInstance(type) as IAsyncPlugin;
7777

78-
// Same as PluginJsonStorage.cs constructor
79-
var assemblyName = assembly.GetName().Name;
80-
metadata.AssemblyName = assemblyName;
81-
metadata.PluginSettingsDirectoryPath = Path.Combine(DataLocation.PluginSettingsDirectory, assemblyName);
82-
metadata.PluginCacheDirectoryPath = Path.Combine(DataLocation.PluginCacheDirectory, assemblyName);
78+
metadata.AssemblyName = assembly.GetName().Name;
8379
}
8480
#if DEBUG
8581
catch (Exception)
@@ -149,8 +145,6 @@ public static IEnumerable<PluginPair> ExecutablePlugins(IEnumerable<PluginMetada
149145
};
150146

151147
plugin.Metadata.AssemblyName = string.Empty;
152-
plugin.Metadata.PluginSettingsDirectoryPath = Path.Combine(DataLocation.PluginSettingsDirectory, plugin.Metadata.Name);
153-
plugin.Metadata.PluginCacheDirectoryPath = Path.Combine(DataLocation.PluginCacheDirectory, plugin.Metadata.Name);
154148

155149
return plugin;
156150
});
@@ -169,8 +163,6 @@ public static IEnumerable<PluginPair> ExecutableV2Plugins(IEnumerable<PluginMeta
169163
};
170164

171165
plugin.Metadata.AssemblyName = string.Empty;
172-
plugin.Metadata.PluginSettingsDirectoryPath = Path.Combine(DataLocation.PluginSettingsDirectory, plugin.Metadata.Name);
173-
plugin.Metadata.PluginCacheDirectoryPath = Path.Combine(DataLocation.PluginCacheDirectory, plugin.Metadata.Name);
174166

175167
return plugin;
176168
});

Flow.Launcher.Infrastructure/Logger/Log.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static class Log
1818

1919
static Log()
2020
{
21-
CurrentLogDirectory = Path.Combine(DataLocation.DataDirectory(), DirectoryName, Constant.Version);
21+
CurrentLogDirectory = DataLocation.VersionLogDirectory;
2222
if (!Directory.Exists(CurrentLogDirectory))
2323
{
2424
Directory.CreateDirectory(CurrentLogDirectory);

0 commit comments

Comments
 (0)