Skip to content

Commit d0cbfde

Browse files
committed
fix: include packaged resources needed at app launch
Load the manifest from the shipped app bundle and copy SwiftPM resource bundles into the release app so Bundle-based resources resolve correctly outside the build directory. Made-with: Cursor
1 parent 2439213 commit d0cbfde

2 files changed

Lines changed: 26 additions & 15 deletions

File tree

Sources/Services/ManifestLoader.swift

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,34 @@ private let log = Logger(subsystem: "com.v0id.setmac", category: "ManifestLoader
55

66
enum ManifestLoader {
77
static func load() -> ToolManifest? {
8-
// Try bundle resource first
9-
if let url = Bundle.module.url(forResource: "tools", withExtension: "json") {
10-
log.info("Loading manifest from bundle: \(url.path, privacy: .public)")
8+
for url in manifestCandidateURLs() {
9+
log.info("Loading manifest from: \(url.path, privacy: .public)")
1110
if let manifest = decode(from: url) {
1211
log.info("Loaded \(manifest.tools.count) tools from manifest")
1312
return manifest
1413
}
15-
log.error("Failed to decode manifest from bundle")
14+
log.error("Failed to decode manifest from: \(url.path, privacy: .public)")
1615
}
1716

18-
// Fall back to project root (dev mode)
19-
let devPath = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
17+
log.error("No manifest found in app bundle or dev path")
18+
return nil
19+
}
20+
21+
private static func manifestCandidateURLs() -> [URL] {
22+
var urls: [URL] = []
23+
24+
if let bundledManifest = Bundle.main.url(forResource: "tools", withExtension: "json") {
25+
urls.append(bundledManifest)
26+
}
27+
28+
let devManifest = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
2029
.appendingPathComponent("Resources")
2130
.appendingPathComponent("tools.json")
22-
if FileManager.default.fileExists(atPath: devPath.path) {
23-
log.info("Loading manifest from dev path: \(devPath.path, privacy: .public)")
24-
if let manifest = decode(from: devPath) {
25-
log.info("Loaded \(manifest.tools.count) tools from manifest")
26-
return manifest
27-
}
28-
log.error("Failed to decode manifest from dev path")
31+
if FileManager.default.fileExists(atPath: devManifest.path) {
32+
urls.append(devManifest)
2933
}
3034

31-
log.error("No manifest found in bundle or dev path")
32-
return nil
35+
return urls
3336
}
3437

3538
private static func decode(from url: URL) -> ToolManifest? {

scripts/bundle.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ if [ -f "Resources/tools.json" ]; then
3333
echo " Embedded tools.json"
3434
fi
3535

36+
# Copy SwiftPM resource bundles so packaged apps can resolve Bundle.module resources.
37+
for resource_bundle in "$BUILD_DIR"/*.bundle; do
38+
if [ -d "$resource_bundle" ]; then
39+
cp -R "$resource_bundle" "$APP_BUNDLE/Contents/Resources/"
40+
echo " Embedded $(basename "$resource_bundle")"
41+
fi
42+
done
43+
3644
# Copy bundled configs if they exist
3745
if [ -d "Resources/configs" ]; then
3846
cp -R "Resources/configs" "$APP_BUNDLE/Contents/Resources/configs"

0 commit comments

Comments
 (0)