fix(nav): preserve HTPC escape behavior
Use Flutter's supported desktop application-exit API so the second root Back press closes Plezy on Windows. Preserve fullscreen when video player navigation is enabled while keeping fullscreen-first Escape behavior for normal desktop use. close #1582
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import 'dart:io' show Platform;
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../utils/platform_detector.dart';
|
||||
|
||||
typedef AppExitApplication = Future<ui.AppExitResponse> Function(ui.AppExitType exitType, int exitCode);
|
||||
|
||||
class AppExitService {
|
||||
static const bool _tvosBuild = bool.fromEnvironment('TVOS_BUILD');
|
||||
static const MethodChannel _channel = MethodChannel('com.plezy/app_exit');
|
||||
@@ -12,7 +15,7 @@ class AppExitService {
|
||||
///
|
||||
/// tvOS has no public API for force-quitting or going Home, so callers that
|
||||
/// handle a physical back/Menu key should let the event continue instead.
|
||||
static Future<bool> requestExit() async {
|
||||
static Future<bool> requestExit({AppExitApplication? exitApplicationForTesting}) async {
|
||||
if (_tvosBuild || PlatformDetector.isAppleTV()) return false;
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
@@ -27,6 +30,14 @@ class AppExitService {
|
||||
}
|
||||
}
|
||||
|
||||
if (PlatformDetector.isDesktopOS()) {
|
||||
final exitApplication =
|
||||
exitApplicationForTesting ??
|
||||
(exitType, exitCode) => ServicesBinding.instance.exitApplication(exitType, exitCode);
|
||||
final response = await exitApplication(ui.AppExitType.required, 0);
|
||||
return response == ui.AppExitResponse.exit;
|
||||
}
|
||||
|
||||
await SystemNavigator.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user