mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
[AltDaemon] Fixes XPC service lookup for Odyssey jailbreak
This commit is contained in:
@@ -15,7 +15,7 @@ class XPCConnectionHandler: NSObject, ConnectionHandler
|
||||
var disconnectionHandler: ((Connection) -> Void)?
|
||||
|
||||
private let dispatchQueue = DispatchQueue(label: "io.altstore.XPCConnectionListener", qos: .utility)
|
||||
private let listener = NSXPCListener.makeListener(machServiceName: XPCConnection.machServiceName)
|
||||
private let listeners = XPCConnection.machServiceNames.map { NSXPCListener.makeListener(machServiceName: $0) }
|
||||
|
||||
deinit
|
||||
{
|
||||
@@ -24,13 +24,16 @@ class XPCConnectionHandler: NSObject, ConnectionHandler
|
||||
|
||||
func startListening()
|
||||
{
|
||||
self.listener.delegate = self
|
||||
self.listener.resume()
|
||||
for listener in self.listeners
|
||||
{
|
||||
listener.delegate = self
|
||||
listener.resume()
|
||||
}
|
||||
}
|
||||
|
||||
func stopListening()
|
||||
{
|
||||
self.listener.suspend()
|
||||
self.listeners.forEach { $0.suspend() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
<dict>
|
||||
<key>cy:io.altstore.altdaemon</key>
|
||||
<true/>
|
||||
<key>lh:io.altstore.altdaemon</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -25,7 +25,7 @@ class FindServerOperation: ResultOperation<Server>
|
||||
let context: OperationContext
|
||||
|
||||
private var isWiredServerConnectionAvailable = false
|
||||
private var isLocalServerConnectionAvailable = false
|
||||
private var localServerMachServiceName: String?
|
||||
|
||||
init(context: OperationContext = OperationContext())
|
||||
{
|
||||
@@ -61,10 +61,10 @@ class FindServerOperation: ResultOperation<Server>
|
||||
|
||||
// Wait for either callback or timeout.
|
||||
DispatchQueue.global().asyncAfter(deadline: .now() + 1.0) {
|
||||
if self.isLocalServerConnectionAvailable
|
||||
if let machServiceName = self.localServerMachServiceName
|
||||
{
|
||||
// Prefer background daemon, if it exists and is running.
|
||||
let server = Server(connectionType: .local)
|
||||
let server = Server(connectionType: .local, machServiceName: machServiceName)
|
||||
self.finish(.success(server))
|
||||
}
|
||||
else if self.isWiredServerConnectionAvailable
|
||||
@@ -105,12 +105,17 @@ fileprivate extension FindServerOperation
|
||||
{
|
||||
func discoverLocalServer()
|
||||
{
|
||||
let connection = XPCConnection()
|
||||
connection.connect { (result) in
|
||||
switch result
|
||||
{
|
||||
case .failure(let error): print("Could not connect to AltDaemon XPC service.", error)
|
||||
case .success: self.isLocalServerConnectionAvailable = true
|
||||
for machServiceName in XPCConnection.machServiceNames
|
||||
{
|
||||
let xpcConnection = NSXPCConnection.makeConnection(machServiceName: machServiceName)
|
||||
|
||||
let connection = XPCConnection(xpcConnection)
|
||||
connection.connect { (result) in
|
||||
switch result
|
||||
{
|
||||
case .failure(let error): print("Could not connect to AltDaemon XPC service \(machServiceName).", error)
|
||||
case .success: self.localServerMachServiceName = machServiceName
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ struct Server: Equatable
|
||||
|
||||
var isPreferred = false
|
||||
var connectionType: ConnectionType = .wireless
|
||||
|
||||
var machServiceName: String?
|
||||
}
|
||||
|
||||
extension Server
|
||||
|
||||
@@ -76,7 +76,7 @@ extension ServerManager
|
||||
|
||||
switch server.connectionType
|
||||
{
|
||||
case .local: self.connectToLocalServer(completion: finish(_:))
|
||||
case .local: self.connectToLocalServer(server, completion: finish(_:))
|
||||
case .wired:
|
||||
guard let incomingConnectionsSemaphore = self.incomingConnectionsSemaphore else { return finish(.failure(ALTServerError(.connectionFailed))) }
|
||||
|
||||
@@ -190,14 +190,18 @@ private extension ServerManager
|
||||
connection.start(queue: self.dispatchQueue)
|
||||
}
|
||||
|
||||
func connectToLocalServer(completion: @escaping (Result<Connection, Error>) -> Void)
|
||||
func connectToLocalServer(_ server: Server, completion: @escaping (Result<Connection, Error>) -> Void)
|
||||
{
|
||||
let connection = XPCConnection()
|
||||
guard let machServiceName = server.machServiceName else { return completion(.failure(ConnectionError.connectionFailed)) }
|
||||
|
||||
let xpcConnection = NSXPCConnection.makeConnection(machServiceName: machServiceName)
|
||||
|
||||
let connection = XPCConnection(xpcConnection)
|
||||
connection.connect { (result) in
|
||||
switch result
|
||||
{
|
||||
case .failure(let error):
|
||||
print("Could not connect to AltDaemon XPC service.", error)
|
||||
print("Could not connect to AltDaemon XPC service \(machServiceName).", error)
|
||||
completion(.failure(error))
|
||||
|
||||
case .success: completion(.success(connection))
|
||||
|
||||
@@ -16,7 +16,10 @@ import Foundation
|
||||
|
||||
extension XPCConnection
|
||||
{
|
||||
public static let machServiceName = "cy:io.altstore.altdaemon"
|
||||
public static let unc0verMachServiceName = "cy:io.altstore.altdaemon"
|
||||
public static let odysseyMachServiceName = "lh:io.altstore.altdaemon"
|
||||
|
||||
public static let machServiceNames = [unc0verMachServiceName, odysseyMachServiceName]
|
||||
}
|
||||
|
||||
public class XPCConnection: NSObject, Connection
|
||||
@@ -30,7 +33,7 @@ public class XPCConnection: NSObject, Connection
|
||||
|
||||
private var error: Error?
|
||||
|
||||
public init(_ xpcConnection: NSXPCConnection = .makeConnection(machServiceName: XPCConnection.machServiceName))
|
||||
public init(_ xpcConnection: NSXPCConnection)
|
||||
{
|
||||
let proxyInterface = NSXPCInterface(with: XPCConnectionProxy.self)
|
||||
xpcConnection.remoteObjectInterface = proxyInterface
|
||||
|
||||
Reference in New Issue
Block a user