hugolabe / Wike

Wikipedia Reader for the GNOME Desktop
https://hugolabe.github.io/Wike/
GNU General Public License v3.0
257 stars 33 forks source link

state files like "historic.json" are saved directly into ~/.local/share instead of a subdirectory #176

Open uninsane opened 10 months ago

uninsane commented 10 months ago

repro:

  1. ls ~/.local/share
    cozy/ dino/ flare/
  2. run wike, and then close it once the UI loads.
  3. ls ~/.local/share
    booklists.json bookmarks.json cookies cozy/ dino/ flare/ historic.json languages.json

observe: several new files (booklists.json, bookmarks.json, ...) appear under ~/.local/share and aren't clearly associated with any particular app, whereas other applications (cozy, dino, flare) place their files under a subdirectory so that it's clear which files belong to which apps.

runtime info

uninsane commented 10 months ago

Wike calculates its data paths in src/data.py:

_data_path = GLib.get_user_data_dir()

class Languages:

  items = {}
  global _data_path
  _file_path = _data_path + '/languages.json'

  ...

the docs for g_get_user_data_dir say

On UNIX platforms this is determined using the mechanisms described in the XDG Base Directory Specification. In this case the directory retrieved will be XDG_DATA_HOME.

the spec in turn says:

$XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used. "

it seems the desired behavior could be achieved with something like this (untested):

- _data_path = GLib.get_user_data_dir()
+ _data_path = os.path.join(GLib.get_user_data_dir(), "wike")

though that doesn't cover data migration for existing installs.

hugolabe commented 10 months ago

Thank you @uninsane

In flatpak this is not a problem since a data folder is created for each application. However, I suppose it would be better to fix it, but I have to make sure that user data is not lost when updating to the new version.