Allow building as a non-flatpak app

This commit is contained in:
kramo
2023-03-16 17:24:03 +01:00
parent bb159f6503
commit 516c020cbc
10 changed files with 65 additions and 13 deletions

View File

@@ -39,10 +39,20 @@ def bottles_parser(parent_widget, action):
"bottles-location", "~/.var/app/com.usebottles.bottles/data/bottles/" "bottles-location", "~/.var/app/com.usebottles.bottles/data/bottles/"
) )
action(None, None) 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( schema.set_string(
"bottles-location", "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) action(None, None)
else: else:

View File

@@ -212,7 +212,8 @@ def create_details_window(parent_widget, game_id=None):
path = os.path.join( path = os.path.join(
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", "cartridges",
"games", "games",
game_id + ".json", game_id + ".json",

View File

@@ -27,7 +27,11 @@ def get_cover(game_id, parent_widget):
return parent_widget.pixbufs[game_id] return parent_widget.pixbufs[game_id]
cover_path = os.path.join( 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): if not os.path.isfile(cover_path):

View File

@@ -22,7 +22,12 @@ import os
def get_games(game_ids=None): 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 = {} games = {}
if not os.path.exists(games_dir): if not os.path.exists(games_dir):

View File

@@ -41,10 +41,20 @@ def heroic_parser(parent_widget, action):
"~/.var/app/com.heroicgameslauncher.hgl/config/heroic/", "~/.var/app/com.heroicgameslauncher.hgl/config/heroic/",
) )
action(None, None) 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( schema.set_string(
"heroic-location", "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) action(None, None)
else: else:

View File

@@ -17,6 +17,7 @@
# #
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import os
import subprocess import subprocess
import sys import sys
@@ -25,7 +26,11 @@ from gi.repository import Gio
def run_command(executable): def run_command(executable):
with subprocess.Popen( 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"): if Gio.Settings.new("hu.kramo.Cartridges").get_boolean("exit-after-launch"):
sys.exit() sys.exit()

View File

@@ -23,7 +23,12 @@ from gi.repository import GdkPixbuf, Gio
def save_cover(game, parent_widget, file_path, pixbuf=None, game_id=None): 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): if not os.path.exists(covers_dir):
os.makedirs(covers_dir) os.makedirs(covers_dir)

View File

@@ -22,7 +22,12 @@ import os
def save_games(games): 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): if not os.path.exists(games_dir):
os.makedirs(games_dir) os.makedirs(games_dir)

View File

@@ -22,7 +22,12 @@ import os
def toggle_hidden(game): 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): if not os.path.exists(games_dir):
return return

View File

@@ -93,7 +93,8 @@ class CartridgesWindow(Adw.ApplicationWindow):
if "removed" in current_games[current_game].keys(): if "removed" in current_games[current_game].keys():
os.remove( os.remove(
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", "cartridges",
"games", "games",
current_game + ".json", current_game + ".json",
@@ -102,7 +103,8 @@ class CartridgesWindow(Adw.ApplicationWindow):
try: try:
os.remove( os.remove(
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", "cartridges",
"covers", "covers",
current_game + ".dat", current_game + ".dat",