mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-02-21 21:36:17 +08:00
Add Swift launcher (#905)
This commit is contained in:
parent
716af1bae2
commit
f4397d36b9
1 changed files with 55 additions and 13 deletions
|
@ -94,7 +94,6 @@ defmodule AppBuilder.MacOS do
|
||||||
Keyword.validate!(options, [
|
Keyword.validate!(options, [
|
||||||
:name,
|
:name,
|
||||||
:version,
|
:version,
|
||||||
:launcher_script,
|
|
||||||
:logo_path,
|
:logo_path,
|
||||||
:info_plist,
|
:info_plist,
|
||||||
:url_schemes,
|
:url_schemes,
|
||||||
|
@ -108,11 +107,19 @@ defmodule AppBuilder.MacOS do
|
||||||
File.mkdir_p!(Path.join([app_bundle_path, "Contents", "Resources"]))
|
File.mkdir_p!(Path.join([app_bundle_path, "Contents", "Resources"]))
|
||||||
File.rename!(release.path, Path.join([app_bundle_path, "Contents", "Resources", "rel"]))
|
File.rename!(release.path, Path.join([app_bundle_path, "Contents", "Resources", "rel"]))
|
||||||
|
|
||||||
launcher_script = options[:launcher_script] || launcher_script(release.name, app_name)
|
launcher_src_path = "tmp/Launcher.swift"
|
||||||
launcher_script_path = Path.join([app_bundle_path, "Contents", "MacOS", app_name])
|
File.write!(launcher_src_path, launcher())
|
||||||
File.mkdir_p!(Path.dirname(launcher_script_path))
|
launcher_path = Path.join([app_bundle_path, "Contents", "MacOS", app_name <> "Launcher"])
|
||||||
File.write!(launcher_script_path, launcher_script)
|
File.mkdir_p!(Path.dirname(launcher_path))
|
||||||
File.chmod!(launcher_script_path, 0o700)
|
|
||||||
|
cmd!("swiftc", [
|
||||||
|
"-warnings-as-errors",
|
||||||
|
"-target",
|
||||||
|
swiftc_target(),
|
||||||
|
"-o",
|
||||||
|
launcher_path,
|
||||||
|
launcher_src_path
|
||||||
|
])
|
||||||
|
|
||||||
logo_path = options[:logo_path] || Application.app_dir(:wx, "examples/demo/erlang.png")
|
logo_path = options[:logo_path] || Application.app_dir(:wx, "examples/demo/erlang.png")
|
||||||
create_logo(app_bundle_path, logo_path)
|
create_logo(app_bundle_path, logo_path)
|
||||||
|
@ -123,14 +130,37 @@ defmodule AppBuilder.MacOS do
|
||||||
release
|
release
|
||||||
end
|
end
|
||||||
|
|
||||||
defp launcher_script(release_name, app_name) do
|
defp launcher do
|
||||||
"""
|
"""
|
||||||
#!/bin/sh
|
import Foundation
|
||||||
set -e
|
import Cocoa
|
||||||
root=$(dirname $(dirname "$0"))
|
|
||||||
$root/Resources/rel/bin/#{release_name} start \\
|
let fm = FileManager.default
|
||||||
1>> ~/Library/Logs/#{app_name}.stdout.log \\
|
let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as! String
|
||||||
2>> ~/Library/Logs/#{app_name}.stderr.log
|
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/mac_app", ofType: "")!
|
||||||
|
|
||||||
|
let task = Process()
|
||||||
|
task.launchPath = releaseScriptPath
|
||||||
|
task.arguments = ["start"]
|
||||||
|
task.standardOutput = logFile
|
||||||
|
task.standardError = logFile
|
||||||
|
try task.run()
|
||||||
|
|
||||||
|
task.waitUntilExit()
|
||||||
|
|
||||||
|
if task.terminationStatus != 0 {
|
||||||
|
let alert = NSAlert()
|
||||||
|
alert.messageText = "\\(appName) exited with error status \\(task.terminationStatus)."
|
||||||
|
alert.informativeText = "Logs available at \\(logPath)."
|
||||||
|
alert.runModal()
|
||||||
|
}
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -163,6 +193,16 @@ defmodule AppBuilder.MacOS do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp swiftc_target do
|
||||||
|
case :erlang.system_info(:system_architecture) do
|
||||||
|
'x86_64' ++ _ ->
|
||||||
|
"x86_64-apple-macosx10.15"
|
||||||
|
|
||||||
|
'aarch64' ++ _ ->
|
||||||
|
"arm64-apple-macosx12"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
## Templates
|
## Templates
|
||||||
|
|
||||||
require EEx
|
require EEx
|
||||||
|
@ -195,6 +235,8 @@ defmodule AppBuilder.MacOS do
|
||||||
<dict>
|
<dict>
|
||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
|
<key>CFBundleExecutable</key>
|
||||||
|
<string><%= app_name %>Launcher</string>
|
||||||
<key>CFBundleName</key>
|
<key>CFBundleName</key>
|
||||||
<string><%= app_name %></string>
|
<string><%= app_name %></string>
|
||||||
<key>CFBundleDisplayName</key>
|
<key>CFBundleDisplayName</key>
|
||||||
|
|
Loading…
Reference in a new issue