From bcb86bc4b0242111e6f4bf4e6538d53baa6b9853 Mon Sep 17 00:00:00 2001 From: NinjaCheetah <58050615+NinjaCheetah@users.noreply.github.com> Date: Mon, 21 Apr 2025 23:27:36 -0400 Subject: [PATCH] Added support for disabling auto-updates via a new config file --- NUSGet.py | 36 ++++++++++--- modules/core.py | 21 ++++++++ qt/py/ui_MainMenu.py | 28 +++++++++- qt/ui/MainMenu.ui | 36 +++++++++++++ resources/translations/nusget_de.ts | 84 ++++++++++++++++------------- resources/translations/nusget_es.ts | 84 ++++++++++++++++------------- resources/translations/nusget_fr.ts | 84 ++++++++++++++++------------- resources/translations/nusget_it.ts | 84 ++++++++++++++++------------- resources/translations/nusget_ko.ts | 84 ++++++++++++++++------------- resources/translations/nusget_nb.ts | 84 ++++++++++++++++------------- resources/translations/nusget_no.ts | 84 ++++++++++++++++------------- resources/translations/nusget_ro.ts | 84 ++++++++++++++++------------- 12 files changed, 488 insertions(+), 305 deletions(-) diff --git a/NUSGet.py b/NUSGet.py index 9f875e2..3a15aab 100644 --- a/NUSGet.py +++ b/NUSGet.py @@ -18,10 +18,7 @@ # nuitka-project: --include-data-dir={MAIN_DIRECTORY}/data=data # nuitka-project: --include-data-dir={MAIN_DIRECTORY}/resources=resources -import os import sys -import json -import pathlib import platform import webbrowser from importlib.metadata import version @@ -84,6 +81,12 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.ui.script_btn.clicked.connect(self.script_btn_pressed) self.ui.pack_archive_chkbox.toggled.connect( lambda: self.ui.archive_file_entry.setEnabled(self.ui.pack_archive_chkbox.isChecked())) + try: + self.ui.auto_update_chkbox.setChecked(config_data["auto_update"]) + except KeyError: + update_setting(config_data, "auto_update", self.ui.auto_update_chkbox.isChecked()) + self.ui.auto_update_chkbox.toggled.connect( + lambda: update_setting(config_data, "auto_update", self.ui.auto_update_chkbox.isChecked())) self.ui.tid_entry.textChanged.connect(self.tid_updated) # Basic intro text set to automatically show when the app loads. This may be changed in the future. libwiipy_version = "v" + version("libWiiPy") @@ -133,11 +136,19 @@ class MainWindow(QMainWindow, Ui_MainWindow): connect_label_to_checkbox(self.ui.use_wiiu_nus_chkbox_lbl, self.ui.use_wiiu_nus_chkbox) connect_label_to_checkbox(self.ui.patch_ios_chkbox_lbl, self.ui.patch_ios_chkbox) connect_label_to_checkbox(self.ui.pack_vwii_mode_chkbox_lbl, self.ui.pack_vwii_mode_chkbox) - # Do a quick check to see if there's a newer release available, and inform the user if there is. - worker = Worker(check_nusget_updates, app, nusget_version) - worker.signals.result.connect(self.prompt_for_update) - worker.signals.progress.connect(self.update_log_text) - self.threadpool.start(worker) + connect_label_to_checkbox(self.ui.auto_update_chkbox_lbl, self.ui.auto_update_chkbox) + try: + auto_update = config_data["auto_update"] + except KeyError: + auto_update = True + config_data["auto_update"] = True + save_config(config_data) + if auto_update: + # Do a quick check to see if there's a newer release available if auto-updates are enabled. + worker = Worker(check_nusget_updates, app, nusget_version) + worker.signals.result.connect(self.prompt_for_update) + worker.signals.progress.connect(self.update_log_text) + self.threadpool.start(worker) def title_double_clicked(self, index): if self.ui.download_btn.isEnabled() is True: @@ -497,6 +508,15 @@ if __name__ == "__main__": if not out_folder.is_dir(): out_folder.mkdir() + # Load the config path and then the configuration data, if it exists. If not, then we should initialize it and write + # it out. + config_file = get_config_file() + if config_file.exists(): + config_data = json.load(open(config_file)) + else: + config_data = {"auto_update": True} + save_config(config_data) + # Load the system plugins directory on Linux for system styles, if it exists. Try using Breeze if available, because # it looks nice, but fallback on kvantum if it isn't, since kvantum is likely to exist. If all else fails, fusion. if platform.system() == "Linux": diff --git a/modules/core.py b/modules/core.py index f3702de..6a456e2 100644 --- a/modules/core.py +++ b/modules/core.py @@ -1,6 +1,9 @@ # "modules/core.py", licensed under the MIT license # Copyright 2024-2025 NinjaCheetah +import os +import json +import pathlib import requests from dataclasses import dataclass from typing import List @@ -60,3 +63,21 @@ def check_nusget_updates(app, current_version: str, progress_callback=None) -> s return new_version progress_callback.emit(app.translate("MainWindow", "\n\nYou're running the latest release of NUSGet.")) return None + +def get_config_file() -> pathlib.Path: + config_dir = pathlib.Path(os.path.join( + os.environ.get('APPDATA') or + os.environ.get('XDG_CONFIG_HOME') or + os.path.join(os.environ['HOME'], '.config'), + "NUSGet" + )) + config_dir.mkdir(exist_ok=True) + return config_dir.joinpath("config.json") + +def save_config(config_data: dict) -> None: + config_file = get_config_file() + open(config_file, "w").write(json.dumps(config_data)) + +def update_setting(config_data: dict, setting: str, value: any) -> None: + config_data[setting] = value + save_config(config_data) diff --git a/qt/py/ui_MainMenu.py b/qt/py/ui_MainMenu.py index 62329a0..954ebfa 100644 --- a/qt/py/ui_MainMenu.py +++ b/qt/py/ui_MainMenu.py @@ -3,7 +3,7 @@ ################################################################################ ## Form generated from reading UI file 'MainMenu.ui' ## -## Created by: Qt User Interface Compiler version 6.8.1 +## Created by: Qt User Interface Compiler version 6.9.0 ## ## WARNING! All changes made in this file will be lost when recompiling UI file! ################################################################################ @@ -372,6 +372,29 @@ class Ui_MainWindow(object): self.verticalLayout_8.addLayout(self.pack_vwii_mode_row) + self.label_2 = QLabel(self.centralwidget) + self.label_2.setObjectName(u"label_2") + self.label_2.setFont(font) + + self.verticalLayout_8.addWidget(self.label_2) + + self.horizontalLayout_2 = QHBoxLayout() + self.horizontalLayout_2.setObjectName(u"horizontalLayout_2") + self.auto_update_chkbox = QCheckBox(self.centralwidget) + self.auto_update_chkbox.setObjectName(u"auto_update_chkbox") + sizePolicy1.setHeightForWidth(self.auto_update_chkbox.sizePolicy().hasHeightForWidth()) + self.auto_update_chkbox.setSizePolicy(sizePolicy1) + + self.horizontalLayout_2.addWidget(self.auto_update_chkbox) + + self.auto_update_chkbox_lbl = QLabel(self.centralwidget) + self.auto_update_chkbox_lbl.setObjectName(u"auto_update_chkbox_lbl") + + self.horizontalLayout_2.addWidget(self.auto_update_chkbox_lbl) + + + self.verticalLayout_8.addLayout(self.horizontalLayout_2) + self.verticalSpacer = QSpacerItem(20, 50, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.MinimumExpanding) self.verticalLayout_8.addItem(self.verticalSpacer) @@ -435,6 +458,9 @@ class Ui_MainWindow(object): self.patch_ios_chkbox_lbl.setText(QCoreApplication.translate("MainWindow", u"Apply patches to IOS (Applies to WADs only)", None)) self.label_4.setText(QCoreApplication.translate("MainWindow", u"vWii Title Settings", None)) self.pack_vwii_mode_chkbox_lbl.setText(QCoreApplication.translate("MainWindow", u"Re-encrypt title using the Wii Common Key", None)) + self.label_2.setText(QCoreApplication.translate("MainWindow", u"App Settings", None)) + self.auto_update_chkbox.setText("") + self.auto_update_chkbox_lbl.setText(QCoreApplication.translate("MainWindow", u"Check for updates on startup", None)) self.log_text_browser.setMarkdown("") self.log_text_browser.setHtml(QCoreApplication.translate("MainWindow", u"\n" "