diff --git a/lib/cwtch/ffi.dart b/lib/cwtch/ffi.dart index 325db72..4078630 100644 --- a/lib/cwtch/ffi.dart +++ b/lib/cwtch/ffi.dart @@ -57,6 +57,8 @@ class CwtchFfi implements Cwtch { ProfileListState profileCN; CwtchNotifier cwtchNotifier; + Isolate cwtchIsolate; + CwtchFfi(ProfileListState profs) { library = DynamicLibrary.open("libCwtch.so"); profileCN = profs; @@ -81,7 +83,7 @@ class CwtchFfi implements Cwtch { // Test non timer getting events from libcwtch-go var _receivePort = ReceivePort(); - var _isolate = await Isolate.spawn(_checkAppbusEvents, _receivePort.sendPort); + cwtchIsolate = await Isolate.spawn(_checkAppbusEvents, _receivePort.sendPort); _receivePort.listen((message) { var env = jsonDecode(message); cwtchNotifier.handleMessage(env["EventType"], env["Data"]); @@ -89,6 +91,13 @@ class CwtchFfi implements Cwtch { //repaintProfileStream = pollRepaintProfileEvents(); } + + @override + void dispose() { + if (cwtchIsolate != null) { + cwtchIsolate.kill(); + } + } /* Stream GetRepaintProfileStream() { return repaintProfileStream;