livebook/app_builder/lib/templates/macos/Launcher.swift.eex
Wojtek Mach fc7328703a
App bundling improvements (#1211)
1. Replace `mix release mac_app|mac_app_dmg|windows_installer` with a single `mix release app`
2. Extract templates (Launcher.swift, Launcher.vbs, etc) into separate
   files in app_builder/lib/templates
3. Don't verify vc_redist.x64.exe checksum as the Microsoft publishes
   new releases on the same URL
2022-06-01 22:29:54 +02:00

54 lines
1.6 KiB
Elixir

<%
additional_paths = [
"rel/erts-#{@release.erts_version}/bin"
] ++ @app_options[:additional_paths]
additional_paths = Enum.map_join(additional_paths, ":", &"\\(resourcePath)/#{&1}")
%>
import Foundation
import Cocoa
func log(_ line: String) {
logFile.write("\(line)\n".data(using: .utf8)!)
}
let fm = FileManager.default
let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as! String
let home = NSHomeDirectory()
let logPath = "\(home)/Library/Logs/\(appName).log"
if !fm.fileExists(atPath: logPath) { fm.createFile(atPath: logPath, contents: Data()) }
let logFile = FileHandle(forUpdatingAtPath: logPath)!
logFile.seekToEndOfFile()
let releaseScriptPath = Bundle.main.path(forResource: "rel/bin/<%= @release.name %>", ofType: "")!
let resourcePath = Bundle.main.resourcePath ?? ""
let additionalPaths = "<%= additional_paths %>"
var environment = ProcessInfo.processInfo.environment
let path = environment["PATH"] ?? ""
environment["PATH"] = "\(additionalPaths):\(path)"
let task = Process()
task.environment = environment
task.launchPath = releaseScriptPath
task.arguments = ["start"]
task.standardOutput = logFile
task.standardError = logFile
log("[\(appName)Launcher] starting release")
try task.run()
log("[\(appName)Launcher] pid: \(task.processIdentifier)")
task.waitUntilExit()
log("[\(appName)Launcher] release exited with \(task.terminationStatus)")
if task.terminationStatus != 0 {
let alert = NSAlert()
alert.alertStyle = .critical
alert.messageText = "\(appName) exited with error status \(task.terminationStatus)."
alert.informativeText = "Logs available at: \(logPath)"
alert.runModal()
}