diff --git a/SUPERCOPY.py b/SUPERCOPY.py index ce913a5..d607aed 100644 --- a/SUPERCOPY.py +++ b/SUPERCOPY.py @@ -3,6 +3,7 @@ files = [ "core/discord_presence.py", "core/file_search.py", "core/headers.py", + "core/updater.py", "core/web_search.py", "main.py" ] diff --git a/core/updater.py b/core/updater.py index 01ae175..05e1b53 100644 --- a/core/updater.py +++ b/core/updater.py @@ -1,27 +1,33 @@ -from git import Repo +from git import Repo, GitCommandError from pathlib import Path -REPO_URL = "https://github.com/n0va-bot/CLARA" -REPO_DIR = Path(__file__).parent +REPO_DIR = Path(__file__).parent.parent def update_repository(): try: + if not (REPO_DIR / ".git").exists(): + return "FAILED", "Not a git repository. Cannot update." + repo = Repo(REPO_DIR) - current_branch = repo.active_branch - - print(f"Fetching latest changes from {current_branch}...") origin = repo.remotes.origin + origin.fetch() - print(f"Pulling changes for branch {current_branch}...") + 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() - print("Repository updated successfully.") - return True + return "UPDATED", "CLARA has been updated successfully." + + except GitCommandError as e: + return "FAILED", f"An error occurred during the update:\n\n{e}" except Exception as e: - print(f"Error updating repository: {e}") - return False + return "FAILED", f"An unexpected error occurred:\n\n{e}" if __name__ == "__main__": - REPO_DIR = Path(__file__).parent / ".." - update_repository() \ No newline at end of file + status, message = update_repository() + print(f"Status: {status}\nMessage: {message}") \ No newline at end of file diff --git a/main.py b/main.py index 0822b3a..ff67130 100644 --- a/main.py +++ b/main.py @@ -449,12 +449,31 @@ class MainWindow(QtWidgets.QMainWindow): QtWidgets.QApplication.restoreOverrideCursor() def update_git(self): - update_repository() - QtWidgets.QMessageBox.information(self, "Update", "Repository updated. Restarting application.") - self.restart_application() + status, message = update_repository() + + if status == "UPDATED": + reply = QtWidgets.QMessageBox.question(self, "Update Successful", + f"{message}\n\nWould you like to restart now to apply the changes?", + QtWidgets.QMessageBox.StandardButton.Yes | QtWidgets.QMessageBox.StandardButton.No, + QtWidgets.QMessageBox.StandardButton.Yes) + if reply == QtWidgets.QMessageBox.StandardButton.Yes: + self.restart_application() + + elif status == "UP_TO_DATE": + QtWidgets.QMessageBox.information(self, "No Updates", message) + + elif status == "FAILED": + QtWidgets.QMessageBox.critical(self, "Update Failed", message) def restart_application(self): - subprocess.Popen([sys.executable] + sys.argv) + presence.end() + + args = [sys.executable] + sys.argv + if "--restart" not in args: + args.append("--restart") + + subprocess.Popen(args) + QtWidgets.QApplication.quit() @@ -475,8 +494,10 @@ def main(): pet.show() + # Gracefully handle shutdown + app.aboutToQuit.connect(presence.end) sys.exit(app.exec()) - presence.end() + if __name__ == "__main__": main() \ No newline at end of file