Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Flow.Launcher.Infrastructure/Storage/JsonStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Flow.Launcher.Infrastructure.Storage
public class JsonStrorage<T> where T : new()
{
private readonly JsonSerializerOptions _serializerSettings;
private T _data;
protected T _data;
// need a new directory name
public const string DirectoryName = "Settings";
public const string FileSuffix = ".json";
Expand Down
5 changes: 5 additions & 0 deletions Flow.Launcher.Infrastructure/Storage/PluginJsonStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ public PluginJsonStorage()

FilePath = Path.Combine(DirectoryPath, $"{dataType.Name}{FileSuffix}");
}

public PluginJsonStorage(T data) : this()
{
_data = data;
}
}
}
72 changes: 71 additions & 1 deletion Flow.Launcher.Plugin/IPublicAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -88,17 +89,86 @@ public interface IPublicAPI
/// </summary>
event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent;

/// <summary>
/// Fuzzy Search the string with the given query. This is the core search mechanism Flow uses
/// </summary>
/// <param name="query">Query string</param>
/// <param name="stringToCompare">The string that will be compared against the query</param>
/// <returns>Match results</returns>
MatchResult FuzzySearch(string query, string stringToCompare);

/// <summary>
/// Http download the spefic url and return as string
/// </summary>
/// <param name="url">URL to call Http Get</param>
/// <param name="token">Cancellation Token</param>
/// <returns>Task to get string result</returns>
Task<string> HttpGetStringAsync(string url, CancellationToken token = default);

/// <summary>
/// Http download the spefic url and return as stream
/// </summary>
/// <param name="url">URL to call Http Get</param>
/// <param name="token">Cancellation Token</param>
/// <returns>Task to get stream result</returns>
Task<Stream> HttpGetStreamAsync(string url, CancellationToken token = default);

Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath);
/// <summary>
/// Download the specific url to a cretain file path
/// </summary>
/// <param name="url">URL to download file</param>
/// <param name="token">place to store file</param>
/// <returns>Task showing the progress</returns>
Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath, CancellationToken token = default);

/// <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>
void AddActionKeyword(string pluginId, string newActionKeyword);

/// <summary>
/// Remove ActionKeyword for specific plugin
/// </summary>
/// <param name="pluginId">ID for plugin that needs to remove action keyword</param>
/// <param name="newActionKeyword">The actionkeyword that is supposed to be removed</param>
void RemoveActionKeyword(string pluginId, string oldActionKeyword);

/// <summary>
/// Log debug message
/// Message will only be logged in Debug mode
/// </summary>
void LogDebug(string className, string message, [CallerMemberName] string methodName = "");

/// <summary>
/// Log info message
/// </summary>
void LogInfo(string className, string message, [CallerMemberName] string methodName = "");

/// <summary>
/// Log warning message
/// </summary>
void LogWarn(string className, string message, [CallerMemberName] string methodName = "");

/// <summary>
/// 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
/// </summary>
void LogException(string className, string message, Exception e, [CallerMemberName] string methodName = "");

/// <summary>
/// Load JsonStorage for current plugin. This is the method used to load settings from json in Flow
/// </summary>
/// <typeparam name="T">Type for deserialization</typeparam>
/// <returns></returns>
T LoadJsonStorage<T>() where T : new();

/// <summary>
/// Save JsonStorage for current plugin. This is the method used to save settings to json in Flow
/// </summary>
/// <typeparam name="T">Type for Serialization</typeparam>
/// <returns></returns>
void SaveJsonStorage<T>(T setting) where T : new();
}
}
85 changes: 31 additions & 54 deletions Flow.Launcher/PublicAPIInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
using System.IO;
using Flow.Launcher.Infrastructure.Http;
using JetBrains.Annotations;
using System.Runtime.CompilerServices;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Infrastructure.Storage;

namespace Flow.Launcher
{
Expand Down Expand Up @@ -67,15 +70,9 @@ public void RestartApp()
UpdateManager.RestartApp(Constant.ApplicationFileName);
}

