mirror of
https://github.com/maxgoedjen/secretive.git
synced 2026-03-08 02:27:24 +01:00
WIP
This commit is contained in:
@@ -69,24 +69,26 @@ struct Secretive: App {
|
||||
extension Secretive {
|
||||
|
||||
private func reinstallAgent() {
|
||||
justUpdatedChecker.check()
|
||||
LaunchAgentController().install {
|
||||
// Wait a second for launchd to kick in (next runloop isn't enough).
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
||||
agentStatusChecker.check()
|
||||
if !agentStatusChecker.running {
|
||||
forceLaunchAgent()
|
||||
}
|
||||
}
|
||||
}
|
||||
// justUpdatedChecker.check()
|
||||
// FIXME: THIS
|
||||
// LaunchAgentController().install {
|
||||
// // Wait a second for launchd to kick in (next runloop isn't enough).
|
||||
// DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
||||
// agentStatusChecker.check()
|
||||
// if !agentStatusChecker.running {
|
||||
// forceLaunchAgent()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private func forceLaunchAgent() {
|
||||
// We've run setup, we didn't just update, launchd is just not doing it's thing.
|
||||
// Force a launch directly.
|
||||
LaunchAgentController().forceLaunch { _ in
|
||||
agentStatusChecker.check()
|
||||
}
|
||||
// FIXME: THIS
|
||||
// LaunchAgentController().forceLaunch { _ in
|
||||
// agentStatusChecker.check()
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,37 +8,35 @@ 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 {
|
||||
let app = 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 {
|
||||
// FIXME: THIS
|
||||
SMLoginItemSetEnabled(Bundle.main.agentBundleID as CFString, enabled)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,32 @@
|
||||
import Foundation
|
||||
import Combine
|
||||
import Synchronization
|
||||
import Observation
|
||||
import Brief
|
||||
|
||||
class PreviewUpdater: UpdaterProtocol {
|
||||
@Observable class PreviewUpdater: UpdaterProtocol {
|
||||
|
||||
var update: Release? {
|
||||
_update.withLock { $0 }
|
||||
}
|
||||
let _update: Mutex<Release?> = .init(nil)
|
||||
|
||||
let update: Release?
|
||||
let testBuild = false
|
||||
|
||||
init(update: Update = .none) {
|
||||
switch update {
|
||||
case .none:
|
||||
self.update = nil
|
||||
_update.withLock {
|
||||
$0 = nil
|
||||
}
|
||||
case .advisory:
|
||||
self.update = Release(name: "10.10.10", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Some regular update")
|
||||
_update.withLock {
|
||||
$0 = Release(name: "10.10.10", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Some regular update")
|
||||
}
|
||||
case .critical:
|
||||
self.update = Release(name: "10.10.10", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Critical Security Update")
|
||||
_update.withLock {
|
||||
$0 = Release(name: "10.10.10", prerelease: false, html_url: URL(string: "https://example.com")!, body: "Critical Security Update")
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import SecretKit
|
||||
|
||||
struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
|
||||
@ObservedObject var store: StoreType
|
||||
@State var store: StoreType
|
||||
@Binding var showing: Bool
|
||||
|
||||
@State private var name = ""
|
||||
@@ -45,7 +45,8 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
}
|
||||
|
||||
func save() {
|
||||
try! store.create(name: name, requiresAuthentication: requiresAuthentication)
|
||||
// FIXME: THIS
|
||||
// try! store.create(name: name, requiresAuthentication: requiresAuthentication)
|
||||
showing = false
|
||||
}
|
||||
|
||||
@@ -93,14 +94,14 @@ struct ThumbnailPickerView<ValueType: Hashable>: View {
|
||||
|
||||
extension ThumbnailPickerView {
|
||||
|
||||
struct Item<ValueType: Hashable>: Identifiable {
|
||||
struct Item<InnerValueType: Hashable>: Identifiable {
|
||||
let id = UUID()
|
||||
let value: ValueType
|
||||
let value: InnerValueType
|
||||
let name: LocalizedStringKey
|
||||
let description: LocalizedStringKey
|
||||
let thumbnail: AnyView
|
||||
|
||||
init<ViewType: View>(value: ValueType, name: LocalizedStringKey, description: LocalizedStringKey, thumbnail: ViewType) {
|
||||
init<ViewType: View>(value: InnerValueType, name: LocalizedStringKey, description: LocalizedStringKey, thumbnail: ViewType) {
|
||||
self.value = value
|
||||
self.name = name
|
||||
self.description = description
|
||||
|
||||
@@ -3,7 +3,7 @@ import SecretKit
|
||||
|
||||
struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
|
||||
@ObservedObject var store: StoreType
|
||||
@State var store: StoreType
|
||||
let secret: StoreType.SecretType
|
||||
var dismissalBlock: (Bool) -> ()
|
||||
|
||||
@@ -49,7 +49,8 @@ struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
}
|
||||
|
||||
func delete() {
|
||||
try! store.delete(secret: secret)
|
||||
// FIXME: THIS
|
||||
// try! store.delete(secret: secret)
|
||||
dismissalBlock(true)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import SecretKit
|
||||
|
||||
struct EmptyStoreView: View {
|
||||
|
||||
@ObservedObject var store: AnySecretStore
|
||||
@State var store: AnySecretStore
|
||||
@Binding var activeSecret: AnySecret.ID?
|
||||
|
||||
var body: some View {
|
||||
@@ -22,8 +22,8 @@ struct EmptyStoreView: View {
|
||||
extension EmptyStoreView {
|
||||
|
||||
enum Constants {
|
||||
static let emptyStoreModifiableTag: AnyHashable = "emptyStoreModifiableTag"
|
||||
static let emptyStoreTag: AnyHashable = "emptyStoreTag"
|
||||
static let emptyStoreModifiableTag = "emptyStoreModifiableTag"
|
||||
static let emptyStoreTag = "emptyStoreTag"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import SecretKit
|
||||
|
||||
struct RenameSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
|
||||
@ObservedObject var store: StoreType
|
||||
@State var store: StoreType
|
||||
let secret: StoreType.SecretType
|
||||
var dismissalBlock: (_ renamed: Bool) -> ()
|
||||
|
||||
@@ -44,7 +44,8 @@ struct RenameSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
}
|
||||
|
||||
func rename() {
|
||||
try? store.update(secret: secret, name: newName)
|
||||
// FIXME: THIS
|
||||
// try? await store.update(secret: secret, name: newName)
|
||||
dismissalBlock(true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import SecretKit
|
||||
|
||||
struct SecretListItemView: View {
|
||||
|
||||
@ObservedObject var store: AnySecretStore
|
||||
@State var store: AnySecretStore
|
||||
var secret: AnySecret
|
||||
@Binding var activeSecret: AnySecret.ID?
|
||||
|
||||
|
||||
@@ -156,8 +156,10 @@ struct SecretAgentSetupView: View {
|
||||
}
|
||||
|
||||
func install() {
|
||||
LaunchAgentController().install()
|
||||
buttonAction()
|
||||
Task {
|
||||
await LaunchAgentController().install()
|
||||
buttonAction()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user