This commit is contained in:
Max Goedjen 2022-02-16 22:02:57 -08:00
parent ba1c4c1563
commit 93b51f9e9b
No known key found for this signature in database
GPG Key ID: E58C21DD77B9B8E8
9 changed files with 52 additions and 100 deletions

View File

@ -19,7 +19,6 @@
5003EF632780081B00DF2006 /* SecureEnclaveSecretKit in Frameworks */ = {isa = PBXBuildFile; productRef = 5003EF622780081B00DF2006 /* SecureEnclaveSecretKit */; }; 5003EF632780081B00DF2006 /* SecureEnclaveSecretKit in Frameworks */ = {isa = PBXBuildFile; productRef = 5003EF622780081B00DF2006 /* SecureEnclaveSecretKit */; };
5003EF652780081B00DF2006 /* SmartCardSecretKit in Frameworks */ = {isa = PBXBuildFile; productRef = 5003EF642780081B00DF2006 /* SmartCardSecretKit */; }; 5003EF652780081B00DF2006 /* SmartCardSecretKit in Frameworks */ = {isa = PBXBuildFile; productRef = 5003EF642780081B00DF2006 /* SmartCardSecretKit */; };
500ED3D427B7934A00A6DC28 /* UpdaterProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5088065927B4A5E40090BD57 /* UpdaterProtocol.swift */; }; 500ED3D427B7934A00A6DC28 /* UpdaterProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5088065927B4A5E40090BD57 /* UpdaterProtocol.swift */; };
500ED3D527B796C800A6DC28 /* Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater.app in Resources */ = {isa = PBXBuildFile; fileRef = 5081F6D027B790DD0094B82D /* Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater.app */; };
500ED3DA27B797EE00A6DC28 /* Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = 5081F6D027B790DD0094B82D /* Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 500ED3DA27B797EE00A6DC28 /* Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = 5081F6D027B790DD0094B82D /* Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
501421622781262300BBAA70 /* Brief in Frameworks */ = {isa = PBXBuildFile; productRef = 501421612781262300BBAA70 /* Brief */; }; 501421622781262300BBAA70 /* Brief in Frameworks */ = {isa = PBXBuildFile; productRef = 501421612781262300BBAA70 /* Brief */; };
501421652781268000BBAA70 /* SecretAgent.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = 50A3B78A24026B7500D209EA /* SecretAgent.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 501421652781268000BBAA70 /* SecretAgent.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = 50A3B78A24026B7500D209EA /* SecretAgent.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
@ -40,7 +39,7 @@
506772C72424784600034DED /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 506772C62424784600034DED /* Credits.rtf */; }; 506772C72424784600034DED /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 506772C62424784600034DED /* Credits.rtf */; };
506772C92425BB8500034DED /* NoStoresView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 506772C82425BB8500034DED /* NoStoresView.swift */; }; 506772C92425BB8500034DED /* NoStoresView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 506772C82425BB8500034DED /* NoStoresView.swift */; };
5079BA0F250F29BF00EA86F4 /* StoreListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5079BA0E250F29BF00EA86F4 /* StoreListView.swift */; }; 5079BA0F250F29BF00EA86F4 /* StoreListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5079BA0E250F29BF00EA86F4 /* StoreListView.swift */; };
5081F6D327B790DD0094B82D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5081F6D227B790DD0094B82D /* AppDelegate.swift */; }; 5081F6D327B790DD0094B82D /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5081F6D227B790DD0094B82D /* main.swift */; };
5081F6D727B790DE0094B82D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5081F6D627B790DE0094B82D /* Assets.xcassets */; }; 5081F6D727B790DE0094B82D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5081F6D627B790DE0094B82D /* Assets.xcassets */; };
5081F6E027B791110094B82D /* UpdaterProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5088065927B4A5E40090BD57 /* UpdaterProtocol.swift */; }; 5081F6E027B791110094B82D /* UpdaterProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5088065927B4A5E40090BD57 /* UpdaterProtocol.swift */; };
5081F6E127B791110094B82D /* Updater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5088065B27B4A6240090BD57 /* Updater.swift */; }; 5081F6E127B791110094B82D /* Updater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5088065B27B4A6240090BD57 /* Updater.swift */; };
@ -155,15 +154,13 @@
506772C82425BB8500034DED /* NoStoresView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoStoresView.swift; sourceTree = "<group>"; }; 506772C82425BB8500034DED /* NoStoresView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoStoresView.swift; sourceTree = "<group>"; };
5079BA0E250F29BF00EA86F4 /* StoreListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreListView.swift; sourceTree = "<group>"; }; 5079BA0E250F29BF00EA86F4 /* StoreListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreListView.swift; sourceTree = "<group>"; };
5081F6D027B790DD0094B82D /* Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater.app; sourceTree = BUILT_PRODUCTS_DIR; }; 5081F6D027B790DD0094B82D /* Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater.app; sourceTree = BUILT_PRODUCTS_DIR; };
5081F6D227B790DD0094B82D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; 5081F6D227B790DD0094B82D /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
5081F6D627B790DE0094B82D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 5081F6D627B790DE0094B82D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
5081F6DB27B790DE0094B82D /* SecretiveUpdater.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SecretiveUpdater.entitlements; sourceTree = "<group>"; }; 5081F6DB27B790DE0094B82D /* SecretiveUpdater.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SecretiveUpdater.entitlements; sourceTree = "<group>"; };
5081F6FF27B792150094B82D /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; }; 5081F6FF27B792150094B82D /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
5088065027B4A5BE0090BD57 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5088065927B4A5E40090BD57 /* UpdaterProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdaterProtocol.swift; sourceTree = "<group>"; }; 5088065927B4A5E40090BD57 /* UpdaterProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdaterProtocol.swift; sourceTree = "<group>"; };
5088065B27B4A6240090BD57 /* Updater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Updater.swift; sourceTree = "<group>"; }; 5088065B27B4A6240090BD57 /* Updater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Updater.swift; sourceTree = "<group>"; };
5088065D27B4A6460090BD57 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; }; 5088068E27B4A6FF0090BD57 /* UpdaterCommunicationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 5; lastKnownFileType = sourcecode.swift; path = UpdaterCommunicationController.swift; sourceTree = "<group>"; };
5088068E27B4A6FF0090BD57 /* UpdaterCommunicationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdaterCommunicationController.swift; sourceTree = "<group>"; };
508A58A9241E06B40069DC07 /* PreviewUpdater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewUpdater.swift; sourceTree = "<group>"; }; 508A58A9241E06B40069DC07 /* PreviewUpdater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewUpdater.swift; sourceTree = "<group>"; };
508A58AB241E121B0069DC07 /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; }; 508A58AB241E121B0069DC07 /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
508A58B2241ED2180069DC07 /* AgentStatusChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgentStatusChecker.swift; sourceTree = "<group>"; }; 508A58B2241ED2180069DC07 /* AgentStatusChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgentStatusChecker.swift; sourceTree = "<group>"; };
@ -242,7 +239,6 @@
50617D9723FCE48E0099B055 /* SecretiveTests */, 50617D9723FCE48E0099B055 /* SecretiveTests */,
50A3B78B24026B7500D209EA /* SecretAgent */, 50A3B78B24026B7500D209EA /* SecretAgent */,
508A58AF241E144C0069DC07 /* Config */, 508A58AF241E144C0069DC07 /* Config */,
5088064927B4A5BE0090BD57 /* SecretiveUpdater */,
5081F6D127B790DD0094B82D /* SecretiveUpdater */, 5081F6D127B790DD0094B82D /* SecretiveUpdater */,
50617D8023FCE48E0099B055 /* Products */, 50617D8023FCE48E0099B055 /* Products */,
5099A08B240243730062B6F2 /* Frameworks */, 5099A08B240243730062B6F2 /* Frameworks */,
@ -300,7 +296,7 @@
5081F6D127B790DD0094B82D /* SecretiveUpdater */ = { 5081F6D127B790DD0094B82D /* SecretiveUpdater */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
5081F6D227B790DD0094B82D /* AppDelegate.swift */, 5081F6D227B790DD0094B82D /* main.swift */,
5088065927B4A5E40090BD57 /* UpdaterProtocol.swift */, 5088065927B4A5E40090BD57 /* UpdaterProtocol.swift */,
5088065B27B4A6240090BD57 /* Updater.swift */, 5088065B27B4A6240090BD57 /* Updater.swift */,
5081F6FF27B792150094B82D /* Main.storyboard */, 5081F6FF27B792150094B82D /* Main.storyboard */,
@ -310,15 +306,6 @@
path = SecretiveUpdater; path = SecretiveUpdater;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
5088064927B4A5BE0090BD57 /* SecretiveUpdater */ = {
isa = PBXGroup;
children = (
5088065027B4A5BE0090BD57 /* Info.plist */,
5088065D27B4A6460090BD57 /* main.swift */,
);
path = SecretiveUpdater;
sourceTree = "<group>";
};
508A58AF241E144C0069DC07 /* Config */ = { 508A58AF241E144C0069DC07 /* Config */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -538,7 +525,6 @@
50617D8A23FCE48E0099B055 /* Preview Assets.xcassets in Resources */, 50617D8A23FCE48E0099B055 /* Preview Assets.xcassets in Resources */,
50617D8723FCE48E0099B055 /* Assets.xcassets in Resources */, 50617D8723FCE48E0099B055 /* Assets.xcassets in Resources */,
506772C72424784600034DED /* Credits.rtf in Resources */, 506772C72424784600034DED /* Credits.rtf in Resources */,
500ED3D527B796C800A6DC28 /* Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater.app in Resources */,
508BF28E25B4F005009EFB7E /* InternetAccessPolicy.plist in Resources */, 508BF28E25B4F005009EFB7E /* InternetAccessPolicy.plist in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
@ -616,7 +602,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
5081F6D327B790DD0094B82D /* AppDelegate.swift in Sources */, 5081F6D327B790DD0094B82D /* main.swift in Sources */,
5081F6E027B791110094B82D /* UpdaterProtocol.swift in Sources */, 5081F6E027B791110094B82D /* UpdaterProtocol.swift in Sources */,
5081F6E127B791110094B82D /* Updater.swift in Sources */, 5081F6E127B791110094B82D /* Updater.swift in Sources */,
); );

