|
1 | | -# This part already exists in the code - it checks for updates on startup |
2 | | -def check_for_updates(parent_window=None, show_result=True): |
3 | | - """ |
4 | | - Check GitHub Releases for a newer version. |
5 | | - Downloads and installs update if available. |
6 | | - """ |
7 | | - try: |
8 | | - url = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/releases/latest" |
9 | | - r = requests.get(url, timeout=10) |
10 | | - r.raise_for_status() |
11 | | - latest = r.json() |
12 | | - |
13 | | - # Compare versions |
14 | | - if Version(latest["tag_name"].lstrip("v")) > Version(VERSION): |
15 | | - # Download new version |
16 | | - download_url = latest["assets"][0]["browser_download_url"] |
17 | | - |
18 | | - # Download and verify |
19 | | - update_dir = Path(os.getenv("LOCALAPPDATA")) / "TimeMachine" / "updates" |
20 | | - update_dir.mkdir(parents=True, exist_ok=True) |
21 | | - new_exe = update_dir / "time-machine-new.exe" |
22 | | - |
23 | | - # Download |
24 | | - with requests.get(download_url, stream=True) as r: |
25 | | - with open(new_exe, "wb") as f: |
26 | | - shutil.copyfileobj(r.raw, f) |
27 | | - |
28 | | - # Launch updater to replace exe |
29 | | - updater_path = get_local_exe_path().parent / "time-machine-updater.exe" |
30 | | - if updater_path.exists(): |
31 | | - subprocess.Popen([ |
32 | | - str(updater_path), |
33 | | - "--target", str(get_local_exe_path()), |
34 | | - "--new", str(new_exe), |
35 | | - "--restart" |
36 | | - ]) |
37 | | - QtWidgets.QApplication.quit() |
38 | | - return True |
39 | | - |
40 | | - except Exception as e: |
41 | | - if show_result: |
42 | | - QtWidgets.QMessageBox.warning(parent_window, "Update Error", str(e)) |
43 | | - return False |
| 1 | +import sys |
| 2 | +from PySide6 import QtWidgets, QtCore |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +VERSION = "0.1.0" |
44 | 6 |
|
45 | | -# Add these lines to enable automatic update checks |
46 | 7 | class MainWindow(QtWidgets.QMainWindow): |
47 | 8 | def __init__(self): |
48 | | - # ... existing init code ... |
49 | | - |
50 | | - # Check for updates every hour |
51 | | - self.update_timer = QtCore.QTimer() |
52 | | - self.update_timer.timeout.connect(lambda: check_for_updates(self, show_result=False)) |
53 | | - self.update_timer.start(3600000) # 1 hour in milliseconds |
54 | | - |
55 | | - # Also check at startup |
56 | | - QtCore.QTimer.singleShot(5000, lambda: check_for_updates(self, show_result=False)) |
| 9 | + super().__init__() |
| 10 | + self.setWindowTitle(f"Time Machine v{VERSION}") |
| 11 | + self.resize(800, 600) |
| 12 | + |
| 13 | +def main(): |
| 14 | + app = QtWidgets.QApplication(sys.argv) |
| 15 | + window = MainWindow() |
| 16 | + window.show() |
| 17 | + sys.exit(app.exec()) |
| 18 | + |
| 19 | +if __name__ == "__main__": |
| 20 | + main() |
0 commit comments