From 89ba4aecaa7c2f12d8af3fbf6c457a270a2cce2a Mon Sep 17 00:00:00 2001 From: kramo Date: Sat, 14 Oct 2023 20:27:56 +0200 Subject: [PATCH] Set last_played if launching from the command line --- cartridges/main.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cartridges/main.py b/cartridges/main.py index c35ba1c..84efcc5 100644 --- a/cartridges/main.py +++ b/cartridges/main.py @@ -22,6 +22,7 @@ import lzma import os import shlex import sys +from time import time from typing import Any, Optional import gi @@ -170,7 +171,9 @@ class CartridgesApplication(Adw.Application): if arg == "--launch": try: game_id = args[index + 1] - data = json.load((shared.games_dir / (game_id + ".json")).open("r")) + data = json.load( + (path := shared.games_dir / (game_id + ".json")).open("r") + ) executable = ( shlex.join(data["executable"]) if isinstance(data["executable"], list) @@ -179,6 +182,10 @@ class CartridgesApplication(Adw.Application): name = data["name"] run_executable(executable) + + data["last_played"] = int(time()) + json.dump(data, path.open("w")) + except (IndexError, KeyError, OSError, json.decoder.JSONDecodeError): return 1