fix(desktop): wakelock issue with multiple tabs in same window (#13956)

Each desktop isolate now independently tracks wakelock state.
  WakelockPlus.disable() is only called when all tabs within the
  same isolate are closed/minimized.

  WakelockPlus ensures screen stays awake as long as any isolate
  has wakelock enabled.

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages
2026-01-05 22:16:35 +08:00
committed by GitHub
parent 7ac03ffefc
commit f65952cf1c
4 changed files with 41 additions and 39 deletions

View File

@@ -24,6 +24,7 @@ import 'package:provider/provider.dart';
import 'package:uni_links/uni_links.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:uuid/uuid.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
import 'package:window_manager/window_manager.dart';
import 'package:window_size/window_size.dart' as window_size;
@@ -2676,6 +2677,31 @@ class SimpleWrapper<T> {
SimpleWrapper(this.value);
}
/// Wakelock manager with reference counting for desktop.
/// Ensures wakelock is only disabled when all sessions are closed/minimized.
///
/// Note: Each isolate has its own WakelockPlus instance with independent assertion.
/// As long as one isolate has wakelock enabled, the screen stays awake.
/// This manager handles multiple tabs within the same isolate.
class WakelockManager {
static final Set<UniqueKey> _enabledKeys = {};
static void enable(UniqueKey key) {
if (isLinux) return;
_enabledKeys.add(key);
WakelockPlus.enable();
}
static void disable(UniqueKey key) {
if (isLinux) return;
if (_enabledKeys.remove(key)) {
if (_enabledKeys.isEmpty) {
WakelockPlus.disable();
}
}
}
}
/// call this to reload current window.
///
/// [Note]