This repository has been archived by the owner on Jan 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #271 from leminlimez/v4.2
v4.2
- Loading branch information
Showing
17 changed files
with
2,683 additions
and
1,050 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from requests import get, RequestException | ||
from json import JSONDecodeError | ||
from devicemanagement.constants import Version | ||
|
||
Nugget_Repo = "leminlimez/Nugget/releases/latest" | ||
|
||
last_fetched_version: str = None | ||
|
||
def is_update_available(version: str, build: int) -> bool: | ||
# check github for if version < tag (or == tag but build > 0) | ||
latest_version = get_latest_version() | ||
if latest_version != None: | ||
if build > 0 and latest_version == version: # on beta version when there is a public release | ||
return True | ||
elif Version(latest_version) > Version(version): | ||
return True | ||
return False | ||
|
||
def get_latest_version() -> str: | ||
global last_fetched_version | ||
# get the cached version | ||
if last_fetched_version != None: | ||
return last_fetched_version | ||
# fetch with web requests | ||
try: | ||
response = get(f"https://api.github.com/repos/{Nugget_Repo}") | ||
response.raise_for_status() # To raise an exception for 4xx/5xx responses | ||
|
||
data = response.json() # Parse the JSON response | ||
|
||
# Check if "tag_name" exists in the response and compare the version | ||
tag_name = data.get("tag_name") | ||
if tag_name: | ||
last_fetched_version = tag_name.replace("v", "") # Remove 'v' from tag_name | ||
return last_fetched_version | ||
except RequestException as e: | ||
print(f"Error fetching data: {e}") | ||
except JSONDecodeError as e: | ||
print(f"Error parsing JSON: {e}") | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.