Skip to content

Commit 3eca743

Browse files
committed
install launch daemon as part of installer
1 parent 16e49a5 commit 3eca743

File tree

9 files changed

+27
-190
lines changed

9 files changed

+27
-190
lines changed

Coder-Desktop/Coder-Desktop/Coder_DesktopApp.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
9696
guard self.vpn.state != .connected, self.state.hasSession else { return }
9797
await self.state.handleTokenExpiry()
9898
}
99-
// If the Helper is pending approval, we should check if it's
100-
// been approved when the tray is opened.
101-
Task { @MainActor in
102-
guard self.vpn.state == .failed(.helperError(.requiresApproval)) else { return }
103-
self.vpn.refreshHelperState()
104-
}
10599
}, content: {
106100
VPNMenu<CoderVPNService, MutagenDaemon>().frame(width: 256)
107101
.environmentObject(self.vpn)
@@ -122,7 +116,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
122116
if await !vpn.loadNetworkExtensionConfig() {
123117
state.reconfigure()
124118
}
125-
await vpn.setupHelper()
126119
}
127120
}
128121

Coder-Desktop/Coder-Desktop/HelperService.swift

Lines changed: 0 additions & 149 deletions
This file was deleted.

Coder-Desktop/Coder-Desktop/VPN/VPNService.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ enum VPNServiceError: Error, Equatable {
3636
case internalError(String)
3737
case systemExtensionError(SystemExtensionState)
3838
case networkExtensionError(NetworkExtensionState)
39-
case helperError(HelperState)
4039

4140
var description: String {
4241
switch self {
@@ -46,8 +45,6 @@ enum VPNServiceError: Error, Equatable {
4645
"SystemExtensionError: \(state.description)"
4746
case let .networkExtensionError(state):
4847
"NetworkExtensionError: \(state.description)"
49-
case let .helperError(state):
50-
"HelperError: \(state.description)"
5148
}
5249
}
5350

@@ -70,13 +67,6 @@ final class CoderVPNService: NSObject, VPNService {
7067
@Published var sysExtnState: SystemExtensionState = .uninstalled
7168
@Published var neState: NetworkExtensionState = .unconfigured
7269
var state: VPNServiceState {
73-
// The ordering here is important. The button to open the settings page
74-
// where the helper is approved is a no-op if the user has a settings
75-
// window on the page where the system extension is approved.
76-
// So, we want to ensure the helper settings button is clicked first.
77-
guard helperState == .installed else {
78-
return .failed(.helperError(helperState))
79-
}
8070
guard sysExtnState == .installed else {
8171
return .failed(.systemExtensionError(sysExtnState))
8272
}
@@ -90,8 +80,6 @@ final class CoderVPNService: NSObject, VPNService {
9080
return tunnelState
9181
}
9282

93-
@Published var helperState: HelperState = .uninstalled
94-
9583
@Published var progress: VPNProgress = .init(stage: .initial, downloadProgress: nil)
9684

9785
@Published var menuState: VPNMenuState = .init()
@@ -119,14 +107,6 @@ final class CoderVPNService: NSObject, VPNService {
119107
return
120108
}
121109

122-
// We have to manually fetch the helper state,
123-
// and we don't want to start the VPN
124-
// if the helper is not ready.
125-
refreshHelperState()
126-
if helperState != .installed {
127-
return
128-
}
129-
130110
menuState.clear()
131111
await startTunnel()
132112
logger.debug("network extension enabled")

Coder-Desktop/Coder-Desktop/Views/VPN/VPNMenu.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,7 @@ struct VPNMenu<VPN: VPNService, FS: FileSyncDaemon>: View {
124124
// Prevent starting the VPN before the user has approved the system extension.
125125
vpn.state == .failed(.systemExtensionError(.needsUserApproval)) ||
126126
// Prevent starting the VPN without a VPN configuration.
127-
vpn.state == .failed(.networkExtensionError(.unconfigured)) ||
128-
// Prevent starting the VPN before the Helper is approved
129-
vpn.state == .failed(.helperError(.requiresApproval)) ||
130-
// Prevent starting the VPN before the Helper is installed
131-
vpn.state == .failed(.helperError(.installing))
127+
vpn.state == .failed(.networkExtensionError(.unconfigured))
132128
)
133129
}
134130
}

Coder-Desktop/Coder-Desktop/Views/VPN/VPNState.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ struct VPNState<VPN: VPNService>: View {
3434
// open the menu bar an extra time
3535
state.reconfigure()
3636
}
37-
case (.failed(.helperError(.requiresApproval)), _):
38-
ApprovalRequiredView<VPN>(
39-
message: "Awaiting Background Item approval",
40-
action: SMAppService.openSystemSettingsLoginItems
41-
)
42-
case (.failed(.helperError(.installing)), _):
43-
HelperProgressView()
4437
case (.disabled, _):
4538
Text("Enable Coder Connect to see workspaces")
4639
.font(.body)

Coder-Desktop/Coder-DesktopHelper/com.coder.Coder-Desktop.Helper.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<dict>
55
<key>Label</key>
66
<string>com.coder.Coder-Desktop.Helper</string>
7-
<key>BundleProgram</key>
8-
<string>Contents/MacOS/com.coder.Coder-Desktop.Helper</string>
7+
<key>Program</key>
8+
<string>/Applications/Coder Desktop.app/Contents/MacOS/com.coder.Coder-Desktop.Helper</string>
99
<key>MachServices</key>
1010
<dict>
1111
<!-- $(TeamIdentifierPrefix) isn't populated here, so this value is hardcoded -->

pkgbuild/scripts/postinstall

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
RUNNING_MARKER_FILE="/tmp/coder_desktop_running"
44

5+
LAUNCH_DAEMON_PLIST_SRC="/Applications/Coder Desktop.app/Contents/Library/LaunchDaemons"
6+
LAUNCH_DAEMON_PLIST_DEST="/Library/LaunchDaemons"
7+
LAUNCH_DAEMON_NAME="com.coder.Coder-Desktop.Helper"
8+
LAUNCH_DAEMON_PLIST_NAME="$LAUNCH_DAEMON_NAME.plist"
9+
LAUNCH_DAEMON_BINARY_PATH="/Applications/Coder Desktop.app/Contents/MacOS/com.coder.Coder-Desktop.Helper"
10+
11+
# Install daemon
12+
# Copy plist into system dir
13+
sudo cp "$LAUNCH_DAEMON_PLIST_SRC"/"$LAUNCH_DAEMON_PLIST_NAME" "$LAUNCH_DAEMON_PLIST_DEST"/"$LAUNCH_DAEMON_PLIST_NAME"
14+
# Set necessary permissions
15+
sudo chmod -R 755 "$LAUNCH_DAEMON_BINARY_PATH"
16+
sudo chmod 644 "$LAUNCH_DAEMON_PLIST_DEST"/"$LAUNCH_DAEMON_PLIST_NAME"
17+
sudo chown root:wheel "$LAUNCH_DAEMON_PLIST_DEST"/"$LAUNCH_DAEMON_PLIST_NAME"
18+
19+
# Load daemon
20+
sudo launchctl enable "system/$LAUNCH_DAEMON_NAME" || true # Might already be enabled
21+
sudo launchctl bootstrap system "$LAUNCH_DAEMON_PLIST_DEST/$LAUNCH_DAEMON_PLIST_NAME"
22+
sudo launchctl kickstart -k "system/$LAUNCH_DAEMON_NAME"
23+
524
# Before this script, or the user, opens the app, make sure
625
# Gatekeeper has ingested the notarization ticket.
726
spctl -avvv "/Applications/Coder Desktop.app"

pkgbuild/scripts/preinstall

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/usr/bin/env bash
22

33
RUNNING_MARKER_FILE="/tmp/coder_desktop_running"
4+
LAUNCH_DAEMON_NAME="com.coder.Coder-Desktop.Helper"
5+
6+
# Stop an existing launch daemon, if it exists
7+
sudo launchctl bootout "system/$LAUNCH_DAEMON_NAME" 2>/dev/null || true
48

59
rm $RUNNING_MARKER_FILE || true
610

scripts/update-cask.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ cask "coder-desktop" do
9494
uninstall quit: [
9595
"com.coder.Coder-Desktop",
9696
"com.coder.Coder-Desktop.VPN",
97+
"com.coder.Coder-Desktop.Helper",
9798
],
9899
login_item: "Coder Desktop"
99100

0 commit comments

Comments
 (0)