Skip to content

Commit

Permalink
Merge pull request #2852 from rokm/fix-macos-default-icon-pyinstaller
Browse files Browse the repository at this point in the history
cocoa: fix default icon search when standalone app is not an .app bundle
  • Loading branch information
freakboy3742 authored Sep 17, 2024
2 parents 3e503e8 + d65a461 commit 76ac0e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions changes/2852.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Apps bundled as standalone frozen binaries (e.g., POSIX builds made with PyInstaller) no longer crash on startup when trying to resolve the app icon.
10 changes: 7 additions & 3 deletions cocoa/src/toga_cocoa/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ def __init__(self, interface, path):
# as an indicator that this is the app's default icon.
# This bundle icon file definition might not contain an extension,
# even thought the actual file will; so force the .icns extension.
bundle_icon = Path(
NSBundle.mainBundle.objectForInfoDictionaryKey("CFBundleIconFile")
bundle_icon = NSBundle.mainBundle.objectForInfoDictionaryKey(
"CFBundleIconFile"
)
if bundle_icon is None:
# Not an .app bundle (e.g., POSIX build made with PyInstaller)
# This can't be tested as the testbed app is bundled by Briefcase.
raise FileNotFoundError() # pragma: no cover
path = NSBundle.mainBundle.pathForResource(
bundle_icon.stem,
Path(bundle_icon).stem,
ofType=".icns",
)
# If the icon file doesn't exist, raise the problem as FileNotFoundError
Expand Down

0 comments on commit 76ac0e1

Please sign in to comment.