Skip to content

Commit

Permalink
Add isRunning()
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuxiang committed Nov 23, 2022
1 parent eb569b6 commit c359868
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ open class AndroidWindowApplication : FlutterApplication() {
var androidWindowMessenger: BinaryMessenger? = null
var mainApi: MainApi? = null
var activity: Activity? = null
var running = false
}

4 changes: 4 additions & 0 deletions android/src/main/kotlin/qiuxiang/android_window/MainApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class MainApi(private val activity: Activity) : Pigeon.MainApi {
requestPermission { result.success(null) }
}

override fun isRunning(result: Pigeon.Result<Boolean>) {
result.success((activity.application as AndroidWindowApplication).running)
}

override fun post(data: MutableMap<Any, Any>?, result: Pigeon.Result<MutableMap<Any, Any>>?) {
activity.app?.androidWindowMessenger?.let {
Pigeon.AndroidWindowHandler(it).handler(data) { response -> result?.success(response) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -61,5 +62,6 @@ class WindowService : android.app.Service() {
override fun onDestroy() {
androidWindow.close()
engine.destroy()
(application as AndroidWindowApplication).running = false
}
}
5 changes: 5 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ Future<bool> canDrawOverlays() {
return _api.canDrawOverlays();
}

/// Checks if the window is running.
Future<bool> isRunning() {
return _api.isRunning();
}

/// Request overlay permission.
///
/// Show screen for controlling which apps can draw on top of other apps.
Expand Down
2 changes: 2 additions & 0 deletions lib/pigeon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c359868

Please sign in to comment.