1
- using Flow . Launcher . Core . ExternalPlugins ;
1
+ using Flow . Launcher . Core . ExternalPlugins ;
2
2
using System ;
3
3
using System . Collections . Concurrent ;
4
4
using System . Collections . Generic ;
@@ -90,6 +90,48 @@ public static async Task ReloadDataAsync()
90
90
} ) . ToArray ( ) ) ;
91
91
}
92
92
93
+ public static async Task OpenExternalPreviewAsync ( string path , bool sendFailToast = true )
94
+ {
95
+ await Task . WhenAll ( AllPlugins . Select ( plugin => plugin . Plugin switch
96
+ {
97
+ IAsyncExternalPreview p => p . OpenPreviewAsync ( path , sendFailToast ) ,
98
+ _ => Task . CompletedTask ,
99
+ } ) . ToArray ( ) ) ;
100
+ }
101
+
102
+ public static async Task CloseExternalPreviewAsync ( )
103
+ {
104
+ await Task . WhenAll ( AllPlugins . Select ( plugin => plugin . Plugin switch
105
+ {
106
+ IAsyncExternalPreview p => p . ClosePreviewAsync ( ) ,
107
+ _ => Task . CompletedTask ,
108
+ } ) . ToArray ( ) ) ;
109
+ }
110
+
111
+ public static async Task SwitchExternalPreviewAsync ( string path , bool sendFailToast = true )
112
+ {
113
+ await Task . WhenAll ( AllPlugins . Select ( plugin => plugin . Plugin switch
114
+ {
115
+ IAsyncExternalPreview p => p . SwitchPreviewAsync ( path , sendFailToast ) ,
116
+ _ => Task . CompletedTask ,
117
+ } ) . ToArray ( ) ) ;
118
+ }
119
+
120
+ public static bool UseExternalPreview ( )
121
+ {
122
+ return GetPluginsForInterface < IAsyncExternalPreview > ( ) . Any ( x => ! x . Metadata . Disabled ) ;
123
+ }
124
+
125
+ public static bool AllowAlwaysPreview ( )
126
+ {
127
+ var plugin = GetPluginsForInterface < IAsyncExternalPreview > ( ) . FirstOrDefault ( x => ! x . Metadata . Disabled ) ;
128
+
129
+ if ( plugin is null )
130
+ return false ;
131
+
132
+ return ( ( IAsyncExternalPreview ) plugin . Plugin ) . AllowAlwaysPreview ( ) ;
133
+ }
134
+
93
135
static PluginManager ( )
94
136
{
95
137
// validate user directory
@@ -380,7 +422,8 @@ public static bool PluginModified(string uuid)
380
422
381
423
382
424
/// <summary>
383
- /// Update a plugin to new version, from a zip file. Will Delete zip after updating.
425
+ /// Update a plugin to new version, from a zip file. By default will remove the zip file if update is via url,
426
+ /// unless it's a local path installation
384
427
/// </summary>
385
428
public static void UpdatePlugin ( PluginMetadata existingVersion , UserPlugin newVersion , string zipFilePath )
386
429
{
@@ -390,11 +433,11 @@ public static void UpdatePlugin(PluginMetadata existingVersion, UserPlugin newVe
390
433
}
391
434
392
435
/// <summary>
393
- /// Install a plugin. Will Delete zip after updating.
436
+ /// Install a plugin. By default will remove the zip file if installation is from url, unless it's a local path installation
394
437
/// </summary>
395
438
public static void InstallPlugin ( UserPlugin plugin , string zipFilePath )
396
439
{
397
- InstallPlugin ( plugin , zipFilePath , true ) ;
440
+ InstallPlugin ( plugin , zipFilePath , checkModified : true ) ;
398
441
}
399
442
400
443
/// <summary>
@@ -420,7 +463,9 @@ internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool c
420
463
// Unzip plugin files to temp folder
421
464
var tempFolderPluginPath = Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) . ToString ( ) ) ;
422
465
System . IO . Compression . ZipFile . ExtractToDirectory ( zipFilePath , tempFolderPluginPath ) ;
423
- File . Delete ( zipFilePath ) ;
466
+
467
+ if ( ! plugin . IsFromLocalInstallPath )
468
+ File . Delete ( zipFilePath ) ;
424
469
425
470
var pluginFolderPath = GetContainingFolderPathAfterUnzip ( tempFolderPluginPath ) ;
426
471
0 commit comments