mirror of
https://github.com/maxgoedjen/secretive.git
synced 2024-11-26 07:27:07 +00:00
Make SettingsStore functions non-static, re-implement them as
subscripts and make settingsStore an environmentObject Fixes: https://github.com/maxgoedjen/secretive/pull/536#discussion_r1508446459
This commit is contained in:
parent
46022962b8
commit
a5a3f1cec9
@ -16,6 +16,7 @@ struct Secretive: App {
|
||||
}()
|
||||
private let agentStatusChecker = AgentStatusChecker()
|
||||
private let justUpdatedChecker = JustUpdatedChecker()
|
||||
private let settingsStore = SettingsStore()
|
||||
|
||||
@AppStorage("defaultsHasRunSetup") var hasRunSetup = false
|
||||
@State private var showingSetup = false
|
||||
@ -27,6 +28,7 @@ struct Secretive: App {
|
||||
.environmentObject(storeList)
|
||||
.environmentObject(Updater(checkOnLaunch: hasRunSetup))
|
||||
.environmentObject(agentStatusChecker)
|
||||
.environmentObject(settingsStore)
|
||||
.onAppear {
|
||||
if !hasRunSetup {
|
||||
showingSetup = true
|
||||
|
@ -8,17 +8,20 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
class SettingsStore {
|
||||
static let service = "com.maxgoedjen.Secretive"
|
||||
class SettingsStore: ObservableObject {
|
||||
let service = "com.maxgoedjen.Secretive"
|
||||
}
|
||||
|
||||
extension SettingsStore {
|
||||
static func set(key: String, value: String) -> Bool {
|
||||
let valueData = value.data(using: String.Encoding.utf8)!
|
||||
subscript(key: String) -> String? {
|
||||
set(value) {
|
||||
guard let valueData = value?.data(using: String.Encoding.utf8)! else {
|
||||
return
|
||||
}
|
||||
|
||||
if let keyVal = get(key: key) {
|
||||
if let keyVal = self[key] {
|
||||
if keyVal == value {
|
||||
return true
|
||||
return
|
||||
}
|
||||
|
||||
let updateQuery: [String: Any] = [kSecClass as String: kSecClassGenericPassword,
|
||||
@ -29,7 +32,7 @@ extension SettingsStore {
|
||||
let status = SecItemUpdate(updateQuery as CFDictionary, attributes as CFDictionary)
|
||||
guard status == errSecSuccess else {
|
||||
print("Couldn't update item in keychain. " + status.description)
|
||||
return false
|
||||
return
|
||||
}
|
||||
} else {
|
||||
let addquery: [String: Any] = [kSecClass as String: kSecClassGenericPassword,
|
||||
@ -40,13 +43,12 @@ extension SettingsStore {
|
||||
let status = SecItemAdd(addquery as CFDictionary, nil)
|
||||
guard status == errSecSuccess else {
|
||||
print("Couldn't add item to keychain. " + status.description)
|
||||
return false
|
||||
return
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
static func get(key: String) -> String? {
|
||||
get {
|
||||
let getquery: [String: Any] = [kSecClass as String: kSecClassGenericPassword,
|
||||
kSecAttrAccount as String: key,
|
||||
kSecAttrServer as String: service,
|
||||
@ -57,4 +59,5 @@ extension SettingsStore {
|
||||
|
||||
return status == errSecSuccess ? String(decoding: item as! Data, as: UTF8.self) : nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user