feat: add notification popup to inform users of malicious ads on megadb

This commit is contained in:
2026-04-10 16:27:53 +02:00
parent 4203969051
commit 14afc821b1
7 changed files with 42 additions and 5 deletions
+22
View File
@@ -1,7 +1,27 @@
from interface.dialogs.notificationpopup import NotificationPopup
from utils.config.settings import save_settings
from PySide6.QtCore import QObject, Signal, Qt
from PySide6.QtWidgets import QMessageBox
from utils.logging.logs import consoleLog from utils.logging.logs import consoleLog
from utils.data.state import state
import webbrowser import webbrowser
import re import re
class UIBridge(QObject):
show_notification = Signal()
ui_bridge = UIBridge()
def show_megadb_notification():
notification_popup = NotificationPopup("Opened MegaDB link in browser", "Beware of malicious Ads. Make sure to have an adblocker installed.\n" '<br><a href="https://ublockorigin.com">Visit uBlock Origin</a>')
notification_popup.setTextFormat(Qt.TextFormat.RichText)
notification_popup.setTextInteractionFlags(Qt.TextInteractionFlag.TextBrowserInteraction)
notification_popup.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
notification_popup.setWindowModality(Qt.WindowModality.ApplicationModal)
button = notification_popup.addButton("Don't show again", QMessageBox.ButtonRole.AcceptRole)
button.clicked.connect(lambda: setattr(state, "show_megadb_notification", False))
save_settings(show_megadb_notification=False)
notification_popup.exec()
def scrape_megadb(url): def scrape_megadb(url):
match = re.search(r"megadb\.net/([a-zA-Z0-9]+)", url) match = re.search(r"megadb\.net/([a-zA-Z0-9]+)", url)
@@ -11,4 +31,6 @@ def scrape_megadb(url):
consoleLog("MegaDB: Captcha required, launching browser...") consoleLog("MegaDB: Captcha required, launching browser...")
webbrowser.open(url) webbrowser.open(url)
if state.show_megadb_notification is True:
ui_bridge.show_notification.emit()
return None return None
+1 -1
View File
@@ -14,4 +14,4 @@ class NotificationPopup(QMessageBox):
if infotext is not None: if infotext is not None:
self.setInformativeText(infotext) self.setInformativeText(infotext)
self.setStandardButtons(QMessageBox.StandardButton.Ok) self.setStandardButtons(QMessageBox.StandardButton.Ok)
+9 -2
View File
@@ -1,3 +1,4 @@
from data.hosts.megadb import show_megadb_notification
from interface.utils.tabhelper import create_tab from interface.utils.tabhelper import create_tab
from interface.dialogs.theme import _accent_selection_color from interface.dialogs.theme import _accent_selection_color
from utils.config.settings import save_settings from utils.config.settings import save_settings
@@ -302,6 +303,11 @@ def settings_dialog(self):
close_to_tray_checkbox.setChecked(state.close_to_tray) close_to_tray_checkbox.setChecked(state.close_to_tray)
close_to_tray_checkbox.toggled.connect(lambda checked: setattr(state, 'close_to_tray', checked)) close_to_tray_checkbox.toggled.connect(lambda checked: setattr(state, 'close_to_tray', checked))
# Show MegaDB Notification
show_megadb_notification_container, show_megadb_notification_checkbox = create_widget(QCheckBox, "Show MegaDB Notifications: ")
show_megadb_notification_checkbox.setChecked(state.show_megadb_notification)
show_megadb_notification_checkbox.toggled.connect(lambda checked: setattr(state, 'show_megadb_notification', checked))
# Save / Cancel buttons # Save / Cancel buttons
layout = QHBoxLayout() layout = QHBoxLayout()
@@ -328,7 +334,8 @@ def settings_dialog(self):
image_as_wallpaper=image_mode_checkbox.isChecked(), image_as_wallpaper=image_mode_checkbox.isChecked(),
image_position=image_position_combo.currentText(), image_position=image_position_combo.currentText(),
accent_color=accent_color_input.text().strip(), accent_color=accent_color_input.text().strip(),
close_to_tray=close_to_tray_checkbox.isChecked() close_to_tray=close_to_tray_checkbox.isChecked(),
show_megadb_notification=show_megadb_notification_checkbox.isChecked()
) )
color = _accent_selection_color() color = _accent_selection_color()
if color: if color:
@@ -343,7 +350,7 @@ def settings_dialog(self):
layout.addWidget(save_btn) layout.addWidget(save_btn)
tabs = QtWidgets.QTabWidget() tabs = QtWidgets.QTabWidget()
create_tab("General", [autoresume_container, update_checkbox_container, transparent_window_container, accent_color_container, close_to_tray_container], tabs=tabs, stretch=True) create_tab("General", [autoresume_container, update_checkbox_container, transparent_window_container, accent_color_container, close_to_tray_container, show_megadb_notification_container], tabs=tabs, stretch=True)
create_tab("Image", [enable_image_container, image_mode_container, image_position_container, image_width_container, image_offset_container, image_opacity_container], tabs=tabs, stretch=True) create_tab("Image", [enable_image_container, image_mode_container, image_position_container, image_width_container, image_offset_container, image_opacity_container], tabs=tabs, stretch=True)
create_tab("Paths", [download_path_container, image_path_container], tabs=tabs, stretch=True) create_tab("Paths", [download_path_container, image_path_container], tabs=tabs, stretch=True)
create_tab("Network", [interface_container, max_connections_container, max_downloads_container, up_speed_limit_container, down_speed_limit_container, api_url_container], tabs=tabs, stretch=True) create_tab("Network", [interface_container, max_connections_container, max_downloads_container, up_speed_limit_container, down_speed_limit_container, api_url_container], tabs=tabs, stretch=True)
+3
View File
@@ -111,6 +111,9 @@ def run_gui(app):
single.on_raise = show_from_tray single.on_raise = show_from_tray
from data.hosts.megadb import ui_bridge, show_megadb_notification
ui_bridge.show_notification.connect(show_megadb_notification)
set_main_window(widget) set_main_window(widget)
widget.show() widget.show()
signal.signal(signal.SIGINT, signal.SIG_DFL) signal.signal(signal.SIGINT, signal.SIG_DFL)
+3 -1
View File
@@ -16,7 +16,8 @@ def create_config():
"autoresume": str(state.autoresume), "autoresume": str(state.autoresume),
"window_transparency": str(state.window_transparency), "window_transparency": str(state.window_transparency),
"accent_color": str(state.accent_color), "accent_color": str(state.accent_color),
"close_to_tray": str(state.close_to_tray) "close_to_tray": str(state.close_to_tray),
"show_megadb_notification": str(state.show_megadb_notification)
} }
config["Network"] = { config["Network"] = {
@@ -88,6 +89,7 @@ def read_config():
state.window_transparency = config.getboolean("General", "window_transparency", fallback=state.window_transparency) state.window_transparency = config.getboolean("General", "window_transparency", fallback=state.window_transparency)
state.accent_color = config.get("General", "accent_color", fallback=state.accent_color) state.accent_color = config.get("General", "accent_color", fallback=state.accent_color)
state.close_to_tray = config.getboolean("General", "close_to_tray", fallback=state.close_to_tray) state.close_to_tray = config.getboolean("General", "close_to_tray", fallback=state.close_to_tray)
state.show_megadb_notification = config.getboolean("General", "show_megadb_notification", fallback=state.show_megadb_notification)
# Network # Network
state.api_url = config.get("Network", "api_url", fallback=state.api_url) state.api_url = config.get("Network", "api_url", fallback=state.api_url)
+3 -1
View File
@@ -8,7 +8,7 @@ import platform
def save_settings(close=lambda: None, apiurl=None, download_path=None, down_speed_limit=None, up_speed_limit=None, image_path=None, autoresume=None, max_connections=None, max_downloads=None, bound_interface=None, image_width=None, image_offset=None, image_opacity=None, image_as_wallpaper=None, image_position=None, accent_color=None, close_to_tray=None): def save_settings(close=lambda: None, apiurl=None, download_path=None, down_speed_limit=None, up_speed_limit=None, image_path=None, autoresume=None, max_connections=None, max_downloads=None, bound_interface=None, image_width=None, image_offset=None, image_opacity=None, image_as_wallpaper=None, image_position=None, accent_color=None, close_to_tray=None, show_megadb_notification=None):
if apiurl is not None: if apiurl is not None:
state.api_url = apiurl state.api_url = apiurl
if download_path is not None: if download_path is not None:
@@ -45,6 +45,8 @@ def save_settings(close=lambda: None, apiurl=None, download_path=None, down_spee
qdarktheme.setup_theme("auto", custom_colors=custom_colors if custom_colors else None) qdarktheme.setup_theme("auto", custom_colors=custom_colors if custom_colors else None)
if close_to_tray is not None: if close_to_tray is not None:
state.close_to_tray = close_to_tray state.close_to_tray = close_to_tray
if show_megadb_notification is not None:
state.show_megadb_notification = show_megadb_notification
update_settings() # Update LibTorrent Session Settings update_settings() # Update LibTorrent Session Settings
consoleLog("Saved Settings") consoleLog("Saved Settings")
+1
View File
@@ -31,6 +31,7 @@ class AppState(QObject):
self.active_interfaces: List = [] self.active_interfaces: List = []
self.bound_interface: Any = None self.bound_interface: Any = None
self.close_to_tray: bool = True self.close_to_tray: bool = True
self.show_megadb_notification: bool = True
# Image # Image
self._image_enabled: bool = False self._image_enabled: bool = False