Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/desktop/desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ def run_tray(self):

tray_image = Image.open(self.resource_path("taskbar.png"))

# taskbar.png is sized for macOS/Windows; Linux trays typically render icons
# at ~22-24px, so the source image looks oversized/blurry there unless scaled down.
if sys.platform.startswith("linux"):
tray_image = tray_image.resize((24, 24), Image.Resampling.LANCZOS)

# Use default on Windows to get "left click to open" behaviour.
# It looks ugly on MacOS (just a bold effect Apple never uses), so don't use it there
make_open_studio_default = sys.platform in ("win32", "Windows")
Expand Down
38 changes: 36 additions & 2 deletions app/desktop/test_desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest
import requests
from PIL import Image
from uvicorn import Config as UvicornConfig

import app.desktop.desktop_server as desktop_server
Expand Down Expand Up @@ -32,9 +33,9 @@ def mock_tk_root():
@pytest.fixture
def mock_image():
"""Mock PIL Image."""
with patch("app.desktop.desktop.Image") as mock_img:
with patch("app.desktop.desktop.Image.open") as mock_image_open:
mock_image_obj = Mock()
mock_img.open.return_value = mock_image_obj
mock_image_open.return_value = mock_image_obj
yield mock_image_obj


Expand Down Expand Up @@ -236,6 +237,39 @@ def test_run_tray_macos_no_default(
menu_calls = mock_kiln_menu_item.call_args_list
assert menu_calls[0][1]["default"] is False

@patch("app.desktop.desktop.sys.platform", "linux")
def test_run_tray_linux_icon_scaling(
self, mock_tk_root, mock_image, mock_kiln_menu_item
):
"""Test run_tray scales the tray icon down on Linux."""
app = DesktopApp(port=TEST_PORT)

with (
patch.object(app, "resource_path", return_value="taskbar.png"),
patch("app.desktop.desktop.KilnTray") as mock_kiln_tray_class,
):
app.run_tray()

mock_image.resize.assert_called_once()
mock_image.resize.assert_called_once_with(
(24, 24), Image.Resampling.LANCZOS
)
resized_image = mock_image.resize.return_value
mock_kiln_tray_class.assert_called_once()
assert mock_kiln_tray_class.call_args.args[1] is resized_image

@patch("app.desktop.desktop.sys.platform", "win32")
def test_run_tray_windows_no_icon_scaling(
self, mock_tk_root, mock_image, mock_kiln_tray, mock_kiln_menu_item
):
"""Test run_tray does not scale the tray icon on Windows."""
app = DesktopApp(port=TEST_PORT)

with patch.object(app, "resource_path", return_value="taskbar.png"):
app.run_tray()

mock_image.resize.assert_not_called()

def test_close_splash_with_pyi_splash(self, mock_tk_root):
"""Test close_splash when pyi_splash is available."""
app = DesktopApp(port=TEST_PORT)
Expand Down