-
-
Notifications
You must be signed in to change notification settings - Fork 455
Use API call to save instead of direct call #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Flow.Launcher/PublicAPIInstance.cs
Outdated
| 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 Dictionary<Type, object>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dynamic seems not working as intended, so I move back to direct cast
|
Did you want me to review and merge, or you still working on the other two todos? |
still working on it. There are a few things that need to be cleaned up. |
|
I didn't find a better way to replace the Dictionary<Type, object> and reflection for registration. So just review the current one. |
|
Version bumps for plugins please :) |
Sure |
| public void Save() | ||
| { | ||
| _storage.Save(); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this removed? settings still needs to be saved right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add a auto save for all registered jsonstorage, so that we don't need to configure isavable for setting, unless they are going to save something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flow.Launcher/Flow.Launcher/PublicAPIInstance.cs
Lines 139 to 146 in b37f9f3
| private void SaveAllJsonStorage() | |
| { | |
| foreach (var value in _pluginJsonStorages.Values) | |
| { | |
| var method = value.GetType().GetMethod("Save"); | |
| method?.Invoke(value, null); | |
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
would this not be a doubling up then, with PluginManager.Save() call?
-
also you need to move this SaveAllJsonStorage() call to here right so when Flow's settings window closed you want to save all plugin settings:
Flow.Launcher/Flow.Launcher/ViewModel/SettingWindowViewModel.cs
Lines 85 to 97 in 9d4af83
public void Save() { foreach (var vm in PluginViewModels) { var id = vm.PluginPair.Metadata.ID; Settings.PluginSettings.Plugins[id].Disabled = vm.PluginPair.Metadata.Disabled; Settings.PluginSettings.Plugins[id].Priority = vm.Priority; } PluginManager.Save(); _storage.Save(); }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- do we want to remove ISavable?
- if it's auto saved, might want to document it somewhere right? for those that develop plugins
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this method is called in SaveAllJsonStorage, so it is impossible to directly call that method here, or else will become infinity recurse.
The call for
PluginManager.Save();
_storage.Save(); do save all plugin setting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i see. hmm how do save plugin settings when user closes settings window? PluginManager.Save() only saves plugin settings where the interface ISavable is applied and _storage.Save() saves Flow's own settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of passing the api to the view, which is not even used, we can and should pass it to the viewmodel, this then allows you to call save plugin settings seperately from the view
| public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PluginManager.Save() only saves plugin settings where the interface ISavable is applied and _storage.Save() saves Flow's own settings.
I have modified PluginManager.Save() to include saving plugins settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static void Save()
{
foreach (var plugin in AllPlugins)
{
var savable = plugin.Plugin as ISavable;
savable?.Save();
}
API.SavePluginSettings();
}|
Not related to this change but I think we should update the comment to give an example scenario where you will need to override the original class instance, i.e. use the override save method and when you just need to use save the original instance. Since you are in this space maybe you could just give a good explanation in the comment that would be awesome. Flow.Launcher/Flow.Launcher.Plugin/IPublicAPI.cs Lines 174 to 188 in b37f9f3
|
|
I have updated the comment. In fact, I don't believe we may actually need the one to overwrite it, because the supposed process is to load and use the loaded file (which will be a new when none exist), and save the original one. Should we remove it? Also, do you think we should modify the name specifically to setting because the file will be stored inside the setting folder. By the way, would you please give me the access for OAuth from Jetbrains IDE integration? Sometimes I may use rider instead of Visual Studio or vscode. Thank you! |
Done |
i am unsure when there will be a circumstance where we needed to save a new instance to the original, so i would say yes
yes |
Thank you! |
| /// <summary> | ||
| /// Save Flow's plugins settings | ||
| /// </summary> | ||
| void SavePluginSettings(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the difference between this method and SaveSettingJsonStorage()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SaveSettingJsonStorage is for a specific Type (or T as generic), but this is for all plugin.
Flow.Launcher.Plugin/IPublicAPI.cs
Outdated
| /// 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 that has registered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it will be better to also explain how setting gets registered in the comment so plugin devs do not need to dig into code to find out.
…cher/Flow.Launcher into MigrateDirectPluginJsonStorage
| public void Save() | ||
| { | ||
| storage.Save(); | ||
| Context.API.SaveSettingJsonStorage<Settings>(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one more question, why does this have to call the save directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explorer plugin contains a call for save every time a new item in its setting is edited. I didn't change it.
It is not ISavable, so I believe it won't be called twice. However, do you think we should remove that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh right, it's not ISavable, just calls infra's save directly. Nah don't worry about it for this PR, using the API is at least better. Let's get this merged in.
close #388
TODO: