13
13
namespace Flow . Launcher . Core . Plugin ;
14
14
15
15
/// <summary>
16
- /// Helper class for installing, updating, and uninstalling plugins.
16
+ /// Class for installing, updating, and uninstalling plugins.
17
17
/// </summary>
18
18
public static class PluginInstaller
19
19
{
@@ -25,6 +25,11 @@ public static class PluginInstaller
25
25
private static IPublicAPI api = null ;
26
26
private static IPublicAPI API => api ??= Ioc . Default . GetRequiredService < IPublicAPI > ( ) ;
27
27
28
+ /// <summary>
29
+ /// Installs a plugin and restarts the application if required by settings. Prompts user for confirmation and handles download if needed.
30
+ /// </summary>
31
+ /// <param name="newPlugin">The plugin to install.</param>
32
+ /// <returns>A Task representing the asynchronous install operation.</returns>
28
33
public static async Task InstallPluginAndCheckRestartAsync ( UserPlugin newPlugin )
29
34
{
30
35
if ( API . PluginModified ( newPlugin . ID ) )
@@ -106,6 +111,11 @@ await DownloadFileAsync(
106
111
}
107
112
}
108
113
114
+ /// <summary>
115
+ /// Installs a plugin from a local zip file and restarts the application if required by settings. Validates the zip and prompts user for confirmation.
116
+ /// </summary>
117
+ /// <param name="filePath">The path to the plugin zip file.</param>
118
+ /// <returns>A Task representing the asynchronous install operation.</returns>
109
119
public static async Task InstallPluginAndCheckRestartAsync ( string filePath )
110
120
{
111
121
UserPlugin plugin ;
@@ -147,6 +157,11 @@ public static async Task InstallPluginAndCheckRestartAsync(string filePath)
147
157
await InstallPluginAndCheckRestartAsync ( plugin ) ;
148
158
}
149
159
160
+ /// <summary>
161
+ /// Uninstalls a plugin and restarts the application if required by settings. Prompts user for confirmation and whether to keep plugin settings.
162
+ /// </summary>
163
+ /// <param name="oldPlugin">The plugin metadata to uninstall.</param>
164
+ /// <returns>A Task representing the asynchronous uninstall operation.</returns>
150
165
public static async Task UninstallPluginAndCheckRestartAsync ( PluginMetadata oldPlugin )
151
166
{
152
167
if ( API . PluginModified ( oldPlugin . ID ) )
@@ -197,6 +212,12 @@ public static async Task UninstallPluginAndCheckRestartAsync(PluginMetadata oldP
197
212
}
198
213
}
199
214
215
+ /// <summary>
216
+ /// Updates a plugin to a new version and restarts the application if required by settings. Prompts user for confirmation and handles download if needed.
217
+ /// </summary>
218
+ /// <param name="newPlugin">The new plugin version to install.</param>
219
+ /// <param name="oldPlugin">The existing plugin metadata to update.</param>
220
+ /// <returns>A Task representing the asynchronous update operation.</returns>
200
221
public static async Task UpdatePluginAndCheckRestartAsync ( UserPlugin newPlugin , PluginMetadata oldPlugin )
201
222
{
202
223
if ( API . ShowMsgBox (
@@ -256,15 +277,25 @@ await DownloadFileAsync(
256
277
}
257
278
}
258
279
259
- private static async Task DownloadFileAsync ( string prgBoxTitle , string downloadUrl , string filePath , CancellationTokenSource cts , bool deleteFile = true , bool showProgress = true )
280
+ /// <summary>
281
+ /// Downloads a file from a URL to a local path, optionally showing a progress box and handling cancellation.
282
+ /// </summary>
283
+ /// <param name="progressBoxTitle">The title for the progress box.</param>
284
+ /// <param name="downloadUrl">The URL to download from.</param>
285
+ /// <param name="filePath">The local file path to save to.</param>
286
+ /// <param name="cts">Cancellation token source for cancelling the download.</param>
287
+ /// <param name="deleteFile">Whether to delete the file if it already exists.</param>
288
+ /// <param name="showProgress">Whether to show a progress box during download.</param>
289
+ /// <returns>A Task representing the asynchronous download operation.</returns>
290
+ private static async Task DownloadFileAsync ( string progressBoxTitle , string downloadUrl , string filePath , CancellationTokenSource cts , bool deleteFile = true , bool showProgress = true )
260
291
{
261
292
if ( deleteFile && File . Exists ( filePath ) )
262
293
File . Delete ( filePath ) ;
263
294
264
295
if ( showProgress )
265
296
{
266
297
var exceptionHappened = false ;
267
- await API . ShowProgressBoxAsync ( prgBoxTitle ,
298
+ await API . ShowProgressBoxAsync ( progressBoxTitle ,
268
299
async ( reportProgress ) =>
269
300
{
270
301
if ( reportProgress == null )
@@ -291,6 +322,11 @@ await API.ShowProgressBoxAsync(prgBoxTitle,
291
322
}
292
323
}
293
324
325
+ /// <summary>
326
+ /// Determines if the plugin install source is a known/approved source (e.g., GitHub and matches an existing plugin author).
327
+ /// </summary>
328
+ /// <param name="url">The URL to check.</param>
329
+ /// <returns>True if the source is known, otherwise false.</returns>
294
330
private static bool InstallSourceKnown ( string url )
295
331
{
296
332
if ( string . IsNullOrEmpty ( url ) )
0 commit comments