From bdbbc687773f15eaf76f6a70f9ae2c6af2b3756d Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Sun, 10 Sep 2023 18:00:47 +0800 Subject: [PATCH] Add: Use GitOverCdn at GUI update check --- deploy/Windows/git.py | 8 ++++---- deploy/git_over_cdn/client.py | 17 +++++++++++++++++ module/webui/updater.py | 9 +++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/deploy/Windows/git.py b/deploy/Windows/git.py index 2843c877e..6193ac313 100644 --- a/deploy/Windows/git.py +++ b/deploy/Windows/git.py @@ -128,14 +128,14 @@ class GitManager(DeployConfig): self.execute(f'"{self.git}" --no-pager log --no-merges -1') Progress.GitShowVersion() - def git_over_cdn(self): + @property + def goc_client(self): client = GitOverCdnClient( url='https://vip.123pan.cn/1815343254/pack/LmeSzinc_StarRailCopilot_master', folder=self.root_filepath, ) client.logger = logger - _ = client.update(keep_changes=self.KeepLocalChanges) - return _ + return client def git_install(self): logger.hr('Update Alas', 0) @@ -146,7 +146,7 @@ class GitManager(DeployConfig): return if self.GitOverCdn: - if self.git_over_cdn(): + if self.goc_client.update(keep_changes=self.KeepLocalChanges): return self.git_repository_init( diff --git a/deploy/git_over_cdn/client.py b/deploy/git_over_cdn/client.py index 6cdbe3533..c238951d4 100644 --- a/deploy/git_over_cdn/client.py +++ b/deploy/git_over_cdn/client.py @@ -215,6 +215,23 @@ class GitOverCdnClient: else: self.git_command('reset', '--hard', f'{self.source}/{self.branch}') + def is_uptodate(self): + """ + Returns: + bool: If repo is up-to-date + """ + _ = self.current_commit + _ = self.latest_commit + if not self.current_commit: + self.logger.error('Failed to get current commit') + return False + if not self.latest_commit: + self.logger.error('Failed to get latest commit') + return False + if self.current_commit == self.latest_commit: + self.logger.info('Already up to date') + return True + def update(self, keep_changes=False): """ Args: diff --git a/module/webui/updater.py b/module/webui/updater.py index d0bf19751..b9841f9a7 100644 --- a/module/webui/updater.py +++ b/module/webui/updater.py @@ -68,6 +68,15 @@ class Updater(DeployConfig, GitManager, PipManager): def _check_update(self) -> bool: self.state = "checking" + + if State.deploy_config.GitOverCdn: + if self.goc_client.is_uptodate(): + logger.info(f"No update") + return False + else: + logger.info(f"New update available") + return True + source = "origin" for _ in range(3): if self.execute(