View File

@ -15,7 +15,7 @@
<BuildableReference <BuildableReference
BuildableIdentifier = "primary" BuildableIdentifier = "primary"
BlueprintIdentifier = "5081F6CF27B790DD0094B82D" BlueprintIdentifier = "5081F6CF27B790DD0094B82D"
BuildableName = "Test.app" BuildableName = "Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater.app"
BlueprintName = "SecretiveUpdater" BlueprintName = "SecretiveUpdater"
ReferencedContainer = "container:Secretive.xcodeproj"> ReferencedContainer = "container:Secretive.xcodeproj">
</BuildableReference> </BuildableReference>
@ -45,7 +45,7 @@
<BuildableReference <BuildableReference
BuildableIdentifier = "primary" BuildableIdentifier = "primary"
BlueprintIdentifier = "5081F6CF27B790DD0094B82D" BlueprintIdentifier = "5081F6CF27B790DD0094B82D"
BuildableName = "Test.app" BuildableName = "Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater.app"
BlueprintName = "SecretiveUpdater" BlueprintName = "SecretiveUpdater"
ReferencedContainer = "container:Secretive.xcodeproj"> ReferencedContainer = "container:Secretive.xcodeproj">
</BuildableReference> </BuildableReference>
@ -62,7 +62,7 @@
<BuildableReference <BuildableReference
BuildableIdentifier = "primary" BuildableIdentifier = "primary"
BlueprintIdentifier = "5081F6CF27B790DD0094B82D" BlueprintIdentifier = "5081F6CF27B790DD0094B82D"
BuildableName = "Test.app" BuildableName = "Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater.app"
BlueprintName = "SecretiveUpdater" BlueprintName = "SecretiveUpdater"
ReferencedContainer = "container:Secretive.xcodeproj"> ReferencedContainer = "container:Secretive.xcodeproj">
</BuildableReference> </BuildableReference>

