Added update coding to the program, as well as fixed it so search lets you autocomplete.
This commit is contained in:
Binary file not shown.
46
update_checker.py
Normal file
46
update_checker.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
# ──────────────────────────────────────────────────────────────────────────────
|
||||||
|
# update_checker.py (fold this into main.py or import it)
|
||||||
|
# ──────────────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import webbrowser
|
||||||
|
from tkinter import messagebox
|
||||||
|
|
||||||
|
# Fill in your GitHub “owner/repo” here:
|
||||||
|
GITHUB_REPO = "YourUsername/YourRepo"
|
||||||
|
|
||||||
|
|
||||||
|
def check_for_updates(local_version: str, repo: str) -> None:
|
||||||
|
"""
|
||||||
|
1. Hits GitHub’s API: /repos/{repo}/releases/latest
|
||||||
|
2. Reads the "tag_name" of the latest release (e.g. "v1.2.60" or "1.2.60").
|
||||||
|
3. Strips any leading "v" and compares semver (major, minor, patch) tuples.
|
||||||
|
4. If GitHub’s version > local_version, prompts user to open the Releases page.
|
||||||
|
"""
|
||||||
|
api_url = f"https://api.github.com/repos/{repo}/releases/latest"
|
||||||
|
try:
|
||||||
|
resp = requests.get(api_url, timeout=5)
|
||||||
|
resp.raise_for_status()
|
||||||
|
data = resp.json()
|
||||||
|
tag = data.get("tag_name", "").lstrip("v")
|
||||||
|
except Exception:
|
||||||
|
return # silently do nothing on network or JSON errors
|
||||||
|
|
||||||
|
def to_tuple(v: str):
|
||||||
|
parts = [int(x) for x in v.split(".") if x.isdigit()]
|
||||||
|
return tuple(parts)
|
||||||
|
|
||||||
|
try:
|
||||||
|
if to_tuple(tag) > to_tuple(local_version):
|
||||||
|
answer = messagebox.askyesno(
|
||||||
|
"Update Available",
|
||||||
|
f"A newer release ({tag}) is available on GitHub.\n"
|
||||||
|
f"You’re currently on {local_version}.\n\n"
|
||||||
|
"Would you like to open the Releases page?"
|
||||||
|
)
|
||||||
|
if answer:
|
||||||
|
webbrowser.open(
|
||||||
|
data.get("html_url", f"https://github.com/{repo}/releases/latest")
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
pass
|
39
versioning.py
Normal file
39
versioning.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# ──────────────────────────────────────────────────────────────────────────────
|
||||||
|
# versioning.py (you could put this at the top of main.py or in its own file)
|
||||||
|
# ──────────────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import shlex
|
||||||
|
|
||||||
|
# Only bump these when you deliberately want to release a new major/minor:
|
||||||
|
MAJOR = 0
|
||||||
|
MINOR = 1
|
||||||
|
|
||||||
|
# Fallback “build” if not in a Git repo (e.g. when you zip up or PyInstaller‐bundle).
|
||||||
|
# In that scenario, commit‐count detection will fail and we’ll use this.
|
||||||
|
__version__ = f"{MAJOR}.{MINOR}.0"
|
||||||
|
|
||||||
|
|
||||||
|
def get_local_version() -> str:
|
||||||
|
"""
|
||||||
|
Try to get the current Git‐based build number via:
|
||||||
|
git rev-list --count HEAD
|
||||||
|
This returns an integer count of commits on HEAD. We build a version string:
|
||||||
|
"<MAJOR>.<MINOR>.<commit_count>"
|
||||||
|
If anything fails (no Git, or not in a repo), we fall back to __version__.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# This returns something like "57\n" if there have been 57 commits.
|
||||||
|
p = subprocess.run(
|
||||||
|
shlex.split("git rev-list --count HEAD"),
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
check=True,
|
||||||
|
text=True
|
||||||
|
)
|
||||||
|
build = p.stdout.strip()
|
||||||
|
# Construct "MAJOR.MINOR.build"
|
||||||
|
return f"{MAJOR}.{MINOR}.{build}"
|
||||||
|
except Exception:
|
||||||
|
# Either git isn’t installed or this isn’t a Git checkout.
|
||||||
|
return __version__
|
Reference in New Issue
Block a user