mirror of
				https://github.com/maxgoedjen/secretive.git
				synced 2025-11-04 09:20:56 +00:00 
			
		
		
		
	.
This commit is contained in:
		
							parent
							
								
									9b1f33b332
								
							
						
					
					
						commit
						5891e64c60
					
				@ -7,7 +7,7 @@ public protocol UpdaterProtocol: ObservableObject {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@MainActor public class Updater: ObservableObject, UpdaterProtocol {
 | 
					public class Updater: ObservableObject, UpdaterProtocol {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Published public var update: Release?
 | 
					    @Published public var update: Release?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -30,10 +30,10 @@ public protocol UpdaterProtocol: ObservableObject {
 | 
				
			|||||||
    public func checkForUpdates() async {
 | 
					    public func checkForUpdates() async {
 | 
				
			||||||
        guard let (data, _) = try? await URLSession.shared.data(from: Constants.updateURL) else { return }
 | 
					        guard let (data, _) = try? await URLSession.shared.data(from: Constants.updateURL) else { return }
 | 
				
			||||||
        guard let releases = try? JSONDecoder().decode([Release].self, from: data) else { return }
 | 
					        guard let releases = try? JSONDecoder().decode([Release].self, from: data) else { return }
 | 
				
			||||||
        evaluate(releases: releases)
 | 
					        await evaluate(releases: releases)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public func ignore(release: Release) {
 | 
					    @MainActor public func ignore(release: Release) {
 | 
				
			||||||
        guard !release.critical else { return }
 | 
					        guard !release.critical else { return }
 | 
				
			||||||
        defaults.set(true, forKey: release.name)
 | 
					        defaults.set(true, forKey: release.name)
 | 
				
			||||||
        update = release
 | 
					        update = release
 | 
				
			||||||
@ -47,7 +47,7 @@ public protocol UpdaterProtocol: ObservableObject {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
extension Updater {
 | 
					extension Updater {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    func evaluate(releases: [Release]) {
 | 
					    @MainActor func evaluate(releases: [Release]) {
 | 
				
			||||||
        guard let release = releases
 | 
					        guard let release = releases
 | 
				
			||||||
                .sorted()
 | 
					                .sorted()
 | 
				
			||||||
                .reversed()
 | 
					                .reversed()
 | 
				
			||||||
 | 
				
			|||||||
@ -33,9 +33,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
 | 
				
			|||||||
        notifier.prompt()
 | 
					        notifier.prompt()
 | 
				
			||||||
        updateSink = updater.$update.sink { update in
 | 
					        updateSink = updater.$update.sink { update in
 | 
				
			||||||
            guard let update = update else { return }
 | 
					            guard let update = update else { return }
 | 
				
			||||||
 | 
					            Task {
 | 
				
			||||||
 | 
					                await MainActor.run {
 | 
				
			||||||
                    self.notifier.notify(update: update, ignore: self.updater.ignore(release:))
 | 
					                    self.notifier.notify(update: update, ignore: self.updater.ignore(release:))
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -79,7 +79,7 @@ class Notifier {
 | 
				
			|||||||
        notificationCenter.add(request, withCompletionHandler: nil)
 | 
					        notificationCenter.add(request, withCompletionHandler: nil)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    func notify(update: Release, ignore: ((Release) -> Void)?) {
 | 
					    func notify(update: Release, ignore: (@MainActor (Release) -> Void)?) {
 | 
				
			||||||
        notificationDelegate.release = update
 | 
					        notificationDelegate.release = update
 | 
				
			||||||
        notificationDelegate.ignore = ignore
 | 
					        notificationDelegate.ignore = ignore
 | 
				
			||||||
        let notificationCenter = UNUserNotificationCenter.current()
 | 
					        let notificationCenter = UNUserNotificationCenter.current()
 | 
				
			||||||
@ -136,7 +136,7 @@ extension Notifier {
 | 
				
			|||||||
class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
 | 
					class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fileprivate var release: Release?
 | 
					    fileprivate var release: Release?
 | 
				
			||||||
    fileprivate var ignore: ((Release) -> Void)?
 | 
					    fileprivate var ignore: (@MainActor (Release) -> Void)?
 | 
				
			||||||
    fileprivate var persistAuthentication: ((AnySecret, AnySecretStore, TimeInterval?) -> Void)?
 | 
					    fileprivate var persistAuthentication: ((AnySecret, AnySecretStore, TimeInterval?) -> Void)?
 | 
				
			||||||
    fileprivate var persistOptions: [String: TimeInterval] = [:]
 | 
					    fileprivate var persistOptions: [String: TimeInterval] = [:]
 | 
				
			||||||
    fileprivate var pendingPersistableStores: [String: AnySecretStore] = [:]
 | 
					    fileprivate var pendingPersistableStores: [String: AnySecretStore] = [:]
 | 
				
			||||||
@ -146,7 +146,7 @@ class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
 | 
					    @MainActor func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
 | 
				
			||||||
        let category = response.notification.request.content.categoryIdentifier
 | 
					        let category = response.notification.request.content.categoryIdentifier
 | 
				
			||||||
        switch category {
 | 
					        switch category {
 | 
				
			||||||
        case Notifier.Constants.updateCategoryIdentitifier:
 | 
					        case Notifier.Constants.updateCategoryIdentitifier:
 | 
				
			||||||
@ -160,7 +160,7 @@ class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
 | 
				
			|||||||
        completionHandler()
 | 
					        completionHandler()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    func handleUpdateResponse(response: UNNotificationResponse) {
 | 
					    @MainActor func handleUpdateResponse(response: UNNotificationResponse) {
 | 
				
			||||||
        guard let update = release else { return }
 | 
					        guard let update = release else { return }
 | 
				
			||||||
        switch response.actionIdentifier {
 | 
					        switch response.actionIdentifier {
 | 
				
			||||||
        case Notifier.Constants.updateActionIdentitifier, UNNotificationDefaultActionIdentifier:
 | 
					        case Notifier.Constants.updateActionIdentitifier, UNNotificationDefaultActionIdentifier:
 | 
				
			||||||
 | 
				
			|||||||
@ -16,8 +16,12 @@ class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    func check() {
 | 
					    func check() {
 | 
				
			||||||
 | 
					        Task {
 | 
				
			||||||
 | 
					            await MainActor.run {
 | 
				
			||||||
                running = instanceSecretAgentProcess != nil
 | 
					                running = instanceSecretAgentProcess != nil
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // All processes, including ones from older versions, etc
 | 
					    // All processes, including ones from older versions, etc
 | 
				
			||||||
    var secretAgentProcesses: [NSRunningApplication] {
 | 
					    var secretAgentProcesses: [NSRunningApplication] {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user