2020-03-15 21:36:07 +00:00
|
|
|
import Foundation
|
|
|
|
import Combine
|
|
|
|
import AppKit
|
2021-01-19 04:08:52 +00:00
|
|
|
import SecretKit
|
2020-03-15 21:36:07 +00:00
|
|
|
|
|
|
|
protocol AgentStatusCheckerProtocol: ObservableObject {
|
|
|
|
var running: Bool { get }
|
2021-12-31 22:59:12 +00:00
|
|
|
var developmentBuild: Bool { get }
|
2020-03-15 21:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol {
|
|
|
|
|
|
|
|
@Published var running: Bool = false
|
|
|
|
|
|
|
|
init() {
|
|
|
|
check()
|
|
|
|
}
|
|
|
|
|
|
|
|
func check() {
|
2020-11-12 01:00:15 +00:00
|
|
|
running = instanceSecretAgentProcess != nil
|
2020-03-15 21:36:07 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 01:00:15 +00:00
|
|
|
// All processes, including ones from older versions, etc
|
|
|
|
var secretAgentProcesses: [NSRunningApplication] {
|
2021-01-19 04:08:52 +00:00
|
|
|
NSRunningApplication.runningApplications(withBundleIdentifier: Bundle.main.agentBundleID)
|
2020-11-12 01:00:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The process corresponding to this instance of Secretive
|
|
|
|
var instanceSecretAgentProcess: NSRunningApplication? {
|
|
|
|
let agents = secretAgentProcesses
|
|
|
|
for agent in agents {
|
|
|
|
guard let url = agent.bundleURL else { continue }
|
2022-01-03 06:52:53 +00:00
|
|
|
if url.absoluteString.contains(Bundle.main.bundleURL.absoluteString) {
|
2020-11-12 01:00:15 +00:00
|
|
|
return agent
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2020-03-15 21:36:07 +00:00
|
|
|
}
|
|
|
|
|
2022-01-03 06:52:53 +00:00
|
|
|
// All processes, _NOT_ including one the instance agent.
|
|
|
|
var noninstanceSecretAgentProcesses: [NSRunningApplication] {
|
|
|
|
NSRunningApplication.runningApplications(withBundleIdentifier: Bundle.main.agentBundleID)
|
|
|
|
.filter({ !($0.bundleURL?.absoluteString.contains(Bundle.main.bundleURL.absoluteString) ?? false) })
|
|
|
|
}
|
2021-12-31 22:59:12 +00:00
|
|
|
|
|
|
|
// Whether Secretive is being run in an Xcode environment.
|
|
|
|
var developmentBuild: Bool {
|
|
|
|
Bundle.main.bundleURL.absoluteString.contains("/Library/Developer/Xcode")
|
|
|
|
}
|
|
|
|
|
2020-03-15 21:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|