Skip to content

Commit bf811c9

Browse files
committed
Support post notification to extension service
1 parent fd1e1cf commit bf811c9

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

Core/Sources/Client/AsyncXPCService.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ public struct AsyncXPCService {
134134
{ service in { service.customCommand(id: id, editorContent: $0, withReply: $1) } }
135135
)
136136
}
137+
138+
public func postNotification(name: String) async throws {
139+
try await withXPCServiceConnected(connection: connection) {
140+
service, continuation in
141+
service.postNotification(name: name) {
142+
continuation.resume(())
143+
}
144+
}
145+
}
146+
147+
public func performAction(name: String, arguments: String) async throws -> String {
148+
try await withXPCServiceConnected(connection: connection) {
149+
service, continuation in
150+
service.performAction(name: name, arguments: arguments) {
151+
continuation.resume($0)
152+
}
153+
}
154+
}
137155
}
138156

139157
struct AutoFinishContinuation<T> {

Core/Sources/Service/XPCService.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,14 @@ public class XPCService: NSObject, XPCServiceProtocol {
184184
reply(nil)
185185
}
186186
}
187+
188+
public func postNotification(name: String, withReply reply: @escaping () -> Void) {
189+
reply()
190+
NSWorkspace.shared.notificationCenter.post(name: .init(name), object: nil)
191+
}
192+
193+
public func performAction(name: String, arguments: String, withReply reply: @escaping (String) -> Void) {
194+
reply("None")
195+
}
187196
}
188197

Core/Sources/XPCShared/XPCServiceProtocol.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,6 @@ public protocol XPCServiceProtocol {
5050

5151
func getXPCServiceVersion(withReply reply: @escaping (String, String) -> Void)
5252
func getXPCServiceAccessibilityPermission(withReply reply: @escaping (Bool) -> Void)
53+
func postNotification(name: String, withReply reply: @escaping () -> Void)
54+
func performAction(name: String, arguments: String, withReply reply: @escaping (String) -> Void)
5355
}

0 commit comments

Comments
 (0)