|
1 | 1 | package betaflight.app; |
2 | 2 |
|
| 3 | +import android.content.Intent; |
| 4 | +import android.hardware.usb.UsbManager; |
3 | 5 | import android.os.Bundle; |
4 | 6 |
|
5 | 7 | import betaflight.app.protocols.serial.BetaflightSerialPlugin; |
6 | 8 | import com.getcapacitor.BridgeActivity; |
7 | 9 | import betaflight.app.protocols.tcp.BetaflightTcpPlugin; |
8 | 10 | import betaflight.app.protocols.ble.BetaflightBlePlugin; |
| 11 | +import betaflight.app.protocols.dfu.BetaflightDfuPlugin; |
9 | 12 |
|
10 | 13 | public class MainActivity extends BridgeActivity { |
11 | 14 | @Override |
12 | 15 | public void onCreate(Bundle savedInstanceState) { |
13 | 16 | registerPlugin(BetaflightSerialPlugin.class); |
14 | 17 | registerPlugin(BetaflightBlePlugin.class); |
15 | 18 | registerPlugin(BetaflightTcpPlugin.class); |
| 19 | + registerPlugin(BetaflightDfuPlugin.class); |
| 20 | + |
| 21 | + // If started or recreated by a USB device attachment intent (e.g. the FC |
| 22 | + // re-enumerates after DFU flash), replace it with a plain launcher intent |
| 23 | + // BEFORE super.onCreate → BridgeActivity.load() processes it. |
| 24 | + // USB events are already handled by plugin BroadcastReceivers; without this |
| 25 | + // guard, Capacitor recreates the WebView and the app appears to restart. |
| 26 | + if (getIntent() != null |
| 27 | + && UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(getIntent().getAction())) { |
| 28 | + setIntent(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)); |
| 29 | + } |
| 30 | + |
16 | 31 | super.onCreate(savedInstanceState); |
17 | 32 | } |
| 33 | + |
| 34 | + @Override |
| 35 | + protected void onNewIntent(Intent intent) { |
| 36 | + if (intent != null |
| 37 | + && UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(intent.getAction())) { |
| 38 | + setIntent(intent); |
| 39 | + return; |
| 40 | + } |
| 41 | + super.onNewIntent(intent); |
| 42 | + } |
18 | 43 | } |
0 commit comments