switch state dirs to XDG dirs instead of Flatpak-specific dirs
This commit is contained in:
12
src/main.py
12
src/main.py
@@ -11,6 +11,12 @@ gi.require_version("Adw", "1")
|
|||||||
|
|
||||||
from gi.repository import Gtk, Adw, Gdk, Gio
|
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):
|
class LemonadeWindow(Gtk.ApplicationWindow):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
@@ -41,7 +47,7 @@ class LemonadeWindow(Gtk.ApplicationWindow):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
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:
|
except FileExistsError as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
@@ -148,8 +154,8 @@ class LemonadeWindow(Gtk.ApplicationWindow):
|
|||||||
try:
|
try:
|
||||||
print(f"Downloading icon for {community['community']['title']}")
|
print(f"Downloading icon for {community['community']['title']}")
|
||||||
name = community["community"]["icon"].split("/")[-1]
|
name = community["community"]["icon"].split("/")[-1]
|
||||||
urllib.request.urlretrieve(community["community"]["icon"], 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"{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"{CACHE_DIR}/{name}")))
|
||||||
print(f"Successfully downloaded icon for {community['community']['title']}")
|
print(f"Successfully downloaded icon for {community['community']['title']}")
|
||||||
except:
|
except:
|
||||||
print(f"Error getting icon for {community['community']['title']}")
|
print(f"Error getting icon for {community['community']['title']}")
|
||||||
|
Reference in New Issue
Block a user