Swiftpack.co - ChimeHQ/ProcessService as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by ChimeHQ.
ChimeHQ/ProcessService 0.1.2
Host an executable within an XPC service
⭐️ 10
🕓 1 week ago
macOS
.package(url: "https://github.com/ChimeHQ/ProcessService.git", from: "0.1.2")

Build Status License Platforms

ProcessService

System to host an executable within an XPC service.

Integration

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/ChimeHQ/ProcessService")
]

Usage

To interact with the service:

import ProcessServiceClient

let userEnv = try await HostedProcess.userEnvironment(with: "com.myxpcservice")

let process = HostedProcess(named: "com.myxpcservice", parameters: params)
let data = try await process.runAndReadStdout()

Here's now to make an XPC service. Make sure to match up the service bundle id with the name you use.

// main.swift

import Foundation

final class ServiceDelegate: NSObject, NSXPCListenerDelegate {
    func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool {
        do {
            try newConnection.configureProcessServiceServer()
        } catch {
            return false
        }
        
        newConnection.activate()

        return true
    }
}

let delegate = ServiceDelegate()
let listener = NSXPCListener.service()

listener.delegate = delegate
listener.resume()

Suggestions or Feedback

We'd love to hear from you! Get in touch via twitter, an issue, or a pull request.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

GitHub

link
Stars: 10
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

v0.1.2
1 week ago
  • Protect ExportedProcessService by making it an actor
  • Handle process termination, close down file handles

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics