Merge pull request #427 from Flow-Launcher/MigrateDirectPluginJsonStorage

Use API call to save instead of direct call
This commit is contained in:
Jeremy Wu 2021-05-19 08:05:43 +10:00 committed by GitHub
commit be8bb8bcd1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 130 additions and 202 deletions

View file

@ -51,6 +51,7 @@ namespace Flow.Launcher.Core.Plugin
var savable = plugin.Plugin as ISavable;
savable?.Save();
}
API.SavePluginSettings();
}
public static async Task ReloadData()

View file

@ -8,7 +8,7 @@ using Flow.Launcher.Infrastructure.UserSettings;
namespace Flow.Launcher.Infrastructure.Storage
{
public class FlowLauncherJsonStorage<T> : JsonStrorage<T> where T : new()
public class FlowLauncherJsonStorage<T> : JsonStorage<T> where T : new()
{
public FlowLauncherJsonStorage()
{

View file

@ -9,7 +9,7 @@ namespace Flow.Launcher.Infrastructure.Storage
/// <summary>
/// Serialize object using json format.
/// </summary>
public class JsonStrorage<T> where T : new()
public class JsonStorage<T> where T : new()
{
protected T _data;
// need a new directory name
@ -23,10 +23,10 @@ namespace Flow.Launcher.Infrastructure.Storage
{
if (File.Exists(FilePath))
{
var searlized = File.ReadAllText(FilePath);
if (!string.IsNullOrWhiteSpace(searlized))
var serialized = File.ReadAllText(FilePath);
if (!string.IsNullOrWhiteSpace(serialized))
{
Deserialize(searlized);
Deserialize(serialized);
}
else
{
@ -40,16 +40,16 @@ namespace Flow.Launcher.Infrastructure.Storage
return _data.NonNull();
}
private void Deserialize(string searlized)
private void Deserialize(string serialized)
{
try
{
_data = JsonSerializer.Deserialize<T>(searlized);
_data = JsonSerializer.Deserialize<T>(serialized);
}
catch (JsonException e)
{
LoadDefault();
Log.Exception($"|JsonStrorage.Deserialize|Deserialize error for json <{FilePath}>", e);
Log.Exception($"|JsonStorage.Deserialize|Deserialize error for json <{FilePath}>", e);
}
if (_data == null)

View file

@ -3,13 +3,13 @@ using Flow.Launcher.Infrastructure.UserSettings;
namespace Flow.Launcher.Infrastructure.Storage
{
public class PluginJsonStorage<T> :JsonStrorage<T> where T : new()
public class PluginJsonStorage<T> :JsonStorage<T> where T : new()
{
public PluginJsonStorage()
{
// C# releated, add python releated below
// C# related, add python related below
var dataType = typeof(T);
var assemblyName = typeof(T).Assembly.GetName().Name;
var assemblyName = dataType.Assembly.GetName().Name;
DirectoryPath = Path.Combine(DataLocation.DataDirectory(), DirectoryName, Constant.Plugins, assemblyName);
Helper.ValidateDirectory(DirectoryPath);

View file

@ -30,10 +30,15 @@ namespace Flow.Launcher.Plugin
void RestartApp();
/// <summary>
/// Save all Flow Launcher settings
/// Save everything, all of Flow Launcher and plugins' data and settings
/// </summary>
void SaveAppAllSettings();
/// <summary>
/// Save all Flow's plugins settings
/// </summary>
void SavePluginSettings();
/// <summary>
/// Reloads any Plugins that have the
/// IReloadable implemented. It refeshes
@ -165,33 +170,20 @@ namespace Flow.Launcher.Plugin
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
/// 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.
/// </summary>
/// <typeparam name="T">Type for deserialization</typeparam>
/// <returns></returns>
T LoadJsonStorage<T>() where T : new();
T LoadSettingJsonStorage<T>() where T : new();
/// <summary>
/// Save JsonStorage for current plugin. This is the method used to save settings to json in Flow.Launcher
/// 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.
/// </summary>
/// <typeparam name="T">Type for Serialization</typeparam>
/// <returns></returns>
void SaveJsonStorage<T>() where T : new();
/// <summary>
/// Save JsonStorage for current plugin. This is the method used to save settings to json in Flow.Launcher
/// This method will override the original class instance loaded from LoadJsonStorage
/// </summary>
/// <typeparam name="T">Type for Serialization</typeparam>
/// <returns></returns>
void SaveJsonStorage<T>(T settings) where T : new();
/// <summary>
/// Backup the JsonStorage you loaded from LoadJsonStorage
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="settings"></param>
void BackupJsonStorage<T>() where T : new();
void SaveSettingJsonStorage<T>() where T : new();
}
}

View file

@ -1,8 +1,9 @@
namespace Flow.Launcher.Plugin
{
/// <summary>
/// Save plugin settings/cache,
/// todo should be merged into a abstract class intead of seperate interface
/// Save addtional plugin data. Inherit this interface if additional data e.g. cache needs to be saved,
/// Otherwise if LoadSettingJsonStorage or SaveSettingJsonStorage has been callded,
/// plugin settings will be automatically saved (see Flow.Launcher/PublicAPIInstance.SavePluginSettings) by Flow
/// </summary>
public interface ISavable
{

View file

@ -76,23 +76,25 @@ namespace Flow.Launcher
public void SaveAppAllSettings()
{
SavePluginSettings();
_mainVM.Save();
_settingsVM.Save();
PluginManager.Save();
ImageLoader.Save();
}
public Task ReloadAllPluginData() => PluginManager.ReloadData();
public void ShowMsgError(string title, string subTitle = "") => ShowMsg(title, subTitle, Constant.ErrorIcon, true);
public void ShowMsgError(string title, string subTitle = "") =>
ShowMsg(title, subTitle, Constant.ErrorIcon, true);
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)
{
Application.Current.Dispatcher.Invoke(() =>
{
var msg = useMainWindowAsOwner ? new Msg { Owner = Application.Current.MainWindow } : new Msg();
var msg = useMainWindowAsOwner ? new Msg {Owner = Application.Current.MainWindow} : new Msg();
msg.Show(title, subTitle, iconPath);
});
}
@ -113,61 +115,70 @@ namespace Flow.Launcher
public List<PluginPair> GetAllPlugins() => PluginManager.AllPlugins.ToList();
public MatchResult FuzzySearch(string query, string stringToCompare) => StringMatcher.FuzzySearch(query, stringToCompare);
public MatchResult FuzzySearch(string query, string stringToCompare) =>
StringMatcher.FuzzySearch(query, stringToCompare);
public Task<string> HttpGetStringAsync(string url, CancellationToken token = default) => Http.GetAsync(url);
public Task<Stream> HttpGetStreamAsync(string url, CancellationToken token = default) => Http.GetStreamAsync(url);
public Task<Stream> HttpGetStreamAsync(string url, CancellationToken token = default) =>
Http.GetStreamAsync(url);
public Task HttpDownloadAsync([NotNull] string url, [NotNull] string filePath, CancellationToken token = default) => Http.DownloadAsync(url, filePath, token);
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 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 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 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 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 void LogException(string className, string message, Exception e,
[CallerMemberName] string methodName = "") => Log.Exception(className, message, e, methodName);
private readonly Dictionary<Type, dynamic> PluginJsonStorages = new Dictionary<Type, dynamic>();
private readonly Dictionary<Type, object> _pluginJsonStorages = new();
public T LoadJsonStorage<T>() where T : new()
public void SavePluginSettings()
{
var type = typeof(T);
if (!PluginJsonStorages.ContainsKey(type))
PluginJsonStorages[type] = new PluginJsonStorage<T>();
return PluginJsonStorages[type].Load();
foreach (var value in _pluginJsonStorages.Values)
{
var method = value.GetType().GetMethod("Save");
method?.Invoke(value, null);
}
}
public void SaveJsonStorage<T>() where T : new()
public T LoadSettingJsonStorage<T>() where T : new()
{
var type = typeof(T);
if (!PluginJsonStorages.ContainsKey(type))
PluginJsonStorages[type] = new PluginJsonStorage<T>();
if (!_pluginJsonStorages.ContainsKey(type))
_pluginJsonStorages[type] = new PluginJsonStorage<T>();
PluginJsonStorages[type].Save();
return ((PluginJsonStorage<T>) _pluginJsonStorages[type]).Load();
}
public void SaveSettingJsonStorage<T>() where T : new()
{
var type = typeof(T);
if (!_pluginJsonStorages.ContainsKey(type))
_pluginJsonStorages[type] = new PluginJsonStorage<T>();
((PluginJsonStorage<T>) _pluginJsonStorages[type]).Save();
}
public void SaveJsonStorage<T>(T settings) where T : new()
{
var type = typeof(T);
PluginJsonStorages[type] = new PluginJsonStorage<T>(settings);
_pluginJsonStorages[type] = new PluginJsonStorage<T>(settings);
PluginJsonStorages[type].Save();
}
public void BackupJsonStorage<T>() where T : new()
{
var type = typeof(T);
if (!PluginJsonStorages.ContainsKey(type))
throw new InvalidOperationException("You haven't registered the JsonStorage for specific Type");
PluginJsonStorages[type].BackupOriginFile();
((PluginJsonStorage<T>) _pluginJsonStorages[type]).Save();
}
public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent;
@ -180,11 +191,12 @@ namespace Flow.Launcher
{
if (GlobalKeyboardEvent != null)
{
return GlobalKeyboardEvent((int)keyevent, vkcode, state);
return GlobalKeyboardEvent((int) keyevent, vkcode, state);
}
return true;
}
#endregion
}
}
}

View file

@ -12,21 +12,19 @@ using Flow.Launcher.Plugin.SharedCommands;
namespace Flow.Launcher.Plugin.BrowserBookmark
{
public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, ISavable, IContextMenu
public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContextMenu
{
private PluginInitContext context;
private List<Bookmark> cachedBookmarks = new List<Bookmark>();
private Settings _settings { get; set;}
private PluginJsonStorage<Settings> _storage { get; set;}
public void Init(PluginInitContext context)
{
this.context = context;
_storage = new PluginJsonStorage<Settings>();
_settings = _storage.Load();
_settings = context.API.LoadSettingJsonStorage<Settings>();
cachedBookmarks = Bookmarks.LoadAllBookmarks();
}
@ -113,11 +111,6 @@ namespace Flow.Launcher.Plugin.BrowserBookmark
return new SettingsControl(_settings);
}
public void Save()
{
_storage.Save();
}
public List<Result> LoadContextMenus(Result selectedResult)
{
return new List<Result>() {

View file

@ -4,7 +4,7 @@
"Name": "Browser Bookmarks",
"Description": "Search your browser bookmarks",
"Author": "qianlifeng, Ioannis G.",
"Version": "1.4.3",
"Version": "1.4.4",
"Language": "csharp",
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
"ExecuteFileName": "Flow.Launcher.Plugin.BrowserBookmark.dll",

View file

@ -12,7 +12,7 @@ using Flow.Launcher.Plugin.Caculator.Views;
namespace Flow.Launcher.Plugin.Caculator
{
public class Main : IPlugin, IPluginI18n, ISavable, ISettingProvider
public class Main : IPlugin, IPluginI18n, ISettingProvider
{
private static readonly Regex RegValidExpressChar = new Regex(
@"^(" +
@ -30,17 +30,11 @@ namespace Flow.Launcher.Plugin.Caculator
private static Settings _settings;
private static SettingsViewModel _viewModel;
static Main()
{
}
public void Init(PluginInitContext context)
{
Context = context;
_viewModel = new SettingsViewModel();
_settings = _viewModel.Settings;
_settings = context.API.LoadSettingJsonStorage<Settings>();
_viewModel = new SettingsViewModel(_settings);
MagesEngine = new Engine(new Configuration
{
@ -187,10 +181,5 @@ namespace Flow.Launcher.Plugin.Caculator
{
return new CalculatorSettings(_viewModel);
}
public void Save()
{
_viewModel.Save();
}
}
}

View file

@ -8,23 +8,15 @@ using Flow.Launcher.Infrastructure.UserSettings;
namespace Flow.Launcher.Plugin.Caculator.ViewModels
{
public class SettingsViewModel : BaseModel, ISavable
public class SettingsViewModel : BaseModel
{
private readonly PluginJsonStorage<Settings> _storage;
public SettingsViewModel()
public SettingsViewModel(Settings settings)
{
_storage = new PluginJsonStorage<Settings>();
Settings = _storage.Load();
Settings = settings;
}
public Settings Settings { get; set; }
public Settings Settings { get; init; }
public IEnumerable<int> MaxDecimalPlacesRange => Enumerable.Range(1, 20);
public void Save()
{
_storage.Save();
}
}
}

View file

@ -4,7 +4,7 @@
"Name": "Calculator",
"Description": "Provide mathematical calculations.(Try 5*3-2 in Flow Launcher)",
"Author": "cxfksword",
"Version": "1.1.7",
"Version": "1.1.8",
"Language": "csharp",
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
"ExecuteFileName": "Flow.Launcher.Plugin.Caculator.dll",

View file

@ -11,7 +11,7 @@ using System.Windows.Controls;
namespace Flow.Launcher.Plugin.Explorer
{
public class Main : ISettingProvider, IAsyncPlugin, ISavable, IContextMenu, IPluginI18n
public class Main : ISettingProvider, IAsyncPlugin, IContextMenu, IPluginI18n
{
internal PluginInitContext Context { get; set; }
@ -31,9 +31,11 @@ namespace Flow.Launcher.Plugin.Explorer
public async Task InitAsync(PluginInitContext context)
{
Context = context;
viewModel = new SettingsViewModel(context);
await viewModel.LoadStorage();
Settings = viewModel.Settings;
Settings = context.API.LoadSettingJsonStorage<Settings>();
viewModel = new SettingsViewModel(context, Settings);
// as at v1.7.0 this is to maintain backwards compatibility, need to be removed afterwards.
if (Settings.QuickFolderAccessLinks.Any())
@ -57,11 +59,6 @@ namespace Flow.Launcher.Plugin.Explorer
return await searchManager.SearchAsync(query, token);
}
public void Save()
{
viewModel.Save();
}
public string GetTranslatedPluginTitle()
{
return Context.API.GetTranslation("plugin_explorer_plugin_name");

View file

@ -9,27 +9,20 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
{
public class SettingsViewModel
{
private readonly PluginJsonStorage<Settings> storage;
internal Settings Settings { get; set; }
internal PluginInitContext Context { get; set; }
public SettingsViewModel(PluginInitContext context)
public SettingsViewModel(PluginInitContext context, Settings settings)
{
Context = context;
storage = new PluginJsonStorage<Settings>();
Settings = storage.Load();
Settings = settings;
}
public Task LoadStorage()
{
return Task.Run(() => Settings = storage.Load());
}
public void Save()
{
storage.Save();
Context.API.SaveSettingJsonStorage<Settings>();
}
internal void RemoveLinkFromQuickAccess(AccessLink selectedRow) => Settings.QuickAccessLinks.Remove(selectedRow);

View file

@ -7,7 +7,7 @@
"Name": "Explorer",
"Description": "Search and manage files and folders. Explorer utilises Windows Index Search",
"Author": "Jeremy Wu",
"Version": "1.7.6",
"Version": "1.7.7",
"Language": "csharp",
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
"ExecuteFileName": "Flow.Launcher.Plugin.Explorer.dll",

View file

@ -8,10 +8,11 @@ using Flow.Launcher.Infrastructure;
using System;
using System.Threading.Tasks;
using System.Threading;
using System.Windows;
namespace Flow.Launcher.Plugin.PluginsManager
{
public class Main : ISettingProvider, IAsyncPlugin, ISavable, IContextMenu, IPluginI18n, IAsyncReloadable
public class Main : ISettingProvider, IAsyncPlugin, IContextMenu, IPluginI18n, IAsyncReloadable
{
internal PluginInitContext Context { get; set; }
@ -33,8 +34,8 @@ namespace Flow.Launcher.Plugin.PluginsManager
public Task InitAsync(PluginInitContext context)
{
Context = context;
viewModel = new SettingsViewModel(context);
Settings = viewModel.Settings;
Settings = context.API.LoadSettingJsonStorage<Settings>();
viewModel = new SettingsViewModel(context, Settings);
contextMenu = new ContextMenu(Context);
pluginManager = new PluginsManager(Context, Settings);
_ = pluginManager.UpdateManifest().ContinueWith(_ =>
@ -78,11 +79,6 @@ namespace Flow.Launcher.Plugin.PluginsManager
};
}
public void Save()
{
viewModel.Save();
}
public string GetTranslatedPluginTitle()
{
return Context.API.GetTranslation("plugin_pluginsmanager_plugin_name");

View file

@ -3,24 +3,16 @@ using Flow.Launcher.Infrastructure.UserSettings;
namespace Flow.Launcher.Plugin.PluginsManager.ViewModels
{
public class SettingsViewModel
internal class SettingsViewModel
{
private readonly PluginJsonStorage<Settings> storage;
internal Settings Settings { get; set; }
internal PluginInitContext Context { get; set; }
public SettingsViewModel(PluginInitContext context)
public SettingsViewModel(PluginInitContext context, Settings settings)
{
Context = context;
storage = new PluginJsonStorage<Settings>();
Settings = storage.Load();
}
public void Save()
{
storage.Save();
Settings = settings;
}
}
}

View file

@ -10,7 +10,7 @@ namespace Flow.Launcher.Plugin.PluginsManager.Views
{
private readonly SettingsViewModel viewModel;
public PluginsManagerSettings(SettingsViewModel viewModel)
internal PluginsManagerSettings(SettingsViewModel viewModel)
{
InitializeComponent();

View file

@ -6,7 +6,7 @@
"Name": "Plugins Manager",
"Description": "Management of installing, uninstalling or updating Flow Launcher plugins",
"Author": "Jeremy Wu",
"Version": "1.8.0",
"Version": "1.8.1",
"Language": "csharp",
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
"ExecuteFileName": "Flow.Launcher.Plugin.PluginsManager.dll",

View file

@ -25,16 +25,14 @@ namespace Flow.Launcher.Plugin.Program
private static BinaryStorage<Win32[]> _win32Storage;
private static BinaryStorage<UWP.Application[]> _uwpStorage;
private readonly PluginJsonStorage<Settings> _settingsStorage;
public Main()
{
_settingsStorage = new PluginJsonStorage<Settings>();
}
public void Save()
{
_settingsStorage.Save();
_win32Storage.Save(_win32s);
_uwpStorage.Save(_uwps);
}
@ -71,7 +69,7 @@ namespace Flow.Launcher.Plugin.Program
{
_context = context;
_settings = _settingsStorage.Load();
_settings = context.API.LoadSettingJsonStorage<Settings>();
await Task.Yield();

View file

@ -4,7 +4,7 @@
"Name": "Program",
"Description": "Search programs in Flow.Launcher",
"Author": "qianlifeng",
"Version": "1.4.5",
"Version": "1.4.6",
"Language": "csharp",
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
"ExecuteFileName": "Flow.Launcher.Plugin.Program.dll",

View file

@ -18,27 +18,14 @@ using Keys = System.Windows.Forms.Keys;
namespace Flow.Launcher.Plugin.Shell
{
public class Main : IPlugin, ISettingProvider, IPluginI18n, IContextMenu, ISavable
public class Main : IPlugin, ISettingProvider, IPluginI18n, IContextMenu
{
private const string Image = "Images/shell.png";
private PluginInitContext context;
private bool _winRStroked;
private readonly KeyboardSimulator _keyboardSimulator = new KeyboardSimulator(new InputSimulator());
private readonly Settings _settings;
private readonly PluginJsonStorage<Settings> _storage;
public Main()
{
_storage = new PluginJsonStorage<Settings>();
_settings = _storage.Load();
}
public void Save()
{
_storage.Save();
}
private Settings _settings;
public List<Result> Query(Query query)
{
@ -285,6 +272,7 @@ namespace Flow.Launcher.Plugin.Shell
{
this.context = context;
context.API.GlobalKeyboardEvent += API_GlobalKeyboardEvent;
_settings = context.API.LoadSettingJsonStorage<Settings>();
}
bool API_GlobalKeyboardEvent(int keyevent, int vkcode, SpecialKeyState state)

View file

@ -4,7 +4,7 @@
"Name": "Shell",
"Description": "Provide executing commands from Flow Launcher",
"Author": "qianlifeng",
"Version": "1.4.0",
"Version": "1.4.1",
"Language": "csharp",
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
"ExecuteFileName": "Flow.Launcher.Plugin.Shell.dll",

View file

@ -7,7 +7,7 @@ using Flow.Launcher.Plugin.SharedCommands;
namespace Flow.Launcher.Plugin.Url
{
public class Main : ISettingProvider,IPlugin, IPluginI18n, ISavable
public class Main : ISettingProvider,IPlugin, IPluginI18n
{
//based on https://gist.github.com/dperini/729294
private const string urlPattern = "^" +
@ -44,20 +44,9 @@ namespace Flow.Launcher.Plugin.Url
"$";
Regex reg = new Regex(urlPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
private PluginInitContext context;
private readonly Settings _settings;
private readonly PluginJsonStorage<Settings> _storage;
public Main()
{
_storage = new PluginJsonStorage<Settings>();
_settings = _storage.Load();
}
public void Save()
{
_storage.Save();
}
private Settings _settings;
public List<Result> Query(Query query)
{
var raw = query.Search;
@ -128,6 +117,8 @@ namespace Flow.Launcher.Plugin.Url
public void Init(PluginInitContext context)
{
this.context = context;
_settings = context.API.LoadSettingJsonStorage<Settings>();
}
public string GetTranslatedPluginTitle()

View file

@ -4,7 +4,7 @@
"Name": "URL",
"Description": "Open the typed URL from Flow Launcher",
"Author": "qianlifeng",
"Version": "1.1.5",
"Version": "1.1.6",
"Language": "csharp",
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
"ExecuteFileName": "Flow.Launcher.Plugin.Url.dll",

View file

@ -14,12 +14,12 @@ using Flow.Launcher.Plugin.SharedCommands;
namespace Flow.Launcher.Plugin.WebSearch
{
public class Main : IAsyncPlugin, ISettingProvider, IPluginI18n, ISavable, IResultUpdated
public class Main : IAsyncPlugin, ISettingProvider, IPluginI18n, IResultUpdated
{
private PluginInitContext _context;
private readonly Settings _settings;
private readonly SettingsViewModel _viewModel;
private Settings _settings;
private SettingsViewModel _viewModel;
internal const string Images = "Images";
internal static string DefaultImagesDirectory;
@ -31,10 +31,6 @@ namespace Flow.Launcher.Plugin.WebSearch
private readonly string SearchSourceGlobalPluginWildCardSign = "*";
public void Save()
{
_viewModel.Save();
}
public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
{
@ -164,12 +160,6 @@ namespace Flow.Launcher.Plugin.WebSearch
return new List<Result>();
}
public Main()
{
_viewModel = new SettingsViewModel();
_settings = _viewModel.Settings;
}
public Task InitAsync(PluginInitContext context)
{
return Task.Run(Init);
@ -177,6 +167,10 @@ namespace Flow.Launcher.Plugin.WebSearch
void Init()
{
_context = context;
_settings = _context.API.LoadSettingJsonStorage<Settings>();
_viewModel = new SettingsViewModel(_settings);
var pluginDirectory = _context.CurrentPluginMetadata.PluginDirectory;
var bundledImagesDirectory = Path.Combine(pluginDirectory, Images);

View file

@ -6,13 +6,12 @@ namespace Flow.Launcher.Plugin.WebSearch
{
private readonly PluginJsonStorage<Settings> _storage;
public SettingsViewModel()
public SettingsViewModel(Settings settings)
{
_storage = new PluginJsonStorage<Settings>();
Settings = _storage.Load();
Settings = settings;
}
public Settings Settings { get; set; }
public Settings Settings { get; }
public void Save()
{

View file

@ -26,7 +26,7 @@
"Name": "Web Searches",
"Description": "Provide the web search ability",
"Author": "qianlifeng",
"Version": "1.3.8",
"Version": "1.3.9",
"Language": "csharp",
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
"ExecuteFileName": "Flow.Launcher.Plugin.WebSearch.dll",