From 1af81e5b4a7efa52b0c718489379993737bada3c Mon Sep 17 00:00:00 2001 From: relikd Date: Wed, 28 Jan 2026 12:43:09 +0100 Subject: [PATCH] fix: file path on macOS 10.13 --- src/main.swift | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main.swift b/src/main.swift index 6732010..c289bf6 100755 --- a/src/main.swift +++ b/src/main.swift @@ -66,17 +66,19 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate { (sender.representedObject as! Entry).run() } + // MARK: - Helper + + private func resFile(_ name: String, _ ext: String?) -> URL { + // if run via .app bundle + return Bundle.main.url(forResource: name, withExtension: ext) + // if calling swift directly + ?? URL(fileURLWithPath: #file + "/../../" + name + (ext == nil ? "" : ("." + ext!))) + } + // MARK: - Manage storage path private func resolvedStorageURL() -> URL { - userStorageURL() - // if run via .app bundle - ?? Bundle.main.url(forResource: "examples", withExtension: nil) - // if calling swift directly - ?? URL(string: "file://" + FileManager.default.currentDirectoryPath + "/" + #file)! - .deletingLastPathComponent() - .deletingLastPathComponent() - .appendingPathComponent("examples") + userStorageURL() ?? resFile("examples", nil) } private func userStorageURL() -> URL? { @@ -204,7 +206,7 @@ struct Entry { var rv: [Entry] = [] for url in (try? FileManager.default.contentsOfDirectory( - at: URL(string: path)!, + at: URL(fileURLWithPath: path), includingPropertiesForKeys: [.isDirectoryKey, .isExecutableKey])) ?? [] { if url.hasDirectoryPath || FileManager.default.isExecutableFile(atPath: url.path) {