Skip to content

Commit 2d0e300

Browse files
committed
fixes
1 parent f8130fb commit 2d0e300

File tree

12 files changed

+49
-41
lines changed

12 files changed

+49
-41
lines changed

‎Telegram-Mac.xcworkspace/contents.xcworkspacedata

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Telegram-Mac/DevicesContext.swift

+44-36
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@ final class DevicesContext : NSObject {
7474

7575
private let updaterContext: UpdaterContext = UpdaterContext()
7676

77-
private(set) var currentCameraId: String? = nil
78-
private(set) var currentMicroId: String? = nil
79-
private(set) var currentOutputId: String? = nil
80-
77+
8178

8279
func updater() -> Signal<(camera: String?, input: String?, output: String?), NoError> {
8380
return Signal { subscriber in
@@ -103,6 +100,21 @@ final class DevicesContext : NSObject {
103100

104101

105102
private let disposable = MetaDisposable()
103+
private let devicesQueue = Queue(name: "devicesQueue")
104+
105+
private let _currentCameraId: Atomic<String?> = Atomic(value: nil)
106+
private let _currentMicroId: Atomic<String?> = Atomic(value: nil)
107+
private let _currentOutputId: Atomic<String?> = Atomic(value: nil)
108+
109+
var currentCameraId: String? {
110+
return _currentCameraId.with { $0 }
111+
}
112+
var currentMicroId: String? {
113+
return _currentMicroId.with { $0 }
114+
}
115+
var currentOutputId: String? {
116+
return _currentOutputId.with { $0 }
117+
}
106118

107119
init(_ accountManager: AccountManager ) {
108120
super.init()
@@ -119,24 +131,32 @@ final class DevicesContext : NSObject {
119131
self?.update()
120132
})
121133

122-
disposable.set(combineLatest(queue: .mainQueue(), voiceCallSettings(accountManager), signal).start(next: { [weak self] settings, devices in
123-
guard let `self` = self else {
124-
return
125-
}
126-
let inputUpdated = self.updateMicroId(settings, devices: devices)
127-
let cameraUpdated = self.updateCameraId(settings, devices: devices)
128-
let outputUpdated = self.updateOutputId(settings, devices: devices)
134+
let currentCameraId = self._currentCameraId
135+
let currentMicroId = self._currentMicroId
136+
let currentOutputId = self._currentOutputId
137+
138+
let updated = combineLatest(queue: devicesQueue, voiceCallSettings(accountManager), signal) |> map { settings, devices -> (camera: String?, input: String?, output: String?) in
139+
let inputUpdated = DevicesContext.updateMicroId(settings, devices: devices)
140+
let cameraUpdated = DevicesContext.updateCameraId(settings, devices: devices)
141+
let outputUpdated = DevicesContext.updateOutputId(settings, devices: devices)
129142

130143
var result:(camera: String?, input: String?, output: String?) = (camera: nil, input: nil, output: nil)
131144

132-
if inputUpdated {
133-
result.input = self.currentMicroId ?? ""
145+
if currentMicroId.swap(inputUpdated) != inputUpdated {
146+
result.input = inputUpdated
134147
}
135-
if cameraUpdated {
136-
result.camera = self.currentCameraId ?? ""
148+
if currentCameraId.swap(cameraUpdated) != cameraUpdated {
149+
result.camera = cameraUpdated
137150
}
138-
if outputUpdated {
139-
result.output = self.currentOutputId ?? ""
151+
if currentOutputId.swap(outputUpdated) != outputUpdated {
152+
result.output = outputUpdated
153+
}
154+
return result
155+
} |> deliverOnMainQueue
156+
157+
disposable.set(updated.start(next: { [weak self] result in
158+
guard let `self` = self else {
159+
return
140160
}
141161
self.updaterContext.status = result
142162

@@ -156,7 +176,7 @@ final class DevicesContext : NSObject {
156176
self.update()
157177
}
158178

159-
@discardableResult func updateCameraId(_ settings: VoiceCallSettings, devices: IODevices) -> Bool {
179+
static func updateCameraId(_ settings: VoiceCallSettings, devices: IODevices) -> String? {
160180
let cameraDevice = devices.camera.first(where: { $0.uniqueID == settings.cameraInputDeviceId })
161181

162182
let activeDevice: AVCaptureDevice?
@@ -172,13 +192,9 @@ final class DevicesContext : NSObject {
172192
activeDevice = devices.camera.first(where: { $0.isConnected && !$0.isSuspended })
173193
}
174194

175-
defer {
176-
self.currentCameraId = activeDevice?.uniqueID
177-
}
178-
179-
return self.currentCameraId != activeDevice?.uniqueID
195+
return activeDevice?.uniqueID
180196
}
181-
@discardableResult func updateMicroId(_ settings: VoiceCallSettings, devices: IODevices) -> Bool {
197+
static func updateMicroId(_ settings: VoiceCallSettings, devices: IODevices) -> String? {
182198
let audiodevice = devices.audioInput.first(where: { $0.uniqueID == settings.audioInputDeviceId })
183199

184200
let activeDevice: AVCaptureDevice?
@@ -194,15 +210,11 @@ final class DevicesContext : NSObject {
194210
activeDevice = devices.audioInput.first(where: { $0.isConnected && !$0.isSuspended })
195211
}
196212

197-
defer {
198-
self.currentMicroId = activeDevice?.uniqueID
199-
}
200-
201-
return self.currentMicroId != activeDevice?.uniqueID
213+
return activeDevice?.uniqueID
202214
}
203215

204-
@discardableResult func updateOutputId(_ settings: VoiceCallSettings, devices: IODevices) -> Bool {
205-
var deviceUid: String = ""
216+
static func updateOutputId(_ settings: VoiceCallSettings, devices: IODevices) -> String? {
217+
var deviceUid: String? = nil
206218
var found = false
207219
for id in devices.audioOutput {
208220
let current = Audio.getDeviceUid(deviceId: id)
@@ -215,11 +227,7 @@ final class DevicesContext : NSObject {
215227
deviceUid = Audio.getDeviceUid(deviceId: Audio.getDefaultOutputDevice())
216228
}
217229

218-
defer {
219-
self.currentOutputId = deviceUid as String
220-
}
221-
222-
return self.currentOutputId != deviceUid as String
230+
return deviceUid
223231
}
224232

225233
deinit {

‎Telegram-Mac/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</dict>
3737
</array>
3838
<key>CFBundleVersion</key>
39-
<string>210125</string>
39+
<string>210126</string>
4040
<key>LSApplicationCategoryType</key>
4141
<string>public.app-category.social-networking</string>
4242
<key>LSFileQuarantineEnabled</key>

‎Telegram.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
27200F1B257C256E00574365 /* DevicesContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27200F1A257C256E00574365 /* DevicesContext.swift */; };
11-
27200F1D257C407F00574365 /* HotKey.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 273F9C0A257BC486004EC51B /* HotKey.framework */; };
11+
27200F21257CCFDB00574365 /* HotKey.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 273F9C0A257BC486004EC51B /* HotKey.framework */; };
1212
27A9904A257A7435009044DB /* SoundEffectPlayQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27A99049257A7435009044DB /* SoundEffectPlayQueue.swift */; };
1313
27A9904E257A8047009044DB /* Pop.wav in Resources */ = {isa = PBXBuildFile; fileRef = 27A9904C257A8044009044DB /* Pop.wav */; };
1414
27A9904F257A8047009044DB /* Purr.wav in Resources */ = {isa = PBXBuildFile; fileRef = 27A9904D257A8046009044DB /* Purr.wav */; };
@@ -1958,7 +1958,7 @@
19581958
isa = PBXFrameworksBuildPhase;
19591959
buildActionMask = 2147483647;
19601960
files = (
1961-
27200F1D257C407F00574365 /* HotKey.framework in Frameworks */,
1961+
27200F21257CCFDB00574365 /* HotKey.framework in Frameworks */,
19621962
D00746EE2577A6BE0000DF74 /* Carbon.framework in Frameworks */,
19631963
D0E7BD6C256AA5570068644D /* TelegramVoip.framework in Frameworks */,
19641964
C22E06261D7F16C000A11C88 /* TGUIKit.framework in Frameworks */,

‎TelegramShare/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<key>CFBundleShortVersionString</key>
2222
<string>7.2.4</string>
2323
<key>CFBundleVersion</key>
24-
<string>210125</string>
24+
<string>210126</string>
2525
<key>LSMinimumSystemVersion</key>
2626
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
2727
<key>NSExtension</key>

0 commit comments

Comments
 (0)