diff --git a/android/src/main/kotlin/qiuxiang/android_window/AndroidWindowApplication.kt b/android/src/main/kotlin/qiuxiang/android_window/AndroidWindowApplication.kt index 5a440e5..f03d654 100644 --- a/android/src/main/kotlin/qiuxiang/android_window/AndroidWindowApplication.kt +++ b/android/src/main/kotlin/qiuxiang/android_window/AndroidWindowApplication.kt @@ -9,5 +9,6 @@ open class AndroidWindowApplication : FlutterApplication() { var androidWindowMessenger: BinaryMessenger? = null var mainApi: MainApi? = null var activity: Activity? = null + var running = false } diff --git a/android/src/main/kotlin/qiuxiang/android_window/MainApi.kt b/android/src/main/kotlin/qiuxiang/android_window/MainApi.kt index 55fca21..93ae56f 100644 --- a/android/src/main/kotlin/qiuxiang/android_window/MainApi.kt +++ b/android/src/main/kotlin/qiuxiang/android_window/MainApi.kt @@ -40,6 +40,10 @@ class MainApi(private val activity: Activity) : Pigeon.MainApi { requestPermission { result.success(null) } } + override fun isRunning(result: Pigeon.Result) { + result.success((activity.application as AndroidWindowApplication).running) + } + override fun post(data: MutableMap?, result: Pigeon.Result>?) { activity.app?.androidWindowMessenger?.let { Pigeon.AndroidWindowHandler(it).handler(data) { response -> result?.success(response) } diff --git a/android/src/main/kotlin/qiuxiang/android_window/WindowService.kt b/android/src/main/kotlin/qiuxiang/android_window/WindowService.kt index 9742ede..df80ca1 100644 --- a/android/src/main/kotlin/qiuxiang/android_window/WindowService.kt +++ b/android/src/main/kotlin/qiuxiang/android_window/WindowService.kt @@ -42,6 +42,7 @@ class WindowService : android.app.Service() { androidWindow.open() startForeground(1, getNotification()) running = true + (application as AndroidWindowApplication).running = true } return super.onStartCommand(intent, flags, startId) } @@ -61,5 +62,6 @@ class WindowService : android.app.Service() { override fun onDestroy() { androidWindow.close() engine.destroy() + (application as AndroidWindowApplication).running = false } } diff --git a/lib/main.dart b/lib/main.dart index 8cb8649..0bec76d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -42,6 +42,11 @@ Future canDrawOverlays() { return _api.canDrawOverlays(); } +/// Checks if the window is running. +Future isRunning() { + return _api.isRunning(); +} + /// Request overlay permission. /// /// Show screen for controlling which apps can draw on top of other apps. diff --git a/lib/pigeon.dart b/lib/pigeon.dart index 7015144..c440768 100644 --- a/lib/pigeon.dart +++ b/lib/pigeon.dart @@ -14,6 +14,8 @@ abstract class MainApi { @async void requestPermission(); @async + bool isRunning(); + @async Map post(Map message); void open(String entry, int width, int height, int x, int y, bool focusable); void close();