Skip to content

Commit 3ad3646

Browse files
committed
Add a way to connect to Pulse automatically
1 parent bf78cc8 commit 3ad3646

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Diff for: Demo/Sources/iOS/Pulse_Demo_iOSApp.swift

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@ struct PulseDemo_iOS: App {
1414
var body: some Scene {
1515
WindowGroup {
1616
NavigationView {
17-
ConsoleView(store: .shared)
17+
ConsoleView(store: .demo)
1818
}
1919
}
2020
}
2121
}
2222

23+
@MainActor
2324
private final class AppViewModel: ObservableObject {
2425
init() {
25-
// - warning: If you are testing it, make sure to switch the demo to use
26-
// the shared store.
26+
// This code registers the store with the `RemoteLogger` (important!)
27+
LoggerStore.shared = .demo
28+
29+
RemoteLogger.shared.isAutomaticConnectionEnabled = true
2730

2831
// NetworkLogger.enableProxy()
2932

Diff for: Sources/Pulse/RemoteLogger/RemoteLogger.swift

+14
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ public final class RemoteLogger: ObservableObject, RemoteLoggerConnectionDelegat
104104
}
105105
}
106106

107+
/// If enabled, the logger will automatically connect to the first available
108+
/// Pulse Mac app and remember it for the next runs.
109+
///
110+
/// - warning: Never use this option in production as, since discovery
111+
/// requires Bluetooth, it will trigger a prompt on the first app run.
112+
public var isAutomaticConnectionEnabled = false {
113+
didSet {
114+
isEnabled = true
115+
}
116+
}
117+
107118
public static let shared = RemoteLogger()
108119

109120
/// - parameter store: The store to be synced with the server. By default,
@@ -270,6 +281,9 @@ public final class RemoteLogger: ObservableObject, RemoteLoggerConnectionDelegat
270281

271282
guard let name = self.knownServers.first(where: { servers[$0] != nil }),
272283
let server = servers[name] else {
284+
if isAutomaticConnectionEnabled, let server = self.servers.first {
285+
connect(to: server)
286+
}
273287
return
274288
}
275289

0 commit comments

Comments
 (0)