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/"
)
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:

View File

@@ -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",

View File

@@ -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):

View File

@@ -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):

View File

@@ -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:

View File

@@ -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()

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):
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)

View File

@@ -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)

View File

@@ -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