using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using Flow.Launcher.Plugin; using Flow.Launcher.Plugin.SharedModels; namespace Flow.Launcher.Core.Plugin.JsonRPCV2Models { public class JsonRPCPublicAPI { private IPublicAPI _api; public JsonRPCPublicAPI(IPublicAPI api) { _api = api; } /// /// Change Flow.Launcher 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 /// public void ChangeQuery(string query, bool requery = false) { _api.ChangeQuery(query, requery); } /// /// Restart Flow Launcher /// public void RestartApp() { _api.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 public void ShellRun(string cmd, string filename = "cmd.exe") { _api.ShellRun(cmd, filename); } /// /// 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) { _api.CopyToClipboard(text, directCopy, showDefaultNotification); } /// /// Save everything, all of Flow Launcher and plugins' data and settings /// public void SaveAppAllSettings() { _api.SaveAppAllSettings(); } /// /// Save all Flow's plugins settings /// public void SavePluginSettings() { _api.SavePluginSettings(); } /// /// Reloads any Plugins that have the /// IReloadable implemented. It refeshes /// Plugin's in memory data with new content /// added by user. /// public Task ReloadAllPluginDataAsync() { return _api.ReloadAllPluginData(); } /// /// Check for new Flow Launcher update /// public void CheckForNewUpdate() { _api.CheckForNewUpdate(); } /// /// Show the error message using Flow's standard error icon. /// /// Message title /// Optional message subtitle public void ShowMsgError(string title, string subTitle = "") { _api.ShowMsgError(title, subTitle); } /// /// Show the MainWindow when hiding /// public void ShowMainWindow() { _api.ShowMainWindow(); } /// /// Hide MainWindow /// public void HideMainWindow() { _api.HideMainWindow(); } /// /// Representing whether the main window is visible /// /// public bool IsMainWindowVisible() { return _api.IsMainWindowVisible(); } /// /// Show message box /// /// Message title /// Message subtitle /// Message icon path (relative path to your plugin folder) public void ShowMsg(string title, string subTitle = "", string iconPath = "") { _api.ShowMsg(title, subTitle, 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 public void ShowMsg(string title, string subTitle, string iconPath, bool useMainWindowAsOwner = true) { _api.ShowMsg(title, subTitle, iconPath, useMainWindowAsOwner); } /// /// Open setting dialog /// public void OpenSettingDialog() { _api.OpenSettingDialog(); } /// /// Get translation of current language /// You need to implement IPluginI18n if you want to support multiple languages for your plugin /// /// /// public string GetTranslation(string key) { return _api.GetTranslation(key); } /// /// Get all loaded plugins /// /// public List GetAllPlugins() { return _api.GetAllPlugins(); } /// /// 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 public MatchResult FuzzySearch(string query, string stringToCompare) { return _api.FuzzySearch(query, stringToCompare); } /// /// Http download the spefic url and return as string /// /// URL to call Http Get /// Cancellation Token /// Task to get string result public Task HttpGetStringAsync(string url, CancellationToken token = default) { return _api.HttpGetStringAsync(url, token); } /// /// Http download the spefic url and return as stream /// /// URL to call Http Get /// Cancellation Token /// Task to get stream result public Task HttpGetStreamAsync(string url, CancellationToken token = default) { return _api.HttpGetStreamAsync(url, token); } /// /// Download the specific url to a cretain file path /// /// URL to download file /// path to save downloaded file /// place to store file /// Task showing the progress public Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath, CancellationToken token = default) { return _api.HttpDownloadAsync(url, filePath, token); } /// /// Add ActionKeyword for specific plugin /// /// ID for plugin that needs to add action keyword /// The actionkeyword that is supposed to be added public void AddActionKeyword(string pluginId, string newActionKeyword) { _api.AddActionKeyword(pluginId, newActionKeyword); } /// /// Remove ActionKeyword for specific plugin /// /// ID for plugin that needs to remove action keyword /// The actionkeyword that is supposed to be removed public void RemoveActionKeyword(string pluginId, string oldActionKeyword) { _api.RemoveActionKeyword(pluginId, 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 public bool ActionKeywordAssigned(string actionKeyword) { return _api.ActionKeywordAssigned(actionKeyword); } /// /// Log debug message /// Message will only be logged in Debug mode /// public void LogDebug(string className, string message, [CallerMemberName] string methodName = "") { _api.LogDebug(className, message, methodName); } /// /// Log info message /// public void LogInfo(string className, string message, [CallerMemberName] string methodName = "") { _api.LogInfo(className, message, methodName); } /// /// Log warning message /// public void LogWarn(string className, string message, [CallerMemberName] string methodName = "") { _api.LogWarn(className, message, methodName); } /// /// 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) { _api.OpenDirectory(DirectoryPath, FileNameOrFilePath); } /// /// 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) { _api.OpenUrl(url, inPrivate); } /// /// 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) { _api.OpenAppUri(appUri); } } }