Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### Bug fixes

* Fix `flet build` and `flet publish` dependency parsing for `project.dependencies` and Poetry constraints with `<`/`<=`, and add coverage for normalized requirement handling ([#6332](https://github.com/flet-dev/flet/issues/6332), [#6340](https://github.com/flet-dev/flet/pull/6340)) by @td3447.
* Fix `find_platform_image` selecting incompatible icon formats (e.g. `.icns` on Windows) by ranking glob results per target platform ([#6381](https://github.com/flet-dev/flet/pull/6381)) by @HG-ha.

### Other changes

Expand Down
43 changes: 31 additions & 12 deletions sdk/python/packages/flet-cli/src/flet_cli/commands/build_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2272,7 +2272,13 @@ def find_platform_image(
hash: HashStamp,
):
"""
Find first matching image file by base name and queue it for copy.
Find the best matching image file for the current target platform.

When multiple files share the same base name (e.g. `icon.icns`,
`icon.ico`, `icon.png`), the method filters out formats that are
incompatible with the build target before selecting the first match.
For example, `.icns` is skipped on Windows builds because
`flutter_launcher_icons` cannot decode it.

Args:
src_path: Source assets directory.
Expand All @@ -2285,17 +2291,30 @@ def find_platform_image(
File name of matched image, or `None` if not found.
"""

images = glob.glob(str(src_path.joinpath(f"{image_name}.*")))
if len(images) > 0:
if self.verbose > 0:
console.log(
f'Found "{image_name}" image at {images[0]}', style=verbose1_style
)
copy_ops.append((images[0], dest_path))
hash.update(images[0])
hash.update(Path(images[0]).stat().st_mtime)
return Path(images[0]).name
return None
# .icns is macOS-only and .ico is Windows-only; filter out
# incompatible formats so flutter_launcher_icons gets a decodable file.
images = list(
filter(
lambda p: not (
(ext := Path(p).suffix.lower()) == ".icns"
and self.target_platform != "macos"
or ext == ".ico"
and self.target_platform != "windows"
),
glob.glob(str(src_path.joinpath(f"{image_name}.*"))),
)
)

if not images:
return None

best = images[0]
if self.verbose > 0:
console.log(f'Found "{image_name}" image at {best}', style=verbose1_style)
copy_ops.append((best, dest_path))
hash.update(best)
hash.update(Path(best).stat().st_mtime)
return Path(best).name

def run(self, args, cwd, env: Optional[dict] = None, capture_output=True):
"""
Expand Down