feat: stop all servers in noti center (#901)

This commit is contained in:
lollipopkit🏳️‍⚧️
2025-09-06 14:04:53 +08:00
committed by GitHub
parent 0c7b72fb2c
commit 05a927753f
5 changed files with 124 additions and 80 deletions

View File

@@ -51,12 +51,31 @@ abstract final class TermSessionManager {
static void init() {
if (isAndroid) {
MethodChans.registerHandler((id) async {
_entries[id]?.disconnect?.call();
});
MethodChans.registerHandler(
(id) async {
_entries[id]?.disconnect?.call();
},
() {
// Stop all connections when notification "Stop All" is pressed
stopAllConnections();
},
);
}
}
/// Called when Android notification "Stop All" button is pressed
static void stopAllConnections() {
// Disconnect all sessions
final disconnectCallbacks = _entries.values.map((e) => e.disconnect).where((cb) => cb != null).toList();
for (final disconnect in disconnectCallbacks) {
disconnect!();
}
// Clear all entries
_entries.clear();
_activeId = null;
_sync();
}
/// Add a session record and push update to Android.
static void add({
required String id,