Skip to content

Commit d37570b

Browse files
authored
Merge pull request #8 from apple1417/master
fix update available notification not immediately clearing after updating
2 parents e0f1461 + db330e0 commit d37570b

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

Readme.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ game specific things:
1919

2020
# Changelog
2121

22-
### v1.7 (Upcoming)
22+
### v1.7
23+
- The "Update Available" notification should now immediately go away upon updating, instead of
24+
waiting a day for the next check.
25+
2326
- Changed the functions the keybind implementation should overwrite from `KeybindType.enable` to
2427
`KeybindType._enable` (+ same for disable). These functions don't need to set `is_enabled`.
2528

mod_list.py

+35-8
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ def get_this_release_tuple(self) -> tuple[int, ...] | None:
228228
return None
229229
return tuple(int(x) for x in version_match.groups())
230230

231-
def get_latest_release_version(self) -> tuple[str, tuple[int, ...]] | tuple[None, None]:
231+
def fetch_latest_version(self) -> tuple[str, tuple[int, ...]] | tuple[None, None]:
232232
"""
233-
Gets the version of the latest release.
233+
Fetches the version of the latest release from github.
234234
235235
Should be called in a thread, as this makes a blocking HTTP request.
236236
@@ -260,6 +260,29 @@ def get_latest_release_version(self) -> tuple[str, tuple[int, ...]] | tuple[None
260260
unrealsdk.logging.dev_warning(traceback.format_exc())
261261
return None, None
262262

263+
def get_latest_cached_version(self) -> tuple[str, tuple[int, ...]] | tuple[None, None]:
264+
"""
265+
Gets the version of the latest release from our cached setting.
266+
267+
Returns:
268+
A tuple of the latest version name and version tuple, or None and None if unknown.
269+
"""
270+
try:
271+
name = self.latest_version_option.value
272+
if name is None:
273+
raise ValueError
274+
275+
match = RE_MANAGER_VERSION.match(name)
276+
if match is None:
277+
raise ValueError
278+
279+
return name, tuple(int(x) for x in match.groups())
280+
281+
except Exception: # noqa: BLE001
282+
self.latest_version_option.value = None
283+
self.save_settings()
284+
return None, None
285+
263286
def perform_version_check(self) -> None:
264287
"""
265288
Checks if there's a newer version, and updates the options appropriately.
@@ -271,16 +294,20 @@ def perform_version_check(self) -> None:
271294
unrealsdk.logging.warning("Skipping SDK update check since current version is unknown")
272295
return
273296

297+
fetch_new_version = False
274298
try:
275299
next_check_time = datetime.fromisoformat(self.next_version_check_time_option.value)
276-
if next_check_time > datetime.now(UTC):
277-
# Not time yet
278-
return
300+
if next_check_time < datetime.now(UTC):
301+
fetch_new_version = True
279302
except ValueError:
280-
# If we failed to parse the option, assume we need a new check
281-
pass
303+
# If we failed to parse the option, assume we need to re-fetch
304+
fetch_new_version = True
305+
306+
if fetch_new_version:
307+
latest_version_name, latest_version_tuple = self.fetch_latest_version()
308+
else:
309+
latest_version_name, latest_version_tuple = self.get_latest_cached_version()
282310

283-
latest_version_name, latest_version_tuple = self.get_latest_release_version()
284311
if latest_version_name is None or latest_version_tuple is None:
285312
return
286313

0 commit comments

Comments
 (0)