mirror of
https://github.com/maxgoedjen/secretive.git
synced 2025-04-18 05:22:11 +00:00
Protocolized
This commit is contained in:
parent
979e5b3e3c
commit
5a75e5440f
@ -13,7 +13,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
list.add(store: SmartCard.Store())
|
list.add(store: SmartCard.Store())
|
||||||
return list
|
return list
|
||||||
}()
|
}()
|
||||||
let updater = Updater()
|
let updater = PreviewUpdater()
|
||||||
|
|
||||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
import SecretKit
|
import SecretKit
|
||||||
|
|
||||||
struct ContentView: View {
|
struct ContentView<UpdaterType: UpdaterProtocol>: View {
|
||||||
|
|
||||||
@ObservedObject var storeList: SecretStoreList
|
@ObservedObject var storeList: SecretStoreList
|
||||||
@ObservedObject var updater: Updater
|
@ObservedObject var updater: UpdaterType
|
||||||
|
|
||||||
@State fileprivate var active: AnySecret.ID?
|
@State fileprivate var active: AnySecret.ID?
|
||||||
@State fileprivate var showingDeletion = false
|
@State fileprivate var showingDeletion = false
|
||||||
@ -92,26 +92,25 @@ struct ContentView: View {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ContentView {
|
fileprivate enum Constants {
|
||||||
|
static let emptyStoreModifiableTag: AnyHashable = "emptyStoreModifiableTag"
|
||||||
enum Constants {
|
static let emptyStoreTag: AnyHashable = "emptyStoreModifiableTag"
|
||||||
static let emptyStoreModifiableTag: AnyHashable = "emptyStoreModifiableTag"
|
|
||||||
static let emptyStoreTag: AnyHashable = "emptyStoreModifiableTag"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//#if DEBUG
|
|
||||||
//
|
#if DEBUG
|
||||||
//struct ContentView_Previews: PreviewProvider {
|
|
||||||
// static var previews: some View {
|
struct ContentView_Previews: PreviewProvider {
|
||||||
// Group {
|
static var previews: some View {
|
||||||
// ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]), updater: PreviewUpdater())
|
Group {
|
||||||
// ContentView(storeList: Preview.storeList(stores: [Preview.Store()], modifiableStores: [Preview.StoreModifiable()]), updater: PreviewUpdater())
|
ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]), updater: PreviewUpdater())
|
||||||
// ContentView(storeList: Preview.storeList(stores: [Preview.Store()]), updater: PreviewUpdater())
|
ContentView(storeList: Preview.storeList(stores: [Preview.Store()], modifiableStores: [Preview.StoreModifiable()]), updater: PreviewUpdater())
|
||||||
// ContentView(storeList: Preview.storeList(modifiableStores: [Preview.StoreModifiable()]), updater: PreviewUpdater())
|
ContentView(storeList: Preview.storeList(stores: [Preview.Store()]), updater: PreviewUpdater())
|
||||||
// }
|
ContentView(storeList: Preview.storeList(modifiableStores: [Preview.StoreModifiable()]), updater: PreviewUpdater())
|
||||||
// }
|
ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]), updater: PreviewUpdater(update: .advisory))
|
||||||
//}
|
ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]), updater: PreviewUpdater(update: .critical))
|
||||||
//
|
}
|
||||||
//#endif
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -1,6 +1,27 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
class PreviewUpdater: ObservableObject, UpdaterProtocol {
|
class PreviewUpdater: UpdaterProtocol {
|
||||||
var update: Release? = nil
|
|
||||||
|
let update: Release?
|
||||||
|
|
||||||
|
init(update: Update = .none) {
|
||||||
|
switch update {
|
||||||
|
case .none:
|
||||||
|
self.update = nil
|
||||||
|
case .advisory:
|
||||||
|
self.update = Release(name: "10.10.10", html_url: URL(string: "https://example.com")!, body: "Some regular update")
|
||||||
|
case .critical:
|
||||||
|
self.update = Release(name: "10.10.10", html_url: URL(string: "https://example.com")!, body: "Critical Security Update")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
extension PreviewUpdater {
|
||||||
|
|
||||||
|
enum Update {
|
||||||
|
case none, advisory, critical
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,9 @@ import Foundation
|
|||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
protocol UpdaterProtocol: ObservableObject {
|
protocol UpdaterProtocol: ObservableObject {
|
||||||
|
|
||||||
var update: Release? { get }
|
var update: Release? { get }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Updater: ObservableObject, UpdaterProtocol {
|
class Updater: ObservableObject, UpdaterProtocol {
|
||||||
@ -10,9 +12,11 @@ class Updater: ObservableObject, UpdaterProtocol {
|
|||||||
@Published var update: Release?
|
@Published var update: Release?
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
DispatchQueue.global().asyncAfter(deadline: .now() + 3) {
|
checkForUpdates()
|
||||||
|
let timer = Timer.scheduledTimer(withTimeInterval: 60*60*24, repeats: true) { _ in
|
||||||
self.checkForUpdates()
|
self.checkForUpdates()
|
||||||
}
|
}
|
||||||
|
timer.tolerance = 60*60
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkForUpdates() {
|
func checkForUpdates() {
|
||||||
@ -49,16 +53,15 @@ class Updater: ObservableObject, UpdaterProtocol {
|
|||||||
extension Updater {
|
extension Updater {
|
||||||
|
|
||||||
enum Constants {
|
enum Constants {
|
||||||
static let updateURL = URL(string: "https://api.github.com/repos/rails/rails/releases/latest")!
|
static let updateURL = URL(string: "https://api.github.com/repos/maxgoedjen/secretive/releases/latest")!
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct Release: Codable {
|
struct Release: Codable {
|
||||||
let name: String
|
let name: String
|
||||||
let html_url: URL
|
let html_url: URL
|
||||||
fileprivate let body: String
|
let body: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user