Skip to content

Commit ffa6e5f

Browse files
committed
review
1 parent 35e8cc3 commit ffa6e5f

File tree

4 files changed

+42
-49
lines changed

4 files changed

+42
-49
lines changed

Coder Desktop/VPNLib/FileSync/FileSyncDaemon.swift

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import os
66
@MainActor
77
public protocol FileSyncDaemon: ObservableObject {
88
var state: DaemonState { get }
9-
func start() async throws
10-
func stop() async throws
9+
func start() async throws(DaemonError)
10+
func stop() async throws(DaemonError)
1111
}
1212

1313
@MainActor
@@ -47,7 +47,7 @@ public class MutagenDaemon: FileSyncDaemon {
4747
}
4848
}
4949

50-
public func start() async throws {
50+
public func start() async throws(DaemonError) {
5151
if case .unavailable = state { return }
5252

5353
// Stop an orphaned daemon, if there is one
@@ -59,16 +59,21 @@ public class MutagenDaemon: FileSyncDaemon {
5959
try mutagenProcess?.run()
6060
} catch {
6161
state = .failed("Failed to start file sync daemon: \(error)")
62-
throw MutagenDaemonError.daemonStartFailure(error)
62+
throw DaemonError.daemonStartFailure(error)
6363
}
6464

65-
try await connect()
65+
do {
66+
try await connect()
67+
} catch {
68+
state = .failed("failed to connect to file sync daemon: \(error)")
69+
throw DaemonError.daemonStartFailure(error)
70+
}
6671

6772
state = .running
68-
logger.info("mutagen daemon started")
73+
logger.info("mutagen daemon started, pid: \(self.mutagenProcess?.processIdentifier.description ?? "unknown")")
6974
}
7075

71-
private func connect() async throws {
76+
private func connect() async throws(DaemonError) {
7277
guard client == nil else {
7378
// Already connected
7479
return
@@ -86,8 +91,8 @@ public class MutagenDaemon: FileSyncDaemon {
8691
)
8792
} catch {
8893
logger.error("Failed to connect to gRPC: \(error)")
89-
try await cleanupGRPC()
90-
throw MutagenDaemonError.connectionFailure(error)
94+
try? await cleanupGRPC()
95+
throw DaemonError.connectionFailure(error)
9196
}
9297
}
9398

@@ -100,7 +105,7 @@ public class MutagenDaemon: FileSyncDaemon {
100105
group = nil
101106
}
102107

103-
public func stop() async throws {
108+
public func stop() async throws(DaemonError) {
104109
if case .unavailable = state { return }
105110
state = .stopped
106111
guard FileManager.default.fileExists(atPath: mutagenDaemonSocket.path) else {
@@ -169,7 +174,7 @@ public enum DaemonState {
169174
case unavailable
170175
}
171176

172-
public enum MutagenDaemonError: Error {
177+
public enum DaemonError: Error {
173178
case daemonStartFailure(Error)
174179
case connectionFailure(Error)
175180
}

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ APP_SIGNING_KEYCHAIN := $(if $(wildcard $(KEYCHAIN_FILE)),$(shell realpath $(KEY
3333
.PHONY: setup
3434
setup: \
3535
$(XCPROJECT) \
36-
proto
36+
$(PROJECT)/VPNLib/vpn.proto \
37+
$(PROJECT)/VPNLib/FileSync/daemon.proto
3738

3839
$(XCPROJECT): $(PROJECT)/project.yml
3940
cd $(PROJECT); \

flake.lock

Lines changed: 14 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,23 @@
44
inputs = {
55
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
66
flake-utils.url = "github:numtide/flake-utils";
7-
grpc-swift.url = "github:i10416/grpc-swift-flake";
7+
flake-parts = {
8+
url = "github:hercules-ci/flake-parts";
9+
inputs.nixpkgs-lib.follows = "nixpkgs";
10+
};
11+
grpc-swift = {
12+
url = "github:i10416/grpc-swift-flake";
13+
inputs.nixpkgs.follows = "nixpkgs";
14+
inputs.flake-parts.follows = "flake-parts";
15+
};
816
};
917

1018
outputs =
1119
{
12-
self,
1320
nixpkgs,
1421
flake-utils,
1522
grpc-swift,
23+
...
1624
}:
1725
flake-utils.lib.eachSystem
1826
(with flake-utils.lib.system; [

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy