diff --git a/src/utils/bottles_parser.py b/src/utils/bottles_parser.py index 906ceaf..49f5f33 100644 --- a/src/utils/bottles_parser.py +++ b/src/utils/bottles_parser.py @@ -39,10 +39,20 @@ def bottles_parser(parent_widget, action): "bottles-location", "~/.var/app/com.usebottles.bottles/data/bottles/" ) action(None, None) - elif os.path.exists(os.path.join(os.environ.get("XDG_DATA_HOME"), "bottles")): + elif os.path.exists( + os.path.join( + os.getenv("XDG_DATA_HOME") + or os.path.expanduser(os.path.join("~", ".local", "share")), + "bottles", + ) + ): schema.set_string( "bottles-location", - os.path.join(os.environ.get("XDG_DATA_HOME"), "bottles"), + os.path.join( + os.getenv("XDG_DATA_HOME") + or os.path.expanduser(os.path.join("~", ".local", "share")), + "bottles", + ), ) action(None, None) else: diff --git a/src/utils/create_details_window.py b/src/utils/create_details_window.py index 9746259..c2158ac 100644 --- a/src/utils/create_details_window.py +++ b/src/utils/create_details_window.py @@ -212,7 +212,8 @@ def create_details_window(parent_widget, game_id=None): path = os.path.join( os.path.join( - os.environ.get("XDG_DATA_HOME"), + os.getenv("XDG_DATA_HOME") + or os.path.expanduser(os.path.join("~", ".local", "share")), "cartridges", "games", game_id + ".json", diff --git a/src/utils/get_cover.py b/src/utils/get_cover.py index 65b0674..1691187 100644 --- a/src/utils/get_cover.py +++ b/src/utils/get_cover.py @@ -27,7 +27,11 @@ def get_cover(game_id, parent_widget): return parent_widget.pixbufs[game_id] cover_path = os.path.join( - os.environ.get("XDG_DATA_HOME"), "cartridges", "covers", game_id + ".tiff" + os.getenv("XDG_DATA_HOME") + or os.path.expanduser(os.path.join("~", ".local", "share")), + "cartridges", + "covers", + game_id + ".tiff", ) if not os.path.isfile(cover_path): diff --git a/src/utils/get_games.py b/src/utils/get_games.py index 5d84ed5..8ae2e2e 100644 --- a/src/utils/get_games.py +++ b/src/utils/get_games.py @@ -22,7 +22,12 @@ import os def get_games(game_ids=None): - games_dir = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "games") + games_dir = os.path.join( + os.getenv("XDG_DATA_HOME") + or os.path.expanduser(os.path.join("~", ".local", "share")), + "cartridges", + "games", + ) games = {} if not os.path.exists(games_dir): diff --git a/src/utils/heroic_parser.py b/src/utils/heroic_parser.py index fef4e39..319e2f6 100644 --- a/src/utils/heroic_parser.py +++ b/src/utils/heroic_parser.py @@ -41,10 +41,20 @@ def heroic_parser(parent_widget, action): "~/.var/app/com.heroicgameslauncher.hgl/config/heroic/", ) action(None, None) - elif os.path.exists(os.path.join(os.environ.get("XDG_CONFIG_HOME"), "heroic")): + elif os.path.exists( + os.path.join( + os.getenv("XDG_CONFIG_HOME") + or os.path.expanduser(os.path.join("~", ".config")), + "heroic", + ) + ): schema.set_string( "heroic-location", - os.path.join(os.environ.get("XDG_CONFIG_HOME"), "heroic"), + os.path.join( + os.getenv("XDG_CONFIG_HOME") + or os.path.expanduser(os.path.join("~", ".config")), + "heroic", + ), ) action(None, None) else: diff --git a/src/utils/run_command.py b/src/utils/run_command.py index 20fbdca..006e9fd 100644 --- a/src/utils/run_command.py +++ b/src/utils/run_command.py @@ -17,6 +17,7 @@ # # SPDX-License-Identifier: GPL-3.0-or-later +import os import subprocess import sys @@ -25,7 +26,11 @@ from gi.repository import Gio def run_command(executable): with subprocess.Popen( - ["flatpak-spawn --host " + executable], shell=True, start_new_session=True + ["flatpak-spawn --host " + executable] + if os.getenv("FLATPAK_ID") == "hu.kramo.Cartridges" + else [executable], + shell=True, + start_new_session=True, ): if Gio.Settings.new("hu.kramo.Cartridges").get_boolean("exit-after-launch"): sys.exit() diff --git a/src/utils/save_cover.py b/src/utils/save_cover.py index 1465048..1fb1ff6 100644 --- a/src/utils/save_cover.py +++ b/src/utils/save_cover.py @@ -23,7 +23,12 @@ from gi.repository import GdkPixbuf, Gio def save_cover(game, parent_widget, file_path, pixbuf=None, game_id=None): - covers_dir = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "covers") + covers_dir = os.path.join( + os.getenv("XDG_DATA_HOME") + or os.path.expanduser(os.path.join("~", ".local", "share")), + "cartridges", + "covers", + ) if not os.path.exists(covers_dir): os.makedirs(covers_dir) diff --git a/src/utils/save_games.py b/src/utils/save_games.py index 16e7790..ff67559 100644 --- a/src/utils/save_games.py +++ b/src/utils/save_games.py @@ -22,7 +22,12 @@ import os def save_games(games): - games_dir = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "games") + games_dir = os.path.join( + os.getenv("XDG_DATA_HOME") + or os.path.expanduser(os.path.join("~", ".local", "share")), + "cartridges", + "games", + ) if not os.path.exists(games_dir): os.makedirs(games_dir) diff --git a/src/utils/toggle_hidden.py b/src/utils/toggle_hidden.py index 69c75ad..fb31260 100644 --- a/src/utils/toggle_hidden.py +++ b/src/utils/toggle_hidden.py @@ -22,7 +22,12 @@ import os def toggle_hidden(game): - games_dir = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "games") + games_dir = os.path.join( + os.getenv("XDG_DATA_HOME") + or os.path.expanduser(os.path.join("~", ".local", "share")), + "cartridges", + "games", + ) if not os.path.exists(games_dir): return diff --git a/src/window.py b/src/window.py index a3d030b..1e84f1f 100644 --- a/src/window.py +++ b/src/window.py @@ -93,7 +93,8 @@ class CartridgesWindow(Adw.ApplicationWindow): if "removed" in current_games[current_game].keys(): os.remove( os.path.join( - os.environ.get("XDG_DATA_HOME"), + os.getenv("XDG_DATA_HOME") + or os.path.expanduser(os.path.join("~", ".local", "share")), "cartridges", "games", current_game + ".json", @@ -102,7 +103,8 @@ class CartridgesWindow(Adw.ApplicationWindow): try: os.remove( os.path.join( - os.environ.get("XDG_DATA_HOME"), + os.getenv("XDG_DATA_HOME") + or os.path.expanduser(os.path.join("~", ".local", "share")), "cartridges", "covers", current_game + ".dat",