mirror of
https://github.com/maxgoedjen/secretive.git
synced 2026-03-06 01:37:22 +01:00
Swift 6 / Concurrency fixes (#578)
* Enable language mode
* WIP
* WIP
* Fix concurrency issues in SmartCardStore
* Switch to SMAppService
* Bump runners
* Base
* Finish Testing migration
* Tweak async for updater
* More
* Backport mutex
* Revert "Backport mutex"
This reverts commit 9b02afb20c.
* WIP
* Reenable
* Fix preview.
* Update package.
* Bump to latest public macOS and Xcode
* Bump back down to 6.1
* Update to Xcode 26.
* Fixed tests.
* More cleanup
* Env fixes
* var->let
* Cleanup
* Persist auth async
* Whitespace.
* Whitespace.
* Cleanup.
* Cleanup
* Redoing locks in actors bc of observable
* Actors.
* .
* Specify b5
* Update package to 6.2
* Fix disabled updater
* Remove preconcurrency warning
* Move updater init
This commit is contained in:
@@ -2,18 +2,22 @@ import Foundation
|
||||
import Combine
|
||||
import AppKit
|
||||
import SecretKit
|
||||
import Observation
|
||||
|
||||
protocol AgentStatusCheckerProtocol: ObservableObject {
|
||||
@MainActor protocol AgentStatusCheckerProtocol: Observable, Sendable {
|
||||
var running: Bool { get }
|
||||
var developmentBuild: Bool { get }
|
||||
func check()
|
||||
}
|
||||
|
||||
class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol {
|
||||
@Observable @MainActor final class AgentStatusChecker: AgentStatusCheckerProtocol {
|
||||
|
||||
@Published var running: Bool = false
|
||||
var running: Bool = false
|
||||
|
||||
init() {
|
||||
check()
|
||||
nonisolated init() {
|
||||
Task { @MainActor in
|
||||
check()
|
||||
}
|
||||
}
|
||||
|
||||
func check() {
|
||||
|
||||
@@ -2,13 +2,13 @@ import Foundation
|
||||
import Combine
|
||||
import AppKit
|
||||
|
||||
protocol JustUpdatedCheckerProtocol: ObservableObject {
|
||||
protocol JustUpdatedCheckerProtocol: Observable {
|
||||
var justUpdated: Bool { get }
|
||||
}
|
||||
|
||||
class JustUpdatedChecker: ObservableObject, JustUpdatedCheckerProtocol {
|
||||
@Observable class JustUpdatedChecker: JustUpdatedCheckerProtocol {
|
||||
|
||||
@Published var justUpdated: Bool = false
|
||||
var justUpdated: Bool = false
|
||||
|
||||
init() {
|
||||
check()
|
||||
|
||||
@@ -8,38 +8,45 @@ struct LaunchAgentController {
|
||||
|
||||
private let logger = Logger(subsystem: "com.maxgoedjen.secretive", category: "LaunchAgentController")
|
||||
|
||||
func install(completion: (() -> Void)? = nil) {
|
||||
func install() async {
|
||||
logger.debug("Installing agent")
|
||||
_ = setEnabled(false)
|
||||
// This is definitely a bit of a "seems to work better" thing but:
|
||||
// Seems to more reliably hit if these are on separate runloops, otherwise it seems like it sometimes doesn't kill old
|
||||
// and start new?
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
||||
try? await Task.sleep(for: .seconds(1))
|
||||
await MainActor.run {
|
||||
_ = setEnabled(true)
|
||||
completion?()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func forceLaunch(completion: ((Bool) -> Void)?) {
|
||||
func forceLaunch() async -> Bool {
|
||||
logger.debug("Agent is not running, attempting to force launch")
|
||||
let url = Bundle.main.bundleURL.appendingPathComponent("Contents/Library/LoginItems/SecretAgent.app")
|
||||
let config = NSWorkspace.OpenConfiguration()
|
||||
config.activates = false
|
||||
NSWorkspace.shared.openApplication(at: url, configuration: config) { app, error in
|
||||
DispatchQueue.main.async {
|
||||
completion?(error == nil)
|
||||
}
|
||||
if let error = error {
|
||||
logger.error("Error force launching \(error.localizedDescription)")
|
||||
} else {
|
||||
logger.debug("Agent force launched")
|
||||
}
|
||||
do {
|
||||
try await NSWorkspace.shared.openApplication(at: url, configuration: config)
|
||||
logger.debug("Agent force launched")
|
||||
return true
|
||||
} catch {
|
||||
logger.error("Error force launching \(error.localizedDescription)")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
private func setEnabled(_ enabled: Bool) -> Bool {
|
||||
SMLoginItemSetEnabled(Bundle.main.agentBundleID as CFString, enabled)
|
||||
let service = SMAppService.loginItem(identifier: Bundle.main.agentBundleID)
|
||||
do {
|
||||
if enabled {
|
||||
try service.register()
|
||||
} else {
|
||||
try service.unregister()
|
||||
}
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user