mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-12 11:06:57 +00:00
android keep screen on option (#8344)
* android keep screen on option Keep screen on option relays on floating window. Three options: Never, During controlled(default), During service is on Signed-off-by: 21pages <sunboeasy@gmail.com> * When rustdesk is in forground, be consistent with the settings Signed-off-by: 21pages <sunboeasy@gmail.com> --------- Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/consts.dart';
|
||||
import 'package:flutter_hbb/main.dart';
|
||||
import 'package:flutter_hbb/mobile/pages/settings_page.dart';
|
||||
import 'package:flutter_hbb/models/chat_model.dart';
|
||||
import 'package:flutter_hbb/models/platform_model.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -421,7 +422,7 @@ class ServerModel with ChangeNotifier {
|
||||
await bind.mainStartService();
|
||||
updateClientState();
|
||||
if (isAndroid) {
|
||||
WakelockPlus.enable();
|
||||
androidUpdatekeepScreenOn();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -514,6 +515,7 @@ class ServerModel with ChangeNotifier {
|
||||
}
|
||||
if (_clients.length != oldClientLenght) {
|
||||
notifyListeners();
|
||||
if (isAndroid) androidUpdatekeepScreenOn();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -548,6 +550,7 @@ class ServerModel with ChangeNotifier {
|
||||
scrollToBottom();
|
||||
notifyListeners();
|
||||
if (isAndroid && !client.authorized) showLoginDialog(client);
|
||||
if (isAndroid) androidUpdatekeepScreenOn();
|
||||
} catch (e) {
|
||||
debugPrint("Failed to call loginRequest,error:$e");
|
||||
}
|
||||
@@ -668,6 +671,7 @@ class ServerModel with ChangeNotifier {
|
||||
final index = _clients.indexOf(client);
|
||||
tabController.remove(index);
|
||||
_clients.remove(client);
|
||||
if (isAndroid) androidUpdatekeepScreenOn();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -691,6 +695,7 @@ class ServerModel with ChangeNotifier {
|
||||
if (desktopType == DesktopType.cm && _clients.isEmpty) {
|
||||
hideCmWindow();
|
||||
}
|
||||
if (isAndroid) androidUpdatekeepScreenOn();
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
debugPrint("onClientRemove failed,error:$e");
|
||||
@@ -702,6 +707,7 @@ class ServerModel with ChangeNotifier {
|
||||
_clients.map((client) => bind.cmCloseConnection(connId: client.id)));
|
||||
_clients.clear();
|
||||
tabController.state.value.tabs.clear();
|
||||
if (isAndroid) androidUpdatekeepScreenOn();
|
||||
}
|
||||
|
||||
void jumpTo(int id) {
|
||||
@@ -739,6 +745,27 @@ class ServerModel with ChangeNotifier {
|
||||
debugPrint("updateVoiceCallState failed: $e");
|
||||
}
|
||||
}
|
||||
|
||||
void androidUpdatekeepScreenOn() async {
|
||||
if (!isAndroid) return;
|
||||
var floatingWindowDisabled =
|
||||
bind.mainGetLocalOption(key: kOptionDisableFloatingWindow) == "Y" ||
|
||||
!await AndroidPermissionManager.check(kSystemAlertWindow);
|
||||
final keepScreenOn = floatingWindowDisabled
|
||||
? KeepScreenOn.never
|
||||
: optionToKeepScreenOn(
|
||||
bind.mainGetLocalOption(key: kOptionKeepScreenOn));
|
||||
final on = ((keepScreenOn == KeepScreenOn.serviceOn) && _isStart) ||
|
||||
(keepScreenOn == KeepScreenOn.duringControlled &&
|
||||
_clients.map((e) => !e.disconnected).isNotEmpty);
|
||||
if (on != await WakelockPlus.enabled) {
|
||||
if (on) {
|
||||
WakelockPlus.enable();
|
||||
} else {
|
||||
WakelockPlus.disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum ClientType {
|
||||
|
||||
Reference in New Issue
Block a user