korapp / plasma-homeassistant

Add Home Assistant to your plasma desktop
GNU General Public License v3.0
57 stars 4 forks source link

Suggestion: Persistent items #12

Closed jhakonen closed 5 months ago

jhakonen commented 9 months ago

Would it be possible to have items be more persistent? So that when you delete a widget where the items are in, those items would not get deleted as well? As it is, its quite easy to delete a widget and not realize that those items you spent quite a bit of time to configure, would disappear as well.

korapp commented 9 months ago

Technically, yes, but currently I don't see a reasonable solution. Natively, the Plasmoid configuration is stored per instance and managed by Plasma. To make it persistent, the plasmoid should have its own configuration mechanism implemented, but:

  1. for only 1 instance of plasmoid is easy. E.g. store the configuration in a single file (which survives deletion of the plasmoid) and read it when a new instance is created. Unfortunately, this is not the case.
  2. storing the configuration per instance brings us back to the beginning: deleting plasmoid loses its connection to the configuration.
  3. however, since the configuration itself would remain, the newly created plasmoid could, for example, suggest importing the old configuration from the list.
  4. we end up with a file containing every configuration ever created by the user, even if one decided to get rid of the plasmoid permanently.

    How about an intermediate solution - adding a text editor as an alternative configuration method? It won't be exactly what you suggest, but at least you'll have copy/paste capability.

jhakonen commented 9 months ago

As in a text editor embedded in to the configuration dialog? That could work indeed. Although I think it might pretty taunting for new users to see that config editor and not being sure what they are supposed to do with it. Would you need to also document its schema so that users would know how to modify it? Also, the config would be lost if you remove the plasmoid instance without remembering to take a backup before, right?

As an alternative could this be instead an import/export functionality? Like see "Advanced Radio Player" plasmoid, it has similar item list that yours have where you can add/edit/hide/remove radio stations. That same page has "Import..." and "Export..." buttons which seem to allow saving and loading stations list as a file. This would avoid exposing the config as something that user would expect to modify, and imply that it's internal data that is not supposed to be modified by hand.

It looks though that the "Advanced Radio Player" doesn't save the stations when you remove the plasmoid instance, though. Is it possible to hook to the instance removal somehow? The plasmoid could perhaps prompt user if they really want to delete the instance and discard their configured items. And then offer an Export... button where they could save their config before removal.

There was a second alternative that came to mind: Instead of storing items per instance, what if those items would be stored in a global config file, like you described in the 1st bullet that would survive instance removal? Then each instance configuration would only contain an association to those items. That association would get deleted on instance removal but items would survive. This could be presented in the configuration dialog so that user would select (=associate) items they would like to include in the plasmoid instance. Those left unselected would remain, but would not be visible in the plasmoid widget on desktop. For an example of this see e.g. "KWin Scripts" under "Window Management" settings. There you can add new scripts, remove scripts, and select/unselect scripts. This way removal of the widget becomes a non-issue as the items would remain, and there would not be need to remember to copy (or backup) the config. A downside would be though that this would only save the items, you would lose e.g. order of items in the widget and any other config you might have wanted to save. However those are pretty easy to re-enter.

korapp commented 9 months ago

Global configuration could work, but in addition to reinventing configuration management, it leads to (4.) leaving a junk configuration file after uninstalling the plasmoid.

As you pointed out, the text editor and import/export options require intentional user action. And as far as I know, no signal is emitted about the user's deletion of a plasmoid. Unless... (last-minute idea) you could check auto backup and select a destination file where the configuration will be saved (overwritten) each time it is changed. In this case, you decide whether, where and which instance will be backed up.

jhakonen commented 9 months ago

I think leaving a configuration file behind is preferable if it allows restoring items when the plasmoid is installed next time. As an analogue, say, if you uninstall your web browser it does not remove you bookmarks, or any other preferences. When you reinstall the same browser it loads those configurations again as if nothing had happened. As such I think its odd that plasmoids discard user settings after removal.

That being said, I think that auto backup is a really good idea. It would avoid that plasmoid removal discarding unsaved settings nicely. User would still need to remember to setup backups, but I think that is acceptable if it is truly something they to want save.

IoSonoAndreaZ commented 6 months ago

you can put a button to export/import configuration