2022-08-08 04:31:38 +00:00
using Flow.Launcher.Plugin.SharedModels ;
2021-01-08 08:05:50 +00:00
using JetBrains.Annotations ;
2021-01-08 07:52:45 +00:00
using System ;
2016-03-28 00:09:40 +00:00
using System.Collections.Generic ;
2022-08-08 04:31:38 +00:00
using System.ComponentModel ;
2021-01-08 08:00:06 +00:00
using System.IO ;
2021-02-14 10:08:30 +00:00
using System.Runtime.CompilerServices ;
2021-01-08 08:00:06 +00:00
using System.Threading ;
using System.Threading.Tasks ;
2014-07-05 15:10:34 +00:00
2020-04-21 09:12:17 +00:00
namespace Flow.Launcher.Plugin
2014-07-05 15:10:34 +00:00
{
2015-01-19 11:14:02 +00:00
/// <summary>
/// Public APIs that plugin can use
/// </summary>
2014-07-05 15:10:34 +00:00
public interface IPublicAPI
{
2015-01-19 11:14:02 +00:00
/// <summary>
2020-04-21 09:12:17 +00:00
/// Change Flow.Launcher query
2015-01-19 11:14:02 +00:00
/// </summary>
/// <param name="query">query text</param>
/// <param name="requery">
2020-04-22 10:26:09 +00:00
/// force requery By default, Flow Launcher will not fire query if your query is same with existing one.
/// Set this to true to force Flow Launcher requerying
2015-01-19 11:14:02 +00:00
/// </param>
2014-07-05 15:10:34 +00:00
void ChangeQuery ( string query , bool requery = false ) ;
2015-11-26 02:04:44 +00:00
/// <summary>
2020-04-22 10:26:09 +00:00
/// Restart Flow Launcher
2021-05-16 07:14:55 +00:00
/// </summary>
2020-04-30 06:54:13 +00:00
void RestartApp ( ) ;
2021-10-09 09:36:38 +00:00
/// <summary>
2021-11-17 18:59:37 +00:00
/// Run a shell command
2021-10-09 09:36:38 +00:00
/// </summary>
/// <param name="cmd">The command or program to run</param>
2021-11-17 18:59:37 +00:00
/// <param name="filename">the shell type to run, e.g. powershell.exe</param>
2021-11-17 10:00:36 +00:00
/// <exception cref="FileNotFoundException">Thrown when unable to find the file specified in the command </exception>
/// <exception cref="Win32Exception">Thrown when error occurs during the execution of the command </exception>
2021-11-17 18:56:51 +00:00
void ShellRun ( string cmd , string filename = "cmd.exe" ) ;
2021-11-30 09:15:55 +00:00
/// <summary>
/// Copy Text to clipboard
/// </summary>
2022-08-08 04:31:38 +00:00
/// <param name="text">Text to save on clipboard</param>
2021-11-30 09:15:55 +00:00
public void CopyToClipboard ( string text ) ;
2021-10-09 09:36:38 +00:00
2019-08-22 11:37:36 +00:00
/// <summary>
2021-05-16 07:14:55 +00:00
/// Save everything, all of Flow Launcher and plugins' data and settings
2019-08-22 11:37:36 +00:00
/// </summary>
void SaveAppAllSettings ( ) ;
2021-05-13 12:49:41 +00:00
/// <summary>
2021-05-16 07:14:55 +00:00
/// Save all Flow's plugins settings
2021-05-13 12:49:41 +00:00
/// </summary>
void SavePluginSettings ( ) ;
2019-10-06 02:44:38 +00:00
/// <summary>
/// Reloads any Plugins that have the
/// IReloadable implemented. It refeshes
/// Plugin's in memory data with new content
/// added by user.
/// </summary>
2021-01-02 07:52:41 +00:00
Task ReloadAllPluginData ( ) ;
2019-10-06 02:44:38 +00:00
2020-02-25 10:08:51 +00:00
/// <summary>
2020-04-22 10:26:09 +00:00
/// Check for new Flow Launcher update
2020-02-25 10:08:51 +00:00
/// </summary>
void CheckForNewUpdate ( ) ;
2021-04-15 22:53:19 +00:00
/// <summary>
/// Show the error message using Flow's standard error icon.
/// </summary>
/// <param name="title">Message title</param>
/// <param name="subTitle">Optional message subtitle</param>
void ShowMsgError ( string title , string subTitle = "" ) ;
2021-10-17 02:28:55 +00:00
/// <summary>
/// Show the MainWindow when hiding
/// </summary>
void ShowMainWindow ( ) ;
2015-01-19 11:14:02 +00:00
/// <summary>
/// Show message box
/// </summary>
/// <param name="title">Message title</param>
/// <param name="subTitle">Message subtitle</param>
/// <param name="iconPath">Message icon path (relative path to your plugin folder)</param>
2020-03-31 11:00:09 +00:00
void ShowMsg ( string title , string subTitle = "" , string iconPath = "" ) ;
/// <summary>
/// Show message box
/// </summary>
/// <param name="title">Message title</param>
/// <param name="subTitle">Message subtitle</param>
/// <param name="iconPath">Message icon path (relative path to your plugin folder)</param>
/// <param name="useMainWindowAsOwner">when true will use main windows as the owner</param>
void ShowMsg ( string title , string subTitle , string iconPath , bool useMainWindowAsOwner = true ) ;
2014-07-05 15:10:34 +00:00
2015-01-19 11:14:02 +00:00
/// <summary>
/// Open setting dialog
/// </summary>
2016-05-22 18:16:39 +00:00
void OpenSettingDialog ( ) ;
2015-02-04 15:16:41 +00:00
2015-01-19 11:14:02 +00:00
/// <summary>
/// Get translation of current language
/// You need to implement IPluginI18n if you want to support multiple languages for your plugin
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
2015-01-06 15:24:11 +00:00
string GetTranslation ( string key ) ;
2015-01-19 11:14:02 +00:00
/// <summary>
/// Get all loaded plugins
/// </summary>
/// <returns></returns>
2014-07-05 15:10:34 +00:00
List < PluginPair > GetAllPlugins ( ) ;
2014-07-19 02:12:11 +00:00
2015-01-19 11:14:02 +00:00
/// <summary>
/// Fired after global keyboard events
/// if you want to hook something like Ctrl+R, you should use this event
/// </summary>
2021-11-27 20:26:20 +00:00
[Obsolete("Unable to Retrieve correct return value")]
2020-04-21 12:16:10 +00:00
event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent ;
2021-11-27 20:26:20 +00:00
/// <summary>
/// Register a callback for Global Keyboard Event
/// </summary>
/// <param name="callback"></param>
public void RegisterGlobalKeyboardCallback ( Func < int , int , SpecialKeyState , bool > callback ) ;
/// <summary>
/// Remove a callback for Global Keyboard Event
/// </summary>
/// <param name="callback"></param>
public void RemoveGlobalKeyboardCallback ( Func < int , int , SpecialKeyState , bool > callback ) ;
2020-12-05 08:55:06 +00:00
2021-02-14 10:25:09 +00:00
/// <summary>
2021-02-14 19:42:18 +00:00
/// Fuzzy Search the string with the given query. This is the core search mechanism Flow uses
2021-02-14 10:25:09 +00:00
/// </summary>
2021-02-14 19:42:18 +00:00
/// <param name="query">Query string</param>
/// <param name="stringToCompare">The string that will be compared against the query</param>
2021-02-14 10:25:09 +00:00
/// <returns>Match results</returns>
2021-01-08 08:00:06 +00:00
MatchResult FuzzySearch ( string query , string stringToCompare ) ;
2021-02-14 10:25:09 +00:00
/// <summary>
2021-02-14 19:42:18 +00:00
/// Http download the spefic url and return as string
2021-02-14 10:25:09 +00:00
/// </summary>
/// <param name="url">URL to call Http Get</param>
/// <param name="token">Cancellation Token</param>
/// <returns>Task to get string result</returns>
2021-01-08 08:00:06 +00:00
Task < string > HttpGetStringAsync ( string url , CancellationToken token = default ) ;
2021-02-14 10:25:09 +00:00
/// <summary>
2021-02-14 19:42:18 +00:00
/// Http download the spefic url and return as stream
2021-02-14 10:25:09 +00:00
/// </summary>
/// <param name="url">URL to call Http Get</param>
/// <param name="token">Cancellation Token</param>
/// <returns>Task to get stream result</returns>
2021-01-08 08:00:06 +00:00
Task < Stream > HttpGetStreamAsync ( string url , CancellationToken token = default ) ;
2021-01-08 08:05:50 +00:00
2021-02-14 10:25:09 +00:00
/// <summary>
/// Download the specific url to a cretain file path
/// </summary>
/// <param name="url">URL to download file</param>
2022-08-08 04:31:38 +00:00
/// <param name="filePath">path to save downloaded file</param>
2021-02-14 10:25:09 +00:00
/// <param name="token">place to store file</param>
/// <returns>Task showing the progress</returns>
2021-02-14 14:43:11 +00:00
Task HttpDownloadAsync ( [ NotNull ] string url , [ NotNull ] string filePath , CancellationToken token = default ) ;
2021-01-08 08:08:39 +00:00
2021-02-14 10:25:09 +00:00
/// <summary>
/// Add ActionKeyword for specific plugin
/// </summary>
/// <param name="pluginId">ID for plugin that needs to add action keyword</param>
/// <param name="newActionKeyword">The actionkeyword that is supposed to be added</param>
2021-01-08 08:08:39 +00:00
void AddActionKeyword ( string pluginId , string newActionKeyword ) ;
2021-02-14 10:25:09 +00:00
/// <summary>
/// Remove ActionKeyword for specific plugin
/// </summary>
/// <param name="pluginId">ID for plugin that needs to remove action keyword</param>
2022-08-08 04:31:38 +00:00
/// <param name="oldActionKeyword">The actionkeyword that is supposed to be removed</param>
2021-01-08 08:08:39 +00:00
void RemoveActionKeyword ( string pluginId , string oldActionKeyword ) ;
2022-07-01 04:56:15 +00:00
/// <summary>
/// Check whether specific ActionKeyword is assigned to any of the plugin
/// </summary>
/// <param name="actionKeyword">The actionkeyword for checking</param>
/// <returns>True if the actionkeyword is already assigned, False otherwise</returns>
bool ActionKeywordAssigned ( string actionKeyword ) ;
2021-02-14 10:25:09 +00:00
/// <summary>
2021-02-14 19:42:18 +00:00
/// Log debug message
2021-02-14 10:25:09 +00:00
/// Message will only be logged in Debug mode
/// </summary>
2021-02-14 10:08:30 +00:00
void LogDebug ( string className , string message , [ CallerMemberName ] string methodName = "" ) ;
2021-02-14 10:25:09 +00:00
/// <summary>
2021-02-14 19:42:18 +00:00
/// Log info message
2021-02-14 10:25:09 +00:00
/// </summary>
2021-02-14 10:08:30 +00:00
void LogInfo ( string className , string message , [ CallerMemberName ] string methodName = "" ) ;
2021-02-14 10:25:09 +00:00
/// <summary>
2021-02-14 19:42:18 +00:00
/// Log warning message
2021-02-14 10:25:09 +00:00
/// </summary>
2021-02-14 10:08:30 +00:00
void LogWarn ( string className , string message , [ CallerMemberName ] string methodName = "" ) ;
2021-02-14 10:25:09 +00:00
/// <summary>
2021-02-14 19:42:18 +00:00
/// Log an Exception. Will throw if in debug mode so developer will be aware,
/// otherwise logs the eror message. This is the primary logging method used for Flow
2021-02-14 10:25:09 +00:00
/// </summary>
2021-02-14 10:08:30 +00:00
void LogException ( string className , string message , Exception e , [ CallerMemberName ] string methodName = "" ) ;
2021-02-14 10:25:09 +00:00
/// <summary>
2021-05-13 11:29:21 +00:00
/// Load JsonStorage for current plugin's setting. This is the method used to load settings from json in Flow.
2021-05-13 05:37:41 +00:00
/// When the file is not exist, it will create a new instance for the specific type.
2021-02-14 10:25:09 +00:00
/// </summary>
/// <typeparam name="T">Type for deserialization</typeparam>
/// <returns></returns>
2021-05-13 11:29:21 +00:00
T LoadSettingJsonStorage < T > ( ) where T : new ( ) ;
2021-02-14 10:08:30 +00:00
2021-02-14 10:25:09 +00:00
/// <summary>
2021-05-13 11:29:21 +00:00
/// Save JsonStorage for current plugin's setting. This is the method used to save settings to json in Flow.Launcher
2021-03-27 09:26:53 +00:00
/// This method will save the original instance loaded with LoadJsonStorage.
2021-05-16 07:11:29 +00:00
/// This API call is for manually Save. Flow will automatically save all setting type that has called LoadSettingJsonStorage or SaveSettingJsonStorage previously.
2021-02-14 10:25:09 +00:00
/// </summary>
/// <typeparam name="T">Type for Serialization</typeparam>
/// <returns></returns>
2021-05-13 11:29:21 +00:00
void SaveSettingJsonStorage < T > ( ) where T : new ( ) ;
2021-11-06 00:23:09 +00:00
/// <summary>
2021-11-10 21:40:15 +00:00
/// Open directory in an explorer configured by user via Flow's Settings. The default is Windows Explorer
2021-11-06 00:23:09 +00:00
/// </summary>
/// <param name="DirectoryPath">Directory Path to open</param>
2023-03-08 10:47:49 +00:00
/// <param name="FileNameOrFilePath">Extra FileName Info</param>
public void OpenDirectory ( string DirectoryPath , string FileNameOrFilePath = null ) ;
2021-12-05 07:19:16 +00:00
2021-12-09 03:39:31 +00:00
/// <summary>
2022-02-03 21:26:42 +00:00
/// Opens the URL with the given Uri object.
/// The browser and mode used is based on what's configured in Flow's default browser settings.
/// </summary>
public void OpenUrl ( Uri url , bool? inPrivate = null ) ;
/// <summary>
/// Opens the URL with the given string.
/// The browser and mode used is based on what's configured in Flow's default browser settings.
/// Non-C# plugins should use this method.
2021-12-09 03:39:31 +00:00
/// </summary>
public void OpenUrl ( string url , bool? inPrivate = null ) ;
2022-01-30 21:34:02 +00:00
/// <summary>
2022-02-03 21:26:42 +00:00
/// Opens the application URI with the given Uri object, e.g. obsidian://search-query-example
/// </summary>
public void OpenAppUri ( Uri appUri ) ;
/// <summary>
/// Opens the application URI with the given string, e.g. obsidian://search-query-example
/// Non-C# plugins should use this method
2022-01-30 21:34:02 +00:00
/// </summary>
public void OpenAppUri ( string appUri ) ;
2014-07-05 15:10:34 +00:00
}
}