mirror of
https://github.com/maxgoedjen/secretive.git
synced 2026-03-08 02:27:24 +01:00
WIP
This commit is contained in:
@@ -69,26 +69,24 @@ struct Secretive: App {
|
||||
extension Secretive {
|
||||
|
||||
private func reinstallAgent() {
|
||||
// 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()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
justUpdatedChecker.check()
|
||||
Task {
|
||||
await LaunchAgentController().install()
|
||||
try? await Task.sleep(for: .seconds(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.
|
||||
// FIXME: THIS
|
||||
// LaunchAgentController().forceLaunch { _ in
|
||||
// agentStatusChecker.check()
|
||||
// }
|
||||
Task {
|
||||
_ = await LaunchAgentController().forceLaunch()
|
||||
agentStatusChecker.check()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,69 +18,69 @@ extension Preview {
|
||||
|
||||
}
|
||||
|
||||
extension Preview {
|
||||
|
||||
class Store: SecretStore, ObservableObject {
|
||||
|
||||
let isAvailable = true
|
||||
let id = UUID()
|
||||
var name: String { "Preview Store" }
|
||||
@Published var secrets: [Secret] = []
|
||||
|
||||
init(secrets: [Secret]) {
|
||||
self.secrets.append(contentsOf: secrets)
|
||||
}
|
||||
|
||||
init(numberOfRandomSecrets: Int = 5) {
|
||||
let new = (0..<numberOfRandomSecrets).map { Secret(name: String(describing: $0)) }
|
||||
self.secrets.append(contentsOf: new)
|
||||
}
|
||||
|
||||
func sign(data: Data, with secret: Preview.Secret, for provenance: SigningRequestProvenance) throws -> Data {
|
||||
return data
|
||||
}
|
||||
|
||||
func verify(signature data: Data, for signature: Data, with secret: Preview.Secret) throws -> Bool {
|
||||
true
|
||||
}
|
||||
|
||||
func existingPersistedAuthenticationContext(secret: Preview.Secret) -> PersistedAuthenticationContext? {
|
||||
nil
|
||||
}
|
||||
|
||||
func persistAuthentication(secret: Preview.Secret, forDuration duration: TimeInterval) throws {
|
||||
}
|
||||
|
||||
func reloadSecrets() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class StoreModifiable: Store, SecretStoreModifiable {
|
||||
override var name: String { "Modifiable Preview Store" }
|
||||
|
||||
func create(name: String, requiresAuthentication: Bool) throws {
|
||||
}
|
||||
|
||||
func delete(secret: Preview.Secret) throws {
|
||||
}
|
||||
|
||||
func update(secret: Preview.Secret, name: String) throws {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Preview {
|
||||
|
||||
static func storeList(stores: [Store] = [], modifiableStores: [StoreModifiable] = []) -> SecretStoreList {
|
||||
let list = SecretStoreList()
|
||||
for store in stores {
|
||||
list.add(store: store)
|
||||
}
|
||||
for storeModifiable in modifiableStores {
|
||||
list.add(store: storeModifiable)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
}
|
||||
//extension Preview {
|
||||
//
|
||||
// class Store: SecretStore, ObservableObject {
|
||||
//
|
||||
// let isAvailable = true
|
||||
// let id = UUID()
|
||||
// var name: String { "Preview Store" }
|
||||
// @Published var secrets: [Secret] = []
|
||||
//
|
||||
// init(secrets: [Secret]) {
|
||||
// self.secrets.append(contentsOf: secrets)
|
||||
// }
|
||||
//
|
||||
// init(numberOfRandomSecrets: Int = 5) {
|
||||
// let new = (0..<numberOfRandomSecrets).map { Secret(name: String(describing: $0)) }
|
||||
// self.secrets.append(contentsOf: new)
|
||||
// }
|
||||
//
|
||||
// func sign(data: Data, with secret: Preview.Secret, for provenance: SigningRequestProvenance) throws -> Data {
|
||||
// return data
|
||||
// }
|
||||
//
|
||||
// func verify(signature data: Data, for signature: Data, with secret: Preview.Secret) throws -> Bool {
|
||||
// true
|
||||
// }
|
||||
//
|
||||
// func existingPersistedAuthenticationContext(secret: Preview.Secret) -> PersistedAuthenticationContext? {
|
||||
// nil
|
||||
// }
|
||||
//
|
||||
// func persistAuthentication(secret: Preview.Secret, forDuration duration: TimeInterval) throws {
|
||||
// }
|
||||
//
|
||||
// func reloadSecrets() {
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// class StoreModifiable: Store, SecretStoreModifiable {
|
||||
// override var name: String { "Modifiable Preview Store" }
|
||||
//
|
||||
// func create(name: String, requiresAuthentication: Bool) throws {
|
||||
// }
|
||||
//
|
||||
// func delete(secret: Preview.Secret) throws {
|
||||
// }
|
||||
//
|
||||
// func update(secret: Preview.Secret, name: String) throws {
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//extension Preview {
|
||||
//
|
||||
// static func storeList(stores: [Store] = [], modifiableStores: [StoreModifiable] = []) -> SecretStoreList {
|
||||
// let list = SecretStoreList()
|
||||
// for store in stores {
|
||||
// list.add(store: store)
|
||||
// }
|
||||
// for storeModifiable in modifiableStores {
|
||||
// list.add(store: storeModifiable)
|
||||
// }
|
||||
// return list
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -193,41 +193,41 @@ extension ContentView {
|
||||
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
|
||||
struct ContentView_Previews: PreviewProvider {
|
||||
|
||||
private static let storeList: SecretStoreList = {
|
||||
let list = SecretStoreList()
|
||||
list.add(store: SecureEnclave.Store())
|
||||
list.add(store: SmartCard.Store())
|
||||
return list
|
||||
}()
|
||||
private static let agentStatusChecker = AgentStatusChecker()
|
||||
private static let justUpdatedChecker = JustUpdatedChecker()
|
||||
|
||||
@State var hasRunSetup = false
|
||||
@State private var showingSetup = false
|
||||
@State private var showingCreation = false
|
||||
|
||||
static var previews: some View {
|
||||
Group {
|
||||
// Empty on modifiable and nonmodifiable
|
||||
ContentView<PreviewUpdater, AgentStatusChecker>(showingCreation: .constant(false), runningSetup: .constant(false), hasRunSetup: .constant(true))
|
||||
.environmentObject(Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]))
|
||||
.environmentObject(PreviewUpdater())
|
||||
.environmentObject(agentStatusChecker)
|
||||
|
||||
// 5 items on modifiable and nonmodifiable
|
||||
ContentView<PreviewUpdater, AgentStatusChecker>(showingCreation: .constant(false), runningSetup: .constant(false), hasRunSetup: .constant(true))
|
||||
.environmentObject(Preview.storeList(stores: [Preview.Store()], modifiableStores: [Preview.StoreModifiable()]))
|
||||
.environmentObject(PreviewUpdater())
|
||||
.environmentObject(agentStatusChecker)
|
||||
}
|
||||
.environmentObject(agentStatusChecker)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
//#if DEBUG
|
||||
//
|
||||
//struct ContentView_Previews: PreviewProvider {
|
||||
//
|
||||
// private static let storeList: SecretStoreList = {
|
||||
// let list = SecretStoreList()
|
||||
// list.add(store: SecureEnclave.Store())
|
||||
// list.add(store: SmartCard.Store())
|
||||
// return list
|
||||
// }()
|
||||
// private static let agentStatusChecker = AgentStatusChecker()
|
||||
// private static let justUpdatedChecker = JustUpdatedChecker()
|
||||
//
|
||||
// @State var hasRunSetup = false
|
||||
// @State private var showingSetup = false
|
||||
// @State private var showingCreation = false
|
||||
//
|
||||
// static var previews: some View {
|
||||
// Group {
|
||||
// // Empty on modifiable and nonmodifiable
|
||||
// ContentView<PreviewUpdater, AgentStatusChecker>(showingCreation: .constant(false), runningSetup: .constant(false), hasRunSetup: .constant(true))
|
||||
// .environmentObject(Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]))
|
||||
// .environmentObject(PreviewUpdater())
|
||||
// .environmentObject(agentStatusChecker)
|
||||
//
|
||||
// // 5 items on modifiable and nonmodifiable
|
||||
// ContentView<PreviewUpdater, AgentStatusChecker>(showingCreation: .constant(false), runningSetup: .constant(false), hasRunSetup: .constant(true))
|
||||
// .environmentObject(Preview.storeList(stores: [Preview.Store()], modifiableStores: [Preview.StoreModifiable()]))
|
||||
// .environmentObject(PreviewUpdater())
|
||||
// .environmentObject(agentStatusChecker)
|
||||
// }
|
||||
// .environmentObject(agentStatusChecker)
|
||||
//
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//#endif
|
||||
|
||||
|
||||
@@ -45,9 +45,10 @@ struct CreateSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
}
|
||||
|
||||
func save() {
|
||||
// FIXME: THIS
|
||||
// try! store.create(name: name, requiresAuthentication: requiresAuthentication)
|
||||
showing = false
|
||||
Task {
|
||||
try! await store.create(name: name, requiresAuthentication: requiresAuthentication)
|
||||
showing = false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -231,19 +232,19 @@ struct NotificationView: View {
|
||||
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
|
||||
struct CreateSecretView_Previews: PreviewProvider {
|
||||
|
||||
static var previews: some View {
|
||||
Group {
|
||||
CreateSecretView(store: Preview.StoreModifiable(), showing: .constant(true))
|
||||
AuthenticationView().environment(\.colorScheme, .dark)
|
||||
AuthenticationView().environment(\.colorScheme, .light)
|
||||
NotificationView().environment(\.colorScheme, .dark)
|
||||
NotificationView().environment(\.colorScheme, .light)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
//#if DEBUG
|
||||
//
|
||||
//struct CreateSecretView_Previews: PreviewProvider {
|
||||
//
|
||||
// static var previews: some View {
|
||||
// Group {
|
||||
// CreateSecretView(store: Preview.StoreModifiable(), showing: .constant(true))
|
||||
// AuthenticationView().environment(\.colorScheme, .dark)
|
||||
// AuthenticationView().environment(\.colorScheme, .light)
|
||||
// NotificationView().environment(\.colorScheme, .dark)
|
||||
// NotificationView().environment(\.colorScheme, .light)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//#endif
|
||||
|
||||
@@ -49,9 +49,10 @@ struct DeleteSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
}
|
||||
|
||||
func delete() {
|
||||
// FIXME: THIS
|
||||
// try! store.delete(secret: secret)
|
||||
dismissalBlock(true)
|
||||
Task {
|
||||
try! await store.delete(secret: secret)
|
||||
dismissalBlock(true)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,8 +44,9 @@ struct RenameSecretView<StoreType: SecretStoreModifiable>: View {
|
||||
}
|
||||
|
||||
func rename() {
|
||||
// FIXME: THIS
|
||||
// try? await store.update(secret: secret, name: newName)
|
||||
dismissalBlock(true)
|
||||
Task {
|
||||
try? await store.update(secret: secret, name: newName)
|
||||
dismissalBlock(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,12 +47,12 @@ struct SecretDetailView<SecretType: Secret>: View {
|
||||
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
|
||||
struct SecretDetailView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
SecretDetailView(secret: Preview.Store(numberOfRandomSecrets: 1).secrets[0])
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
//#if DEBUG
|
||||
//
|
||||
//struct SecretDetailView_Previews: PreviewProvider {
|
||||
// static var previews: some View {
|
||||
// SecretDetailView(secret: Preview.Store(numberOfRandomSecrets: 1).secrets[0])
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//#endif
|
||||
|
||||
Reference in New Issue
Block a user