From 700156cf642b512831366892f79d22c7a0035476 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Tue, 29 Oct 2024 11:18:50 -0400 Subject: [PATCH 1/5] Only listen for events on existing sites --- lib/models/Site.dart | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/models/Site.dart b/lib/models/Site.dart index 46ee231..05efa36 100644 --- a/lib/models/Site.dart +++ b/lib/models/Site.dart @@ -93,20 +93,22 @@ class Site { this.rawConfig = rawConfig; this.lastManagedUpdate = lastManagedUpdate; - _updates = EventChannel('net.defined.nebula/$id'); - _updates.receiveBroadcastStream().listen((d) { - try { - _updateFromJson(d); - _change.add(null); - } catch (err) { - //TODO: handle the error - print(err); - } - }, onError: (err) { - _updateFromJson(err.details); - var error = err as PlatformException; - _change.addError(error.message ?? 'An unexpected error occurred'); - }); + if (id != null) { + _updates = EventChannel('net.defined.nebula/$id'); + _updates.receiveBroadcastStream().listen((d) { + try { + _updateFromJson(d); + _change.add(null); + } catch (err) { + //TODO: handle the error + print(err); + } + }, onError: (err) { + _updateFromJson(err.details); + var error = err as PlatformException; + _change.addError(error.message ?? 'An unexpected error occurred'); + }); + } } factory Site.fromJson(Map json) { From a922eef801a133865146e5d2471d9463aa42a4af Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Tue, 29 Oct 2024 11:23:40 -0400 Subject: [PATCH 2/5] Add missing super call in configureFlutterEngine --- .../src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/android/app/src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt b/android/app/src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt index 29b4dda..131026e 100644 --- a/android/app/src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt +++ b/android/app/src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt @@ -54,6 +54,7 @@ class MainActivity: FlutterActivity() { } override fun configureFlutterEngine(flutterEngine: FlutterEngine) { + super.configureFlutterEngine(flutterEngine) appContext = context //TODO: Initializing in the constructor leads to a context lacking info we need, figure out the right way to do this sites = Sites(flutterEngine) From 60dd6dacaa1e2a48f0d833508197636cfa68246d Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Tue, 29 Oct 2024 11:24:32 -0400 Subject: [PATCH 3/5] Fix ContextCompat.registerReceiver flag --- .../src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/app/src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt b/android/app/src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt index 131026e..ebe71c2 100644 --- a/android/app/src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt +++ b/android/app/src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt @@ -100,7 +100,7 @@ class MainActivity: FlutterActivity() { apiClient = APIClient(context) - ContextCompat.registerReceiver(context, refreshReceiver, IntentFilter(ACTION_REFRESH_SITES), RECEIVER_NOT_EXPORTED) + ContextCompat.registerReceiver(context, refreshReceiver, IntentFilter(ACTION_REFRESH_SITES), ContextCompat.RECEIVER_NOT_EXPORTED) enqueueDNUpdater() } From 9e403b87108b717e413c6fc105adc42363b5203f Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Tue, 29 Oct 2024 12:02:08 -0400 Subject: [PATCH 4/5] Use this.id --- lib/models/Site.dart | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/models/Site.dart b/lib/models/Site.dart index 05efa36..df98dfc 100644 --- a/lib/models/Site.dart +++ b/lib/models/Site.dart @@ -93,22 +93,20 @@ class Site { this.rawConfig = rawConfig; this.lastManagedUpdate = lastManagedUpdate; - if (id != null) { - _updates = EventChannel('net.defined.nebula/$id'); - _updates.receiveBroadcastStream().listen((d) { - try { - _updateFromJson(d); - _change.add(null); - } catch (err) { - //TODO: handle the error - print(err); - } - }, onError: (err) { - _updateFromJson(err.details); - var error = err as PlatformException; - _change.addError(error.message ?? 'An unexpected error occurred'); - }); - } + _updates = EventChannel('net.defined.nebula/${this.id}'); + _updates.receiveBroadcastStream().listen((d) { + try { + _updateFromJson(d); + _change.add(null); + } catch (err) { + //TODO: handle the error + print(err); + } + }, onError: (err) { + _updateFromJson(err.details); + var error = err as PlatformException; + _change.addError(error.message ?? 'An unexpected error occurred'); + }); } factory Site.fromJson(Map json) { From 9ccc9ae986d9f8c878b4840e213bfaa9072a7462 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Tue, 29 Oct 2024 13:57:12 -0400 Subject: [PATCH 5/5] Remove call to register plugins It's handled by the call to `super` --- .../src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/android/app/src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt b/android/app/src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt index ebe71c2..a78be8d 100644 --- a/android/app/src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt +++ b/android/app/src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt @@ -58,9 +58,7 @@ class MainActivity: FlutterActivity() { appContext = context //TODO: Initializing in the constructor leads to a context lacking info we need, figure out the right way to do this sites = Sites(flutterEngine) - - GeneratedPluginRegistrant.registerWith(flutterEngine) - + ui = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL) ui!!.setMethodCallHandler { call, result -> when(call.method) {