Use API call to save instead of direct call#427
Conversation
Flow.Launcher/PublicAPIInstance.cs
Outdated
There was a problem hiding this comment.
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.
why is this removed? settings still needs to be saved right?
There was a problem hiding this comment.
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.
Flow.Launcher/Flow.Launcher/PublicAPIInstance.cs
Lines 139 to 146 in b37f9f3
There was a problem hiding this comment.
-
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
There was a problem hiding this comment.
- 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.
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.
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.
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
There was a problem hiding this comment.
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.
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.
what's the difference between this method and SaveSettingJsonStorage()?
There was a problem hiding this comment.
SaveSettingJsonStorage is for a specific Type (or T as generic), but this is for all plugin.
Flow.Launcher.Plugin/IPublicAPI.cs
Outdated
There was a problem hiding this comment.
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.
one more question, why does this have to call the save directly?
There was a problem hiding this comment.
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.
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: