forked from bitgapp/eqMac
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEQMClients.swift
More file actions
73 lines (60 loc) · 1.57 KB
/
Copy pathEQMClients.swift
File metadata and controls
73 lines (60 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// EQMClients.swift
// eqMac
//
// Created by Nodeful on 29/08/2021.
// Copyright © 2021 Bitgapp. All rights reserved.
//
import Foundation
import CoreAudio.AudioServerPlugIn
import Shared
class EQMClients {
private static let mutex = Mutex()
static var clients: [UInt32: EQMClient] = [:]
static func add (_ client: EQMClient) {
mutex.lock()
clients[client.clientId] = client
mutex.unlock()
}
static func remove (_ client: EQMClient) {
mutex.lock()
clients.removeValue(forKey: client.clientId)
mutex.unlock()
}
static func get (clientId: UInt32) -> EQMClient? {
mutex.lock()
let client = clients[clientId]
mutex.unlock()
return client
}
static func get (processId: pid_t) -> EQMClient? {
mutex.lock()
let client = clients.values.first { $0.processId == processId }
mutex.unlock()
return client
}
static func get (bundleId: String) -> [EQMClient] {
mutex.lock()
let matchingClients = clients.values.filter { client in
return client.bundleId == bundleId
}
mutex.unlock()
return matchingClients
}
static func get (client: EQMClient) -> EQMClient? {
if let byClient = get(clientId: client.clientId) {
return byClient
}
if let byProcessId = get(processId: client.processId) {
return byProcessId
}
if let bundleId = client.bundleId {
let bundles = get(bundleId: bundleId)
return bundles[0]
}
return nil
}
static var isAppClientPresent: Bool {
return Array(clients.values).contains { $0.bundleId == APP_BUNDLE_ID }
}
}