Skip to content

Commit c6c657e

Browse files
Keralinclaude
andcommitted
fix: improve Docker socket detection and modernize app entry point
- Detect Docker socket from docker context (fixes #77, #76, #72, #69) - Add fallback support for OrbStack and Colima sockets - Include /opt/homebrew/bin in PATH for Apple Silicon Macs - Modernize main.swift using NSApplication.shared.run() instead of deprecated NSApplicationMain() - Update AppDelegate access pattern in menu classes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent aee2cad commit c6c657e

File tree

4 files changed

+77
-18
lines changed

4 files changed

+77
-18
lines changed

Ace Link/Extensions/Process.swift

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,71 @@ extension Process {
1616
set { standardErrorMap.setObject(NSString(string: newValue), forKey: self) }
1717
}
1818

19-
var userDockerSocket: String? {
20-
let home = FileManager.default.homeDirectoryForCurrentUser
21-
let userSocketPath = home.path + "/.docker/run/docker.sock"
22-
if FileManager.default.fileExists(atPath: userSocketPath) {
23-
return userSocketPath
19+
/// Returns the Docker socket path by checking (in order):
20+
/// 1. Docker context (supports Docker Desktop, OrbStack, Rancher Desktop, Colima, etc.)
21+
/// 2. User-specific socket (~/.docker/run/docker.sock)
22+
/// 3. OrbStack socket (~/.orbstack/run/docker.sock)
23+
/// 4. Colima socket (~/.colima/default/docker.sock)
24+
/// 5. Legacy system socket (/var/run/docker.sock)
25+
var dockerSocket: String? {
26+
let home = FileManager.default.homeDirectoryForCurrentUser.path
27+
let fileManager = FileManager.default
28+
29+
// 1. Try to get socket from docker context (respects user's configured context)
30+
if let contextSocket = getDockerContextSocket() {
31+
return contextSocket
32+
}
33+
34+
// 2. Fallback to known socket paths
35+
let knownSockets = [
36+
home + "/.docker/run/docker.sock", // Docker Desktop (new)
37+
home + "/.orbstack/run/docker.sock", // OrbStack
38+
home + "/.colima/default/docker.sock", // Colima
39+
"/var/run/docker.sock", // Legacy/Linux
40+
]
41+
42+
for socketPath in knownSockets {
43+
if fileManager.fileExists(atPath: socketPath) {
44+
os_log("Found Docker socket at: %{public}@", socketPath)
45+
return socketPath
46+
}
2447
}
48+
49+
return nil
50+
}
51+
52+
/// Gets the Docker socket from the current docker context using `docker context inspect`
53+
private func getDockerContextSocket() -> String? {
54+
let task = Foundation.Process()
55+
task.launchPath = "/usr/bin/env"
56+
task.arguments = ["docker", "context", "inspect", "--format", "{{.Endpoints.docker.Host}}"]
57+
task.environment = [
58+
"PATH": ProcessInfo.processInfo.environment["PATH"]! + ":/usr/local/bin:/opt/local/bin:/opt/homebrew/bin",
59+
]
60+
61+
let pipe = Pipe()
62+
task.standardOutput = pipe
63+
task.standardError = FileHandle.nullDevice
64+
65+
do {
66+
try task.run()
67+
task.waitUntilExit()
68+
69+
if task.terminationStatus == 0 {
70+
let data = pipe.fileHandleForReading.readDataToEndOfFile()
71+
if let output = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines),
72+
output.hasPrefix("unix://") {
73+
let socketPath = String(output.dropFirst(7)) // Remove "unix://"
74+
if FileManager.default.fileExists(atPath: socketPath) {
75+
os_log("Docker context socket: %{public}@", socketPath)
76+
return socketPath
77+
}
78+
}
79+
}
80+
} catch {
81+
os_log("Failed to get docker context: %{public}@", error.localizedDescription)
82+
}
83+
2584
return nil
2685
}
2786

@@ -31,16 +90,15 @@ extension Process {
3190
process.launchPath = "/usr/bin/env"
3291
process.arguments = arguments
3392
process.environment = [
34-
// Modify PATH to include dirs containing local binaries.
35-
"PATH": ProcessInfo.processInfo.environment["PATH"]! + ":/usr/local/bin:/opt/local/bin",
93+
// Modify PATH to include dirs containing local binaries (including Homebrew on Apple Silicon).
94+
"PATH": ProcessInfo.processInfo.environment["PATH"]! + ":/usr/local/bin:/opt/local/bin:/opt/homebrew/bin",
3695
// Don't attempt to download/run arm64 packages because they're not supported.
3796
"DOCKER_DEFAULT_PLATFORM": "linux/amd64",
3897
]
3998

40-
// Docker-for-Mac allows both /Users/<user>/.docker/run/docker.sock (new)
41-
// and /var/run/docker.sock (legacy but supported).
42-
if let userDockerSocket = process.userDockerSocket {
43-
process.environment?["DOCKER_HOST"] = "unix://" + userDockerSocket
99+
// Set Docker socket from context or known paths (supports Docker Desktop, OrbStack, Colima, etc.)
100+
if let dockerSocket = process.dockerSocket {
101+
process.environment?["DOCKER_HOST"] = "unix://" + dockerSocket
44102
}
45103

46104
os_log("Running command: %{public}@", arguments.joined(separator: " ").scrubHashes())

Ace Link/Menu/HistoryMenu.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ class HistoryMenu: PartialMenu {
102102
let playlistLines = fileContents.components(separatedBy: CharacterSet.newlines)
103103
for line in playlistLines where line.hasPrefix("http://") {
104104
if let historyURL = URL(string: line) {
105-
if let file = ExtractStream.from(historyURL: historyURL) {
105+
if let file = ExtractStream.from(historyURL: historyURL),
106+
let appDelegate = NSApplication.shared.delegate as? AppDelegate {
106107
appDelegate.openStream(file)
107108
}
108109
}

Ace Link/Menu/OpenStreamMenu.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class OpenStreamMenu: PartialMenu {
2828

2929
@objc
3030
private func openStreamFromClipboard(_: NSMenuItem?) {
31-
if let stream = streamFromClipboard {
31+
if let stream = streamFromClipboard,
32+
let appDelegate = NSApplication.shared.delegate as? AppDelegate {
3233
appDelegate.openStream(stream)
3334
}
3435
}

Ace Link/main.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Cocoa
22

3-
let appDelegate = AppDelegate()
4-
5-
NSApplication.shared.delegate = appDelegate
6-
7-
_ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv)
3+
let app = NSApplication.shared
4+
let delegate = AppDelegate()
5+
app.delegate = delegate
6+
app.run()

0 commit comments

Comments
 (0)