From 320dd49ce025f002fe10fcf05a26bd03e2afda9a Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Wed, 11 Nov 2020 16:16:44 -0800 Subject: [PATCH] Better processing. --- .../Controllers/AgentStatusChecker.swift | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Secretive/Controllers/AgentStatusChecker.swift b/Secretive/Controllers/AgentStatusChecker.swift index 02b7f84..d09cd32 100644 --- a/Secretive/Controllers/AgentStatusChecker.swift +++ b/Secretive/Controllers/AgentStatusChecker.swift @@ -15,11 +15,24 @@ class AgentStatusChecker: ObservableObject, AgentStatusCheckerProtocol { } func check() { - running = secretAgentProcess != nil + running = instanceSecretAgentProcess != nil } - var secretAgentProcess: NSRunningApplication? { - NSRunningApplication.runningApplications(withBundleIdentifier: Constants.secretAgentAppID).first + // All processes, including ones from older versions, etc + var secretAgentProcesses: [NSRunningApplication] { + NSRunningApplication.runningApplications(withBundleIdentifier: Constants.secretAgentAppID) + } + + // 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 } + if url.absoluteString.hasPrefix(Bundle.main.bundleURL.absoluteString) { + return agent + } + } + return nil } }