Use main container path as launcher argument

Rather than "Contents/MacOS/Passepartout", raising a permission
error.

Also add .hides to prevent window from showing on launch.
This commit is contained in:
Davide De Rosa 2022-06-25 18:41:08 +02:00
parent df0d40c556
commit b966826f19
2 changed files with 10 additions and 11 deletions

View File

@ -42,7 +42,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
}
Task {
do {
try await NSWorkspace.shared.openApplication(at: appURL, configuration: .init())
let cfg = NSWorkspace.OpenConfiguration()
cfg.hides = true
try await NSWorkspace.shared.openApplication(at: appURL, configuration: cfg)
} catch {
NSLog("Unable to launch main app: \(error)")
}

View File

@ -29,16 +29,13 @@ extension Constants {
enum Launcher {
static let appId = "com.algoritmico.ios.Passepartout"
static let appURL: URL = {
let url = URL(fileURLWithPath: Bundle.main.bundlePath)
var components = url.pathComponents
components.removeLast()
components.removeLast()
components.removeLast()
components.append("MacOS")
components.append(Constants.Global.appName)
let newPath = NSString.path(withComponents: components)
return URL(fileURLWithPath: newPath)
private static let appPath: String = {
let path = Bundle.main.bundlePath as NSString
var components = path.pathComponents
components.removeLast(4)
return NSString.path(withComponents: components)
}()
static let appURL = URL(fileURLWithPath: appPath)
}
}