mirror of
				https://github.com/maxgoedjen/secretive.git
				synced 2025-11-04 09:20:56 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
import Foundation
 | 
						|
import Combine
 | 
						|
import AppKit
 | 
						|
import SecretKit
 | 
						|
import Observation
 | 
						|
 | 
						|
protocol AgentStatusCheckerProtocol: Observable {
 | 
						|
    var running: Bool { get }
 | 
						|
    var developmentBuild: Bool { get }
 | 
						|
}
 | 
						|
 | 
						|
@Observable class AgentStatusChecker: AgentStatusCheckerProtocol {
 | 
						|
 | 
						|
    var running: Bool = false
 | 
						|
 | 
						|
    init() {
 | 
						|
        check()
 | 
						|
    }
 | 
						|
 | 
						|
    func check() {
 | 
						|
        running = instanceSecretAgentProcess != nil
 | 
						|
    }
 | 
						|
 | 
						|
    // All processes, including ones from older versions, etc
 | 
						|
    var secretAgentProcesses: [NSRunningApplication] {
 | 
						|
        NSRunningApplication.runningApplications(withBundleIdentifier: Bundle.main.agentBundleID)
 | 
						|
    }
 | 
						|
 | 
						|
    // 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
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    // Whether Secretive is being run in an Xcode environment.
 | 
						|
    var developmentBuild: Bool {
 | 
						|
        Bundle.main.bundleURL.absoluteString.contains("/Library/Developer/Xcode")
 | 
						|
    }
 | 
						|
 | 
						|
}
 | 
						|
 | 
						|
 |