Move shared values to shared

This commit is contained in:
kramo
2023-05-21 17:28:29 +02:00
parent ab21e8b38b
commit 203393dea0
14 changed files with 186 additions and 154 deletions

View File

@@ -23,6 +23,7 @@ from time import time
from gi.repository import Adw, Gio, GLib, Gtk
from PIL import Image
from . import shared
from .create_dialog import create_dialog
from .game import Game
from .game_cover import GameCover
@@ -57,14 +58,15 @@ class DetailsWindow(Adw.Window):
self.cover_button_delete_revealer.set_reveal_child(False)
self.cover_changed = True
def __init__(self, win, game=None, **kwargs):
def __init__(self, game=None, **kwargs):
super().__init__(**kwargs)
self.set_transient_for(win)
self.win = win
self.win = shared.win
self.game = game
self.game_cover = GameCover({self.cover})
self.set_transient_for(self.win)
if self.game:
self.set_title(_("Edit Game Details"))
self.name.set_text(self.game.name)
@@ -153,7 +155,6 @@ class DetailsWindow(Adw.Window):
numbers.append(int(current_game.replace("imported_", "")))
self.game = Game(
self.win,
{
"game_id": f"imported_{str(max(numbers) + 1)}",
"hidden": False,
@@ -191,7 +192,6 @@ class DetailsWindow(Adw.Window):
if self.cover_changed:
save_cover(
self.win,
self.game.game_id,
self.game_cover.path,
)
@@ -199,7 +199,7 @@ class DetailsWindow(Adw.Window):
self.game.save()
if not self.game_cover.get_pixbuf():
SGDBSave(self.win, {self.game})
SGDBSave({self.game})
self.game_cover.pictures.remove(self.cover)
@@ -224,7 +224,7 @@ class DetailsWindow(Adw.Window):
self.cover_changed = True
def resize():
self.game_cover.new_cover(resize_cover(self.win, path))
self.game_cover.new_cover(resize_cover(path))
self.toggle_loading()
self.toggle_loading()

View File

@@ -59,11 +59,11 @@ class Game(Gtk.Box):
blacklisted = None
game_cover = None
def __init__(self, win, data, **kwargs):
def __init__(self, data, **kwargs):
super().__init__(**kwargs)
self.win = win
self.app = win.get_application()
self.win = shared.win
self.app = self.win.get_application()
self.update_values(data)
@@ -127,7 +127,7 @@ class Game(Gtk.Box):
setattr(self, key, value)
def save(self):
self.win.games_dir.mkdir(parents=True, exist_ok=True)
shared.games_dir.mkdir(parents=True, exist_ok=True)
attrs = (
"added",
@@ -151,7 +151,7 @@ class Game(Gtk.Box):
json.dump(
{attr: getattr(self, attr) for attr in attrs if attr},
(self.win.games_dir / f"{self.game_id}.json").open("w"),
(shared.games_dir / f"{self.game_id}.json").open("w"),
indent=4,
sort_keys=True,
)
@@ -239,11 +239,11 @@ class Game(Gtk.Box):
self.spinner.set_spinning(loading)
def get_cover_path(self):
cover_path = self.win.covers_dir / f"{self.game_id}.gif"
cover_path = shared.covers_dir / f"{self.game_id}.gif"
if cover_path.is_file():
return cover_path
cover_path = self.win.covers_dir / f"{self.game_id}.tiff"
cover_path = shared.covers_dir / f"{self.game_id}.tiff"
if cover_path.is_file():
return cover_path

View File

@@ -26,7 +26,7 @@ from . import shared
from .check_install import check_install
def bottles_installed(win, path=None):
def bottles_installed(path=None):
location_key = "bottles-location"
bottles_dir = (
path if path else Path(shared.schema.get_string(location_key)).expanduser()
@@ -39,7 +39,7 @@ def bottles_installed(win, path=None):
if path
else (
Path.home() / ".var/app/com.usebottles.bottles/data/bottles",
win.data_dir / "bottles",
shared.data_dir / "bottles",
)
)
@@ -48,8 +48,8 @@ def bottles_installed(win, path=None):
return bottles_dir
def bottles_importer(win):
bottles_dir = bottles_installed(win)
def bottles_importer():
bottles_dir = bottles_installed()
if not bottles_dir:
return
@@ -59,7 +59,7 @@ def bottles_importer(win):
library = yaml.load(data, Loader=yaml.Loader)
importer = win.importer
importer = shared.importer
importer.total_queue += len(library)
importer.queue += len(library)
@@ -69,7 +69,10 @@ def bottles_importer(win):
values["game_id"] = f'bottles_{game["id"]}'
if values["game_id"] in win.games and not win.games[values["game_id"]].removed:
if (
values["game_id"] in shared.win.games
and not shared.win.games[values["game_id"]].removed
):
importer.save_game()
continue

View File

@@ -27,7 +27,7 @@ from . import shared
from .check_install import check_install
def heroic_installed(win, path=None):
def heroic_installed(path=None):
location_key = "heroic-location"
heroic_dir = (
path if path else Path(shared.schema.get_string(location_key)).expanduser()
@@ -40,7 +40,7 @@ def heroic_installed(win, path=None):
if path
else (
Path.home() / ".var/app/com.heroicgameslauncher.hgl/config/heroic",
win.config_dir / "heroic",
shared.config_dir / "heroic",
)
)
@@ -52,13 +52,13 @@ def heroic_installed(win, path=None):
return heroic_dir
def heroic_importer(win):
heroic_dir = heroic_installed(win)
def heroic_importer():
heroic_dir = heroic_installed()
if not heroic_dir:
return
current_time = int(time())
importer = win.importer
importer = shared.importer
# Import Epic games
if not shared.schema.get_boolean("heroic-import-epic"):
@@ -82,8 +82,8 @@ def heroic_importer(win):
values["game_id"] = f"heroic_epic_{app_name}"
if (
values["game_id"] in win.games
and not win.games[values["game_id"]].removed
values["game_id"] in shared.win.games
and not shared.win.games[values["game_id"]].removed
):
importer.save_game()
continue
@@ -131,8 +131,8 @@ def heroic_importer(win):
values["game_id"] = f"heroic_gog_{app_name}"
if (
values["game_id"] in win.games
and not win.games[values["game_id"]].removed
values["game_id"] in shared.win.games
and not shared.win.games[values["game_id"]].removed
):
importer.save_game()
continue
@@ -179,8 +179,8 @@ def heroic_importer(win):
values["game_id"] = f"heroic_sideload_{app_name}"
if (
values["game_id"] in win.games
and not win.games[values["game_id"]].removed
values["game_id"] in shared.win.games
and not shared.win.games[values["game_id"]].removed
):
importer.save_game()
continue

View File

@@ -31,12 +31,15 @@ from .check_install import check_install
from .save_cover import resize_cover
def get_game(task, current_time, win, row):
def get_game(task, current_time, row):
values = {}
values["game_id"] = f"itch_{row[0]}"
if values["game_id"] in win.games and not win.games[values["game_id"]].removed:
if (
values["game_id"] in shared.win.games
and not shared.win.games[values["game_id"]].removed
):
task.return_value((None, None))
return
@@ -63,22 +66,22 @@ def get_game(task, current_time, win, row):
game_cover = GdkPixbuf.Pixbuf.new_from_stream_at_scale(
tmp_file.read(), 2, 2, False
).scale_simple(*win.image_size, GdkPixbuf.InterpType.BILINEAR)
).scale_simple(*shared.image_size, GdkPixbuf.InterpType.BILINEAR)
itch_pixbuf = GdkPixbuf.Pixbuf.new_from_stream(tmp_file.read())
itch_pixbuf = itch_pixbuf.scale_simple(
win.image_size[0],
itch_pixbuf.get_height() * (win.image_size[0] / itch_pixbuf.get_width()),
shared.image_size[0],
itch_pixbuf.get_height() * (shared.image_size[0] / itch_pixbuf.get_width()),
GdkPixbuf.InterpType.BILINEAR,
)
itch_pixbuf.composite(
game_cover,
0,
(win.image_size[1] - itch_pixbuf.get_height()) / 2,
(shared.image_size[1] - itch_pixbuf.get_height()) / 2,
itch_pixbuf.get_width(),
itch_pixbuf.get_height(),
0,
(win.image_size[1] - itch_pixbuf.get_height()) / 2,
(shared.image_size[1] - itch_pixbuf.get_height()) / 2,
1.0,
1.0,
GdkPixbuf.InterpType.BILINEAR,
@@ -91,16 +94,15 @@ def get_game(task, current_time, win, row):
task.return_value((values, game_cover))
def get_games_async(win, rows, importer):
def get_games_async(rows, importer):
current_time = int(time())
# Wrap the function in another one as Gio.Task.run_in_thread does not allow for passing args
def create_func(current_time, win, row):
def create_func(current_time, row):
def wrapper(task, *_args):
get_game(
task,
current_time,
win,
row,
)
@@ -111,15 +113,15 @@ def get_games_async(win, rows, importer):
# No need for an if statement as final_value would be None for games we don't want to save
importer.save_game(
final_values[0],
resize_cover(win, pixbuf=final_values[1]),
resize_cover(pixbuf=final_values[1]),
)
for row in rows:
task = Gio.Task.new(None, None, update_games)
task.run_in_thread(create_func(current_time, win, row))
task.run_in_thread(create_func(current_time, row))
def itch_installed(win, path=None):
def itch_installed(path=None):
location_key = "itch-location"
itch_dir = (
path if path else Path(shared.schema.get_string(location_key)).expanduser()
@@ -132,7 +134,7 @@ def itch_installed(win, path=None):
if path
else (
Path.home() / ".var/app/io.itch.itch/config/itch",
win.config_dir / "itch",
shared.config_dir / "itch",
)
)
@@ -144,14 +146,14 @@ def itch_installed(win, path=None):
return itch_dir
def itch_importer(win):
itch_dir = itch_installed(win)
def itch_importer():
itch_dir = itch_installed()
if not itch_dir:
return
database_path = (itch_dir / "db").expanduser()
db_cache_dir = win.cache_dir / "cartridges" / "itch"
db_cache_dir = shared.cache_dir / "cartridges" / "itch"
db_cache_dir.mkdir(parents=True, exist_ok=True)
# Copy the file because sqlite3 doesn't like databases in /run/user/
@@ -183,8 +185,8 @@ def itch_importer(win):
# No need to unlink temp files as they disappear when the connection is closed
database_tmp_path.unlink(missing_ok=True)
importer = win.importer
importer = shared.importer
importer.total_queue += len(rows)
importer.queue += len(rows)
get_games_async(win, rows, importer)
get_games_async(rows, importer)

View File

@@ -26,7 +26,7 @@ from . import shared
from .check_install import check_install
def lutris_installed(win, path=None):
def lutris_installed(path=None):
location_key = "lutris-location"
lutris_dir = (
path if path else Path(shared.schema.get_string(location_key)).expanduser()
@@ -39,7 +39,7 @@ def lutris_installed(win, path=None):
if path
else (
Path.home() / ".var/app/net.lutris.Lutris/data/lutris",
win.data_dir / "lutris",
shared.data_dir / "lutris",
)
)
@@ -48,7 +48,7 @@ def lutris_installed(win, path=None):
return lutris_dir
def lutris_cache_exists(win, path=None):
def lutris_cache_exists(path=None):
cache_key = "lutris-cache-location"
cache_dir = path if path else Path(shared.schema.get_string(cache_key)).expanduser()
cache_check = "coverart"
@@ -59,7 +59,7 @@ def lutris_cache_exists(win, path=None):
if path
else (
Path.home() / ".var" / "app" / "net.lutris.Lutris" / "cache" / "lutris",
win.cache_dir / "lutris",
shared.cache_dir / "lutris",
)
)
@@ -70,16 +70,16 @@ def lutris_cache_exists(win, path=None):
return cache_dir
def lutris_importer(win):
lutris_dir = lutris_installed(win)
def lutris_importer():
lutris_dir = lutris_installed()
if not lutris_dir:
return
cache_dir = lutris_cache_exists(win)
cache_dir = lutris_cache_exists()
if not cache_dir:
return
db_cache_dir = win.cache_dir / "cartridges" / "lutris"
db_cache_dir = shared.cache_dir / "cartridges" / "lutris"
db_cache_dir.mkdir(parents=True, exist_ok=True)
# Copy the file because sqlite3 doesn't like databases in /run/user/
@@ -113,7 +113,7 @@ def lutris_importer(win):
current_time = int(time())
importer = win.importer
importer = shared.importer
importer.total_queue += len(rows)
importer.queue += len(rows)
@@ -122,7 +122,10 @@ def lutris_importer(win):
values["game_id"] = f"lutris_{row[3]}_{row[0]}"
if values["game_id"] in win.games and not win.games[values["game_id"]].removed:
if (
values["game_id"] in shared.win.games
and not shared.win.games[values["game_id"]].removed
):
importer.save_game()
continue

View File

@@ -43,7 +43,7 @@ def update_values_from_data(content, values):
return values
def get_game(task, datatypes, current_time, win, appmanifest, steam_dir):
def get_game(task, datatypes, current_time, appmanifest, steam_dir):
values = {}
data = appmanifest.read_text("utf-8")
@@ -57,7 +57,10 @@ def get_game(task, datatypes, current_time, win, appmanifest, steam_dir):
values["game_id"] = f'steam_{values["appid"]}'
if values["game_id"] in win.games and not win.games[values["game_id"]].removed:
if (
values["game_id"] in shared.win.games
and not shared.win.games[values["game_id"]].removed
):
task.return_value((None, None))
return
@@ -93,18 +96,17 @@ def get_game(task, datatypes, current_time, win, appmanifest, steam_dir):
task.return_value((values, image_path if image_path.exists() else None))
def get_games_async(win, appmanifests, steam_dir, importer):
def get_games_async(appmanifests, steam_dir, importer):
datatypes = ["appid", "name"]
current_time = int(time())
# Wrap the function in another one as Gio.Task.run_in_thread does not allow for passing args
def create_func(datatypes, current_time, win, appmanifest, steam_dir):
def create_func(datatypes, current_time, appmanifest, steam_dir):
def wrapper(task, *_args):
get_game(
task,
datatypes,
current_time,
win,
appmanifest,
steam_dir,
)
@@ -118,12 +120,10 @@ def get_games_async(win, appmanifests, steam_dir, importer):
for appmanifest in appmanifests:
task = Gio.Task.new(None, None, update_games)
task.run_in_thread(
create_func(datatypes, current_time, win, appmanifest, steam_dir)
)
task.run_in_thread(create_func(datatypes, current_time, appmanifest, steam_dir))
def steam_installed(win, path=None):
def steam_installed(path=None):
location_key = "steam-location"
steam_dir = Path(shared.schema.get_string(location_key)).expanduser()
check = "steamapps"
@@ -136,7 +136,7 @@ def steam_installed(win, path=None):
else (
steam_dir,
Path.home() / ".steam",
win.data_dir / "Steam",
shared.data_dir / "Steam",
Path.home() / ".var/app/com.valvesoftware.Steam/data/Steam",
)
)
@@ -151,8 +151,8 @@ def steam_installed(win, path=None):
return steam_dir
def steam_importer(win):
steam_dir = steam_installed(win)
def steam_importer():
steam_dir = steam_installed()
if not steam_dir:
return
@@ -175,8 +175,8 @@ def steam_importer(win):
if open_file.is_file() and "appmanifest" in open_file.name:
appmanifests.append(open_file)
importer = win.importer
importer = shared.importer
importer.total_queue += len(appmanifests)
importer.queue += len(appmanifests)
get_games_async(win, appmanifests, steam_dir, importer)
get_games_async(appmanifests, steam_dir, importer)

View File

@@ -130,7 +130,7 @@ class CartridgesApplication(Adw.Application):
def on_preferences_action(
self, _action=None, _parameter=None, page_name=None, expander_row=None
):
win = PreferencesWindow(self.win)
win = PreferencesWindow()
if page_name:
win.set_visible_page_name(page_name)
if expander_row:
@@ -144,36 +144,36 @@ class CartridgesApplication(Adw.Application):
self.win.active_game.toggle_hidden()
def on_edit_game_action(self, *_args):
DetailsWindow(self.win, self.win.active_game)
DetailsWindow(self.win.active_game)
def on_add_game_action(self, *_args):
DetailsWindow(self.win)
DetailsWindow()
def on_import_action(self, *_args):
self.win.importer = Importer(self.win)
shared.importer = Importer()
self.win.importer.blocker = True
shared.importer.blocker = True
if self.win.schema.get_boolean("steam"):
steam_importer(self.win)
if shared.schema.get_boolean("steam"):
steam_importer()
if self.win.schema.get_boolean("lutris"):
lutris_importer(self.win)
if shared.schema.get_boolean("lutris"):
lutris_importer()
if self.win.schema.get_boolean("heroic"):
heroic_importer(self.win)
if shared.schema.get_boolean("heroic"):
heroic_importer()
if self.win.schema.get_boolean("bottles"):
bottles_importer(self.win)
if shared.schema.get_boolean("bottles"):
bottles_importer()
if self.win.schema.get_boolean("itch"):
itch_importer(self.win)
if shared.schema.get_boolean("itch"):
itch_importer()
self.win.importer.blocker = False
shared.importer.blocker = False
if self.win.importer.import_dialog.is_visible and self.win.importer.queue == 0:
self.win.importer.queue = 1
self.win.importer.save_game()
if shared.importer.import_dialog.is_visible and shared.importer.queue == 0:
shared.importer.queue = 1
shared.importer.save_game()
def on_remove_game_action(self, *_args):
self.win.active_game.remove_game()

View File

@@ -88,11 +88,11 @@ class PreferencesWindow(Adw.PreferencesWindow):
# Widgets and their properties to check whether to import after closing the window
import_changed_widgets = {}
def __init__(self, win, **kwargs):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.win = win
self.win = shared.win
self.file_chooser = Gtk.FileDialog()
self.set_transient_for(win)
self.set_transient_for(self.win)
self.toast = Adw.Toast.new(_("All games removed"))
self.toast.set_button_label(_("Undo"))
@@ -276,7 +276,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
if response == "choose_folder":
win.choose_folder(widget, set_dir)
if globals()[f"{source_id}_installed"](win, path):
if globals()[f"{source_id}_installed"](path):
self.import_changed = True
self.set_subtitle(win, source_id)

View File

@@ -1,4 +1,54 @@
from gi.repository import Gio
# shared.py
#
# Copyright 2022-2023 kramo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
import os
from pathlib import Path
from gi.repository import Gdk, Gio
schema = Gio.Settings.new("hu.kramo.Cartridges")
state_schema = Gio.Settings.new("hu.kramo.Cartridges.State")
data_dir = (
Path(os.getenv("XDG_DATA_HOME"))
if "XDG_DATA_HOME" in os.environ
else Path.home() / ".local" / "share"
)
config_dir = (
Path(os.getenv("XDG_CONFIG_HOME"))
if "XDG_CONFIG_HOME" in os.environ
else Path.home() / ".config"
)
cache_dir = (
Path(os.getenv("XDG_CACHE_HOME"))
if "XDG_CACHE_HOME" in os.environ
else Path.home() / ".cache"
)
games_dir = data_dir / "cartridges" / "games"
covers_dir = data_dir / "cartridges" / "covers"
scale_factor = max(
monitor.get_scale_factor() for monitor in Gdk.Display.get_default().get_monitors()
)
image_size = (200 * scale_factor, 300 * scale_factor)
# pylint: disable=invalid-name
win = None
importer = None

View File

@@ -19,6 +19,7 @@
from gi.repository import Adw, GLib, Gtk
from . import shared
from .create_dialog import create_dialog
from .game import Game
from .save_cover import resize_cover, save_cover
@@ -26,8 +27,8 @@ from .steamgriddb import SGDBSave
class Importer:
def __init__(self, win):
self.win = win
def __init__(self):
self.win = shared.win
self.total_queue = 0
self.queue = 0
self.games_no = 0
@@ -46,7 +47,7 @@ class Importer:
modal=True,
default_width=350,
default_height=-1,
transient_for=win,
transient_for=self.win,
deletable=False,
)
@@ -54,10 +55,10 @@ class Importer:
def save_game(self, values=None, cover_path=None):
if values:
game = Game(self.win, values)
game = Game(values)
if save_cover:
save_cover(self.win, game.game_id, resize_cover(self.win, cover_path))
save_cover(game.game_id, resize_cover(cover_path))
self.games.add(game)
@@ -74,7 +75,7 @@ class Importer:
self.queue = len(self.games)
self.import_statuspage.set_title(_("Importing Covers…"))
self.update_progressbar()
SGDBSave(self.win, self.games, self)
SGDBSave(self.games, self)
else:
self.done()

