diff --git a/app/config/paths.py b/app/config/paths.py index a0cdde4e..1964e978 100644 --- a/app/config/paths.py +++ b/app/config/paths.py @@ -6,9 +6,11 @@ from PySide6.QtCore import QStandardPaths +IS_COMPILED = "__compiled__" in globals() + executableDir = ( Path(sys.executable).resolve().parent - if "__compiled__" in globals() + if IS_COMPILED else Path(".") ) @@ -23,6 +25,11 @@ QStandardPaths.StandardLocation.GenericDataLocation )) / "GhostDownloader" + +def hasNoAutoUpdateMarker() -> bool: + return (executableDir / "gd_no_auto_update").is_file() + + def isPortable() -> bool: return APP_DATA_DIR == str(PORTABLE_PATH) diff --git a/app/startup.py b/app/startup.py index a7c7bffe..16cb104c 100644 --- a/app/startup.py +++ b/app/startup.py @@ -84,6 +84,15 @@ def bindNotifications(taskService, notifyCompleted, notifyDiskSpace): def checkUpdateAtStartup(updateService): from app.config.cfg import cfg + from app.config.paths import IS_COMPILED, hasNoAutoUpdateMarker + if hasNoAutoUpdateMarker(): + from loguru import logger + logger.info("Auto update disabled by gd_no_auto_update marker") + if cfg.shouldCheckUpdateAtStartup.value: + cfg.set(cfg.shouldCheckUpdateAtStartup, False) + return + if not IS_COMPILED: + return if not cfg.shouldCheckUpdateAtStartup.value: return updateService.check() diff --git a/app/view/pages/setting_page.py b/app/view/pages/setting_page.py index 13d16a49..bee200b0 100644 --- a/app/view/pages/setting_page.py +++ b/app/view/pages/setting_page.py @@ -310,7 +310,10 @@ def _initCards(self) -> None: self.tr("在系统启动时静默运行 Ghost Downloader"), cfg.shouldRunAtLogin, ) - from app.config.paths import APP_DATA_DIR, isPortable + from app.config.paths import APP_DATA_DIR, hasNoAutoUpdateMarker, isPortable + noAutoUpdate = hasNoAutoUpdateMarker() + if noAutoUpdate and cfg.shouldCheckUpdateAtStartup.value: + cfg.set(cfg.shouldCheckUpdateAtStartup, False) if isPortable(): self.migrateCard = PushSettingCard( self.tr("切换到用户模式"), FluentIcon.SYNC, @@ -324,12 +327,14 @@ def _initCards(self) -> None: self.tr("当前为用户模式,数据保存在: {0}").format(APP_DATA_DIR), ) - softwareCards = [ - SwitchSettingCard(FluentIcon.UPDATE, self.tr("在应用程序启动时检查更新"), - self.tr("新版本将更稳定,并具有更多功能"), - cfg.shouldCheckUpdateAtStartup), - self.autoRunCard, - ] + self.autoUpdateCard = SwitchSettingCard( + FluentIcon.UPDATE, self.tr("在应用程序启动时检查更新"), + self.tr("新版本将更稳定,并具有更多功能"), + cfg.shouldCheckUpdateAtStartup, + ) + if noAutoUpdate: + self.autoUpdateCard.hide() + softwareCards = [self.autoUpdateCard, self.autoRunCard] if not IS_ANDROID: softwareCards.append( ComboBoxSettingCard( @@ -367,6 +372,8 @@ def _initCards(self) -> None: self.tr("检查更新"), FluentIcon.INFO, self.tr("关于"), f"© Copyright {YEAR}, {AUTHOR}. Version {VERSION}", ) + if noAutoUpdate: + self.aboutCard.button.hide() self.aboutGroup.addSettingCards([ HyperlinkCard(AUTHOR_URL, self.tr("打开作者的个人空间"), FluentIcon.PROJECTOR,