public void RestarApp()
{
RestartApp();
}
public void RestarApp() => RestartApp();

public void CheckForNewUpdate()
{
_settingsVM.UpdateApp();
}
public void CheckForNewUpdate() => _settingsVM.UpdateApp();

public void SaveAppAllSettings()
{
Expand All @@ -85,15 +82,9 @@ public void SaveAppAllSettings()
ImageLoader.Save();
}

public Task ReloadAllPluginData()
{
return PluginManager.ReloadData();
}
public Task ReloadAllPluginData() => PluginManager.ReloadData();

public void ShowMsg(string title, string subTitle = "", string iconPath = "")
{
ShowMsg(title, subTitle, iconPath, true);
}
public void ShowMsg(string title, string subTitle = "", string iconPath = "") => ShowMsg(title, subTitle, iconPath, true);

public void ShowMsg(string title, string subTitle, string iconPath, bool useMainWindowAsOwner = true)
{
Expand All @@ -112,54 +103,40 @@ public void OpenSettingDialog()
});
}

public void StartLoadingBar()
{
_mainVM.ProgressBarVisibility = Visibility.Visible;
}
public void StartLoadingBar() => _mainVM.ProgressBarVisibility = Visibility.Visible;

public void StopLoadingBar()
{
_mainVM.ProgressBarVisibility = Visibility.Collapsed;
}
public void StopLoadingBar() => _mainVM.ProgressBarVisibility = Visibility.Collapsed;

public string GetTranslation(string key)
{
return InternationalizationManager.Instance.GetTranslation(key);
}
public string GetTranslation(string key) => InternationalizationManager.Instance.GetTranslation(key);

public List<PluginPair> GetAllPlugins()
{
return PluginManager.AllPlugins.ToList();
}

public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent;
public List<PluginPair> GetAllPlugins() => PluginManager.AllPlugins.ToList();

public MatchResult FuzzySearch(string query, string stringToCompare) => StringMatcher.FuzzySearch(query, stringToCompare);

public Task<string> HttpGetStringAsync(string url, CancellationToken token = default)
{
return Http.GetAsync(url);
}
public Task<string> HttpGetStringAsync(string url, CancellationToken token = default) => Http.GetAsync(url);

public Task<Stream> HttpGetStreamAsync(string url, CancellationToken token = default)
{
return Http.GetStreamAsync(url);
}
public Task<Stream> HttpGetStreamAsync(string url, CancellationToken token = default) => Http.GetStreamAsync(url);

public Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath)
{
return Http.DownloadAsync(url, filePath);
}
public Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath, CancellationToken token = default) => Http.DownloadAsync(url, filePath, token);

public void AddActionKeyword(string pluginId, string newActionKeyword)
{
PluginManager.AddActionKeyword(pluginId, newActionKeyword);
}
public void AddActionKeyword(string pluginId, string newActionKeyword) => PluginManager.AddActionKeyword(pluginId, newActionKeyword);

public void RemoveActionKeyword(string pluginId, string oldActionKeyword) => PluginManager.RemoveActionKeyword(pluginId, oldActionKeyword);

public void LogDebug(string className, string message, [CallerMemberName] string methodName = "") => Log.Debug(className, message, methodName);

public void LogInfo(string className, string message, [CallerMemberName] string methodName = "") => Log.Info(className, message, methodName);

public void LogWarn(string className, string message, [CallerMemberName] string methodName = "") => Log.Warn(className, message, methodName);

public void LogException(string className, string message, Exception e, [CallerMemberName] string methodName = "") => Log.Exception(className, message, e, methodName);

public T LoadJsonStorage<T>() where T : new() => new PluginJsonStorage<T>().Load();

public void SaveJsonStorage<T>(T setting) where T : new() => new PluginJsonStorage<T>(setting).Save();

public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent;

public void RemoveActionKeyword(string pluginId, string oldActionKeyword)
{
PluginManager.RemoveActionKeyword(pluginId, oldActionKeyword);
}
#endregion

#region Private Methods
Expand Down