View File

@@ -27,7 +27,7 @@ from PIL import Image, ImageSequence
from . import shared
def resize_cover(win, cover_path=None, pixbuf=None):
def resize_cover(cover_path=None, pixbuf=None):
if not cover_path and not pixbuf:
return None
@@ -55,7 +55,7 @@ def resize_cover(win, cover_path=None, pixbuf=None):
image = image.convert("RGBA")
tmp_path = Path(Gio.File.new_tmp("XXXXXX.tiff")[0].get_path())
image.resize(win.image_size).save(
image.resize(shared.image_size).save(
tmp_path,
compression="tiff_adobe_deflate"
if shared.schema.get_boolean("high-quality-images")
@@ -65,11 +65,11 @@ def resize_cover(win, cover_path=None, pixbuf=None):
return tmp_path
def save_cover(win, game_id, cover_path):
win.covers_dir.mkdir(parents=True, exist_ok=True)
def save_cover(game_id, cover_path):
shared.covers_dir.mkdir(parents=True, exist_ok=True)
animated_path = win.covers_dir / f"{game_id}.gif"
static_path = win.covers_dir / f"{game_id}.tiff"
animated_path = shared.covers_dir / f"{game_id}.gif"
static_path = shared.covers_dir / f"{game_id}.tiff"
# Remove previous covers
animated_path.unlink(missing_ok=True)
@@ -83,7 +83,7 @@ def save_cover(win, game_id, cover_path):
animated_path if cover_path.suffix == ".gif" else static_path,
)
if game_id in win.game_covers:
win.game_covers[game_id].new_cover(
if game_id in shared.win.game_covers:
shared.win.game_covers[game_id].new_cover(
animated_path if cover_path.suffix == ".gif" else static_path
)

View File

@@ -9,8 +9,8 @@ from .save_cover import save_cover, resize_cover
class SGDBSave:
def __init__(self, win, games, importer=None):
self.win = win
def __init__(self, games, importer=None):
self.win = shared.win
self.importer = importer
self.exception = None
@@ -36,8 +36,8 @@ class SGDBSave:
and (
(shared.schema.get_boolean("sgdb-prefer"))
or not (
(self.win.covers_dir / f"{game.game_id}.gif").is_file()
or (self.win.covers_dir / f"{game.game_id}.tiff").is_file()
(shared.covers_dir / f"{game.game_id}.gif").is_file()
or (shared.covers_dir / f"{game.game_id}.tiff").is_file()
)
)
)
@@ -94,9 +94,8 @@ class SGDBSave:
Path(tmp_file.get_path()).write_bytes(response.content)
save_cover(
self.win,
game.game_id,
resize_cover(self.win, tmp_file.get_path()),
resize_cover(tmp_file.get_path()),
)
task.return_value(game)

View File

@@ -18,12 +18,11 @@
# SPDX-License-Identifier: GPL-3.0-or-later
import json
import os
from datetime import datetime
from pathlib import Path
from gi.repository import Adw, Gdk, Gio, GLib, Gtk
from gi.repository import Adw, Gio, GLib, Gtk
from . import shared
from .game import Game
@@ -77,35 +76,10 @@ class CartridgesWindow(Adw.ApplicationWindow):
def __init__(self, **kwargs):
super().__init__(**kwargs)
shared.win = self
self.previous_page = self.library_view
self.data_dir = (
Path(os.getenv("XDG_DATA_HOME"))
if "XDG_DATA_HOME" in os.environ
else Path.home() / ".local" / "share"
)
self.config_dir = (
Path(os.getenv("XDG_CONFIG_HOME"))
if "XDG_CONFIG_HOME" in os.environ
else Path.home() / ".config"
)
self.cache_dir = (
Path(os.getenv("XDG_CACHE_HOME"))
if "XDG_CACHE_HOME" in os.environ
else Path.home() / ".cache"
)
self.games_dir = self.data_dir / "cartridges" / "games"
self.covers_dir = self.data_dir / "cartridges" / "covers"
self.schema = Gio.Settings.new("hu.kramo.Cartridges")
scale_factor = max(
monitor.get_scale_factor()
for monitor in Gdk.Display.get_default().get_monitors()
)
self.image_size = (200 * scale_factor, 300 * scale_factor)
self.details_view.set_measure_overlay(self.details_view_box, True)
self.details_view.set_clip_overlay(self.details_view_box, False)
@@ -119,22 +93,22 @@ class CartridgesWindow(Adw.ApplicationWindow):
games = {}
if self.games_dir.exists():
for open_file in self.games_dir.iterdir():
if shared.games_dir.exists():
for open_file in shared.games_dir.iterdir():
data = json.load(open_file.open())
games[data["game_id"]] = data
for game_id, game in games.items():
if game.get("removed"):
for path in (
self.games_dir / f"{game_id}.json",
self.covers_dir / f"{game_id}.tiff",
self.covers_dir / f"{game_id}.gif",
shared.games_dir / f"{game_id}.json",
shared.covers_dir / f"{game_id}.tiff",
shared.covers_dir / f"{game_id}.gif",
):
path.unlink(missing_ok=True)
else:
Game(self, game).update()
Game(game).update()
# Connect search entries
self.search_bar.connect_entry(self.search_entry)