feat(launcher): add portable windows launcher (#976)

* feat(windows): add standalone portable executable, splash screen, and system tray

* test: fix test_get_wsl_windows_user_profile_falls_back_to_users_dir on Windows

* Refactor launcher: isolate desktop logic into launcher.py, clean app.py/requirements, update build scripts, and add tests

* chore: clean launcher test whitespace

---------

Co-authored-by: Alexandre Teixeira <alexandremagteixeira@gmail.com>
This commit is contained in:
Kfir Sadeh
2026-06-16 06:58:16 +03:00
committed by GitHub
parent 648db61b45
commit d795d9a923
8 changed files with 346 additions and 3 deletions
+62
View File
@@ -0,0 +1,62 @@
# tests/test_launcher.py
import sys
import os
from unittest import mock
import pytest
from launcher import NullWriter, create_tray_image, on_open_browser, on_exit, open_browser
def test_null_writer():
writer = NullWriter()
# writing and flushing should not raise any exceptions
writer.write("hello")
writer.flush()
assert writer.isatty() is False
def test_create_tray_image():
try:
from PIL import Image
img = create_tray_image()
assert isinstance(img, Image.Image)
assert img.size == (64, 64)
except ImportError:
pytest.skip("Pillow/PIL not installed in test environment")
def test_on_open_browser():
with mock.patch("webbrowser.open") as mock_open:
icon_mock = mock.Mock()
item_mock = mock.Mock()
url = "http://127.0.0.1:7000"
on_open_browser(icon_mock, item_mock, url)
mock_open.assert_called_once_with(url)
def test_on_exit():
with mock.patch("os._exit") as mock_exit:
icon_mock = mock.Mock()
item_mock = mock.Mock()
on_exit(icon_mock, item_mock)
icon_mock.stop.assert_called_once()
mock_exit.assert_called_once_with(0)
def test_open_browser():
with mock.patch("webbrowser.open") as mock_open, \
mock.patch("time.sleep") as mock_sleep:
# Test when splash_root is None
with mock.patch("launcher.splash_root", None):
open_browser("http://127.0.0.1:7000")
mock_open.assert_called_once_with("http://127.0.0.1:7000")
mock_sleep.assert_called_once_with(3.5)
with mock.patch("webbrowser.open") as mock_open, \
mock.patch("time.sleep") as mock_sleep:
# Test when splash_root is present and gets destroyed
mock_splash = mock.Mock()
with mock.patch("launcher.splash_root", mock_splash):
open_browser("http://127.0.0.1:7000")
mock_splash.after.assert_called_once()
+6 -2
View File
@@ -153,6 +153,7 @@ def test_get_wsl_windows_user_profile_prefers_powershell(monkeypatch):
def test_get_wsl_windows_user_profile_falls_back_to_users_dir(monkeypatch):
import os
monkeypatch.setattr(platform_compat, "is_wsl", lambda: True)
def raise_run(*_a, **_k):
@@ -166,11 +167,14 @@ def test_get_wsl_windows_user_profile_falls_back_to_users_dir(monkeypatch):
)
def fake_isdir(path):
return path in {"/mnt/c/Users", "/mnt/c/Users/alice"}
return os.path.normpath(path) in {
os.path.normpath("/mnt/c/Users"),
os.path.normpath("/mnt/c/Users/alice")
}
monkeypatch.setattr(platform_compat.os.path, "isdir", fake_isdir)
assert platform_compat.get_wsl_windows_user_profile() == "/mnt/c/Users/alice"
assert platform_compat.get_wsl_windows_user_profile() == os.path.join("/mnt/c/Users", "alice")
def test_get_wsl_windows_user_profile_returns_none_when_nothing_found(monkeypatch):