mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-03-28 15:41:03 +03:00
Address code review feedback: fix memory lifecycle and improve error message
- Move capture session lifecycle to main thread - Add strong capture of captureSession in asyncAfter block to prevent premature deallocation - Improve error message to inform user about potential impact and suggested action Co-authored-by: rustdesk <71636191+rustdesk@users.noreply.github.com>
This commit is contained in:
@@ -216,23 +216,26 @@ class MainFlutterWindow: NSWindow {
|
|||||||
AVCaptureDevice.requestAccess(for: .audio, completionHandler: { granted in
|
AVCaptureDevice.requestAccess(for: .audio, completionHandler: { granted in
|
||||||
if granted {
|
if granted {
|
||||||
// Instantiate an audio capture session to trigger macOS registration
|
// Instantiate an audio capture session to trigger macOS registration
|
||||||
if let audioDevice = AVCaptureDevice.default(for: .audio) {
|
// This needs to run on main thread to ensure proper lifecycle
|
||||||
do {
|
DispatchQueue.main.async {
|
||||||
let audioInput = try AVCaptureDeviceInput(device: audioDevice)
|
if let audioDevice = AVCaptureDevice.default(for: .audio) {
|
||||||
let captureSession = AVCaptureSession()
|
do {
|
||||||
captureSession.beginConfiguration()
|
let audioInput = try AVCaptureDeviceInput(device: audioDevice)
|
||||||
if captureSession.canAddInput(audioInput) {
|
let captureSession = AVCaptureSession()
|
||||||
captureSession.addInput(audioInput)
|
captureSession.beginConfiguration()
|
||||||
|
if captureSession.canAddInput(audioInput) {
|
||||||
|
captureSession.addInput(audioInput)
|
||||||
|
}
|
||||||
|
captureSession.commitConfiguration()
|
||||||
|
// Start and immediately stop the session to trigger registration
|
||||||
|
captureSession.startRunning()
|
||||||
|
// Keep a strong reference and stop after a brief moment
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [captureSession] in
|
||||||
|
captureSession.stopRunning()
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
NSLog("[RustDesk] Error creating audio capture session for permission registration: %@. The app may not appear in System Settings > Privacy & Security > Microphone. Please verify permissions manually.", error.localizedDescription)
|
||||||
}
|
}
|
||||||
captureSession.commitConfiguration()
|
|
||||||
// Start and immediately stop the session to trigger registration
|
|
||||||
captureSession.startRunning()
|
|
||||||
// Stop after a brief moment to ensure registration is complete
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
|
||||||
captureSession.stopRunning()
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
NSLog("[RustDesk] Error creating audio capture session for permission registration: %@", error.localizedDescription)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user