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