switch state dirs to XDG dirs instead of Flatpak-specific dirs

This commit is contained in:
2024-02-01 11:15:17 +00:00
parent d62fb2d5e8
commit fcd12576e6

View File

@@ -11,6 +11,12 @@ gi.require_version("Adw", "1")
from gi.repository import Gtk, Adw, Gdk, Gio
# TODO: don't hardcode; use XDG dirs instead of HOME.
if False: # flatpak
CACHE_DIR = os.path.join(os.environ['XDG_RUNTIME_DIR'], 'app/ml.mdwalters.Lemonade/cache')
else: # non-flatpak
CACHE_DIR = os.path.join(os.environ['HOME'], '.cache/ml.mdwalters.Lemonade')
class LemonadeWindow(Gtk.ApplicationWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@@ -41,7 +47,7 @@ class LemonadeWindow(Gtk.ApplicationWindow):
"""
try:
os.mkdir(os.path.join(f"{os.environ['XDG_RUNTIME_DIR']}/app/ml.mdwalters.Lemonade", "cache"))
os.mkdir(CACHE_DIR)
except FileExistsError as e:
print(e)
@@ -148,8 +154,8 @@ class LemonadeWindow(Gtk.ApplicationWindow):
try:
print(f"Downloading icon for {community['community']['title']}")
name = community["community"]["icon"].split("/")[-1]
urllib.request.urlretrieve(community["community"]["icon"], f"{os.environ['XDG_RUNTIME_DIR']}/app/ml.mdwalters.Lemonade/cache/{name}")
avatar.set_custom_image(Gdk.Texture.new_from_file(Gio.File.new_for_path(f"{os.environ['XDG_RUNTIME_DIR']}/app/ml.mdwalters.Lemonade/cache/{name}")))
urllib.request.urlretrieve(community["community"]["icon"], f"{CACHE_DIR}/{name}")
avatar.set_custom_image(Gdk.Texture.new_from_file(Gio.File.new_for_path(f"{CACHE_DIR}/{name}")))
print(f"Successfully downloaded icon for {community['community']['title']}")
except:
print(f"Error getting icon for {community['community']['title']}")