1- using Flow . Launcher . Core . ExternalPlugins ;
1+ using Flow . Launcher . Core . ExternalPlugins ;
22using System ;
33using System . Collections . Concurrent ;
44using System . Collections . Generic ;
@@ -90,6 +90,48 @@ public static async Task ReloadDataAsync()
9090 } ) . ToArray ( ) ) ;
9191 }
9292
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+
93135 static PluginManager ( )
94136 {
95137 // validate user directory
@@ -380,7 +422,8 @@ public static bool PluginModified(string uuid)
380422
381423
382424 /// <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
384427 /// </summary>
385428 public static void UpdatePlugin ( PluginMetadata existingVersion , UserPlugin newVersion , string zipFilePath )
386429 {
@@ -390,11 +433,11 @@ public static void UpdatePlugin(PluginMetadata existingVersion, UserPlugin newVe
390433 }
391434
392435 /// <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
394437 /// </summary>
395438 public static void InstallPlugin ( UserPlugin plugin , string zipFilePath )
396439 {
397- InstallPlugin ( plugin , zipFilePath , true ) ;
440+ InstallPlugin ( plugin , zipFilePath , checkModified : true ) ;
398441 }
399442
400443 /// <summary>
@@ -420,7 +463,9 @@ internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool c
420463 // Unzip plugin files to temp folder
421464 var tempFolderPluginPath = Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) . ToString ( ) ) ;
422465 System . IO . Compression . ZipFile . ExtractToDirectory ( zipFilePath , tempFolderPluginPath ) ;
423- File . Delete ( zipFilePath ) ;
466+
467+ if ( ! plugin . IsFromLocalInstallPath )
468+ File . Delete ( zipFilePath ) ;
424469
425470 var pluginFolderPath = GetContainingFolderPathAfterUnzip ( tempFolderPluginPath ) ;
426471
0 commit comments