mirror of
https://github.com/maxgoedjen/secretive.git
synced 2026-03-06 09:47:22 +01:00
Working
This commit is contained in:
@@ -34,9 +34,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
logger.debug("SecretAgent finished launching")
|
||||
Task {
|
||||
let inputParser = try XPCAgentInputParser()
|
||||
for await session in socketController.sessions {
|
||||
Task {
|
||||
let inputParser = SSHAgentInputParser()
|
||||
do {
|
||||
for await message in session.messages {
|
||||
let request = try await inputParser.parse(data: message)
|
||||
|
||||
@@ -1,10 +1,41 @@
|
||||
import Foundation
|
||||
import SecretAgentKit
|
||||
|
||||
struct XPCAgentInputParser: SSHAgentInputParserProtocol {
|
||||
public final class XPCAgentInputParser: SSHAgentInputParserProtocol {
|
||||
|
||||
func parse(data: Data) async throws -> SSHAgent.Request {
|
||||
fatalError()
|
||||
private let session: XPCSession
|
||||
|
||||
public init() throws {
|
||||
if #available(macOS 26.0, *) {
|
||||
session = try XPCSession(xpcService: "com.maxgoedjen.Secretive.AgentRequestParser", requirement: .isFromSameTeam())
|
||||
} else {
|
||||
session = try XPCSession(xpcService: "com.maxgoedjen.Secretive.AgentRequestParser")
|
||||
}
|
||||
}
|
||||
|
||||
public func parse(data: Data) async throws -> SSHAgent.Request {
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
do {
|
||||
try session.send(data) { result in
|
||||
switch result {
|
||||
case .success(let result):
|
||||
do {
|
||||
continuation.resume(returning: try result.decode(as: SSHAgent.Request.self))
|
||||
} catch {
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
case .failure(let error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
session.cancel(reason: "Done")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user