From 24dc7f4a3d6b9a22b2acbc6d46886d18ba4b8b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Wed, 18 Sep 2024 23:14:31 +0200 Subject: [PATCH] fruity: Fix unreliable modeswitch activation Where its Promise could be resolved more than once. --- src/fruity/device-monitor.vala | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/fruity/device-monitor.vala b/src/fruity/device-monitor.vala index aee0091a4..d478bb78e 100644 --- a/src/fruity/device-monitor.vala +++ b/src/fruity/device-monitor.vala @@ -814,7 +814,6 @@ namespace Frida.Fruity { public async void activate_modeswitch_support (Cancellable? cancellable) throws IOError { modeswitch_allowed = true; - modeswitch_activated = new Promise (); modeswitch_udids_pending = new Gee.HashSet (); foreach (var transport in usb_transports.to_array ()) { var usb_device = transport.usb_device; @@ -825,12 +824,15 @@ namespace Frida.Fruity { } } if (!modeswitch_udids_pending.is_empty) { + modeswitch_activated = new Promise (); try { yield modeswitch_activated.future.wait_async (cancellable); } catch (Error e) { assert_not_reached (); } + modeswitch_activated = null; } + modeswitch_udids_pending = null; } private void perform_usb_work () { @@ -971,9 +973,8 @@ namespace Frida.Fruity { if (AtomicUint.dec_and_test (ref pending_usb_device_arrivals) && state == STARTING) usb_started.resolve (true); - if (device != null && modeswitch_udids_pending != null) { - modeswitch_udids_pending.remove (device.udid); - if (modeswitch_udids_pending.is_empty) + if (device != null && modeswitch_udids_pending != null && modeswitch_udids_pending.remove (device.udid)) { + if (modeswitch_udids_pending.is_empty && modeswitch_activated != null) modeswitch_activated.resolve (true); } }