From 24f36f43f7f1847879dd533d0a36748030ac61ae Mon Sep 17 00:00:00 2001 From: Jamie Gravendeel Date: Sun, 30 Nov 2025 13:17:15 +0100 Subject: [PATCH] games: Add initial actions --- cartridges/games.py | 25 +++++++++++++++++++++++- flatpak/page.kramo.Cartridges.Devel.json | 3 ++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/cartridges/games.py b/cartridges/games.py index ad0a680..3e7e43a 100644 --- a/cartridges/games.py +++ b/cartridges/games.py @@ -4,8 +4,12 @@ # SPDX-FileCopyrightText: Copyright 2025 Jamie Gravendeel import json +import os +import subprocess from collections.abc import Generator from json import JSONDecodeError +from pathlib import Path +from shlex import quote from types import UnionType from typing import Any @@ -32,7 +36,7 @@ _PROPERTIES: dict[str, tuple[type | UnionType, bool]] = { } -class Game(GObject.Object): +class Game(Gio.SimpleActionGroup): """Game data class.""" __gtype_name__ = __qualname__ @@ -73,6 +77,25 @@ class Game(GObject.Object): setattr(self, name, value) + self.add_action_entries((("play", lambda *_: self.play()),)) + self.add_action(Gio.PropertyAction.new("hide", self, "hidden")) + self.add_action(Gio.PropertyAction.new("remove", self, "removed")) + + def play(self): + """Run the executable command in a shell.""" + if Path("/.flatpak-info").exists(): + executable = f"flatpak-spawn --host /bin/sh -c {quote(self.executable)}" + else: + executable = self.executable + + subprocess.Popen( # noqa: S602 + executable, + cwd=Path.home(), + shell=True, + start_new_session=True, + creationflags=subprocess.CREATE_NEW_PROCESS_GROUP if os.name == "nt" else 0, + ) + def _load() -> Generator[Game]: for path in _GAMES_DIR.glob("*.json"): diff --git a/flatpak/page.kramo.Cartridges.Devel.json b/flatpak/page.kramo.Cartridges.Devel.json index 6bd2b6b..1c895a0 100644 --- a/flatpak/page.kramo.Cartridges.Devel.json +++ b/flatpak/page.kramo.Cartridges.Devel.json @@ -8,7 +8,8 @@ "--share=ipc", "--socket=fallback-x11", "--device=dri", - "--socket=wayland" + "--socket=wayland", + "--talk-name=org.freedesktop.Flatpak" ], "cleanup": [ "/include",