Skip to content

Commit

Permalink
Merge pull request #1766 from freakboy3742/macos-icon-flush
Browse files Browse the repository at this point in the history
Ensure macOS apps pick up new icons after an update
  • Loading branch information
mhsmith authored May 2, 2024
2 parents 6d7424a + 4ef0e88 commit a8aa076
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions changes/1766.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
macOS apps bundles are touched after a resource update to ensure the icon cache is flushed.
4 changes: 2 additions & 2 deletions src/briefcase/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,8 @@ def install_app_resources(self, app: AppConfig):
# Briefcase v0.3.18 - splash screens deprecated.
if getattr(app, "splash", None):
self.logger.warning(
"Splash screens are now configured based on the icon. "
"The splash configuration will be ignored."
"\nSplash screens are now configured based on the icon. "
"The splash configuration will be ignored.\n"
)

for extension, doctype in self.document_type_icon_targets(app).items():
Expand Down
1 change: 1 addition & 0 deletions src/briefcase/commands/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ def new_app(
$ cd {context['app_name']}
$ briefcase dev
"""
)

Expand Down
7 changes: 7 additions & 0 deletions src/briefcase/platforms/macOS/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ def install_app_support_package(self, app: AppConfig):
arch=self.tools.host_arch,
)

def install_app_resources(self, app: AppConfig):
super().install_app_resources(app)

# macOS will cache application icons. Touching the .app folder flushes the icon
# cache for the app, ensuring the current icon is loaded.
self.binary_path(app).touch(exist_ok=True)


class macOSAppUpdateCommand(macOSAppCreateCommand, UpdateCommand):
description = "Update an existing macOS app."
Expand Down
24 changes: 24 additions & 0 deletions tests/platforms/macOS/app/test_create.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import subprocess
import sys
import time
from unittest import mock

import pytest
Expand Down Expand Up @@ -285,6 +287,28 @@ def test_permissions_context(
assert context == create_command.permissions_context(first_app, x_permissions)


def test_install_app_resources(create_command, first_app_templated, tmp_path):
"""The app bundle's modification time is updated when app resources are
installed."""
# Get the initial app modification time
initial_timestamp = os.path.getmtime(
create_command.binary_path(first_app_templated)
)

# Add a small sleep to make sure that a touch will definitely result in an updated
# modification time
time.sleep(0.1)

# Install resources
create_command.install_app_resources(first_app_templated)

# Modification time has been updated, and is newer
assert (
os.path.getmtime(create_command.binary_path(first_app_templated))
> initial_timestamp
)


@pytest.mark.parametrize(
"host_arch, other_arch",
[
Expand Down

0 comments on commit a8aa076

Please sign in to comment.