using Flow.Launcher.Plugin.SharedModels; using JetBrains.Annotations; using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using System.Windows; namespace Flow.Launcher.Plugin { /// /// Public APIs that plugin can use /// public interface IPublicAPI { /// /// Change Flow.Launcher query. /// When current results are from context menu or history, it will go back to query results before changing query. /// /// query text /// /// Force requery. By default, Flow Launcher will not fire query if your query is same with existing one. /// Set this to to force Flow Launcher requerying /// void ChangeQuery(string query, bool requery = false); /// /// Restart Flow Launcher /// void RestartApp(); /// /// Run a shell command /// /// The command or program to run /// the shell type to run, e.g. powershell.exe /// Thrown when unable to find the file specified in the command /// Thrown when error occurs during the execution of the command void ShellRun(string cmd, string filename = "cmd.exe"); /// /// Copies the passed in text and shows a message indicating whether the operation was completed successfully. /// When directCopy is set to true and passed in text is the path to a file or directory, /// the actual file/directory will be copied to clipboard. Otherwise the text itself will still be copied to clipboard. /// /// Text to save on clipboard /// When true it will directly copy the file/folder from the path specified in text /// Whether to show the default notification from this method after copy is done. /// It will show file/folder/text is copied successfully. /// Turn this off to show your own notification after copy is done.> public void CopyToClipboard(string text, bool directCopy = false, bool showDefaultNotification = true); /// /// Save everything, all of Flow Launcher and plugins' data and settings /// void SaveAppAllSettings(); /// /// Save all Flow's plugins settings /// void SavePluginSettings(); /// /// Reloads any Plugins that have the /// IReloadable implemented. It refeshes /// Plugin's in memory data with new content /// added by user. /// Task ReloadAllPluginData(); /// /// Check for new Flow Launcher update /// void CheckForNewUpdate(); /// /// Show the error message using Flow's standard error icon. /// /// Message title /// Optional message subtitle void ShowMsgError(string title, string subTitle = ""); /// /// Show the MainWindow when hiding /// void ShowMainWindow(); /// /// Hide MainWindow /// void HideMainWindow(); /// /// Representing whether the main window is visible /// /// bool IsMainWindowVisible(); /// /// Invoked when the visibility of the main window has changed. Currently, the plugin will continue to be subscribed even if it is turned off. /// event VisibilityChangedEventHandler VisibilityChanged; /// /// Show message box /// /// Message title /// Message subtitle /// Message icon path (relative path to your plugin folder) void ShowMsg(string title, string subTitle = "", string iconPath = ""); /// /// Show message box /// /// Message title /// Message subtitle /// Message icon path (relative path to your plugin folder) /// when true will use main windows as the owner void ShowMsg(string title, string subTitle, string iconPath, bool useMainWindowAsOwner = true); /// /// Open setting dialog /// void OpenSettingDialog(); /// /// Get translation of current language /// You need to implement IPluginI18n if you want to support multiple languages for your plugin /// /// /// string GetTranslation(string key); /// /// Get all loaded plugins /// /// List GetAllPlugins(); /// /// Register a callback for Global Keyboard Event /// /// public void RegisterGlobalKeyboardCallback(Func callback); /// /// Remove a callback for Global Keyboard Event /// /// public void RemoveGlobalKeyboardCallback(Func callback); /// /// Fuzzy Search the string with the given query. This is the core search mechanism Flow uses /// /// Query string /// The string that will be compared against the query /// Match results MatchResult FuzzySearch(string query, string stringToCompare); /// /// Http download the spefic url and return as string /// /// URL to call Http Get /// Cancellation Token /// Task to get string result Task HttpGetStringAsync(string url, CancellationToken token = default); /// /// Http download the spefic url and return as stream /// /// URL to call Http Get /// Cancellation Token /// Task to get stream result Task HttpGetStreamAsync(string url, CancellationToken token = default); /// /// Download the specific url to a cretain file path /// /// URL to download file /// path to save downloaded file /// /// Action to report progress. The input of the action is the progress value which is a double value between 0 and 100. /// It will be called if url support range request and the reportProgress is not null. /// /// place to store file /// Task showing the progress Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath, Action reportProgress = null, CancellationToken token = default); /// /// Add ActionKeyword for specific plugin /// /// ID for plugin that needs to add action keyword /// The actionkeyword that is supposed to be added void AddActionKeyword(string pluginId, string newActionKeyword); /// /// Remove ActionKeyword for specific plugin /// /// ID for plugin that needs to remove action keyword /// The actionkeyword that is supposed to be removed void RemoveActionKeyword(string pluginId, string oldActionKeyword); /// /// Check whether specific ActionKeyword is assigned to any of the plugin /// /// The actionkeyword for checking /// True if the actionkeyword is already assigned, False otherwise bool ActionKeywordAssigned(string actionKeyword); /// /// Log debug message /// Message will only be logged in Debug mode /// void LogDebug(string className, string message, [CallerMemberName] string methodName = ""); /// /// Log info message /// void LogInfo(string className, string message, [CallerMemberName] string methodName = ""); /// /// Log warning message /// void LogWarn(string className, string message, [CallerMemberName] string methodName = ""); /// /// 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 /// void LogException(string className, string message, Exception e, [CallerMemberName] string methodName = ""); /// /// Load JsonStorage for current plugin's setting. This is the method used to load settings from json in Flow. /// When the file is not exist, it will create a new instance for the specific type. /// /// Type for deserialization /// T LoadSettingJsonStorage() where T : new(); /// /// Save JsonStorage for current plugin's setting. This is the method used to save settings to json in Flow.Launcher /// This method will save the original instance loaded with LoadJsonStorage. /// This API call is for manually Save. Flow will automatically save all setting type that has called LoadSettingJsonStorage or SaveSettingJsonStorage previously. /// /// Type for Serialization /// void SaveSettingJsonStorage() where T : new(); /// /// Open directory in an explorer configured by user via Flow's Settings. The default is Windows Explorer /// /// Directory Path to open /// Extra FileName Info public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null); /// /// 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. /// public void OpenUrl(Uri url, bool? inPrivate = null); /// /// 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. /// public void OpenUrl(string url, bool? inPrivate = null); /// /// Opens the application URI with the given Uri object, e.g. obsidian://search-query-example /// public void OpenAppUri(Uri appUri); /// /// Opens the application URI with the given string, e.g. obsidian://search-query-example /// Non-C# plugins should use this method /// public void OpenAppUri(string appUri); /// /// Toggles Game Mode. off -> on and backwards /// public void ToggleGameMode(); /// /// Switches Game Mode to given value /// /// New Game Mode status public void SetGameMode(bool value); /// /// Representing Game Mode status /// /// public bool IsGameModeOn(); /// /// Reloads the query. /// When current results are from context menu or history, it will go back to query results before requerying. /// /// Choose the first result after reload if true; keep the last selected result if false. Default is true. public void ReQuery(bool reselect = true); /// /// Back to the query results. /// This method should run when selected item is from context menu or history. /// public void BackToQueryResults(); /// /// Displays a standardised Flow message box. /// /// The message of the message box. /// The caption of the message box. /// Specifies which button or buttons to display. /// Specifies the icon to display. /// Specifies the default result of the message box. /// Specifies which message box button is clicked by the user. public MessageBoxResult ShowMsgBox(string messageBoxText, string caption = "", MessageBoxButton button = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.OK); /// /// Displays a standardised Flow message box. /// If there is issue when showing the message box, it will return null. /// /// The caption of the message box. /// /// Time-consuming task function, whose input is the action to report progress. /// The input of the action is the progress value which is a double value between 0 and 100. /// If there are any exceptions, this action will be null. /// /// When user closes the progress box manually by button or esc key, this action will be called. /// A progress box interface. public Task ShowProgressBoxAsync(string caption, Func, Task> reportProgressAsync, Action forceClosed = null); } }