From 43369ae14359ae7c28ae849a520c23f6c4ace26f Mon Sep 17 00:00:00 2001 From: Dummerle <44114474+Dummerle@users.noreply.github.com> Date: Thu, 23 Jun 2022 20:11:09 +0200 Subject: [PATCH] Revert "Add a restart function in debug settings to easier test game helper" This reverts commit cbf51b6bb73621ea43d839fa5694ec726b11d95c. --- rare/__main__.py | 23 ++++++++++++++--------- rare/app.py | 10 +++------- rare/components/tabs/games/game_utils.py | 1 - rare/components/tabs/settings/debug.py | 19 ------------------- 4 files changed, 17 insertions(+), 36 deletions(-) diff --git a/rare/__main__.py b/rare/__main__.py index 91a2bc41..79a1ef69 100644 --- a/rare/__main__.py +++ b/rare/__main__.py @@ -1,4 +1,5 @@ #!/usr/bin/python +import argparse import os import pathlib import sys @@ -59,11 +60,11 @@ def main(): launch_minimal_parser.add_argument("--skip_update_check", help="Do not check for updates", action="store_true") launch_minimal_parser.add_argument('--wine-bin', dest='wine_bin', action='store', metavar='', - default=os.environ.get('LGDRY_WINE_BINARY', None), - help='Set WINE binary to use to launch the app') + default=os.environ.get('LGDRY_WINE_BINARY', None), + help='Set WINE binary to use to launch the app') launch_minimal_parser.add_argument('--wine-prefix', dest='wine_pfx', action='store', metavar='', - default=os.environ.get('LGDRY_WINE_PREFIX', None), - help='Set WINE prefix to use') + default=os.environ.get('LGDRY_WINE_PREFIX', None), + help='Set WINE prefix to use') launch_minimal_parser.add_argument("--ask-alyways-sync", help="Ask for cloud saves", action="store_true") @@ -93,9 +94,16 @@ def main(): helper.start_game(args) return - from rare.utils.paths import data_dir - if os.path.exists(os.path.join(data_dir, "singleton.lock")): + from rare.utils import singleton + + try: + # this object only allows one instance per machine + + me = singleton.SingleInstance() + except singleton.SingleInstanceException: print("Rare is already running") + from rare.utils.paths import data_dir + with open(os.path.join(data_dir, "lockfile"), "w") as file: if args.subparser == "launch": file.write(f"launch {args.app_name}") @@ -104,9 +112,6 @@ def main(): file.close() return - from pathlib import Path - Path(os.path.join(data_dir, "singleton.lock")).touch() - if args.subparser == "launch": args.silent = True diff --git a/rare/app.py b/rare/app.py index e2d4d460..33144b48 100644 --- a/rare/app.py +++ b/rare/app.py @@ -25,7 +25,7 @@ from rare.components.tray_icon import TrayIcon from rare.shared import LegendaryCoreSingleton, GlobalSignalsSingleton, ArgumentsSingleton from rare.shared.image_manager import ImageManagerSingleton from rare.utils import legendary_utils, config_helper -from rare.utils.paths import cache_dir, resources_path, tmp_dir, data_dir +from rare.utils.paths import cache_dir, resources_path, tmp_dir from rare.utils.utils import set_color_pallete, set_style_sheet start_time = time.strftime("%y-%m-%d--%H-%M") # year-month-day-hour-minute @@ -38,9 +38,7 @@ logger = logging.getLogger("Rare") def excepthook(exc_type, exc_value, exc_tb): tb = "".join(traceback.format_exception(exc_type, exc_value, exc_tb)) - os.remove(os.path.join(data_dir, "singleton.lock")) print("Error") - if exc_tb == HTTPError: try: if LegendaryCoreSingleton().login(): @@ -143,8 +141,8 @@ class App(QApplication): self.setProperty("rareDefaultQtStyle", self.style().objectName()) if ( - self.settings.value("color_scheme", None) is None - and self.settings.value("style_sheet", None) is None + self.settings.value("color_scheme", None) is None + and self.settings.value("style_sheet", None) is None ): self.settings.setValue("color_scheme", "") self.settings.setValue("style_sheet", "RareStyle") @@ -277,8 +275,6 @@ class App(QApplication): self.tray_icon.deleteLater() self.processEvents() shutil.rmtree(tmp_dir) - if os.path.exists(os.path.join(data_dir, "singleton.lock")): - os.remove(os.path.join(data_dir, "singleton.lock")) os.makedirs(tmp_dir) self.exit(exit_code) diff --git a/rare/components/tabs/games/game_utils.py b/rare/components/tabs/games/game_utils.py index 34b80f56..a017dc7b 100644 --- a/rare/components/tabs/games/game_utils.py +++ b/rare/components/tabs/games/game_utils.py @@ -115,7 +115,6 @@ class GameProcess(QObject): self.socket.close() self.deleteLater() self._game_finished(-1234) # 1234 is exit code for startup - return logger.error(f"{self.app_name}: {self.socket.errorString()}") def _game_finished(self, exit_code: int): diff --git a/rare/components/tabs/settings/debug.py b/rare/components/tabs/settings/debug.py index 01e5d7d5..66e4cacf 100644 --- a/rare/components/tabs/settings/debug.py +++ b/rare/components/tabs/settings/debug.py @@ -1,12 +1,5 @@ -import os - -from PyQt5.QtCore import QProcess from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton -from rare.shared import GlobalSignalsSingleton, ArgumentsSingleton -from rare.utils import utils -from rare.utils.paths import data_dir - class DebugSettings(QWidget): def __init__(self): @@ -17,19 +10,7 @@ class DebugSettings(QWidget): self.layout().addWidget(self.raise_runtime_exception_button) self.raise_runtime_exception_button.clicked.connect(self.raise_exception) - self.restart_button = QPushButton("Restart") - self.layout().addWidget(self.restart_button) - self.restart_button.clicked.connect(self.restart) self.layout().addStretch(1) - def restart(self): - executable = utils.get_rare_executable() - if os.path.exists(os.path.join(data_dir, "singleton.lock")): - os.remove(os.path.join(data_dir, "singleton.lock")) - GlobalSignalsSingleton().exit_app.emit(0) - if ArgumentsSingleton().debug: - executable.append("--debug") - QProcess.startDetached(executable[0], executable[1:]) - def raise_exception(self): raise RuntimeError("Debug Crash")