mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-09-20 10:05:57 +08:00
wip
This commit is contained in:
parent
7a207bd631
commit
fcae74a01b
|
@ -19,17 +19,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
button = NSButton(title: "Press me!", target: self, action: #selector(pressMe))
|
||||
button.isEnabled = false
|
||||
|
||||
ElixirKit.API.start(
|
||||
name: "demo",
|
||||
readyHandler: {
|
||||
// GUI updates need to happen on the main thread.
|
||||
DispatchQueue.main.sync {
|
||||
NotificationCenter.default.addObserver(forName: ElixirKit.API.ready, object: nil, queue: .current) { n in
|
||||
self.button.isEnabled = true
|
||||
}
|
||||
|
||||
ElixirKit.API.publish("log", "Hello from AppKit!")
|
||||
|
||||
ElixirKit.API.addObserver(queue: .main) { (name, data) in
|
||||
}
|
||||
|
||||
ElixirKit.API.addObserver(queue: .current) { (name, data) in
|
||||
switch name {
|
||||
case "log":
|
||||
print("[client] " + data)
|
||||
|
@ -37,8 +33,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
fatalError("unknown event \(name)")
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
ElixirKit.API.start(
|
||||
name: "demo",
|
||||
terminationHandler: { _ in
|
||||
print("terminating...")
|
||||
NSApp.terminate(nil)
|
||||
}
|
||||
)
|
||||
|
@ -69,11 +68,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
}
|
||||
|
||||
func applicationWillTerminate(_ aNotification: Notification) {
|
||||
ElixirKit.API.stop()
|
||||
print("applicationWillTerminate")
|
||||
/* ElixirKit.API.stop() */
|
||||
}
|
||||
|
||||
@objc
|
||||
func pressMe() {
|
||||
print("[client] button pressed!")
|
||||
ElixirKit.API.publish("log", "button pressed!")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,9 +10,7 @@ struct Demo {
|
|||
exit(signal)
|
||||
}
|
||||
|
||||
ElixirKit.API.start(
|
||||
name: "demo",
|
||||
readyHandler: {
|
||||
NotificationCenter.default.addObserver(forName: ElixirKit.API.ready, object: nil, queue: .main) { n in
|
||||
ElixirKit.API.publish("log", "Hello from Swift!")
|
||||
|
||||
ElixirKit.API.addObserver(queue: .main) { (name, data) in
|
||||
|
@ -24,8 +22,8 @@ struct Demo {
|
|||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
ElixirKit.API.start(name: "demo")
|
||||
ElixirKit.API.waitUntilExit()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ public class API {
|
|||
static var process: Process?
|
||||
private static var release: Release?
|
||||
|
||||
public static let ready = NSNotification.Name("elixirkit.ready")
|
||||
|
||||
static let didReceiveEvent = NSNotification.Name("elixirkit.event")
|
||||
|
||||
public static var isRunning: Bool {
|
||||
|
@ -13,13 +15,14 @@ public class API {
|
|||
}
|
||||
}
|
||||
|
||||
internal static var isReady = false
|
||||
|
||||
public static func start(
|
||||
name: String,
|
||||
logPath: String? = nil,
|
||||
readyHandler: @escaping () -> Void,
|
||||
terminationHandler: ((Process) -> Void)? = nil) {
|
||||
|
||||
release = Release(name: name, logPath: logPath, readyHandler: readyHandler, terminationHandler: terminationHandler)
|
||||
release = Release(name: name, logPath: logPath, terminationHandler: terminationHandler)
|
||||
}
|
||||
|
||||
public static func publish(_ name: String, _ data: String) {
|
||||
|
@ -47,7 +50,6 @@ private class Release {
|
|||
let logger: Logger
|
||||
let listener: NWListener
|
||||
var connection: Connection?
|
||||
let readyHandler: () -> Void
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
|
||||
var isRunning: Bool {
|
||||
|
@ -59,10 +61,8 @@ private class Release {
|
|||
init(
|
||||
name: String,
|
||||
logPath: String? = nil,
|
||||
readyHandler: @escaping () -> Void,
|
||||
terminationHandler: ((Process) -> Void)? = nil) {
|
||||
|
||||
self.readyHandler = readyHandler
|
||||
logger = Logger(logPath: logPath)
|
||||
listener = try! NWListener(using: .tcp, on: .any)
|
||||
|
||||
|
@ -134,7 +134,8 @@ private class Release {
|
|||
|
||||
private func didAccept(conn: NWConnection) {
|
||||
self.connection = Connection(conn: conn, logger: logger)
|
||||
readyHandler()
|
||||
API.isReady = true
|
||||
NotificationCenter.default.post(name: API.ready, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,3 +61,13 @@ if Mix.target() == :app do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
if Mix.target() == :app or Mix.env() == :test do
|
||||
defmodule LivebookApp.Utils do
|
||||
@moduledoc false
|
||||
|
||||
def url_for_open("") do
|
||||
(LivebookWeb.Endpoint.access_url())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -140,7 +140,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
}
|
||||
|
||||
struct NewNotebookIntent: AppIntent {
|
||||
static var title: LocalizedStringResource = "Create New Livebook (v2)"
|
||||
static var title: LocalizedStringResource = "Create New Livebook"
|
||||
|
||||
static var description = IntentDescription("Create a new notebook.")
|
||||
|
||||
|
|
Loading…
Reference in a new issue