Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
android:icon="@mipmap/ic_launcher"
android:label="Bettbox"
android:banner="@drawable/tv_banner"
android:enableOnBackInvokedCallback="true">
android:enableOnBackInvokedCallback="false">
<activity
android:name="com.appshub.bettbox.MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:alwaysRetainTaskState="true"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode|colorMode"
android:exported="true"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
Expand Down
17 changes: 16 additions & 1 deletion android/app/src/main/kotlin/com/appshub/bettbox/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ class MainActivity : FlutterActivity() {

override fun shouldDestroyEngineWithHost(): Boolean = false

/**
* HyperOS can unregister Flutter's predictive-back callback after an
* Activity restore or a display-mode change. Always forward legacy back
* events to Flutter so the current route gets the first chance to pop.
*/
@Deprecated("Deprecated in Java")
override fun onBackPressed() {
val engine = flutterEngine
if (engine != null) {
engine.navigationChannel.popRoute()
} else {
super.onBackPressed()
}
}

override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
return try {
super.dispatchTouchEvent(ev)
Expand All @@ -91,4 +106,4 @@ class MainActivity : FlutterActivity() {
override fun onDestroy() {
super.onDestroy()
}
}
}
46 changes: 33 additions & 13 deletions lib/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ class AppController {
}

if (wasRunning) {
await globalState.handleStart(
[updateRunTime, updateTraffic],
!keepVpnService,
);
await globalState.handleStart([
updateRunTime,
updateTraffic,
], !keepVpnService);
_scheduleCheckIpRefresh();
_backgroundLoad();
}
Expand Down Expand Up @@ -1167,9 +1167,13 @@ class AppController {
await _handlePreference();
await _handlerDisclaimer();
if (system.isWindows) {
unawaited(setProcessPriority(_ref.read(appSettingProvider).enableHighPriority).catchError((e) {
commonPrint.log('Failed to set initial process priority: $e');
}));
unawaited(
setProcessPriority(
_ref.read(appSettingProvider).enableHighPriority,
).catchError((e) {
commonPrint.log('Failed to set initial process priority: $e');
}),
);
}
_ref.read(initProvider.notifier).value = true;
}
Expand Down Expand Up @@ -1197,7 +1201,8 @@ class AppController {
}
}
final hasProfile = _ref.read(currentProfileProvider) != null;
final shouldStart = hasProfile &&
final shouldStart =
hasProfile &&
(globalState.isStart || _ref.read(appSettingProvider).autoRun);

if (shouldStart) {
Expand Down Expand Up @@ -1351,7 +1356,9 @@ class AppController {
ageSecretKey: ageSecretKey,
).update();
if (globalState.navigatorKey.currentState?.canPop() ?? false) {
globalState.navigatorKey.currentState?.popUntil((route) => route.isFirst);
globalState.navigatorKey.currentState?.popUntil(
(route) => route.isFirst,
);
}
toProfiles();
await addProfile(profile);
Expand All @@ -1376,7 +1383,9 @@ class AppController {
_ref.read(loadingProvider.notifier).value = true;
try {
await Future.delayed(const Duration(milliseconds: 500));
final profile = await Profile.normal(label: platformFile?.name).saveFile(bytes);
final profile = await Profile.normal(
label: platformFile?.name,
).saveFile(bytes);
globalState.navigatorKey.currentState?.popUntil((route) => route.isFirst);
toProfiles();
await addProfile(profile);
Expand Down Expand Up @@ -1704,9 +1713,18 @@ class AppController {
});
}

Future<void> updateTray([bool focus = false, bool silent = false, bool force = false]) async {
Future<void> updateTray([
bool focus = false,
bool silent = false,
bool force = false,
]) async {
final trayState = _ref.read(trayStateProvider);
await tray.update(trayState: trayState, focus: focus, silent: silent, force: force);
await tray.update(
trayState: trayState,
focus: focus,
silent: silent,
force: force,
);
}

Future<void> _processRecoveryArchive(
Expand Down Expand Up @@ -2244,7 +2262,9 @@ class AppController {
// Use default widgets if merged is empty
return mergedWidgets.isNotEmpty
? mergedWidgets
: (system.isAndroid ? defaultAndroidDashboardWidgets : defaultDashboardWidgets);
: (system.isAndroid
? defaultAndroidDashboardWidgets
: defaultDashboardWidgets);
}

Future<T?> safeRun<T>(
Expand Down
13 changes: 8 additions & 5 deletions lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,15 @@ class HomeBackScope extends ConsumerWidget {
globalState.appController.toPage(PageLabel.dashboard);
return;
}
final canPop = Navigator.canPop(context);
if (canPop) {
Navigator.pop(context);
} else {
await globalState.appController.handleBackOrExit();
// Use the global navigator key rather than the local build
// context — the latter may become stale after display-mode
// changes on Xiaomi HyperOS (e.g. enabling "Show refresh rate").
final navigatorState = globalState.navigatorKey.currentState;
if (navigatorState != null && navigatorState.canPop()) {
navigatorState.pop();
return;
}
await globalState.appController.handleBackOrExit();
},
child: child,
);
Expand Down
1 change: 0 additions & 1 deletion lib/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class GlobalState {
bool _needsTaskRestart = false;
Timer? _backgroundCleanupTimer;
final Lock _scriptEvaluateLock = Lock();

bool isInit = false;

bool get isStart => startTime != null && startTime!.isBeforeNow;
Expand Down