View File

@ -29,19 +29,12 @@ struct Secretive: App {
.environmentObject(UpdateChecker(checkOnLaunch: hasRunSetup)) .environmentObject(UpdateChecker(checkOnLaunch: hasRunSetup))
.environmentObject(agentStatusChecker) .environmentObject(agentStatusChecker)
.onAppear { .onAppear {
updaterController.configure() updaterController.installUpdate(url: URL(string: "https://github.com/maxgoedjen/secretive/releases/download/v2.1.1/Secretive.zip")!)
if !hasRunSetup { if !hasRunSetup {
showingSetup = true showingSetup = true
} }
} }
.onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in .onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in
Task {
do {
let path = try await updaterController.updater?.installUpdate(url: URL(string: "https://github.com/maxgoedjen/secretive/releases/download/v2.1.1/Secretive.zip")!)
} catch {
print(error)
}
}
guard hasRunSetup else { return } guard hasRunSetup else { return }
agentStatusChecker.check() agentStatusChecker.check()
if agentStatusChecker.running && justUpdatedChecker.justUpdated { if agentStatusChecker.running && justUpdatedChecker.justUpdated {

View File

@ -15,12 +15,11 @@ class UpdaterCommunicationController: ObservableObject {
init() { init() {
} }
func configure() { func installUpdate(url: URL) {
guard !running else { return } guard !running else { return }
// TODO: Set disabled on launch. Only enable when I have an update to install. _ = SMLoginItemSetEnabled(Bundle.main.updaterBundleID as CFString, false)
let x = SMLoginItemSetEnabled("Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater" as CFString, false) SMLoginItemSetEnabled(Bundle.main.updaterBundleID as CFString, true)
let y = SMLoginItemSetEnabled("Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater" as CFString, true) connection = NSXPCConnection(machServiceName: Bundle.main.updaterBundleID)
connection = NSXPCConnection(machServiceName: "Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater")
connection?.remoteObjectInterface = NSXPCInterface(with: UpdaterProtocol.self) connection?.remoteObjectInterface = NSXPCInterface(with: UpdaterProtocol.self)
connection?.invalidationHandler = { connection?.invalidationHandler = {
Logger().warning("XPC connection invalidated") Logger().warning("XPC connection invalidated")
@ -29,10 +28,12 @@ class UpdaterCommunicationController: ObservableObject {
updater = connection?.remoteObjectProxyWithErrorHandler({ error in updater = connection?.remoteObjectProxyWithErrorHandler({ error in
Logger().error("\(String(describing: error))") Logger().error("\(String(describing: error))")
}) as? UpdaterProtocol }) as? UpdaterProtocol
Task {
print(try await updater?.installUpdate(url: URL(string: "https://google.com")!))
}
running = true running = true
let existingURL = Bundle.main.bundleURL
Task {
let result = try await updater?.installUpdate(url: url, to: existingURL)
print(result)
}
} }
} }

View File

@ -4,4 +4,5 @@ import Foundation
extension Bundle { extension Bundle {
public var agentBundleID: String {(self.bundleIdentifier?.replacingOccurrences(of: "Host", with: "SecretAgent"))!} public var agentBundleID: String {(self.bundleIdentifier?.replacingOccurrences(of: "Host", with: "SecretAgent"))!}
public var hostBundleID: String {(self.bundleIdentifier?.replacingOccurrences(of: "SecretAgent", with: "Host"))!} public var hostBundleID: String {(self.bundleIdentifier?.replacingOccurrences(of: "SecretAgent", with: "Host"))!}
public var updaterBundleID: String { "Z72PRUAWF6.com.maxgoedjen.SecretiveUpdater" }
} }

View File

@ -1,43 +0,0 @@
import Cocoa
@main
class AppDelegate: NSObject, NSApplicationDelegate {
let delegate = ServiceDelegate(exportedObject: Updater())
let listener = NSXPCListener(machServiceName: Bundle.main.bundleIdentifier!)
func applicationDidFinishLaunching(_ aNotification: Notification) {
listener.delegate = delegate
listener.resume()
Task {
try! await delegate.exported.authorize()
}
}
func applicationWillTerminate(_ aNotification: Notification) {
}
func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
return false
}
}
class ServiceDelegate: NSObject, NSXPCListenerDelegate {
let exported: UpdaterProtocol
init(exportedObject: UpdaterProtocol) {
self.exported = exportedObject
}
func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool {
newConnection.exportedInterface = NSXPCInterface(with: UpdaterProtocol.self)
newConnection.exportedObject = exported
newConnection.resume()
return true
}
}

View File

@ -8,13 +8,18 @@ import Security.AuthorizationTags
class Updater: UpdaterProtocol { class Updater: UpdaterProtocol {
func installUpdate(url: URL) async throws -> String { func installUpdate(url: URL, to destinationURL: URL) async throws -> String {
// try await authorize()
// let (downloadedURL, _) = try await URLSession.shared.download(from: url) // let (downloadedURL, _) = try await URLSession.shared.download(from: url)
// let unzipped = try await decompress(url: downloadedURL) // let unzipped = try await decompress(url: downloadedURL)
// try await move(url: unzipped, to: destinationURL)
// let config = NSWorkspace.OpenConfiguration() // let config = NSWorkspace.OpenConfiguration()
// config.activates = true // config.activates = true
// TODO: clean
_ = try await authorize()
// if let host = NSRunningApplication.runningApplications(withBundleIdentifier: "com.maxgoedjen.Secretive.Host").first(where: { $0.bundleURL?.path.hasPrefix("/Applications") ?? false }) {
// host.terminate()
// //
// }
return "OK" return "OK"
} }
@ -37,43 +42,51 @@ class Updater: UpdaterProtocol {
return appURL return appURL
} }
func move(url: URL) async throws { func move(url: URL, to destinationURL: URL) async throws {
try await authorize() let auth = try await authorize()
try await move(url: url) try await move(url: url, to: destinationURL)
try await revokeAuthorization() try await revokeAuthorization(auth)
} }
func authorize() async throws { func authorize() async throws -> AuthorizationRef {
let flags = AuthorizationFlags() let flags = AuthorizationFlags()
var authorization: AuthorizationRef? = nil var authorization: AuthorizationRef? = nil
let status = AuthorizationCreate(nil, nil, flags, &authorization) AuthorizationCreate(nil, nil, flags, &authorization)
print(status)
print("Hello")
let authFlags: AuthorizationFlags = [.interactionAllowed, .extendRights, .preAuthorize] let authFlags: AuthorizationFlags = [.interactionAllowed, .extendRights, .preAuthorize]
var result: OSStatus?
kAuthorizationRightExecute.withCString { cString in kAuthorizationRightExecute.withCString { cString in
var item = AuthorizationItem(name: cString, valueLength: 0, value: nil, flags: 0) var item = AuthorizationItem(name: cString, valueLength: 0, value: nil, flags: 0)
withUnsafeMutablePointer(to: &item) { pointer in withUnsafeMutablePointer(to: &item) { pointer in
var rights = AuthorizationRights(count: 1, items: pointer) var rights = AuthorizationRights(count: 1, items: pointer)
let out = AuthorizationCopyRights(authorization!, &rights, nil, authFlags, nil) result = AuthorizationCopyRights(authorization!, &rights, nil, authFlags, nil)
print(out)
} }
} }
guard result == errAuthorizationSuccess, let authorization = authorization else {
throw RightsNotAcquiredError()
} }
return authorization
func revokeAuthorization() async throws {
} }
func priveledgedMove(url: URL) async throws { func revokeAuthorization(_ authorization: AuthorizationRef) async throws {
AuthorizationFree(authorization, .destroyRights)
}
func priveledgedMove(url: URL, to destination: URL) async throws {
try FileManager.default.replaceItemAt(destination, withItemAt: url)
} }
} }
extension Updater { extension Updater {
struct DecompressionError: Error, LocalizedError { struct DecompressionError: Error, LocalizedError {
let reason: String let reason: String
} }
struct RightsNotAcquiredError: Error, LocalizedError {
}
} }
extension URLSession { extension URLSession {

View File

@ -3,7 +3,6 @@ import Brief
@objc public protocol UpdaterProtocol { @objc public protocol UpdaterProtocol {
func installUpdate(url: URL) async throws -> String func installUpdate(url: URL, to: URL) async throws -> String
func authorize() async throws
} }

View File

@ -19,6 +19,8 @@ class ServiceDelegate: NSObject, NSXPCListenerDelegate {
let updater = Updater() let updater = Updater()
let delegate = ServiceDelegate(exportedObject: Updater()) let delegate = ServiceDelegate(exportedObject: Updater())
let listener = NSXPCListener.service() let listener = NSXPCListener(machServiceName: Bundle.main.bundleIdentifier!)
listener.delegate = delegate listener.delegate = delegate
listener.resume() listener.resume()
try "Hello world".data(using: .utf8)?.write(to: URL(fileURLWithPath: "/Users/max/Downloads/\(UUID().uuidString).txt"))
RunLoop.current.run()