style(macos): swiftformat sources
parent
47a1774dc0
commit
8c6a592523
|
|
@ -157,7 +157,10 @@ struct AnthropicAuthControls: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let creds = try await AnthropicOAuth.exchangeCode(code: parsed.code, state: parsed.state, verifier: pkce.verifier)
|
let creds = try await AnthropicOAuth.exchangeCode(
|
||||||
|
code: parsed.code,
|
||||||
|
state: parsed.state,
|
||||||
|
verifier: pkce.verifier)
|
||||||
try PiOAuthStore.saveAnthropicOAuth(creds)
|
try PiOAuthStore.saveAnthropicOAuth(creds)
|
||||||
self.refresh()
|
self.refresh()
|
||||||
self.pkce = nil
|
self.pkce = nil
|
||||||
|
|
|
||||||
|
|
@ -57,4 +57,3 @@ enum AnthropicOAuthCodeState {
|
||||||
return String(text[full])
|
return String(text[full])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,7 @@ actor CameraCaptureService {
|
||||||
|
|
||||||
private nonisolated static func clampDurationMs(_ ms: Int?) -> Int {
|
private nonisolated static func clampDurationMs(_ ms: Int?) -> Int {
|
||||||
let v = ms ?? 3000
|
let v = ms ?? 3000
|
||||||
return min(60_000, max(250, v))
|
return min(60000, max(250, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
private nonisolated static func exportToMP4(inputURL: URL, outputURL: URL) async throws {
|
private nonisolated static func exportToMP4(inputURL: URL, outputURL: URL) async throws {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import Foundation
|
||||||
import OSLog
|
import OSLog
|
||||||
|
|
||||||
enum ControlRequestHandler {
|
enum ControlRequestHandler {
|
||||||
|
|
||||||
struct NodeListNode: Codable {
|
struct NodeListNode: Codable {
|
||||||
var nodeId: String
|
var nodeId: String
|
||||||
var displayName: String?
|
var displayName: String?
|
||||||
|
|
@ -559,7 +558,7 @@ enum ControlRequestHandler {
|
||||||
let payload = try await self.invokeLocalNode(
|
let payload = try await self.invokeLocalNode(
|
||||||
command: "screen.record",
|
command: "screen.record",
|
||||||
params: params,
|
params: params,
|
||||||
timeoutMs: 120000)
|
timeoutMs: 120_000)
|
||||||
guard let dict = payload as? [String: Any],
|
guard let dict = payload as? [String: Any],
|
||||||
let base64 = dict["base64"] as? String,
|
let base64 = dict["base64"] as? String,
|
||||||
let data = Data(base64Encoded: base64)
|
let data = Data(base64Encoded: base64)
|
||||||
|
|
|
||||||
|
|
@ -182,7 +182,9 @@ final class HoverHUDController {
|
||||||
|
|
||||||
private func targetFrame() -> NSRect {
|
private func targetFrame() -> NSRect {
|
||||||
guard let anchor = self.anchorProvider?() else {
|
guard let anchor = self.anchorProvider?() else {
|
||||||
return WindowPlacement.topRightFrame(size: NSSize(width: self.width, height: self.height), padding: self.padding)
|
return WindowPlacement.topRightFrame(
|
||||||
|
size: NSSize(width: self.width, height: self.height),
|
||||||
|
padding: self.padding)
|
||||||
}
|
}
|
||||||
|
|
||||||
let screen = NSScreen.screens.first { screen in
|
let screen = NSScreen.screens.first { screen in
|
||||||
|
|
@ -213,7 +215,11 @@ final class HoverHUDController {
|
||||||
|
|
||||||
private func installDismissMonitor() {
|
private func installDismissMonitor() {
|
||||||
guard self.dismissMonitor == nil, let window else { return }
|
guard self.dismissMonitor == nil, let window else { return }
|
||||||
self.dismissMonitor = NSEvent.addGlobalMonitorForEvents(matching: [.leftMouseDown, .rightMouseDown, .otherMouseDown]) { [weak self] _ in
|
self.dismissMonitor = NSEvent.addGlobalMonitorForEvents(matching: [
|
||||||
|
.leftMouseDown,
|
||||||
|
.rightMouseDown,
|
||||||
|
.otherMouseDown,
|
||||||
|
]) { [weak self] _ in
|
||||||
guard let self, self.model.isVisible else { return }
|
guard let self, self.model.isVisible else { return }
|
||||||
let pt = NSEvent.mouseLocation
|
let pt = NSEvent.mouseLocation
|
||||||
if !window.frame.contains(pt) {
|
if !window.frame.contains(pt) {
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,7 @@ actor MacNodeBridgePairingClient {
|
||||||
}
|
}
|
||||||
defer { timeout.cancel() }
|
defer { timeout.cancel() }
|
||||||
return try await withTaskCancellationHandler(operation: {
|
return try await withTaskCancellationHandler(operation: {
|
||||||
return try await task.value
|
try await task.value
|
||||||
}, onCancel: {
|
}, onCancel: {
|
||||||
timeout.cancel()
|
timeout.cancel()
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -271,8 +271,8 @@ actor MacNodeBridgeSession {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func makeStateStream(
|
private static func makeStateStream(
|
||||||
for connection: NWConnection,
|
for connection: NWConnection) -> AsyncStream<NWConnection.State>
|
||||||
) -> AsyncStream<NWConnection.State> {
|
{
|
||||||
AsyncStream { continuation in
|
AsyncStream { continuation in
|
||||||
connection.stateUpdateHandler = { state in
|
connection.stateUpdateHandler = { state in
|
||||||
continuation.yield(state)
|
continuation.yield(state)
|
||||||
|
|
@ -288,9 +288,9 @@ actor MacNodeBridgeSession {
|
||||||
|
|
||||||
private static func waitForReady(
|
private static func waitForReady(
|
||||||
_ stream: AsyncStream<NWConnection.State>,
|
_ stream: AsyncStream<NWConnection.State>,
|
||||||
timeoutSeconds: Double,
|
timeoutSeconds: Double) async throws
|
||||||
) async throws {
|
{
|
||||||
try await withTimeout(seconds: timeoutSeconds) {
|
try await self.withTimeout(seconds: timeoutSeconds) {
|
||||||
for await state in stream {
|
for await state in stream {
|
||||||
switch state {
|
switch state {
|
||||||
case .ready:
|
case .ready:
|
||||||
|
|
@ -313,8 +313,8 @@ actor MacNodeBridgeSession {
|
||||||
|
|
||||||
private static func withTimeout<T: Sendable>(
|
private static func withTimeout<T: Sendable>(
|
||||||
seconds: Double,
|
seconds: Double,
|
||||||
operation: @escaping @Sendable () async throws -> T,
|
operation: @escaping @Sendable () async throws -> T) async throws -> T
|
||||||
) async throws -> T {
|
{
|
||||||
let task = Task { try await operation() }
|
let task = Task { try await operation() }
|
||||||
let timeout = Task {
|
let timeout = Task {
|
||||||
try await Task.sleep(nanoseconds: UInt64(seconds * 1_000_000_000))
|
try await Task.sleep(nanoseconds: UInt64(seconds * 1_000_000_000))
|
||||||
|
|
@ -322,7 +322,7 @@ actor MacNodeBridgeSession {
|
||||||
}
|
}
|
||||||
defer { timeout.cancel() }
|
defer { timeout.cancel() }
|
||||||
return try await withTaskCancellationHandler(operation: {
|
return try await withTaskCancellationHandler(operation: {
|
||||||
return try await task.value
|
try await task.value
|
||||||
}, onCancel: {
|
}, onCancel: {
|
||||||
timeout.cancel()
|
timeout.cancel()
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -185,15 +185,15 @@ final class MacNodeModeCoordinator {
|
||||||
var continuation: CheckedContinuation<NWEndpoint?, Never>?
|
var continuation: CheckedContinuation<NWEndpoint?, Never>?
|
||||||
|
|
||||||
func finish(_ endpoint: NWEndpoint?) {
|
func finish(_ endpoint: NWEndpoint?) {
|
||||||
lock.lock()
|
self.lock.lock()
|
||||||
defer { lock.unlock() }
|
defer { lock.unlock() }
|
||||||
if resolved { return }
|
if self.resolved { return }
|
||||||
resolved = true
|
self.resolved = true
|
||||||
for browser in browsers {
|
for browser in self.browsers {
|
||||||
browser.cancel()
|
browser.cancel()
|
||||||
}
|
}
|
||||||
continuation?.resume(returning: endpoint)
|
self.continuation?.resume(returning: endpoint)
|
||||||
continuation = nil
|
self.continuation = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -239,11 +239,11 @@ enum MacNodeTokenStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
static func loadToken() -> String? {
|
static func loadToken() -> String? {
|
||||||
let raw = defaults.string(forKey: tokenKey)?.trimmingCharacters(in: .whitespacesAndNewlines)
|
let raw = self.defaults.string(forKey: self.tokenKey)?.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
return raw?.isEmpty == false ? raw : nil
|
return raw?.isEmpty == false ? raw : nil
|
||||||
}
|
}
|
||||||
|
|
||||||
static func saveToken(_ token: String) {
|
static func saveToken(_ token: String) {
|
||||||
defaults.set(token, forKey: tokenKey)
|
self.defaults.set(token, forKey: self.tokenKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ actor MacNodeRuntime {
|
||||||
|
|
||||||
func handleInvoke(_ req: BridgeInvokeRequest) async -> BridgeInvokeResponse {
|
func handleInvoke(_ req: BridgeInvokeRequest) async -> BridgeInvokeResponse {
|
||||||
let command = req.command
|
let command = req.command
|
||||||
if (command.hasPrefix("canvas.") || command.hasPrefix("canvas.a2ui.")) && !Self.canvasEnabled() {
|
if command.hasPrefix("canvas.") || command.hasPrefix("canvas.a2ui."), !Self.canvasEnabled() {
|
||||||
return BridgeInvokeResponse(
|
return BridgeInvokeResponse(
|
||||||
id: req.id,
|
id: req.id,
|
||||||
ok: false,
|
ok: false,
|
||||||
|
|
@ -199,7 +199,7 @@ actor MacNodeRuntime {
|
||||||
let ready = try await CanvasManager.shared.eval(sessionKey: "main", javaScript: """
|
let ready = try await CanvasManager.shared.eval(sessionKey: "main", javaScript: """
|
||||||
(() => Boolean(globalThis.clawdisA2UI))
|
(() => Boolean(globalThis.clawdisA2UI))
|
||||||
""")
|
""")
|
||||||
if ready != "true" && ready != "true\n" {
|
if ready != "true", ready != "true\n" {
|
||||||
return Self.errorResponse(req, code: .unavailable, message: "A2UI not ready")
|
return Self.errorResponse(req, code: .unavailable, message: "A2UI not ready")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -332,10 +332,11 @@ actor MacNodeRuntime {
|
||||||
|
|
||||||
let out = NSImage(size: target)
|
let out = NSImage(size: target)
|
||||||
out.lockFocus()
|
out.lockFocus()
|
||||||
image.draw(in: NSRect(origin: .zero, size: target),
|
image.draw(
|
||||||
from: NSRect(origin: .zero, size: size),
|
in: NSRect(origin: .zero, size: target),
|
||||||
operation: .copy,
|
from: NSRect(origin: .zero, size: size),
|
||||||
fraction: 1.0)
|
operation: .copy,
|
||||||
|
fraction: 1.0)
|
||||||
out.unlockFocus()
|
out.unlockFocus()
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ import Foundation
|
||||||
import OSLog
|
import OSLog
|
||||||
import UserNotifications
|
import UserNotifications
|
||||||
|
|
||||||
struct NodePairingReconcilePolicy {
|
enum NodePairingReconcilePolicy {
|
||||||
static let activeIntervalMs: UInt64 = 15_000
|
static let activeIntervalMs: UInt64 = 15000
|
||||||
static let resyncDelayMs: UInt64 = 250
|
static let resyncDelayMs: UInt64 = 250
|
||||||
|
|
||||||
static func shouldPoll(pendingCount: Int, isPresenting: Bool) -> Bool {
|
static func shouldPoll(pendingCount: Int, isPresenting: Bool) -> Bool {
|
||||||
|
|
@ -522,7 +522,7 @@ final class NodePairingApprovalPrompter {
|
||||||
defer { model.stop() }
|
defer { model.stop() }
|
||||||
|
|
||||||
let deadline = Date().addingTimeInterval(5.0)
|
let deadline = Date().addingTimeInterval(5.0)
|
||||||
while model.masters.isEmpty && Date() < deadline {
|
while model.masters.isEmpty, Date() < deadline {
|
||||||
try? await Task.sleep(nanoseconds: 200_000_000)
|
try? await Task.sleep(nanoseconds: 200_000_000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -488,7 +488,10 @@ struct OnboardingView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let creds = try await AnthropicOAuth.exchangeCode(code: parsed.code, state: parsed.state, verifier: pkce.verifier)
|
let creds = try await AnthropicOAuth.exchangeCode(
|
||||||
|
code: parsed.code,
|
||||||
|
state: parsed.state,
|
||||||
|
verifier: pkce.verifier)
|
||||||
try PiOAuthStore.saveAnthropicOAuth(creds)
|
try PiOAuthStore.saveAnthropicOAuth(creds)
|
||||||
self.refreshAnthropicOAuthStatus()
|
self.refreshAnthropicOAuthStatus()
|
||||||
self.anthropicAuthStatus = "Connected. Pi can now use Claude."
|
self.anthropicAuthStatus = "Connected. Pi can now use Claude."
|
||||||
|
|
|
||||||
|
|
@ -98,8 +98,8 @@ final class ScreenRecordService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private nonisolated static func clampDurationMs(_ ms: Int?) -> Int {
|
private nonisolated static func clampDurationMs(_ ms: Int?) -> Int {
|
||||||
let v = ms ?? 10_000
|
let v = ms ?? 10000
|
||||||
return min(60_000, max(250, v))
|
return min(60000, max(250, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
private nonisolated static func clampFps(_ fps: Double?) -> Double {
|
private nonisolated static func clampFps(_ fps: Double?) -> Double {
|
||||||
|
|
@ -144,8 +144,8 @@ private final class StreamRecorder: NSObject, SCStreamOutput, SCStreamDelegate,
|
||||||
let audioSettings: [String: Any] = [
|
let audioSettings: [String: Any] = [
|
||||||
AVFormatIDKey: kAudioFormatMPEG4AAC,
|
AVFormatIDKey: kAudioFormatMPEG4AAC,
|
||||||
AVNumberOfChannelsKey: 1,
|
AVNumberOfChannelsKey: 1,
|
||||||
AVSampleRateKey: 44_100,
|
AVSampleRateKey: 44100,
|
||||||
AVEncoderBitRateKey: 96_000,
|
AVEncoderBitRateKey: 96000,
|
||||||
]
|
]
|
||||||
let audioInput = AVAssetWriterInput(mediaType: .audio, outputSettings: audioSettings)
|
let audioInput = AVAssetWriterInput(mediaType: .audio, outputSettings: audioSettings)
|
||||||
audioInput.expectsMediaDataInRealTime = true
|
audioInput.expectsMediaDataInRealTime = true
|
||||||
|
|
@ -247,9 +247,13 @@ private final class StreamRecorder: NSObject, SCStreamOutput, SCStreamDelegate,
|
||||||
self.audioInput?.markAsFinished()
|
self.audioInput?.markAsFinished()
|
||||||
self.writer.finishWriting {
|
self.writer.finishWriting {
|
||||||
if let err = self.writer.error {
|
if let err = self.writer.error {
|
||||||
cont.resume(throwing: ScreenRecordService.ScreenRecordError.writeFailed(err.localizedDescription))
|
cont
|
||||||
|
.resume(throwing: ScreenRecordService.ScreenRecordError
|
||||||
|
.writeFailed(err.localizedDescription))
|
||||||
} else if self.writer.status != .completed {
|
} else if self.writer.status != .completed {
|
||||||
cont.resume(throwing: ScreenRecordService.ScreenRecordError.writeFailed("Failed to finalize video"))
|
cont
|
||||||
|
.resume(throwing: ScreenRecordService.ScreenRecordError
|
||||||
|
.writeFailed("Failed to finalize video"))
|
||||||
} else {
|
} else {
|
||||||
cont.resume()
|
cont.resume()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ struct ClawdisCLI {
|
||||||
let multiplier: Double = switch unit {
|
let multiplier: Double = switch unit {
|
||||||
case "ms": 1
|
case "ms": 1
|
||||||
case "s": 1000
|
case "s": 1000
|
||||||
case "m": 60_000
|
case "m": 60000
|
||||||
default: 1
|
default: 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1009,7 +1009,7 @@ struct ClawdisCLI {
|
||||||
let ms = durationMs ?? 3000
|
let ms = durationMs ?? 3000
|
||||||
return min(180, max(10, TimeInterval(ms) / 1000.0 + 10))
|
return min(180, max(10, TimeInterval(ms) / 1000.0 + 10))
|
||||||
case let .screenRecord(_, durationMs, _, _, _):
|
case let .screenRecord(_, durationMs, _, _, _):
|
||||||
let ms = durationMs ?? 10_000
|
let ms = durationMs ?? 10000
|
||||||
return min(180, max(10, TimeInterval(ms) / 1000.0 + 10))
|
return min(180, max(10, TimeInterval(ms) / 1000.0 + 10))
|
||||||
default:
|
default:
|
||||||
// Fail-fast so callers (incl. SSH tool calls) don't hang forever.
|
// Fail-fast so callers (incl. SSH tool calls) don't hang forever.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue