Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Update Checks on Main Menu Startup #703

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/assets/ba_data/python/bascenev1lib/mainmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
if TYPE_CHECKING:
from typing import Any

SEND_UPDATE_MESSAGE = True


class MainMenuActivity(bs.Activity[bs.Player, bs.Team]):
"""Activity showing the rotating main menu bg stuff."""
Expand Down Expand Up @@ -412,6 +414,13 @@ def try_again() -> None:

bui.apptimer(2.0, try_again)

if app.config.resolve('Automatically Check for Updates'):
app.classic.master_server_v1_get(
'bsLatestBuildNumber',
{'debug': env.debug},
callback=bs.WeakCall(self._on_update_check_response),
)

app.classic.main_menu_did_initial_transition = True

def _update(self) -> None:
Expand Down Expand Up @@ -865,6 +874,25 @@ def _update_attract_mode(self) -> None:
attract_mode=True,
)

def _on_update_check_response(self, data: dict[str, Any] | None) -> None:
global SEND_UPDATE_MESSAGE # pylint: disable=global-statement
if (
SEND_UPDATE_MESSAGE
and data
and data.get('build_number', 0) > bs.app.env.engine_build_number
):
bs.screenmessage(
'A new update for ${APP_NAME} is available!', (0.0, 1.0, 0.0)
)
bs.screenmessage(
'(You can disable automatic update checks in'
' Settings->Advanced)',
(1.0, 1.0, 0.0),
)
SEND_UPDATE_MESSAGE = False
with self.context:
bs.getsound('ding').play(host_only=True)


class NewsDisplay:
"""Wrangles news display."""
Expand Down
18 changes: 17 additions & 1 deletion src/assets/ba_data/python/bauiv1lib/settings/advanced.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Released under the MIT License. See LICENSE for details.
#
# pylint: disable=too-many-lines
"""UI functionality for advanced settings."""

from __future__ import annotations
Expand Down Expand Up @@ -90,7 +91,7 @@ def __init__(
self._scroll_width = self._width - (100 + 2 * x_inset)
self._scroll_height = self._height - 115.0
self._sub_width = self._scroll_width * 0.95
self._sub_height = 870.0
self._sub_height = 912.0

if self._show_always_use_internal_keyboard:
self._sub_height += 62
Expand Down Expand Up @@ -465,6 +466,16 @@ def _rebuild(self) -> None:
maxwidth=430,
)

v -= 42
self._auto_update_check_box = ConfigCheckBox(
parent=self._subcontainer,
position=(50, v),
size=(self._sub_width - 100, 30),
configkey='Automatically Check for Updates',
scale=1.0,
maxwidth=430,
)

v -= 42
self._show_demos_when_idle_check_box = ConfigCheckBox(
parent=self._subcontainer,
Expand Down Expand Up @@ -844,6 +855,8 @@ def _save_state(self) -> None:
sel_name = 'ShowDeprecatedLoginTypes'
elif sel == self._show_game_ping_check_box.widget:
sel_name = 'ShowPing'
elif sel == self._auto_update_check_box.widget:
sel_name = 'AutoUpdateCheck'
elif sel == self._disable_camera_shake_check_box.widget:
sel_name = 'DisableCameraShake'
elif (
Expand Down Expand Up @@ -888,6 +901,7 @@ def _save_state(self) -> None:

def _restore_state(self) -> None:
# pylint: disable=too-many-branches
# pylint: disable=too-many-statements
try:
assert bui.app.classic is not None
sel_name = bui.app.ui_v1.window_states.get(type(self), {}).get(
Expand Down Expand Up @@ -915,6 +929,8 @@ def _restore_state(self) -> None:
sel = self._show_deprecated_login_types_check_box.widget
elif sel_name == 'ShowPing':
sel = self._show_game_ping_check_box.widget
elif sel_name == 'AutoUpdateCheck':
sel = self._auto_update_check_box.widget
elif sel_name == 'DisableCameraShake':
sel = self._disable_camera_shake_check_box.widget
elif (
Expand Down