Skip to content

Commit

Permalink
Make mmk-updater optional
Browse files Browse the repository at this point in the history
  • Loading branch information
melianmiko committed Sep 20, 2024
1 parent ba712bf commit 70fcb44
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
10 changes: 6 additions & 4 deletions openfreebuds_qt/app/helper/update_widget_helper.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from typing import Optional

from PyQt6.QtWidgets import QWidget, QLabel

from mmk_updater import MmkUpdaterComon
from openfreebuds.utils.logger import create_logger

from openfreebuds_qt.config import OfbQtConfigParser
from openfreebuds_qt.generic import IOfbQtApplication

Expand All @@ -20,6 +16,9 @@ def __init__(self, root_widget: QWidget, label_widget: QLabel, ctx: IOfbQtApplic

def update_widget(self):
updater = self.ctx.updater_service.updater
if updater is None:
self.root_widget.setVisible(False)
return

log.info(f"{updater.has_update} {updater.release_info}")
if updater.has_update:
Expand All @@ -31,6 +30,9 @@ def update_widget(self):

def user_hide(self):
updater = self.ctx.updater_service.updater
if updater is None:
self.root_widget.setVisible(False)
return

self.config.set("updater", "ignored_version", updater.release_info.version)
self.config.save()
Expand Down
7 changes: 7 additions & 0 deletions openfreebuds_qt/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ def __init__(self, ctx: IOfbQtApplication):
self.extra_options_button.setMenu(self.extra_menu)
self._fill_extras_menu()

# Helpers
self.tabs = OfbQtSettingsTabHelper(self.tabs_list_content, self.body_content)
self.update_view = OfbQtUpdateWidgetHelper(self.updater_root, self.updater_header, self.ctx)

# Asyncio & update loop staff
self._ui_update_task: Optional[asyncio.Task] = None
self._update_check_task: Optional[asyncio.Task] = None
self._ui_modules: list[OfbQtCommonModule] = []
Expand Down Expand Up @@ -84,6 +86,10 @@ def __init__(self, ctx: IOfbQtApplication):
self.tabs.set_active_tab(*self.default_tab)

def _fill_extras_menu(self):
self.check_updates_action = self.extra_menu.addAction(self.tr("Check for updates..."))
# noinspection PyUnresolvedReferences
self.check_updates_action.triggered.connect(self.on_check_updates)

bugreport_action = self.extra_menu.addAction(self.tr("Bugreport..."))
bugreport_action.setShortcut("F2")
# noinspection PyUnresolvedReferences
Expand Down Expand Up @@ -162,6 +168,7 @@ async def _update_loop(self):

# First-time force update everything
await self._update_ui(OfbCoreEvent(None))
self.check_updates_action.setEnabled(self.ctx.updater_service.updater is not None)
self.update_view.update_widget()

try:
Expand Down
43 changes: 29 additions & 14 deletions openfreebuds_qt/utils/updater/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
from typing import Optional

from PyQt6.QtWidgets import QWidget
from openfreebuds_qt.config import OfbQtConfigParser

from mmk_updater import UpdateCheckerConfig
from mmk_updater.qt import MmkUpdaterQt

from openfreebuds.utils.logger import create_logger
from openfreebuds_qt.config import OfbQtConfigParser
from openfreebuds_qt.constants import STORAGE_PATH
from openfreebuds_qt.version_info import VERSION

try:
from mmk_updater import UpdateCheckerConfig
from mmk_updater.qt import MmkUpdaterQt
except ImportError:
UpdateCheckerConfig = None
MmkUpdaterQt = None

log = create_logger("OfbQtUpdaterService")


class OfbQtUpdaterService:
def __init__(self, parent: QWidget):
Expand All @@ -18,18 +25,26 @@ def __init__(self, parent: QWidget):
is_win32 = sys.platform == "win32"
mode = self.config.get("updater", "mode", "show")

self.updater_config = UpdateCheckerConfig(
server_url="https://st.mmk.pw/openfreebuds",
current_version=VERSION,
state_location=STORAGE_PATH / "qt_updater.json",
app_display_name="OpenFreebuds",
notify_method=(UpdateCheckerConfig.NotifyMethod.POP_UP
if is_win32 and mode == "show"
else UpdateCheckerConfig.NotifyMethod.NONE)
)
self.updater = MmkUpdaterQt(parent, self.updater_config)
if UpdateCheckerConfig is not None and MmkUpdaterQt is not None:
self.updater_config = UpdateCheckerConfig(
server_url="https://st.mmk.pw/openfreebuds",
current_version=VERSION,
state_location=STORAGE_PATH / "qt_updater.json",
app_display_name="OpenFreebuds",
notify_method=(UpdateCheckerConfig.NotifyMethod.POP_UP
if is_win32 and mode == "show"
else UpdateCheckerConfig.NotifyMethod.NONE)
)
self.updater = MmkUpdaterQt(parent, self.updater_config) # type: MmkUpdaterQt
else:
self.updater_config = None
self.updater = None # type: MmkUpdaterQt

async def boot(self):
if UpdateCheckerConfig is None:
log.info("Skip, unavailable")
return

if self.config.get("updater", "mode", "show") == "off":
return

Expand Down

0 comments on commit 70fcb44

Please sign in to comment.