From b46ffe5f4bf74ad16c361c752985b8f9788659fe Mon Sep 17 00:00:00 2001 From: Serkan Sepil <71099292+serkansepil@users.noreply.github.com> Date: Tue, 30 Jun 2026 01:45:47 +0300 Subject: [PATCH] Fix packaged app asset loading --- Info.plist | 4 ++-- Sources/uppod/Theme.swift | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Info.plist b/Info.plist index 4f650ef..0d2c9cc 100644 --- a/Info.plist +++ b/Info.plist @@ -22,9 +22,9 @@ CFBundlePackageType APPL CFBundleVersion - 1 + 2 CFBundleShortVersionString - 0.1 + 0.1.1 LSMinimumSystemVersion 14.0 LSUIElement diff --git a/Sources/uppod/Theme.swift b/Sources/uppod/Theme.swift index 9ca55a2..a6e7050 100644 --- a/Sources/uppod/Theme.swift +++ b/Sources/uppod/Theme.swift @@ -31,16 +31,23 @@ enum Theme { } } -/// Loads a bundled PNG by name, trying the packaged `.app` bundle first, then the SwiftPM module -/// bundle (dev / `swift run`). Centralizes the dual-lookup that the UI used to repeat per call site. +/// Loads a bundled PNG by name. Release `.app` builds use `Bundle.main`; debug SwiftPM runs can +/// fall back to `Bundle.module`. enum AppImage { static func png(_ name: String) -> NSImage? { - for bundle in [Bundle.main, Bundle.module] { - if let url = bundle.url(forResource: name, withExtension: "png"), - let image = NSImage(contentsOf: url) { - return image - } + if let image = png(name, in: Bundle.main) { + return image } + #if DEBUG + if let image = png(name, in: Bundle.module) { + return image + } + #endif return nil } + + private static func png(_ name: String, in bundle: Bundle) -> NSImage? { + guard let url = bundle.url(forResource: name, withExtension: "png") else { return nil } + return NSImage(contentsOf: url) + } }