Skip to content

Commit c359868

Browse files
committed
Add isRunning()
1 parent eb569b6 commit c359868

File tree

5 files changed

+14
-0
lines changed

5 files changed

+14
-0
lines changed

android/src/main/kotlin/qiuxiang/android_window/AndroidWindowApplication.kt

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ open class AndroidWindowApplication : FlutterApplication() {
99
var androidWindowMessenger: BinaryMessenger? = null
1010
var mainApi: MainApi? = null
1111
var activity: Activity? = null
12+
var running = false
1213
}
1314

android/src/main/kotlin/qiuxiang/android_window/MainApi.kt

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class MainApi(private val activity: Activity) : Pigeon.MainApi {
4040
requestPermission { result.success(null) }
4141
}
4242

43+
override fun isRunning(result: Pigeon.Result<Boolean>) {
44+
result.success((activity.application as AndroidWindowApplication).running)
45+
}
46+
4347
override fun post(data: MutableMap<Any, Any>?, result: Pigeon.Result<MutableMap<Any, Any>>?) {
4448
activity.app?.androidWindowMessenger?.let {
4549
Pigeon.AndroidWindowHandler(it).handler(data) { response -> result?.success(response) }

android/src/main/kotlin/qiuxiang/android_window/WindowService.kt

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class WindowService : android.app.Service() {
4242
androidWindow.open()
4343
startForeground(1, getNotification())
4444
running = true
45+
(application as AndroidWindowApplication).running = true
4546
}
4647
return super.onStartCommand(intent, flags, startId)
4748
}
@@ -61,5 +62,6 @@ class WindowService : android.app.Service() {
6162
override fun onDestroy() {
6263
androidWindow.close()
6364
engine.destroy()
65+
(application as AndroidWindowApplication).running = false
6466
}
6567
}

lib/main.dart

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ Future<bool> canDrawOverlays() {
4242
return _api.canDrawOverlays();
4343
}
4444

45+
/// Checks if the window is running.
46+
Future<bool> isRunning() {
47+
return _api.isRunning();
48+
}
49+
4550
/// Request overlay permission.
4651
///
4752
/// Show screen for controlling which apps can draw on top of other apps.

lib/pigeon.dart

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ abstract class MainApi {
1414
@async
1515
void requestPermission();
1616
@async
17+
bool isRunning();
18+
@async
1719
Map post(Map message);
1820
void open(String entry, int width, int height, int x, int y, bool focusable);
1921
void close();

0 commit comments

Comments
 (0)