better updater
This commit is contained in:
@@ -3,6 +3,24 @@ from pathlib import Path
|
|||||||
|
|
||||||
REPO_DIR = Path(__file__).parent.parent
|
REPO_DIR = Path(__file__).parent.parent
|
||||||
|
|
||||||
|
def is_update_available():
|
||||||
|
try:
|
||||||
|
if not (REPO_DIR / ".git").exists():
|
||||||
|
return False
|
||||||
|
|
||||||
|
repo = Repo(REPO_DIR)
|
||||||
|
origin = repo.remotes.origin
|
||||||
|
|
||||||
|
origin.fetch()
|
||||||
|
local_commit = repo.head.commit
|
||||||
|
remote_commit = origin.refs[repo.active_branch.name].commit
|
||||||
|
|
||||||
|
return local_commit != remote_commit
|
||||||
|
except GitCommandError:
|
||||||
|
return False
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
def update_repository():
|
def update_repository():
|
||||||
try:
|
try:
|
||||||
if not (REPO_DIR / ".git").exists():
|
if not (REPO_DIR / ".git").exists():
|
||||||
@@ -11,14 +29,6 @@ def update_repository():
|
|||||||
repo = Repo(REPO_DIR)
|
repo = Repo(REPO_DIR)
|
||||||
origin = repo.remotes.origin
|
origin = repo.remotes.origin
|
||||||
|
|
||||||
origin.fetch()
|
|
||||||
|
|
||||||
local_commit = repo.head.commit
|
|
||||||
remote_commit = origin.refs[repo.active_branch.name].commit
|
|
||||||
|
|
||||||
if local_commit == remote_commit:
|
|
||||||
return "UP_TO_DATE", "You are already on the latest version."
|
|
||||||
|
|
||||||
origin.pull()
|
origin.pull()
|
||||||
|
|
||||||
return "UPDATED", "CLARA has been updated successfully."
|
return "UPDATED", "CLARA has been updated successfully."
|
||||||
|
|||||||
11
main.py
11
main.py
@@ -8,7 +8,7 @@ from core.file_search import find
|
|||||||
from core.web_search import MullvadLetaWrapper
|
from core.web_search import MullvadLetaWrapper
|
||||||
from core.discord_presence import presence
|
from core.discord_presence import presence
|
||||||
from core.app_launcher import list_apps, launch
|
from core.app_launcher import list_apps, launch
|
||||||
from core.updater import update_repository
|
from core.updater import update_repository, is_update_available
|
||||||
|
|
||||||
ASSET = Path(__file__).parent / "assets" / "2ktan.png"
|
ASSET = Path(__file__).parent / "assets" / "2ktan.png"
|
||||||
|
|
||||||
@@ -472,6 +472,12 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
QtWidgets.QApplication.restoreOverrideCursor()
|
QtWidgets.QApplication.restoreOverrideCursor()
|
||||||
|
|
||||||
def update_git(self):
|
def update_git(self):
|
||||||
|
update_available = is_update_available()
|
||||||
|
|
||||||
|
if not update_available:
|
||||||
|
QtWidgets.QMessageBox.information(self, "No Updates", "You are already on the latest version.")
|
||||||
|
return
|
||||||
|
|
||||||
status, message = update_repository()
|
status, message = update_repository()
|
||||||
|
|
||||||
if status == "UPDATED":
|
if status == "UPDATED":
|
||||||
@@ -482,9 +488,6 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
if reply == QtWidgets.QMessageBox.StandardButton.Yes:
|
if reply == QtWidgets.QMessageBox.StandardButton.Yes:
|
||||||
self.restart_application()
|
self.restart_application()
|
||||||
|
|
||||||
elif status == "UP_TO_DATE":
|
|
||||||
QtWidgets.QMessageBox.information(self, "No Updates", message)
|
|
||||||
|
|
||||||
elif status == "FAILED":
|
elif status == "FAILED":
|
||||||
QtWidgets.QMessageBox.critical(self, "Update Failed", message)
|
QtWidgets.QMessageBox.critical(self, "Update Failed", message)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user