Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Simplify Photos platform channels

Neeraj Gupta27fefce7d11e
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/PhotosPlatformPlugin.kt b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/PhotosPlatformPlugin.kt
index 0b44f526a5..8fd0550957 100644
--- a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/PhotosPlatformPlugin.kt
+++ b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/PhotosPlatformPlugin.kt
@@ -1,24 +1,28 @@
package io.ente.photos.platform
import io.ente.photos.platform.flutter.CountryNamesChannelAdapter
-import io.ente.photos.platform.flutter.PhotosPlatformChannelRouter
+import io.ente.photos.platform.flutter.DeviceHealthChannelAdapter
+import io.ente.photos.platform.flutter.DeviceTrashChannelAdapter
import io.ente.photos.platform.flutter.ProcessLockChannelAdapter
import io.flutter.embedding.engine.plugins.FlutterPlugin
class PhotosPlatformPlugin : FlutterPlugin {
- private val channelRouter = PhotosPlatformChannelRouter()
private val countryNamesAdapter = CountryNamesChannelAdapter()
+ private val deviceHealthAdapter = DeviceHealthChannelAdapter()
+ private val deviceTrashAdapter = DeviceTrashChannelAdapter()
private val processLockAdapter = ProcessLockChannelAdapter()
override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
- channelRouter.attach(binding)
countryNamesAdapter.attach(binding)
+ deviceHealthAdapter.attach(binding)
+ deviceTrashAdapter.attach(binding)
processLockAdapter.attach(binding)
}
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
- channelRouter.detach()
countryNamesAdapter.detach()
+ deviceHealthAdapter.detach()
+ deviceTrashAdapter.detach()
processLockAdapter.detach()
}
}
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/DeviceHealthChannelAdapter.kt b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/DeviceHealthChannelAdapter.kt
index eb2e6b211d..f03df79f9c 100644
--- a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/DeviceHealthChannelAdapter.kt
+++ b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/DeviceHealthChannelAdapter.kt
@@ -15,12 +15,15 @@ import io.flutter.plugin.common.MethodChannel
internal class DeviceHealthChannelAdapter :
MethodChannel.MethodCallHandler,
EventChannel.StreamHandler {
+ private lateinit var methodChannel: MethodChannel
private lateinit var eventChannel: EventChannel
private lateinit var service: DeviceHealthService
private var eventSink: EventChannel.EventSink? = null
fun attach(binding: FlutterPlugin.FlutterPluginBinding) {
service = DeviceHealthService(binding.applicationContext)
+ methodChannel = MethodChannel(binding.binaryMessenger, METHOD_CHANNEL)
+ methodChannel.setMethodCallHandler(this)
eventChannel = EventChannel(binding.binaryMessenger, EVENT_CHANNEL)
eventChannel.setStreamHandler(this)
}
@@ -50,6 +53,7 @@ internal class DeviceHealthChannelAdapter :
fun detach() {
eventSink = null
service.stopObserving()
+ methodChannel.setMethodCallHandler(null)
eventChannel.setStreamHandler(null)
}
@@ -124,6 +128,7 @@ internal class DeviceHealthChannelAdapter :
}
private companion object {
+ const val METHOD_CHANNEL = "io.ente.photos.platform/device_health"
const val EVENT_CHANNEL = "io.ente.photos.platform/device_health_events"
}
}
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/DeviceTrashChannelAdapter.kt b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/DeviceTrashChannelAdapter.kt
index 2f103dda0f..db52f0e397 100644
--- a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/DeviceTrashChannelAdapter.kt
+++ b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/DeviceTrashChannelAdapter.kt
@@ -9,9 +9,12 @@ import io.flutter.plugin.common.MethodChannel
internal class DeviceTrashChannelAdapter : MethodChannel.MethodCallHandler {
private lateinit var service: DeviceTrashService
+ private lateinit var methodChannel: MethodChannel
fun attach(binding: FlutterPlugin.FlutterPluginBinding) {
service = DeviceTrashService(binding.applicationContext)
+ methodChannel = MethodChannel(binding.binaryMessenger, METHOD_CHANNEL)
+ methodChannel.setMethodCallHandler(this)
}
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) =
@@ -32,6 +35,7 @@ internal class DeviceTrashChannelAdapter : MethodChannel.MethodCallHandler {
}
fun detach() {
+ methodChannel.setMethodCallHandler(null)
service.close()
}
@@ -41,4 +45,8 @@ internal class DeviceTrashChannelAdapter : MethodChannel.MethodCallHandler {
"deleteBy" to deleteBy,
"deviceFolder" to deviceFolder,
)
+
+ private companion object {
+ const val METHOD_CHANNEL = "io.ente.photos.platform/device_trash"
+ }
}
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/PhotosPlatformChannelRouter.kt b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/PhotosPlatformChannelRouter.kt
deleted file mode 100644
index 1b44c62694..0000000000
--- a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/PhotosPlatformChannelRouter.kt
+++ /dev/null
@@ -1,38 +0,0 @@
-package io.ente.photos.platform.flutter
-
-import io.flutter.embedding.engine.plugins.FlutterPlugin
-import io.flutter.plugin.common.MethodCall
-import io.flutter.plugin.common.MethodChannel
-
-internal class PhotosPlatformChannelRouter : MethodChannel.MethodCallHandler {
- private val healthAdapter = DeviceHealthChannelAdapter()
- private val trashAdapter = DeviceTrashChannelAdapter()
- private lateinit var methodChannel: MethodChannel
-
- fun attach(binding: FlutterPlugin.FlutterPluginBinding) {
- healthAdapter.attach(binding)
- trashAdapter.attach(binding)
- methodChannel = MethodChannel(binding.binaryMessenger, METHOD_CHANNEL)
- methodChannel.setMethodCallHandler(this)
- }
-
- override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
- when {
- call.method.startsWith("deviceHealth.") -> healthAdapter.onMethodCall(call, result)
-
- call.method.startsWith("deviceTrash.") -> trashAdapter.onMethodCall(call, result)
-
- else -> result.notImplemented()
- }
- }
-
- fun detach() {
- methodChannel.setMethodCallHandler(null)
- healthAdapter.detach()
- trashAdapter.detach()
- }
-
- private companion object {
- const val METHOD_CHANNEL = "io.ente.photos.platform"
- }
-}
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/ios/Flutter/DeviceHealthChannelAdapter.swift b/mobile/apps/photos/plugins/ente_photos_platform/ios/Flutter/DeviceHealthChannelAdapter.swift
index aa9082e864..fe6ba8e206 100644
--- a/mobile/apps/photos/plugins/ente_photos_platform/ios/Flutter/DeviceHealthChannelAdapter.swift
+++ b/mobile/apps/photos/plugins/ente_photos_platform/ios/Flutter/DeviceHealthChannelAdapter.swift
@@ -46,7 +46,7 @@ final class DeviceHealthChannelAdapter: NSObject {
}
}
- private static let methodChannelName = "io.ente.photos.platform"
+ private static let methodChannelName = "io.ente.photos.platform/device_health"
private static let eventChannelName = "io.ente.photos.platform/device_health_events"
}
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/lib/src/device_health.dart b/mobile/apps/photos/plugins/ente_photos_platform/lib/src/device_health.dart
index c176b22b77..f5ec959ee8 100644
--- a/mobile/apps/photos/plugins/ente_photos_platform/lib/src/device_health.dart
+++ b/mobile/apps/photos/plugins/ente_photos_platform/lib/src/device_health.dart
@@ -210,17 +210,13 @@ abstract interface class DeviceHealthSource {
Stream<DeviceHealthSnapshot> get updates;
}
-abstract interface class DeviceMemorySource {
- Future<DeviceMemorySnapshot> getMemorySnapshot();
-}
-
-class DeviceHealthClient implements DeviceHealthSource, DeviceMemorySource {
+class DeviceHealthClient implements DeviceHealthSource {
DeviceHealthClient({MethodChannel? methodChannel, EventChannel? eventChannel})
: _methodChannel = methodChannel ?? const MethodChannel(_methodChannelName),
_eventChannel = eventChannel ?? const EventChannel(_eventChannelName);
static final instance = DeviceHealthClient();
- static const _methodChannelName = 'io.ente.photos.platform';
+ static const _methodChannelName = 'io.ente.photos.platform/device_health';
static const _eventChannelName =
'io.ente.photos.platform/device_health_events';
@@ -239,7 +235,6 @@ class DeviceHealthClient implements DeviceHealthSource, DeviceMemorySource {
return DeviceHealthSnapshot.fromMap(result);
}
- @override
Future<DeviceMemorySnapshot> getMemorySnapshot() async {
final result = await _methodChannel.invokeMethod<Map<dynamic, dynamic>>(
'deviceHealth.getMemorySnapshot',
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/lib/src/device_trash.dart b/mobile/apps/photos/plugins/ente_photos_platform/lib/src/device_trash.dart
index a5c92a8b90..71dbe871bc 100644
--- a/mobile/apps/photos/plugins/ente_photos_platform/lib/src/device_trash.dart
+++ b/mobile/apps/photos/plugins/ente_photos_platform/lib/src/device_trash.dart
@@ -25,7 +25,9 @@ class DeviceTrashFile {
class DeviceTrashClient {
static final instance = DeviceTrashClient();
- static const _methodChannel = MethodChannel('io.ente.photos.platform');
+ static const _methodChannel = MethodChannel(
+ 'io.ente.photos.platform/device_trash',
+ );
Future<List<DeviceTrashFile>> getFiles() async {
if (!Platform.isAndroid) {