forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceDelegate.swift
More file actions
48 lines (39 loc) · 1.17 KB
/
ServiceDelegate.swift
File metadata and controls
48 lines (39 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import Foundation
import Logger
import XPCShared
class ServiceDelegate: NSObject, NSXPCListenerDelegate {
func listener(
_: NSXPCListener,
shouldAcceptNewConnection newConnection: NSXPCConnection
) -> Bool {
newConnection.exportedInterface = NSXPCInterface(
with: CommunicationBridgeXPCServiceProtocol.self
)
let exportedObject = XPCService()
newConnection.exportedObject = exportedObject
newConnection.resume()
Logger.temp.debug("Accepted new connection.")
return true
}
}
class XPCService: CommunicationBridgeXPCServiceProtocol {
static var endpoint: NSXPCListenerEndpoint?
func launchExtensionServiceIfNeeded(
withReply reply: @escaping (NSXPCListenerEndpoint?) -> Void
) {
#if DEBUG
reply(Self.endpoint)
#else
// launch the app
reply(endpoint)
#endif
}
func quit(withReply reply: () -> Void) {
listener.invalidate()
exit(0)
}
func updateServiceEndpoint(endpoint: NSXPCListenerEndpoint, withReply reply: () -> Void) {
Self.endpoint = endpoint
reply()
}
}