Coder Social home page Coder Social logo

colemancda / processservice Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chimehq/processservice

0.0 2.0 0.0 218 KB

Host an executable within an XPC service

License: BSD 3-Clause "New" or "Revised" License

Shell 1.37% C++ 47.10% Objective-C 3.07% Swift 48.47%

processservice's Introduction

Build Status License Platforms Documentation

ProcessService

System to host an executable within an XPC service.

Integration

Swift Package Manager

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

XPC Service

To be useful, you also need an actual XPC service that hosts the process server. Distributing an XPC service using SPM requires a workaround: bundling a pre-built binary in an xcframework. This comes with two disadvantages. It requires that you both link and embed the framework, which incurs size and potential launch-time impact. And, second, it requires a bootstrapping step to ensure the service can be found at runtime anywhere within the running process.

This is all optional and provided for convenience. You can just build your own service if you want.

import ProcessServiceContainer

ServiceContainer.bootstrap()

let userEnv = try await HostedProcess.userEnvironment(with: ServiceContainer.name)

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.

processservice's People

Contributors

mattmassicotte avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.