mirror of
https://github.com/maxgoedjen/secretive.git
synced 2024-11-22 05:27:28 +00:00
Add notice if agent isn't running (#47)
* Add agent checker * Check on foreground
This commit is contained in:
parent
bde9085d31
commit
9daae8957a
@ -33,6 +33,8 @@
|
|||||||
50731666241DF8660023809E /* Updater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50731665241DF8660023809E /* Updater.swift */; };
|
50731666241DF8660023809E /* Updater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50731665241DF8660023809E /* Updater.swift */; };
|
||||||
50731669241E00C20023809E /* NoticeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50731668241E00C20023809E /* NoticeView.swift */; };
|
50731669241E00C20023809E /* NoticeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50731668241E00C20023809E /* NoticeView.swift */; };
|
||||||
508A58AA241E06B40069DC07 /* PreviewUpdater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508A58A9241E06B40069DC07 /* PreviewUpdater.swift */; };
|
508A58AA241E06B40069DC07 /* PreviewUpdater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508A58A9241E06B40069DC07 /* PreviewUpdater.swift */; };
|
||||||
|
508A58B3241ED2180069DC07 /* AgentStatusChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508A58B2241ED2180069DC07 /* AgentStatusChecker.swift */; };
|
||||||
|
508A58B5241ED48F0069DC07 /* PreviewAgentStatusChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508A58B4241ED48F0069DC07 /* PreviewAgentStatusChecker.swift */; };
|
||||||
5099A02423FD2AAA0062B6F2 /* CreateSecretView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5099A02323FD2AAA0062B6F2 /* CreateSecretView.swift */; };
|
5099A02423FD2AAA0062B6F2 /* CreateSecretView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5099A02323FD2AAA0062B6F2 /* CreateSecretView.swift */; };
|
||||||
5099A02723FE34FA0062B6F2 /* SmartCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5099A02623FE34FA0062B6F2 /* SmartCard.swift */; };
|
5099A02723FE34FA0062B6F2 /* SmartCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5099A02623FE34FA0062B6F2 /* SmartCard.swift */; };
|
||||||
5099A02923FE35240062B6F2 /* SmartCardStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5099A02823FE35240062B6F2 /* SmartCardStore.swift */; };
|
5099A02923FE35240062B6F2 /* SmartCardStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5099A02823FE35240062B6F2 /* SmartCardStore.swift */; };
|
||||||
@ -186,6 +188,8 @@
|
|||||||
50731668241E00C20023809E /* NoticeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoticeView.swift; sourceTree = "<group>"; };
|
50731668241E00C20023809E /* NoticeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoticeView.swift; sourceTree = "<group>"; };
|
||||||
508A58A9241E06B40069DC07 /* PreviewUpdater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewUpdater.swift; sourceTree = "<group>"; };
|
508A58A9241E06B40069DC07 /* PreviewUpdater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewUpdater.swift; sourceTree = "<group>"; };
|
||||||
508A58AB241E121B0069DC07 /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
|
508A58AB241E121B0069DC07 /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
|
||||||
|
508A58B2241ED2180069DC07 /* AgentStatusChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgentStatusChecker.swift; sourceTree = "<group>"; };
|
||||||
|
508A58B4241ED48F0069DC07 /* PreviewAgentStatusChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewAgentStatusChecker.swift; sourceTree = "<group>"; };
|
||||||
5099A02323FD2AAA0062B6F2 /* CreateSecretView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateSecretView.swift; sourceTree = "<group>"; };
|
5099A02323FD2AAA0062B6F2 /* CreateSecretView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateSecretView.swift; sourceTree = "<group>"; };
|
||||||
5099A02623FE34FA0062B6F2 /* SmartCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartCard.swift; sourceTree = "<group>"; };
|
5099A02623FE34FA0062B6F2 /* SmartCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartCard.swift; sourceTree = "<group>"; };
|
||||||
5099A02823FE35240062B6F2 /* SmartCardStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartCardStore.swift; sourceTree = "<group>"; };
|
5099A02823FE35240062B6F2 /* SmartCardStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartCardStore.swift; sourceTree = "<group>"; };
|
||||||
@ -322,6 +326,7 @@
|
|||||||
50617D8923FCE48E0099B055 /* Preview Assets.xcassets */,
|
50617D8923FCE48E0099B055 /* Preview Assets.xcassets */,
|
||||||
50617DD123FCEFA90099B055 /* PreviewStore.swift */,
|
50617DD123FCEFA90099B055 /* PreviewStore.swift */,
|
||||||
508A58A9241E06B40069DC07 /* PreviewUpdater.swift */,
|
508A58A9241E06B40069DC07 /* PreviewUpdater.swift */,
|
||||||
|
508A58B4241ED48F0069DC07 /* PreviewAgentStatusChecker.swift */,
|
||||||
);
|
);
|
||||||
path = "Preview Content";
|
path = "Preview Content";
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -412,6 +417,7 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
50731665241DF8660023809E /* Updater.swift */,
|
50731665241DF8660023809E /* Updater.swift */,
|
||||||
|
508A58B2241ED2180069DC07 /* AgentStatusChecker.swift */,
|
||||||
);
|
);
|
||||||
path = Controllers;
|
path = Controllers;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -768,6 +774,7 @@
|
|||||||
50C385A9240B636500AF2719 /* SetupView.swift in Sources */,
|
50C385A9240B636500AF2719 /* SetupView.swift in Sources */,
|
||||||
50617D8523FCE48E0099B055 /* ContentView.swift in Sources */,
|
50617D8523FCE48E0099B055 /* ContentView.swift in Sources */,
|
||||||
50617DD223FCEFA90099B055 /* PreviewStore.swift in Sources */,
|
50617DD223FCEFA90099B055 /* PreviewStore.swift in Sources */,
|
||||||
|
508A58B3241ED2180069DC07 /* AgentStatusChecker.swift in Sources */,
|
||||||
50C385A52407A76D00AF2719 /* SecretDetailView.swift in Sources */,
|
50C385A52407A76D00AF2719 /* SecretDetailView.swift in Sources */,
|
||||||
5099A02423FD2AAA0062B6F2 /* CreateSecretView.swift in Sources */,
|
5099A02423FD2AAA0062B6F2 /* CreateSecretView.swift in Sources */,
|
||||||
50731666241DF8660023809E /* Updater.swift in Sources */,
|
50731666241DF8660023809E /* Updater.swift in Sources */,
|
||||||
@ -775,6 +782,7 @@
|
|||||||
50BB046B2418AAAE00D6E079 /* EmptyStoreView.swift in Sources */,
|
50BB046B2418AAAE00D6E079 /* EmptyStoreView.swift in Sources */,
|
||||||
50731669241E00C20023809E /* NoticeView.swift in Sources */,
|
50731669241E00C20023809E /* NoticeView.swift in Sources */,
|
||||||
50617D8323FCE48E0099B055 /* AppDelegate.swift in Sources */,
|
50617D8323FCE48E0099B055 /* AppDelegate.swift in Sources */,
|
||||||
|
508A58B5241ED48F0069DC07 /* PreviewAgentStatusChecker.swift in Sources */,
|
||||||
508A58AA241E06B40069DC07 /* PreviewUpdater.swift in Sources */,
|
508A58AA241E06B40069DC07 /* PreviewUpdater.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
@ -14,10 +14,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
return list
|
return list
|
||||||
}()
|
}()
|
||||||
let updater = Updater()
|
let updater = Updater()
|
||||||
|
let agentStatusChecker = AgentStatusChecker()
|
||||||
|
|
||||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||||
|
let contentView = ContentView(storeList: storeList, updater: updater, agentStatusChecker: agentStatusChecker, runSetupBlock: { self.runSetup(sender: nil) })
|
||||||
let contentView = ContentView(storeList: storeList, updater: updater)
|
|
||||||
// Create the window and set the content view.
|
// Create the window and set the content view.
|
||||||
window = NSWindow(
|
window = NSWindow(
|
||||||
contentRect: NSRect(x: 0, y: 0, width: 480, height: 300),
|
contentRect: NSRect(x: 0, y: 0, width: 480, height: 300),
|
||||||
@ -38,6 +38,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
runSetupIfNeeded()
|
runSetupIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func applicationDidBecomeActive(_ notification: Notification) {
|
||||||
|
agentStatusChecker.check()
|
||||||
|
}
|
||||||
|
|
||||||
@IBAction func add(sender: AnyObject?) {
|
@IBAction func add(sender: AnyObject?) {
|
||||||
var addWindow: NSWindow!
|
var addWindow: NSWindow!
|
||||||
let addView = CreateSecretView(store: storeList.modifiableStore!) {
|
let addView = CreateSecretView(store: storeList.modifiableStore!) {
|
||||||
|
33
Secretive/Controllers/AgentStatusChecker.swift
Normal file
33
Secretive/Controllers/AgentStatusChecker.swift
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import Foundation
|
||||||
|
import Combine
|
||||||
|
import AppKit
|
||||||
|
|
||||||
|
protocol AgentStatusCheckerProtocol: ObservableObject {
|
||||||
|
var running: Bool { get }
|
||||||
|
}
|
||||||
|
|
||||||
|
class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol {
|
||||||
|
|
||||||
|
@Published var running: Bool = false
|
||||||
|
|
||||||
|
init() {
|
||||||
|
check()
|
||||||
|
}
|
||||||
|
|
||||||
|
func check() {
|
||||||
|
running = secretAgentProcess != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var secretAgentProcess: NSRunningApplication? {
|
||||||
|
NSRunningApplication.runningApplications(withBundleIdentifier: Constants.secretAgentAppID).first
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
extension AgentStatusChecker {
|
||||||
|
|
||||||
|
enum Constants {
|
||||||
|
static let secretAgentAppID = "com.maxgoedjen.Secretive.SecretAgent"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
12
Secretive/Preview Content/PreviewAgentStatusChecker.swift
Normal file
12
Secretive/Preview Content/PreviewAgentStatusChecker.swift
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import Foundation
|
||||||
|
import Combine
|
||||||
|
|
||||||
|
class PreviewAgentStatusChecker: AgentStatusCheckerProtocol {
|
||||||
|
|
||||||
|
let running: Bool
|
||||||
|
|
||||||
|
init(running: Bool = true) {
|
||||||
|
self.running = running
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,10 +1,12 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
import SecretKit
|
import SecretKit
|
||||||
|
|
||||||
struct ContentView<UpdaterType: UpdaterProtocol>: View {
|
struct ContentView<UpdaterType: UpdaterProtocol, AgentStatusCheckerType: AgentStatusCheckerProtocol>: View {
|
||||||
|
|
||||||
@ObservedObject var storeList: SecretStoreList
|
@ObservedObject var storeList: SecretStoreList
|
||||||
@ObservedObject var updater: UpdaterType
|
@ObservedObject var updater: UpdaterType
|
||||||
|
@ObservedObject var agentStatusChecker: AgentStatusCheckerType
|
||||||
|
var runSetupBlock: (() -> Void)?
|
||||||
|
|
||||||
@State fileprivate var active: AnySecret.ID?
|
@State fileprivate var active: AnySecret.ID?
|
||||||
@State fileprivate var showingDeletion = false
|
@State fileprivate var showingDeletion = false
|
||||||
@ -15,6 +17,9 @@ struct ContentView<UpdaterType: UpdaterProtocol>: View {
|
|||||||
if updater.update != nil {
|
if updater.update != nil {
|
||||||
updateNotice()
|
updateNotice()
|
||||||
}
|
}
|
||||||
|
if !agentStatusChecker.running {
|
||||||
|
agentNotice()
|
||||||
|
}
|
||||||
NavigationView {
|
NavigationView {
|
||||||
List(selection: $active) {
|
List(selection: $active) {
|
||||||
ForEach(storeList.stores) { store in
|
ForEach(storeList.stores) { store in
|
||||||
@ -82,6 +87,12 @@ struct ContentView<UpdaterType: UpdaterProtocol>: View {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func agentNotice() -> some View {
|
||||||
|
NoticeView(text: "Secret Agent isn't running. Run setup again to fix.", severity: .advisory, actionTitle: "Run Setup") {
|
||||||
|
self.runSetupBlock?()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func delete<SecretType: Secret>(secret: SecretType) {
|
func delete<SecretType: Secret>(secret: SecretType) {
|
||||||
deletingSecret = AnySecret(secret)
|
deletingSecret = AnySecret(secret)
|
||||||
self.showingDeletion = true
|
self.showingDeletion = true
|
||||||
@ -110,12 +121,22 @@ fileprivate enum Constants {
|
|||||||
struct ContentView_Previews: PreviewProvider {
|
struct ContentView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
Group {
|
Group {
|
||||||
ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]), updater: PreviewUpdater())
|
ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)],
|
||||||
ContentView(storeList: Preview.storeList(stores: [Preview.Store()], modifiableStores: [Preview.StoreModifiable()]), updater: PreviewUpdater())
|
modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]),
|
||||||
ContentView(storeList: Preview.storeList(stores: [Preview.Store()]), updater: PreviewUpdater())
|
updater: PreviewUpdater(),
|
||||||
ContentView(storeList: Preview.storeList(modifiableStores: [Preview.StoreModifiable()]), updater: PreviewUpdater())
|
agentStatusChecker: PreviewAgentStatusChecker())
|
||||||
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()], modifiableStores: [Preview.StoreModifiable()]), updater: PreviewUpdater(),
|
||||||
ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]), updater: PreviewUpdater(update: .critical))
|
agentStatusChecker: PreviewAgentStatusChecker())
|
||||||
|
ContentView(storeList: Preview.storeList(stores: [Preview.Store()]), updater: PreviewUpdater(),
|
||||||
|
agentStatusChecker: PreviewAgentStatusChecker())
|
||||||
|
ContentView(storeList: Preview.storeList(modifiableStores: [Preview.StoreModifiable()]), updater: PreviewUpdater(),
|
||||||
|
agentStatusChecker: PreviewAgentStatusChecker())
|
||||||
|
ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]), updater: PreviewUpdater(update: .advisory),
|
||||||
|
agentStatusChecker: PreviewAgentStatusChecker())
|
||||||
|
ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]), updater: PreviewUpdater(update: .critical),
|
||||||
|
agentStatusChecker: PreviewAgentStatusChecker())
|
||||||
|
ContentView(storeList: Preview.storeList(stores: [Preview.Store(numberOfRandomSecrets: 0)], modifiableStores: [Preview.StoreModifiable(numberOfRandomSecrets: 0)]), updater: PreviewUpdater(update: .critical),
|
||||||
|
agentStatusChecker: PreviewAgentStatusChecker(running: false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user