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:
@@ -139,6 +139,8 @@ const String kOptionToggleViewOnly = "view-only";
|
||||
|
||||
const String kOptionDisableFloatingWindow = "disable-floating-window";
|
||||
|
||||
const String kOptionKeepScreenOn = "keep-screen-on";
|
||||
|
||||
const String kUrlActionClose = "close";
|
||||
|
||||
const String kTabLabelHomePage = "Home";
|
||||
|
||||
@@ -35,12 +35,41 @@ class SettingsPage extends StatefulWidget implements PageShape {
|
||||
|
||||
const url = 'https://rustdesk.com/';
|
||||
|
||||
enum KeepScreenOn {
|
||||
never,
|
||||
duringControlled,
|
||||
serviceOn,
|
||||
}
|
||||
|
||||
String _keepScreenOnToOption(KeepScreenOn value) {
|
||||
switch (value) {
|
||||
case KeepScreenOn.never:
|
||||
return 'never';
|
||||
case KeepScreenOn.duringControlled:
|
||||
return 'during-controlled';
|
||||
case KeepScreenOn.serviceOn:
|
||||
return 'service-on';
|
||||
}
|
||||
}
|
||||
|
||||
KeepScreenOn optionToKeepScreenOn(String value) {
|
||||
switch (value) {
|
||||
case 'never':
|
||||
return KeepScreenOn.never;
|
||||
case 'service-on':
|
||||
return KeepScreenOn.serviceOn;
|
||||
default:
|
||||
return KeepScreenOn.duringControlled;
|
||||
}
|
||||
}
|
||||
|
||||
class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {
|
||||
final _hasIgnoreBattery =
|
||||
false; //androidVersion >= 26; // remove because not work on every device
|
||||
var _ignoreBatteryOpt = false;
|
||||
var _enableStartOnBoot = false;
|
||||
var _floatingWindowDisabled = false;
|
||||
var _keepScreenOn = KeepScreenOn.duringControlled; // relay on floating window
|
||||
var _enableAbr = false;
|
||||
var _denyLANDiscovery = false;
|
||||
var _onlyWhiteList = false;
|
||||
@@ -96,6 +125,15 @@ class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {
|
||||
_floatingWindowDisabled = floatingWindowDisabled;
|
||||
}
|
||||
|
||||
final keepScreenOn = _floatingWindowDisabled
|
||||
? KeepScreenOn.never
|
||||
: optionToKeepScreenOn(
|
||||
bind.mainGetLocalOption(key: kOptionKeepScreenOn));
|
||||
if (keepScreenOn != _keepScreenOn) {
|
||||
update = true;
|
||||
_keepScreenOn = keepScreenOn;
|
||||
}
|
||||
|
||||
final enableAbrRes = option2bool(
|
||||
kOptionEnableAbr, await bind.mainGetOption(key: kOptionEnableAbr));
|
||||
if (enableAbrRes != _enableAbr) {
|
||||
@@ -524,6 +562,29 @@ class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {
|
||||
? null
|
||||
: onFloatingWindowChanged));
|
||||
|
||||
enhancementsTiles.add(_getPopupDialogRadioEntry(
|
||||
title: 'Keep screen on',
|
||||
list: [
|
||||
_RadioEntry('Never', _keepScreenOnToOption(KeepScreenOn.never)),
|
||||
_RadioEntry('During controlled',
|
||||
_keepScreenOnToOption(KeepScreenOn.duringControlled)),
|
||||
_RadioEntry('During service is on',
|
||||
_keepScreenOnToOption(KeepScreenOn.serviceOn)),
|
||||
],
|
||||
getter: () => _keepScreenOnToOption(_floatingWindowDisabled
|
||||
? KeepScreenOn.never
|
||||
: optionToKeepScreenOn(
|
||||
bind.mainGetLocalOption(key: kOptionKeepScreenOn))),
|
||||
asyncSetter: isOptionFixed(kOptionKeepScreenOn) || _floatingWindowDisabled
|
||||
? null
|
||||
: (value) async {
|
||||
await bind.mainSetLocalOption(
|
||||
key: kOptionKeepScreenOn, value: value);
|
||||
setState(() => _keepScreenOn = optionToKeepScreenOn(value));
|
||||
gFFI.serverModel.androidUpdatekeepScreenOn();
|
||||
},
|
||||
));
|
||||
|
||||
final disabledSettings = bind.isDisableSettings();
|
||||
final settings = SettingsList(
|
||||
sections: [
|
||||
@@ -947,7 +1008,7 @@ class _RadioEntry {
|
||||
typedef _RadioEntryGetter = String Function();
|
||||
typedef _RadioEntrySetter = Future<void> Function(String);
|
||||
|
||||
_getPopupDialogRadioEntry({
|
||||
SettingsTile _getPopupDialogRadioEntry({
|
||||
required String title,
|
||||
required List<_RadioEntry> list,
|
||||
required _RadioEntryGetter getter,
|
||||
@@ -1001,7 +1062,7 @@ _getPopupDialogRadioEntry({
|
||||
|
||||
return SettingsTile(
|
||||
title: Text(translate(title)),
|
||||
onPressed: (context) => showDialog(),
|
||||
onPressed: asyncSetter == null ? null : (context) => showDialog(),
|
||||
value: Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 8),
|
||||
child: Obx(() => Text(translate(valueText.value))),
|
||||
|
||||
@@ -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