Skip to content

Commit 932f0f0

Browse files
committed
App: implement proper handling of open -a EmacsOpen <url-or-file> calls
Replace prototype code which called emacsopen CLI tool with calls to EmacsOpenLibrary functions
1 parent e4d4df6 commit 932f0f0

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

Sources/EmacsOpenApp/EmacsOpen.swift

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,8 @@ import UserNotifications
4343

4444
class AppDelegate: NSObject, NSApplicationDelegate {
4545

46-
let path = "/Users/matt/sw/emacsopen/emacsopen"
47-
4846
func applicationDidFinishLaunching(_: Notification) {
4947
NSApp.setActivationPolicy(.accessory)
50-
let path = "/Users/matt/sw/emacsopen/emacsopen"
51-
runCommand("echo hello")
52-
runCommand(path)
53-
5448
print("Hello World from SwiftUI menu bar app!")
5549

5650
// Request notification permissions
@@ -80,26 +74,25 @@ class AppDelegate: NSObject, NSApplicationDelegate {
8074
func applicationWillTerminate(_ notification: Notification) { print("bye from callback") }
8175

8276
func application(_ application: NSApplication, open urls: [URL]) {
83-
for url in urls {
84-
if url.scheme == "org-protocol" {
85-
runCommand("\(path) emacsopen \(url.absoluteString)")
86-
} else {
87-
runCommand("\(path) eemacsopen \(url.path)")
88-
}
77+
// Called when (re-)opened via 'open -a EmacsOpenApp <file-or-url>'
78+
showNotification(
79+
title: "Opening URLs",
80+
message: "URLs: \(urls.map { $0.absoluteString }.joined(separator: ", "))"
81+
)
82+
if urls.isEmpty {
83+
_ = emacsOpen.activateFrame(createFrame: false)
84+
} else {
85+
_ = emacsOpen.openInGui(
86+
filesOrLink: urls.map { $0.scheme == "org-protocol" ? $0.absoluteString : $0.path },
87+
block: false,
88+
createFrame: false
89+
)
8990
}
9091
NSApp.terminate(nil)
9192
}
9293

9394
}
9495

95-
func runCommand(_ command: String) {
96-
let task = Process()
97-
task.launchPath = "/bin/bash"
98-
task.arguments = ["-c", command]
99-
task.launch()
100-
task.waitUntilExit()
101-
}
102-
10396
func showNotification(title: String, message: String) {
10497
let content = UNMutableNotificationContent()
10598
content.title = title

0 commit comments

Comments
 (0)