Skip to content

Commit 3425429

Browse files
committed
small bug fixes
1 parent 9bc21e1 commit 3425429

File tree

6 files changed

+47
-44
lines changed

6 files changed

+47
-44
lines changed

src/switchcraft/assets/splash.png

-29.6 KB
Loading

src/switchcraft/gui_modern/app.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ def __init__(self, page: ft.Page, splash_proc=None):
153153

154154
# Now add listener
155155
self.notification_service.add_listener(self._on_notification_update)
156-
# Sync initial state (badge, etc)
156+
# Sync initial state (badge, etc) WITHOUT triggering system toasts for old ones
157+
notifs = self.notification_service.get_notifications()
158+
if notifs:
159+
self._last_notif_id = notifs[0]["id"]
157160
self._on_notification_update()
158161

159162
# Back button (Early init for AppBar)
@@ -269,14 +272,29 @@ def _open_help(self, e):
269272
url = self._get_help_url(current_idx)
270273
logger.info(f"Opening help for index {current_idx}: {url}")
271274

272-
# Use page.launch_url for cross-platform compatibility (Web/Desktop)
275+
if not url:
276+
return
277+
278+
# Try usage of webbrowser for desktop (more reliable)
279+
if not IS_WEB:
280+
try:
281+
import webbrowser
282+
webbrowser.open(url)
283+
return
284+
except Exception as wb_ex:
285+
logger.warning(f"webbrowser.open failed: {wb_ex}")
286+
287+
# Fallback to Flet's launch_url (Web or fallback)
273288
self.page.launch_url(url)
274289

275290
except Exception as ex:
276291
logger.error(f"Failed to open help: {ex}")
277-
self.page.snack_bar = ft.SnackBar(ft.Text(f"Failed to open help: {ex}"), bgcolor="RED")
278-
self.page.snack_bar.open = True
279-
self.page.update()
292+
try:
293+
self.page.snack_bar = ft.SnackBar(ft.Text(f"Failed to open help: {ex}"), bgcolor="RED")
294+
self.page.snack_bar.open = True
295+
self.page.update()
296+
except Exception:
297+
pass
280298

281299
def _terminate_splash(self):
282300
"""

src/switchcraft/gui_modern/utils/view_utils.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -401,16 +401,16 @@ def _open_dialog_safe(self, dlg):
401401
return False
402402

403403
try:
404-
# Method 1: Modern API (Preferred)
405-
if hasattr(page, 'open'):
406-
try:
407-
logger.debug("Attempting to open dialog using page.open()...")
408-
page.open(dlg)
409-
page.update()
410-
logger.info("Dialog opened successfully using page.open()")
411-
return True
412-
except Exception as e:
413-
logger.warning(f"page.open(dlg) failed: {e}. Falling back to legacy mode.")
404+
# Method 1: Modern API (Preferred) - DISABLED due to visibility issues on Windows Desktop
405+
# if hasattr(page, 'open'):
406+
# try:
407+
# logger.debug("Attempting to open dialog using page.open()...")
408+
# page.open(dlg)
409+
# page.update()
410+
# logger.info("Dialog opened successfully using page.open()")
411+
# return True
412+
# except Exception as e:
413+
# logger.warning(f"page.open(dlg) failed: {e}. Falling back to legacy mode.")
414414

415415
# Method 2: Legacy API (Fallback)
416416
logger.debug("Attempting to open dialog using legacy page.dialog...")

src/switchcraft/gui_modern/views/settings_view.py

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -823,38 +823,22 @@ def _run():
823823
self._run_in_background(_run)
824824

825825
def _on_github_login_click(self, e):
826-
"""Handle GitHub login button click."""
827-
self._ensure_backend()
826+
"""Handle the GitHub login button click."""
828827
try:
829-
logger.debug("_on_github_login_click STARTED")
830-
# Visual feedback
831-
if hasattr(e.control, 'text'):
832-
e.control.text = "Clicked..."
833-
e.control.update()
834-
elif hasattr(e.control, 'content') and hasattr(e.control.content, 'controls'):
835-
# It's likely a row with Icon+Text
836-
for c in e.control.content.controls:
837-
if isinstance(c, ft.Text):
838-
c.value = "Clicked..."
839-
e.control.update()
840-
841-
logger.info("GitHub login clicked (direct handler)")
828+
logger.info("[GITHUB_LOGIN] Button clicked. Context: " + ("Desktop" if not IS_WEB else "Web"))
842829
self._ensure_backend() # Restore context first
830+
843831
# Show snack immediately
844-
self._show_snack("Starting GitHub Login...", "BLUE")
832+
self.app_page.snack_bar = ft.SnackBar(ft.Text("Starting GitHub Login flow..."), bgcolor="BLUE")
833+
self.app_page.snack_bar.open = True
834+
self.app_page.update()
835+
836+
logger.info("[GITHUB_LOGIN] Showing permission dialog...")
845837
# Proceed to permission dialog
846838
self._show_permission_dialog(self._start_github_login)
847-
logger.debug("_on_github_login_click FINISHED")
839+
logger.debug("[GITHUB_LOGIN] _on_github_login_click method finished")
848840
except Exception as ex:
849-
logger.exception(f"CRITICAL: Failed in _on_github_login_click: {ex}")
850-
# Try to show error on button
851-
try:
852-
if hasattr(e.control, 'text'):
853-
e.control.text = f"Err: {str(ex)[:20]}"
854-
e.control.bgcolor = "RED"
855-
e.control.update()
856-
except:
857-
pass
841+
logger.exception(f"[GITHUB_LOGIN] CRITICAL error in _on_github_login_click: {ex}")
858842
self._show_snack(f"Login Error: {ex}", "RED")
859843

860844
def _show_permission_dialog(self, callback):
@@ -973,6 +957,7 @@ async def _run_login_flow():
973957
# We run this in a thread executor if it's synchronous, or directly if async
974958
# AuthService.initiate_device_flow is likely sync (requests), so we wrap it
975959
import asyncio
960+
from switchcraft.services.auth_service import AuthService
976961

977962
logger.debug("Starting GitHub login flow (Async)...")
978963

src/switchcraft/services/auth_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def check_token_once(cls, device_code: str) -> Optional[str]:
7777
"""
7878
headers = {"Accept": "application/json"}
7979
data = {
80-
"client_id": cls.CLIENT_ID,
80+
"client_id": cls.get_client_id() or "Ov23liFQxD8H5In5LqBM",
8181
"device_code": device_code,
8282
"grant_type": "urn:ietf:params:oauth:grant-type:device_code"
8383
}
@@ -116,7 +116,7 @@ def poll_for_token(cls, device_code: str, interval: int = 5, expires_in: int = 9
116116

117117
headers = {"Accept": "application/json"}
118118
data = {
119-
"client_id": cls.CLIENT_ID,
119+
"client_id": cls.get_client_id() or "Ov23liFQxD8H5In5LqBM",
120120
"device_code": device_code,
121121
"grant_type": "urn:ietf:params:oauth:grant-type:device_code"
122122
}

src/switchcraft_winget/utils/winget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def get_package_details(self, package_id: str) -> Dict[str, str]:
340340
try:
341341
# Use 'winget show' which provides full manifest details
342342
# Add --disable-interactivity to prevent any interactive prompts
343-
cmd = ["winget", "show", "--id", package_id, "--source", "winget",
343+
cmd = ["winget", "show", "--id", package_id,
344344
"--disable-interactivity"]
345345
kwargs = self._get_subprocess_kwargs()
346346
logger.debug(f"Getting package details via CLI for: {package_id}")

0 commit comments

Comments
 (0)