1
0
Fork 0
mirror of synced 2024-06-07 21:24:41 +12:00

Add a restart function in debug settings to easier test game helper

This commit is contained in:
Dummerle 2022-06-19 22:50:13 +02:00
parent 87a110b62b
commit cbf51b6bb7
No known key found for this signature in database
GPG key ID: AB68CC59CA39F2F1
4 changed files with 36 additions and 17 deletions

View file

@ -1,5 +1,4 @@
#!/usr/bin/python
import argparse
import os
import pathlib
import sys
@ -60,11 +59,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='<wine binary>',
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='<wine pfx path>',
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")
@ -94,16 +93,9 @@ def main():
helper.start_game(args)
return
from rare.utils import singleton
try:
# this object only allows one instance per machine
me = singleton.SingleInstance()
except singleton.SingleInstanceException:
from rare.utils.paths import data_dir
if os.path.exists(os.path.join(data_dir, "singleton.lock")):
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}")
@ -112,6 +104,9 @@ 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

View file

@ -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
from rare.utils.paths import cache_dir, resources_path, tmp_dir, data_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,7 +38,9 @@ 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():
@ -141,8 +143,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")
@ -275,6 +277,8 @@ 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)

View file

@ -114,6 +114,7 @@ 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):

View file

@ -1,5 +1,12 @@
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):
@ -10,7 +17,19 @@ 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")