mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-02-18 23:41:48 +01:00
cleanup streams on exit
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:bike_control/utils/core.dart';
|
||||
import 'package:bike_control/utils/keymap/apps/custom_app.dart';
|
||||
import 'package:bike_control/utils/keymap/buttons.dart';
|
||||
import 'package:dartx/dartx.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -82,13 +81,9 @@ class ShimanoDi2 extends BluetoothDevice {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
super.showInformation(context),
|
||||
Text(
|
||||
'Make sure to set your Di2 buttons to D-Fly channels in the Shimano E-TUBE app.',
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey),
|
||||
),
|
||||
if (core.actionHandler.supportedApp is! CustomApp)
|
||||
if (!core.settings.getShowOnboarding())
|
||||
Text(
|
||||
'Use a custom keymap to support ${scanResult.name}',
|
||||
'Make sure to set your Di2 buttons to D-Fly channels in the Shimano E-TUBE app.',
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -17,13 +17,15 @@ class AndroidActions extends BaseActions {
|
||||
|
||||
final accessibilityHandler = Accessibility();
|
||||
StreamSubscription<void>? _keymapUpdateSubscription;
|
||||
StreamSubscription<WindowEvent>? _accessibilitySubscription;
|
||||
StreamSubscription<AKeyEvent>? _hidKeyPressedSubscription;
|
||||
|
||||
AndroidActions({super.supportedModes = const [SupportedMode.touch, SupportedMode.media]});
|
||||
|
||||
@override
|
||||
void init(SupportedApp? supportedApp) {
|
||||
super.init(supportedApp);
|
||||
streamEvents().listen((windowEvent) {
|
||||
_accessibilitySubscription = streamEvents().listen((windowEvent) {
|
||||
if (supportedApp != null) {
|
||||
windowInfo = windowEvent;
|
||||
}
|
||||
@@ -38,7 +40,7 @@ class AndroidActions extends BaseActions {
|
||||
updateHandledKeys();
|
||||
});
|
||||
|
||||
hidKeyPressed().listen((keyPressed) async {
|
||||
_hidKeyPressedSubscription = hidKeyPressed().listen((keyPressed) async {
|
||||
final hidDevice = HidDevice(keyPressed.source);
|
||||
final button = hidDevice.getOrAddButton(keyPressed.hidKey, () => ControllerButton(keyPressed.hidKey));
|
||||
|
||||
@@ -129,4 +131,11 @@ class AndroidActions extends BaseActions {
|
||||
|
||||
accessibilityHandler.setHandledKeys(handledKeys);
|
||||
}
|
||||
|
||||
@override
|
||||
void cleanup() {
|
||||
_accessibilitySubscription?.cancel();
|
||||
_keymapUpdateSubscription?.cancel();
|
||||
_hidKeyPressedSubscription?.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ abstract class BaseActions {
|
||||
|
||||
BaseActions({required this.supportedModes});
|
||||
|
||||
void cleanup();
|
||||
|
||||
void init(SupportedApp? supportedApp) {
|
||||
this.supportedApp = supportedApp;
|
||||
debugPrint('Supported app: ${supportedApp?.name ?? "None"}');
|
||||
@@ -183,4 +185,7 @@ class StubActions extends BaseActions {
|
||||
performedActions.add((button, isKeyDown, isKeyUp));
|
||||
return Future.value(Ignored('${button.name.splitByUpperCase()} clicked'));
|
||||
}
|
||||
|
||||
@override
|
||||
void cleanup() {}
|
||||
}
|
||||
|
||||
@@ -96,4 +96,7 @@ class DesktopActions extends BaseActions {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void cleanup() {}
|
||||
}
|
||||
|
||||
@@ -32,4 +32,7 @@ class RemoteActions extends BaseActions {
|
||||
// for remote actions we use the relative position only
|
||||
return keyPair.touchPosition;
|
||||
}
|
||||
|
||||
@override
|
||||
void cleanup() {}
|
||||
}
|
||||
|
||||
@@ -290,6 +290,7 @@ class NotificationRequirement extends PlatformRequirement {
|
||||
core.connection.disconnectAll();
|
||||
}
|
||||
if (message == 'close') {
|
||||
core.actionHandler.cleanup();
|
||||
core.connection.stop();
|
||||
SystemNavigator.pop();
|
||||
AndroidFlutterLocalNotificationsPlugin().stopForegroundService();
|
||||
|
||||
Reference in New Issue
Block a user