Browser Update Warnings implemented after big bang menu refactor

This commit is contained in:
SimplifiedPrivacy 2026-11-18 11:24:31 -05:00
parent ee1157d9ab
commit 49d4bdc87b
3 changed files with 75 additions and 18 deletions

View file

@ -16,7 +16,7 @@ class ProfileDto():
location_icon_path: Path location_icon_path: Path
app_icon_path: Path app_icon_path: Path
protocol_icon_path: Path protocol_icon_path: Path
needs_warning: bool = False needs_warning: bool
@dataclass @dataclass
@ -29,12 +29,36 @@ class RenderProfileDto():
detail_image: Path detail_image: Path
primary_asset: Path primary_asset: Path
raised_primary_asset: bool raised_primary_asset: bool
needs_warning: bool
def _is_browser_box_this_image(image_path: Path, profile_type: ProfileType, is_tor: bool) -> Path|None: def _evaluate_app_warnings(profile_type: ProfileType, application: dict) -> bool:
"""Check if the application needs a warning to upgrade"""
if not profile_type == ProfileType.SESSION:
return False
if not application:
return False
format_revision = application.get("format_revision", 1)
if format_revision == 2:
return False
else:
return True
def _is_browser_box_this_image(image_path: Path, profile_type: ProfileType, is_tor: bool, needs_warning: bool) -> Path|None:
"""Should the browser box be the detail image? If so, give us the image path""" """Should the browser box be the detail image? If so, give us the image path"""
if needs_warning:
app_image = "unsupported_browser_only.png"
else:
app_image = "browser only.png"
if profile_type == ProfileType.SESSION and not is_tor: # (tor doesn't need the browser border) if profile_type == ProfileType.SESSION and not is_tor: # (tor doesn't need the browser border)
final_image_path = Path(image_path, "browser only.png") final_image_path = Path(image_path, app_image)
if not final_image_path.exists(): if not final_image_path.exists():
final_image_path = None final_image_path = None
else: else:
@ -42,7 +66,6 @@ def _is_browser_box_this_image(image_path: Path, profile_type: ProfileType, is_t
return final_image_path return final_image_path
def convert_one_render_dto(raw_dict: dict) -> Optional[RenderProfileDto]: def convert_one_render_dto(raw_dict: dict) -> Optional[RenderProfileDto]:
"""Get a DTO for the left side of the menu's rendering.""" """Get a DTO for the left side of the menu's rendering."""
@ -79,7 +102,11 @@ def convert_one_render_dto(raw_dict: dict) -> Optional[RenderProfileDto]:
operator_name = operator.get("name", "N/A") operator_name = operator.get("name", "N/A")
sp_operator = bool(operator_name in ("Simplified Privacy", "simplified privacy")) sp_operator = bool(operator_name in ("Simplified Privacy", "simplified privacy"))
is_tor = bool(protocol == ProtocolChoice.TOR) is_tor = bool(protocol == ProtocolChoice.TOR)
detail_image = None
application = raw_dict.get("application_version")
needs_warning = _evaluate_app_warnings(profile_type=profile_type, application=application)
# detail_image = None
if sp_operator or is_tor: if sp_operator or is_tor:
raised_primary_asset = True raised_primary_asset = True
@ -90,7 +117,7 @@ def convert_one_render_dto(raw_dict: dict) -> Optional[RenderProfileDto]:
protocol=protocol protocol=protocol
) )
detail_image = _is_browser_box_this_image(image_path=image_path, profile_type=profile_type, is_tor=is_tor) detail_image = _is_browser_box_this_image(image_path=image_path, profile_type=profile_type, is_tor=is_tor, needs_warning=needs_warning)
else: else:
raised_primary_asset = False raised_primary_asset = False
@ -101,7 +128,13 @@ def convert_one_render_dto(raw_dict: dict) -> Optional[RenderProfileDto]:
larger_version=True larger_version=True
) )
primary_asset = _is_browser_box_this_image(image_path=image_path, profile_type=profile_type, is_tor=is_tor) # warning to false, so the text doesn't clash with the text,
primary_asset = _is_browser_box_this_image(image_path=image_path, profile_type=profile_type, is_tor=is_tor, needs_warning=False)
# # then because we need to warn them somehow, do so with the operator name,
# operator_name = "Upgrade Browser!"
# location_text = "Upgrade Browser!"
# nostr_public_key = "Go to Edit Profile to Upgrade"
@ -113,7 +146,8 @@ def convert_one_render_dto(raw_dict: dict) -> Optional[RenderProfileDto]:
nostr_public_key=nostr_public_key, nostr_public_key=nostr_public_key,
detail_image=detail_image, detail_image=detail_image,
primary_asset=primary_asset, primary_asset=primary_asset,
raised_primary_asset=raised_primary_asset raised_primary_asset=raised_primary_asset,
needs_warning=needs_warning
) )
@ -147,12 +181,8 @@ def convert_to_dto(raw_dict: dict) -> ProfileDto:
app_name=application.get('application_code', "na") if application else "na" app_name=application.get('application_code', "na") if application else "na"
) )
format_revision = raw_dict.get("format_revision", 1) # Warnings for unsupported browser:
needs_warning = _evaluate_app_warnings(profile_type=profile_type, application=application)
if profile_type == ProfileType.SYSTEM or format_revision == 2:
needs_warning = False
else:
needs_warning = True
protocol_icon_path = get_protocol_icon_path( protocol_icon_path = get_protocol_icon_path(
image_path=image_path, image_path=image_path,

View file

@ -15,6 +15,7 @@ from core.models.Result import ResultError
from pathlib import Path from pathlib import Path
from dataclasses import dataclass from dataclasses import dataclass
from typing import Optional, Dict from typing import Optional, Dict
import random
@dataclass @dataclass
class PreEdit: class PreEdit:
@ -79,6 +80,18 @@ class RegistrationState:
self.selections[category] = None self.selections[category] = None
def _apply_order_filter(self, category: str, order: list) -> list:
"""apply custom sorting or filtering based on the category"""
if category == "browser":
# browser is reversed order (so highest IDs are first)
return order[::-1]
if category == "location":
# location is random order
return random.sample(order, len(order))
return order
def _load_all_data(self, default_data: Optional[dict] = None): def _load_all_data(self, default_data: Optional[dict] = None):
"""Load the data for a given category, and then register that data""" """Load the data for a given category, and then register that data"""
load_config = { load_config = {
@ -102,10 +115,15 @@ class RegistrationState:
def _register_category(self, category: str, data: dict, default_data: Optional[dict], default_idx: int = 0): def _register_category(self, category: str, data: dict, default_data: Optional[dict], default_idx: int = 0):
"""Setup a category with a given data set and default index""" """Setup a category with a given data set and default index"""
if isinstance(data, list): if isinstance(data, list):
data = {item: item for item in data} data = {item: item for item in data}
self.all_options[category] = data self.all_options[category] = data
self.order_map[category] = list(data.keys()) # self.order_map[category] = list(data.keys())
raw_order = list(data.keys())
self.order_map[category] = self._apply_order_filter(category, raw_order)
# Default selection logic # Default selection logic
if default_data is not None: if default_data is not None:

View file

@ -546,14 +546,23 @@ class MenuPage(Page):
operator_name = dto.operator_name operator_name = dto.operator_name
nostr_public_key = dto.nostr_public_key nostr_public_key = dto.nostr_public_key
detail_image = dto.detail_image detail_image = dto.detail_image
needs_warning = dto.needs_warning
if needs_warning:
top_text = "Upgrade browser!"
bottom_text = "Go to Edit Profile, and Pick a New Browser."
else:
top_text = f"Location: {location_text}\n\nOperator: {operator_name}"
bottom_text = f"Nostr: {nostr_public_key}"
color = "black" if profile_type == ProfileType.SESSION else "white" color = "black" if profile_type == ProfileType.SESSION else "white"
self._detail_image(detail_image, (20, 125, 100, 100)) self._detail_image(detail_image, (20, 125, 100, 100))
text_blocks = [ text_blocks = [
((130, 110, 260, 250), f"Location: {location_text}\n\nOperator: {operator_name}", ((130, 110, 260, 250), top_text,
QtGui.QTextOption.WrapMode.WrapAtWordBoundaryOrAnywhere), QtGui.QTextOption.WrapMode.WrapAtWordBoundaryOrAnywhere),
((20, 260, 370, 80), f"Nostr: {nostr_public_key}", QtGui.QTextOption.WrapMode.WrapAnywhere), ((20, 260, 370, 80), bottom_text, QtGui.QTextOption.WrapMode.WrapAnywhere),
] ]
for geometry, text, wrapping in text_blocks: for geometry, text, wrapping in text_blocks:
widget = QTextEdit(self) widget = QTextEdit(self)