mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-11-04 08:34:12 +00:00
* fix web break introduced in 38f130071 fix(linux): enable mouse side buttons in remote sessions (#14848)
* feat(shortcuts): user-configurable keyboard shortcuts for session actions
Adds a keyboard shortcut feature (Rust matcher + Dart UI + cross-language
parity tests) that lets users bind combinations like Ctrl+Alt+Shift+P to
session actions. Bindings are stored in LocalConfig under
`keyboard-shortcuts`; the matcher gates dispatch on `enabled` and
`pass_through` flags so flipping the master switch off is a hard stop.
Wire-up summary:
- src/keyboard/shortcuts.rs: matcher, default bindings, parity test against
flutter/test/fixtures/default_keyboard_shortcuts.json
- src/keyboard.rs: shortcut intercept in process_event{,_with_session},
feature-gated to `flutter`; runs before key swapping so users bind to
physical keys
- src/flutter_ffi.rs: main_reload_keyboard_shortcuts +
main_get_default_keyboard_shortcuts; reload_from_config seeded in main_init
- flutter/lib/common/widgets/keyboard_shortcuts/: shared config page body,
recording dialog, shortcut display formatter, action group registry
- flutter/lib/desktop/pages/desktop_keyboard_shortcuts_page.dart and
flutter/lib/mobile/pages/mobile_keyboard_shortcuts_page.dart: platform
shells around the shared body
- flutter/lib/models/shortcut_model.dart: per-session ShortcutModel +
registerSessionShortcutActions for actions with no toolbar TToggleMenu /
TRadioMenu (fullscreen, switch display/tab, close tab, voice call, etc.)
- flutter/lib/common/widgets/toolbar.dart: optional `actionId` field on
TToggleMenu / TRadioMenu, plus per-helper auto-register pass that wires
tagged entries' existing onChanged into the ShortcutModel
- flutter/test/keyboard_shortcuts_test.dart + fixtures: cross-language
parity (default bindings, supported key vocabulary)
Design principles applied during review:
1. Additions are fine; modifications to original logic must be deliberate.
Tagging an existing TToggleMenu entry with `actionId:` is an addition.
Rewriting its onChanged to satisfy a new contract is a modification —
and was reverted for every case where the original click behavior was
working. Four closures were touched and then reverted (mobile View
Mode, Privacy mode multi-impl, Relative mouse mode, Reverse mouse
wheel); their shortcuts are wired via standalone closures in
shortcut_model.dart instead.
2. Toolbar auto-register is reserved for entries whose onChanged is
inherently self-flipping — typically `sessionToggleOption(name)` where
the named option is flipped in place and the input bool is unused. The
register pass passes `!menu.value` from registration time, which is
harmless under self-flipping but wrong for closures that consume the
input bool directly. Tagging a non-self-flipping entry forces a closure
rewrite; choose non-toolbar registration in that case.
3. When shortcuts are disabled, toolbar behavior must be bit-for-bit
unchanged. The matcher's `enabled`-gate already guarantees no
dispatch; the auto-register pass is left unconditional (its only effect
is HashMap operations on a separate ShortcutModel) so mid-session
enable works without a reconnect. The trade-off is intentional and
documented at the top of toolbarControls.
4. Comments stay terse. Rationale lives in one place — the doc comment of
the helper or registration site, not duplicated at every call site.
5. Where an existing helper needs a new optional behavior (e.g.
`_OptionCheckBox` gaining a tooltip slot), the new branch must reduce
to byte-identical output for existing callers (`trailing == null`
case → original `Expanded(Text)` layout). Verified.
6. Action IDs and labels stay consistent. Renamed `reset_cursor` →
`reset_canvas` so the action ID matches its user-facing label
("Reset canvas") and capability flag.
Out-of-scope but included:
- AGENTS.md: documents flutter_rust_bridge no-codegen workflow and the
Web target's hand-written TS client, since both are load-bearing for
any new FFI work.
- remote_toolbar.dart: i18n fix for the per-monitor tooltip ("All
monitors" / "Monitor #N"), unrelated to shortcuts but kept here.
* langs
* fix(keyboard): shortcuts, harden config and callback lifecycle
Signed-off-by: fufesou <linlong1266@gmail.com>
* feat(keyboard): shortcuts, color of "Reset to defaults"
Signed-off-by: fufesou <linlong1266@gmail.com>
* feat(keyboard): shortcuts, release keys before shortcut callback
Signed-off-by: fufesou <linlong1266@gmail.com>
* feat(keyboard): shortcuts, debug web
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix(keyboard): iPad, icon
Signed-off-by: fufesou <linlong1266@gmail.com>
* langs: add shortcut keys to az, gl, ur
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ra4my61t8q1FN5n59wB16D
* fix(keyboard): shortcuts, keep local modifiers and release keys on the right session
When a chord fired, the shortcut path reused release_remote_keys(), which
replays synthetic releases through process_event(). That cleared the local
MODIFIERS_STATE while the user still held the modifiers, so the next key of
a held chord no longer matched and leaked to the remote, and it sent the
releases to the globally current session instead of the one that typed the
chord.
The shortcut path now releases the remote keys itself: it sends through the
caller's session, and restores the modifiers it released on the remote as
still held locally. The press that fired is remembered until its release,
so its auto repeats and its release are consumed instead of reaching the
remote.
Also state the contract for unavailable actions: a bound chord always
belongs to RustDesk and is a no-op when the session has no handler.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ra4my61t8q1FN5n59wB16D
* fix(keyboard): shortcuts, record the physical key
The recording dialog and the Web Flutter matcher named keys by
LogicalKeyboardKey, while the native matcher sees the physical key through
its USB HID usage and the Web JS matcher through KeyboardEvent.code. On
AZERTY, QWERTZ, Dvorak and similar layouts a recorded binding then did not
fire, or fired from another key.
Name keys by their physical position everywhere: physicalKeyName maps the
USB HID usage to the stored name. A new fixture pins every name to its USB
HID usage, checked on the Dart side and against rdev::usb_hid_key_from_code
on the Rust side, and a test covers AZERTY and QWERTZ events.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ra4my61t8q1FN5n59wB16D
* fix(keyboard): shortcuts, keep an empty binding list on re-enable
setEnabled seeded the defaults whenever the binding list was empty, so a
user who cleared every binding got all defaults back after disable and
enable. Seed only when the config has never held a bindings list.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ra4my61t8q1FN5n59wB16D
* fix(keyboard): shortcuts, track every fired key until its release
FIRED_KEY held a single key, so overlapping shortcut keys broke it: with the
chord held, P then C overwrote P, P's release reached the remote, and a P
repeat could fire the screenshot again. A repeat after the modifiers were
released was also treated as a new press and leaked to the remote.
Keep a set of fired keys instead. Once a press fires, every event of that
key belongs to RustDesk until its release: repeats are consumed without
dispatching, whatever the modifiers do, and the release removes the key.
Entries whose release never arrives are dropped when a session view is
entered or a session is closed, not by guessing from the modifiers.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ra4my61t8q1FN5n59wB16D
* fix(keyboard): shortcuts, keep fired keys per session
FIRED_KEYS was process-global while dispatch is per session. Closing or
entering any session cleared the fired keys of all of them, so a key still
held in another session leaked its release to that remote, and a key fired
in one session made the same key in another session look like a repeat.
Key the fired set by session: try_dispatch resolves the session first and
only looks at that session's keys, and session_close clears only the
closing session. Entering a session view no longer clears anything: it is
a pointer enter, and a fired key may still be physically held across it.
A key whose release is missed otherwise heals itself: its next press is
consumed as a repeat and that release removes it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ra4my61t8q1FN5n59wB16D
* fix(shortcuts): preserve input state and refresh action availability
* fix(keyboard): shortcuts, keep a fired key owned across session close
Close tab is itself a shortcut, so the session that consumed the key press
is gone before the key is released. Both matchers dropped the key with the
session: the Flutter dispatcher removed its own entries in clear(), and the
Rust set was keyed by session and cleared in session_close. The release,
and the repeats while the key stayed held, then reached the next session's
remote as ordinary input.
Ownership of a fired key is physical, so it is now one set shared by every
session on each side, and closing a session no longer touches it: clear()
only drops the pending action and modifier replay, and the Rust session
state only tracks released modifiers. A key whose release is missed heals
itself on its next press. Entering view-only with the Flutter input source
still clears the Rust set, since that source stops routing key events to it.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ra4my61t8q1FN5n59wB16D
* fix(keyboard): shortcuts, drop the Toggle Input Source action
The action switches the key capture backend between key down and key up.
Fired-key ownership lives in whichever matcher saw the press, the Flutter
dispatcher or the Rust set, and there is no handoff between them: after the
switch the repeats and the release of the held key reach the other backend,
which forwards them to the remote and, while the chord is held, matches the
action again and toggles the source back. Remove the shortcut instead of
building a handoff for one action. The toolbar radio menu is unchanged.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ra4my61t8q1FN5n59wB16D
* perf(keyboard): shortcuts, parse the config once per stored value
The Flutter matcher read the local config three times and parsed its JSON
three times on every key press in legacy mode, on Web and in view-only.
Keep one parsed snapshot keyed by the raw stored string, so a key press
costs one config read and no parsing while the config is unchanged. The
existing readers are thin views of the same snapshot.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ra4my61t8q1FN5n59wB16D
* fix(keyboard): shortcuts, run focus-changing actions on key release
Close tab and tab switching move keyboard focus to another session before
the key that fired them is released. On Linux the Flutter input source
routes map-mode sessions through the Rust matcher and legacy-mode sessions
through the Dart matcher, and neither knows the other's fired keys, so
after such an action the repeats and the release of the held key reached
the next session's remote, and the key stayed recorded as fired in the
matcher that saw the press.
Routing Linux legacy mode through the Rust FFI path instead is not a drop-in
change: the raw key handler builds its event with no unicode, so Rust's
legacy mode would fall back to US key names and lose the layout-aware
characters the Dart path sends today, and it would take modifiers from the
X11 key state instead of Flutter's.
Run these three actions when the fired key is released. The matcher that
consumed the press then also sees the repeats and the release, the remote
modifiers are still released on the press, and a session that closes drops
the action it owed. Both matchers keep the same list of actions.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ra4my61t8q1FN5n59wB16D
* test(keyboard): shortcuts, pin the key-up action list on both sides
kShortcutActionsRunOnKeyUp and runs_on_release are two hand-kept lists of
the actions that run on key release. Add a shared fixture and check each
side against it, the way the key vocabulary and the default bindings are
already checked, so adding a focus-changing action on one side breaks a
test until the other side follows. The Dart test also checks that every
listed id is a configurable action.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ra4my61t8q1FN5n59wB16D
* fix: prevent lost input after remote session shortcuts
Avoid synthetic Alt presses that activate the Windows system menu
and swallow the next character.
Trigger restart, switch-sides, and chat actions on key release so
focus changes cannot leave subsequent shortcut presses ignored.
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix(mobile): correct Chat keyboard and input helper behavior
- Keep soft keyboard and helper hidden when Chat opens via shortcut
- Restore soft input on touch and remote focus after Chat closes
- Handle modifier releases while Chat owns focus
- Clear hidden virtual modifiers while preserving held keys and Pin behavior
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix(shortcuts): prevent recording non-simultaneous key combinations
Build new captures from currently held keys instead of reusing released
letters. Preserve the last valid chord after release so it can be saved.
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix(shortcuts): isolate window actions and prevent duplicate Alt presses
- Dispatch shortcut actions only to the originating session window.
- Clear local modifier state on focus loss without resending modifiers
already released to Windows peers, preventing lost following input.
- Strengthen the regression assertion against extra Alt keydown events
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact(shortcuts): empty default shortcuts for Cmd+Option+Shift+Del on macOS and iOS
Because Del may be ambiguous for new macOS users.
Cmd+Option+Shift+Backspace is "Empty Trash without confirmation" shortcut on macOS.
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: use session peer platform for Ctrl+Alt+Del events
Fix Android-to-Linux Ctrl+Alt+Del delivery by using the session's peer
platform instead of the desktop global session, which defaults to Windows
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: hide relative mouse mode shortcuts on Wayland
Separate relative mouse mode availability from screenshot support.
Filter unsupported actions and defaults while preserving saved bindings
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: align shortcut availability with platform support
- Hide unsupported mobile and web shortcut actions
- Enable mobile scaling and Android voice call shortcuts
- Use openMonitorInTheSameTab() for display switching
- Preserve cursor position when switching displays on desktop and web
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: prevent held-key shortcut recording bypass
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: preserve keyboard input after shortcut dialogs
Run native clipboard shortcuts on key release and wait for remote modifier releases before dispatching.
Release remote modifiers when mobile local UI takes focus, and document the tested iPad Bluetooth Mute shortcut limitation.
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: preserve remote key state during local shortcuts
Keep unrelated held keys pressed for session actions that retain input. Preserve key release when focus or input handling changes, and avoid synthetic Alt taps during shortcut dispatch.
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: suspend saved relative mouse shortcuts on Wayland
Filter the native active binding cache without changing stored configuration, so the binding becomes available again under X11.
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: exclude unsupported Wayland shortcuts from Flutter matching
Keep saved bindings intact while filtering the active config used by the Flutter matcher. Cover stored bindings and enable/pass-through flags in the existing shortcut tests.
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: retain forwarded key ownership across shortcut repeats
Ignore repeat presses for keys already forwarded to the peer, and release ordinary held keys before Show My Cursor enables view-only. Cover both paths with converter-level regressions.
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: release Flutter-held keys before view-only shortcuts
Track ordinary keys forwarded by the Dart matcher paths and await their releases before View Only or Show My Cursor disables input. Keep Mute key ownership and existing empty-cleanup timing unchanged.
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: filter active Flutter shortcuts by platform capabilities
Reuse the Settings action filter for saved bindings while preserving storage, default-seeding behavior and configurable Apple Ctrl+Alt+Del bindings.
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: filter native shortcut caches for mobile controllers
Suspend saved desktop-only actions on Android and iOS and hide unavailable iOS actions without changing persisted bindings. Keep native cache filtering aligned with Flutter platform capabilities.
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: share filtered shortcut bindings with the Web matcher
Pass the active platform config to JavaScript at startup and after settings changes, preserving unsupported saved bindings in local storage.
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: release Flutter-held keys before focus-changing shortcuts
Drain ordinary keys owned by the original session before run-on-key-up
actions and native clipboard callbacks. Preserve Mute holds, pending-action
cancellation and Web clipboard key-down activation.
Document the required Web matcher counterpart in the bridge:
rustdesk/rustdesk-web-js@94abe431d6
Validation: 61 native Flutter tests, 32 Chrome/HTML tests, targeted analysis
and Windows debug build.
Signed-off-by: fufesou <linlong1266@gmail.com>
* refact: remove the useless comments
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: prevent Windows menu activation from Alt-only shortcuts
Neutralize the forwarded Alt with a balanced temporary Ctrl press when a consumed local shortcut releases its only modifier in Windows Map mode. Keep physical modifier tracking and normal Alt pass-through unchanged.
Add a regression covering both Alt keys, trigger repeats and the eventual physical release. Verified with 36 native shortcut tests and real Windows menu/input checks.
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: prevent Alt menu activation in all keyboard modes
Extend Windows Alt-only shortcut neutralization to Translate and Legacy. Keep the temporary Ctrl packets in Map mode so Legacy modifier synchronization cannot release Alt before Ctrl.
Extend the existing regression across keyboard modes and decode scan, virtual and control-key events. Verify 36 native tests and 34 Windows menu replay cases.
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: initialize outgoing chat before shortcut dispatch
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: guard Windows Alt release in Flutter legacy shortcuts
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: coordinate Web shortcut dispatch and Alt modifier cleanup
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: distinguish AltGraph from ordinary Alt shortcuts
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: dispatch macOS Web shortcuts without waiting for keyup
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: support legacy peers in privacy mode shortcut
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: exclude AltGraph from Flutter shortcut matching
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix: exclude GTK AltGr input from raw shortcut matching
Signed-off-by: fufesou <linlong1266@gmail.com>
* test: trim redundant keyboard shortcut coverage
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix(keyboard): prevent Cmd shortcuts from opening remote Start
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix(shortcuts): guard Windows menu keys after Ctrl/Cmd swapping
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix(shortcuts): align recording and display routing
Reject non-Apple AltGraph captures to match runtime filtering. Honor individual-display windows for next, previous, and all-display shortcuts.
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix(shortcuts): reject GTK AltGr chords in recorder
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix(android): restore keyboard focus for modifier-first input
Focus the existing FlutterView when a modifier is pressed without native view focus. This restores shortcut-first input after returning to RustDesk while preserving focused inputs and normal key dispatch.
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix(shortcuts): release held keys before keyboard mode changes
Drain Flutter-forwarded keys before keyboard-mode shortcut actions so releases use the original encoding. This prevents held keys from remaining down after a Web Input source 2 mode change.
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix(i18n): use sentence case for shortcut labels
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix(mobile): preserve touch modifiers in the input helper
Keep touch-selected modifiers visible after hiding the keyboard. Clear physical modifier releases locally in view-only mode so they do not reopen the helper.
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix(web): preserve modifiers across Legacy-to-Map shortcuts
Signed-off-by: fufesou <linlong1266@gmail.com>
* fix(shortcuts): check support before registering all displays view
Signed-off-by: fufesou <linlong1266@gmail.com>
---------
Signed-off-by: fufesou <linlong1266@gmail.com>
Co-authored-by: fufesou <linlong1266@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1463 lines
52 KiB
Dart
1463 lines
52 KiB
Dart
import 'dart:async';
|
|
import 'dart:convert';
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_hbb/common/widgets/setting_widgets.dart';
|
|
import 'package:flutter_hbb/desktop/pages/desktop_setting_page.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:settings_ui/settings_ui.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
import 'package:url_launcher/url_launcher_string.dart';
|
|
|
|
import '../../common.dart';
|
|
import '../../common/widgets/dialog.dart';
|
|
import '../../common/widgets/login.dart';
|
|
import '../../consts.dart';
|
|
import '../../models/model.dart';
|
|
import '../../models/platform_model.dart';
|
|
import '../widgets/deploy_dialog.dart';
|
|
import '../../models/shortcut_model.dart';
|
|
import '../widgets/dialog.dart';
|
|
import 'home_page.dart';
|
|
import 'mobile_keyboard_shortcuts_page.dart';
|
|
import 'scan_page.dart';
|
|
|
|
class SettingsPage extends StatefulWidget implements PageShape {
|
|
@override
|
|
final title = translate("Settings");
|
|
|
|
@override
|
|
final icon = Icon(Icons.settings);
|
|
|
|
@override
|
|
final appBarActions = bind.isDisableSettings() ? [] : [ScanButton()];
|
|
|
|
@override
|
|
State<SettingsPage> createState() => _SettingsState();
|
|
}
|
|
|
|
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 _checkUpdateOnStartup = false;
|
|
var _showTerminalExtraKeys = false;
|
|
var _floatingWindowDisabled = false;
|
|
var _keepScreenOn = KeepScreenOn.duringControlled; // relay on floating window
|
|
var _enableAbr = false;
|
|
var _denyLANDiscovery = false;
|
|
var _onlyWhiteList = false;
|
|
var _onlyIdWhiteList = false;
|
|
var _enableDirectIPAccess = false;
|
|
var _enableRecordSession = false;
|
|
var _enableHardwareCodec = false;
|
|
var _allowWebSocket = false;
|
|
var _autoRecordIncomingSession = false;
|
|
var _autoRecordOutgoingSession = false;
|
|
var _allowAutoDisconnect = false;
|
|
var _localIP = "";
|
|
var _directAccessPort = "";
|
|
var _fingerprint = "";
|
|
var _buildDate = "";
|
|
var _myId = "";
|
|
var _autoDisconnectTimeout = "";
|
|
var _hideServer = false;
|
|
var _hideProxy = false;
|
|
var _hideNetwork = false;
|
|
var _hideWebSocket = false;
|
|
var _enableTrustedDevices = false;
|
|
var _enableTcpPunch = false;
|
|
var _enableUdpPunch = false;
|
|
var _allowInsecureTlsFallback = false;
|
|
var _disableUdp = false;
|
|
var _enableIpv6Punch = false;
|
|
var _enableWebrtc = false;
|
|
var _isUsingPublicServer = false;
|
|
var _allowAskForNoteAtEndOfConnection = false;
|
|
var _preventSleepWhileConnected = true;
|
|
|
|
_SettingsState() {
|
|
_enableAbr = option2bool(
|
|
kOptionEnableAbr, bind.mainGetOptionSync(key: kOptionEnableAbr));
|
|
_denyLANDiscovery = !option2bool(kOptionEnableLanDiscovery,
|
|
bind.mainGetOptionSync(key: kOptionEnableLanDiscovery));
|
|
_onlyWhiteList = whitelistNotEmpty();
|
|
_onlyIdWhiteList = idWhitelistNotEmpty();
|
|
_enableDirectIPAccess = option2bool(
|
|
kOptionDirectServer, bind.mainGetOptionSync(key: kOptionDirectServer));
|
|
_enableRecordSession = option2bool(kOptionEnableRecordSession,
|
|
bind.mainGetOptionSync(key: kOptionEnableRecordSession));
|
|
_enableHardwareCodec = option2bool(kOptionEnableHwcodec,
|
|
bind.mainGetOptionSync(key: kOptionEnableHwcodec));
|
|
_allowWebSocket = mainGetBoolOptionSync(kOptionAllowWebSocket);
|
|
_allowInsecureTlsFallback =
|
|
mainGetBoolOptionSync(kOptionAllowInsecureTLSFallback);
|
|
_disableUdp = bind.mainGetOptionSync(key: kOptionDisableUdp) == 'Y';
|
|
_autoRecordIncomingSession = option2bool(kOptionAllowAutoRecordIncoming,
|
|
bind.mainGetOptionSync(key: kOptionAllowAutoRecordIncoming));
|
|
_autoRecordOutgoingSession = option2bool(kOptionAllowAutoRecordOutgoing,
|
|
bind.mainGetLocalOption(key: kOptionAllowAutoRecordOutgoing));
|
|
_localIP = bind.mainGetOptionSync(key: 'local-ip-addr');
|
|
_directAccessPort = bind.mainGetOptionSync(key: kOptionDirectAccessPort);
|
|
_allowAutoDisconnect = option2bool(kOptionAllowAutoDisconnect,
|
|
bind.mainGetOptionSync(key: kOptionAllowAutoDisconnect));
|
|
_autoDisconnectTimeout =
|
|
bind.mainGetOptionSync(key: kOptionAutoDisconnectTimeout);
|
|
_hideServer =
|
|
bind.mainGetBuildinOption(key: kOptionHideServerSetting) == 'Y';
|
|
_hideProxy = bind.mainGetBuildinOption(key: kOptionHideProxySetting) == 'Y';
|
|
_hideNetwork =
|
|
bind.mainGetBuildinOption(key: kOptionHideNetworkSetting) == 'Y';
|
|
_hideWebSocket =
|
|
bind.mainGetBuildinOption(key: kOptionHideWebSocketSetting) == 'Y' ||
|
|
isWeb;
|
|
_enableTrustedDevices = mainGetBoolOptionSync(kOptionEnableTrustedDevices);
|
|
_enableTcpPunch = mainGetLocalBoolOptionSync(kOptionEnableTcpPunch);
|
|
_enableUdpPunch = mainGetLocalBoolOptionSync(kOptionEnableUdpPunch);
|
|
_enableIpv6Punch = mainGetLocalBoolOptionSync(kOptionEnableIpv6Punch);
|
|
_enableWebrtc = mainGetLocalBoolOptionSync(kOptionEnableWebrtc);
|
|
_allowAskForNoteAtEndOfConnection =
|
|
mainGetLocalBoolOptionSync(kOptionAllowAskForNoteAtEndOfConnection);
|
|
_preventSleepWhileConnected =
|
|
mainGetLocalBoolOptionSync(kOptionKeepAwakeDuringOutgoingSessions);
|
|
_showTerminalExtraKeys =
|
|
mainGetLocalBoolOptionSync(kOptionEnableShowTerminalExtraKeys);
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addObserver(this);
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
|
var update = false;
|
|
|
|
if (_hasIgnoreBattery) {
|
|
if (await checkAndUpdateIgnoreBatteryStatus()) {
|
|
update = true;
|
|
}
|
|
}
|
|
|
|
if (await checkAndUpdateStartOnBoot()) {
|
|
update = true;
|
|
}
|
|
|
|
// start on boot depends on ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS and SYSTEM_ALERT_WINDOW
|
|
var enableStartOnBoot =
|
|
await gFFI.invokeMethod(AndroidChannel.kGetStartOnBootOpt);
|
|
if (enableStartOnBoot) {
|
|
if (!await canStartOnBoot()) {
|
|
enableStartOnBoot = false;
|
|
gFFI.invokeMethod(AndroidChannel.kSetStartOnBootOpt, false);
|
|
}
|
|
}
|
|
|
|
if (enableStartOnBoot != _enableStartOnBoot) {
|
|
update = true;
|
|
_enableStartOnBoot = enableStartOnBoot;
|
|
}
|
|
|
|
var checkUpdateOnStartup =
|
|
mainGetLocalBoolOptionSync(kOptionEnableCheckUpdate);
|
|
if (checkUpdateOnStartup != _checkUpdateOnStartup) {
|
|
update = true;
|
|
_checkUpdateOnStartup = checkUpdateOnStartup;
|
|
}
|
|
|
|
var floatingWindowDisabled =
|
|
bind.mainGetLocalOption(key: kOptionDisableFloatingWindow) == "Y" ||
|
|
!await AndroidPermissionManager.check(kSystemAlertWindow);
|
|
if (floatingWindowDisabled != _floatingWindowDisabled) {
|
|
update = true;
|
|
_floatingWindowDisabled = floatingWindowDisabled;
|
|
}
|
|
|
|
final keepScreenOn = _floatingWindowDisabled
|
|
? KeepScreenOn.never
|
|
: optionToKeepScreenOn(
|
|
bind.mainGetLocalOption(key: kOptionKeepScreenOn));
|
|
if (keepScreenOn != _keepScreenOn) {
|
|
update = true;
|
|
_keepScreenOn = keepScreenOn;
|
|
}
|
|
|
|
final fingerprint = await bind.mainGetFingerprint();
|
|
if (_fingerprint != fingerprint) {
|
|
update = true;
|
|
_fingerprint = fingerprint;
|
|
}
|
|
|
|
final buildDate = await bind.mainGetBuildDate();
|
|
if (_buildDate != buildDate) {
|
|
update = true;
|
|
_buildDate = buildDate;
|
|
}
|
|
|
|
final myId = await bind.mainGetMyId();
|
|
if (_myId != myId) {
|
|
update = true;
|
|
_myId = myId;
|
|
}
|
|
|
|
final isUsingPublicServer = await bind.mainIsUsingPublicServer();
|
|
if (_isUsingPublicServer != isUsingPublicServer) {
|
|
update = true;
|
|
_isUsingPublicServer = isUsingPublicServer;
|
|
}
|
|
|
|
if (update) {
|
|
setState(() {});
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
if (state == AppLifecycleState.resumed) {
|
|
() async {
|
|
final ibs = await checkAndUpdateIgnoreBatteryStatus();
|
|
final sob = await checkAndUpdateStartOnBoot();
|
|
if (ibs || sob) {
|
|
setState(() {});
|
|
}
|
|
}();
|
|
}
|
|
}
|
|
|
|
Future<bool> checkAndUpdateIgnoreBatteryStatus() async {
|
|
final res = await AndroidPermissionManager.check(
|
|
kRequestIgnoreBatteryOptimizations);
|
|
if (_ignoreBatteryOpt != res) {
|
|
_ignoreBatteryOpt = res;
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
Future<bool> checkAndUpdateStartOnBoot() async {
|
|
if (!await canStartOnBoot() && _enableStartOnBoot) {
|
|
_enableStartOnBoot = false;
|
|
debugPrint(
|
|
"checkAndUpdateStartOnBoot and set _enableStartOnBoot -> false");
|
|
gFFI.invokeMethod(AndroidChannel.kSetStartOnBootOpt, false);
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Provider.of<FfiModel>(context);
|
|
final outgoingOnly = bind.isOutgoingOnly();
|
|
final incomingOnly = bind.isIncomingOnly();
|
|
final customClientSection = CustomSettingsSection(
|
|
child: Column(
|
|
children: [
|
|
if (bind.isCustomClient())
|
|
Align(
|
|
alignment: Alignment.center,
|
|
child: loadPowered(context),
|
|
),
|
|
Align(
|
|
alignment: Alignment.center,
|
|
child: loadLogo(),
|
|
)
|
|
],
|
|
));
|
|
final List<AbstractSettingsTile> enhancementsTiles = [];
|
|
final enable2fa = bind.mainHasValid2FaSync();
|
|
final List<AbstractSettingsTile> tfaTiles = [
|
|
SettingsTile.switchTile(
|
|
title: Text(translate('enable-2fa-title')),
|
|
initialValue: enable2fa,
|
|
onToggle: (v) async {
|
|
update() async {
|
|
setState(() {});
|
|
}
|
|
|
|
if (v == false) {
|
|
CommonConfirmDialog(
|
|
gFFI.dialogManager, translate('cancel-2fa-confirm-tip'), () {
|
|
change2fa(callback: update);
|
|
});
|
|
} else {
|
|
change2fa(callback: update);
|
|
}
|
|
},
|
|
),
|
|
if (enable2fa)
|
|
SettingsTile.switchTile(
|
|
title: Text(translate('Telegram bot')),
|
|
initialValue: bind.mainHasValidBotSync(),
|
|
onToggle: (v) async {
|
|
update() async {
|
|
setState(() {});
|
|
}
|
|
|
|
if (v == false) {
|
|
CommonConfirmDialog(
|
|
gFFI.dialogManager, translate('cancel-bot-confirm-tip'), () {
|
|
changeBot(callback: update);
|
|
});
|
|
} else {
|
|
changeBot(callback: update);
|
|
}
|
|
},
|
|
),
|
|
if (enable2fa)
|
|
SettingsTile.switchTile(
|
|
title: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(translate('Enable trusted devices')),
|
|
Text('* ${translate('enable-trusted-devices-tip')}',
|
|
style: Theme.of(context).textTheme.bodySmall),
|
|
],
|
|
),
|
|
initialValue: _enableTrustedDevices,
|
|
onToggle: isOptionFixed(kOptionEnableTrustedDevices)
|
|
? null
|
|
: (v) async {
|
|
mainSetBoolOption(kOptionEnableTrustedDevices, v);
|
|
setState(() {
|
|
_enableTrustedDevices = v;
|
|
});
|
|
},
|
|
),
|
|
if (enable2fa && _enableTrustedDevices)
|
|
SettingsTile(
|
|
title: Text(translate('Manage trusted devices')),
|
|
trailing: Icon(Icons.arrow_forward_ios),
|
|
onPressed: (context) {
|
|
Navigator.push(context, MaterialPageRoute(builder: (context) {
|
|
return _ManageTrustedDevices();
|
|
}));
|
|
})
|
|
];
|
|
final List<AbstractSettingsTile> shareScreenTiles = [
|
|
SettingsTile.switchTile(
|
|
title: Text(translate('Deny LAN discovery')),
|
|
initialValue: _denyLANDiscovery,
|
|
onToggle: isOptionFixed(kOptionEnableLanDiscovery)
|
|
? null
|
|
: (v) async {
|
|
await bind.mainSetOption(
|
|
key: kOptionEnableLanDiscovery,
|
|
value: bool2option(kOptionEnableLanDiscovery, !v));
|
|
final newValue = !option2bool(kOptionEnableLanDiscovery,
|
|
await bind.mainGetOption(key: kOptionEnableLanDiscovery));
|
|
setState(() {
|
|
_denyLANDiscovery = newValue;
|
|
});
|
|
},
|
|
),
|
|
SettingsTile.switchTile(
|
|
title: Row(children: [
|
|
Expanded(child: Text(translate('Use IP Whitelisting'))),
|
|
Offstage(
|
|
offstage: !_onlyWhiteList,
|
|
child: const Icon(Icons.warning_amber_rounded,
|
|
color: Color.fromARGB(255, 255, 204, 0)))
|
|
.marginOnly(left: 5)
|
|
]),
|
|
initialValue: _onlyWhiteList,
|
|
onToggle: (_) async {
|
|
update() async {
|
|
final onlyWhiteList = whitelistNotEmpty();
|
|
if (onlyWhiteList != _onlyWhiteList) {
|
|
setState(() {
|
|
_onlyWhiteList = onlyWhiteList;
|
|
});
|
|
}
|
|
}
|
|
|
|
changeWhiteList(callback: update);
|
|
},
|
|
),
|
|
SettingsTile.switchTile(
|
|
title: Row(children: [
|
|
Expanded(child: Text(translate('Use ID whitelisting'))),
|
|
Offstage(
|
|
offstage: !_onlyIdWhiteList,
|
|
child: const Icon(Icons.warning_amber_rounded,
|
|
color: Color.fromARGB(255, 255, 204, 0)))
|
|
.marginOnly(left: 5)
|
|
]),
|
|
initialValue: _onlyIdWhiteList,
|
|
onToggle: (_) async {
|
|
update() async {
|
|
final onlyIdWhiteList = idWhitelistNotEmpty();
|
|
if (onlyIdWhiteList != _onlyIdWhiteList) {
|
|
setState(() {
|
|
_onlyIdWhiteList = onlyIdWhiteList;
|
|
});
|
|
}
|
|
}
|
|
|
|
changeIdWhiteList(callback: update);
|
|
},
|
|
),
|
|
SettingsTile.switchTile(
|
|
title: Text(translate('Adaptive bitrate')),
|
|
initialValue: _enableAbr,
|
|
onToggle: isOptionFixed(kOptionEnableAbr)
|
|
? null
|
|
: (v) async {
|
|
await mainSetBoolOption(kOptionEnableAbr, v);
|
|
final newValue = await mainGetBoolOption(kOptionEnableAbr);
|
|
setState(() {
|
|
_enableAbr = newValue;
|
|
});
|
|
},
|
|
),
|
|
SettingsTile.switchTile(
|
|
title: Text(translate('Enable recording session')),
|
|
initialValue: _enableRecordSession,
|
|
onToggle: isOptionFixed(kOptionEnableRecordSession)
|
|
? null
|
|
: (v) async {
|
|
await mainSetBoolOption(kOptionEnableRecordSession, v);
|
|
final newValue =
|
|
await mainGetBoolOption(kOptionEnableRecordSession);
|
|
setState(() {
|
|
_enableRecordSession = newValue;
|
|
});
|
|
},
|
|
),
|
|
SettingsTile.switchTile(
|
|
title: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(translate("Direct IP Access")),
|
|
Offstage(
|
|
offstage: !_enableDirectIPAccess,
|
|
child: Text(
|
|
'${translate("Local Address")}: $_localIP${_directAccessPort.isEmpty ? "" : ":$_directAccessPort"}',
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
)),
|
|
])),
|
|
Offstage(
|
|
offstage: !_enableDirectIPAccess,
|
|
child: IconButton(
|
|
padding: EdgeInsets.zero,
|
|
icon: Icon(
|
|
Icons.edit,
|
|
size: 20,
|
|
),
|
|
onPressed: isOptionFixed(kOptionDirectAccessPort)
|
|
? null
|
|
: () async {
|
|
final port = await changeDirectAccessPort(
|
|
_localIP, _directAccessPort);
|
|
setState(() {
|
|
_directAccessPort = port;
|
|
});
|
|
}))
|
|
]),
|
|
initialValue: _enableDirectIPAccess,
|
|
onToggle: isOptionFixed(kOptionDirectServer)
|
|
? null
|
|
: (_) async {
|
|
_enableDirectIPAccess = !_enableDirectIPAccess;
|
|
String value =
|
|
bool2option(kOptionDirectServer, _enableDirectIPAccess);
|
|
await bind.mainSetOption(
|
|
key: kOptionDirectServer, value: value);
|
|
setState(() {});
|
|
},
|
|
),
|
|
SettingsTile.switchTile(
|
|
title: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(translate("auto_disconnect_option_tip")),
|
|
Offstage(
|
|
offstage: !_allowAutoDisconnect,
|
|
child: Text(
|
|
'${_autoDisconnectTimeout.isEmpty ? '10' : _autoDisconnectTimeout} min',
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
)),
|
|
])),
|
|
Offstage(
|
|
offstage: !_allowAutoDisconnect,
|
|
child: IconButton(
|
|
padding: EdgeInsets.zero,
|
|
icon: Icon(
|
|
Icons.edit,
|
|
size: 20,
|
|
),
|
|
onPressed: isOptionFixed(kOptionAutoDisconnectTimeout)
|
|
? null
|
|
: () async {
|
|
final timeout = await changeAutoDisconnectTimeout(
|
|
_autoDisconnectTimeout);
|
|
setState(() {
|
|
_autoDisconnectTimeout = timeout;
|
|
});
|
|
}))
|
|
]),
|
|
initialValue: _allowAutoDisconnect,
|
|
onToggle: isOptionFixed(kOptionAllowAutoDisconnect)
|
|
? null
|
|
: (_) async {
|
|
_allowAutoDisconnect = !_allowAutoDisconnect;
|
|
String value = bool2option(
|
|
kOptionAllowAutoDisconnect, _allowAutoDisconnect);
|
|
await bind.mainSetOption(
|
|
key: kOptionAllowAutoDisconnect, value: value);
|
|
setState(() {});
|
|
},
|
|
)
|
|
];
|
|
if (_hasIgnoreBattery) {
|
|
enhancementsTiles.insert(
|
|
0,
|
|
SettingsTile.switchTile(
|
|
initialValue: _ignoreBatteryOpt,
|
|
title: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(translate('Keep RustDesk background service')),
|
|
Text('* ${translate('Ignore Battery Optimizations')}',
|
|
style: Theme.of(context).textTheme.bodySmall),
|
|
]),
|
|
onToggle: (v) async {
|
|
if (v) {
|
|
await AndroidPermissionManager.request(
|
|
kRequestIgnoreBatteryOptimizations);
|
|
} else {
|
|
final res = await gFFI.dialogManager.show<bool>(
|
|
(setState, close, context) => CustomAlertDialog(
|
|
title: Text(translate("Open System Setting")),
|
|
content: Text(translate(
|
|
"android_open_battery_optimizations_tip")),
|
|
actions: [
|
|
dialogButton("Cancel",
|
|
onPressed: () => close(), isOutline: true),
|
|
dialogButton(
|
|
"Open System Setting",
|
|
onPressed: () => close(true),
|
|
),
|
|
],
|
|
));
|
|
if (res == true) {
|
|
AndroidPermissionManager.startAction(
|
|
kActionApplicationDetailsSettings);
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
enhancementsTiles.add(SettingsTile.switchTile(
|
|
initialValue: _enableStartOnBoot,
|
|
title: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Text(translate('Start on boot')),
|
|
Text(
|
|
'* ${translate('Start the screen sharing service on boot, requires special permissions')}',
|
|
style: Theme.of(context).textTheme.bodySmall),
|
|
]),
|
|
onToggle: (toValue) async {
|
|
if (toValue) {
|
|
// 1. request kIgnoreBatteryOptimizations
|
|
if (!await AndroidPermissionManager.check(
|
|
kRequestIgnoreBatteryOptimizations)) {
|
|
if (!await AndroidPermissionManager.request(
|
|
kRequestIgnoreBatteryOptimizations)) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
// 2. request kSystemAlertWindow
|
|
if (!await AndroidPermissionManager.check(kSystemAlertWindow)) {
|
|
if (!await AndroidPermissionManager.request(kSystemAlertWindow)) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
// (Optional) 3. request input permission
|
|
}
|
|
setState(() => _enableStartOnBoot = toValue);
|
|
|
|
gFFI.invokeMethod(AndroidChannel.kSetStartOnBootOpt, toValue);
|
|
}));
|
|
|
|
if (!bind.isCustomClient()) {
|
|
enhancementsTiles.add(
|
|
SettingsTile.switchTile(
|
|
initialValue: _checkUpdateOnStartup,
|
|
title:
|
|
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Text(translate('Check for software update on startup')),
|
|
]),
|
|
onToggle: (bool toValue) async {
|
|
await mainSetLocalBoolOption(kOptionEnableCheckUpdate, toValue);
|
|
setState(() => _checkUpdateOnStartup = toValue);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
enhancementsTiles.add(
|
|
SettingsTile.switchTile(
|
|
initialValue: _showTerminalExtraKeys,
|
|
title: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Text(translate('Show terminal extra keys')),
|
|
]),
|
|
onToggle: (bool v) async {
|
|
await mainSetLocalBoolOption(kOptionEnableShowTerminalExtraKeys, v);
|
|
final newValue =
|
|
mainGetLocalBoolOptionSync(kOptionEnableShowTerminalExtraKeys);
|
|
setState(() {
|
|
_showTerminalExtraKeys = newValue;
|
|
});
|
|
},
|
|
),
|
|
);
|
|
|
|
onFloatingWindowChanged(bool toValue) async {
|
|
if (toValue) {
|
|
if (!await AndroidPermissionManager.check(kSystemAlertWindow)) {
|
|
if (!await AndroidPermissionManager.request(kSystemAlertWindow)) {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
final disable = !toValue;
|
|
bind.mainSetLocalOption(
|
|
key: kOptionDisableFloatingWindow,
|
|
value: disable ? 'Y' : defaultOptionNo);
|
|
setState(() => _floatingWindowDisabled = disable);
|
|
gFFI.serverModel.androidUpdatekeepScreenOn();
|
|
}
|
|
|
|
enhancementsTiles.add(SettingsTile.switchTile(
|
|
initialValue: !_floatingWindowDisabled,
|
|
title: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Text(translate('Floating window')),
|
|
Text('* ${translate('floating_window_tip')}',
|
|
style: Theme.of(context).textTheme.bodySmall),
|
|
]),
|
|
onToggle: bind.mainIsOptionFixed(key: kOptionDisableFloatingWindow)
|
|
? 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 hideSecuritySettings =
|
|
bind.mainGetBuildinOption(key: kOptionHideSecuritySetting) == 'Y';
|
|
final settings = SettingsList(
|
|
sections: [
|
|
customClientSection,
|
|
if (!bind.isDisableAccount())
|
|
SettingsSection(
|
|
title: Text(translate('Account')),
|
|
tiles: [
|
|
SettingsTile(
|
|
title: Obx(() => Text(gFFI.userModel.userName.value.isEmpty
|
|
? translate('Login')
|
|
: '${translate('Logout')} (${gFFI.userModel.accountLabelWithHandle})')),
|
|
leading: Obx(() {
|
|
final avatar = bind.mainResolveAvatarUrl(
|
|
avatar: gFFI.userModel.avatar.value);
|
|
return buildAvatarWidget(
|
|
avatar: avatar,
|
|
size: 28,
|
|
borderRadius: null,
|
|
fallback: Icon(Icons.person),
|
|
) ??
|
|
Icon(Icons.person);
|
|
}),
|
|
onPressed: (context) {
|
|
if (gFFI.userModel.userName.value.isEmpty) {
|
|
loginDialog();
|
|
} else {
|
|
logOutConfirmDialog();
|
|
}
|
|
},
|
|
),
|
|
],
|
|
),
|
|
SettingsSection(title: Text(translate("Settings")), tiles: [
|
|
if (!disabledSettings && !_hideNetwork && !_hideServer)
|
|
SettingsTile(
|
|
title: Text(translate('ID/Relay Server')),
|
|
leading: Icon(Icons.cloud),
|
|
onPressed: (context) {
|
|
showServerSettings(gFFI.dialogManager, (callback) async {
|
|
_isUsingPublicServer = await bind.mainIsUsingPublicServer();
|
|
setState(callback);
|
|
});
|
|
}),
|
|
if (!_hideNetwork && !_hideProxy)
|
|
SettingsTile(
|
|
title: Text(translate('Socks5/Http(s) Proxy')),
|
|
leading: Icon(Icons.network_ping),
|
|
onPressed: (context) {
|
|
changeSocks5Proxy();
|
|
}),
|
|
if (isAndroid && !bind.isOutgoingOnly())
|
|
SettingsTile(
|
|
title: Text(translate('Deploy')),
|
|
leading: Icon(Icons.cloud_upload),
|
|
onPressed: (context) {
|
|
showDeployDialog();
|
|
}),
|
|
if (!disabledSettings && !_hideNetwork && !_hideWebSocket)
|
|
SettingsTile.switchTile(
|
|
title: Text(translate('Use WebSocket')),
|
|
initialValue: _allowWebSocket,
|
|
onToggle: isOptionFixed(kOptionAllowWebSocket)
|
|
? null
|
|
: (v) async {
|
|
await mainSetBoolOption(kOptionAllowWebSocket, v);
|
|
final newValue =
|
|
await mainGetBoolOption(kOptionAllowWebSocket);
|
|
setState(() {
|
|
_allowWebSocket = newValue;
|
|
});
|
|
},
|
|
),
|
|
if (!_isUsingPublicServer)
|
|
SettingsTile.switchTile(
|
|
title: Text(translate('Allow insecure TLS fallback')),
|
|
initialValue: _allowInsecureTlsFallback,
|
|
onToggle: isOptionFixed(kOptionAllowInsecureTLSFallback)
|
|
? null
|
|
: (v) async {
|
|
await mainSetBoolOption(
|
|
kOptionAllowInsecureTLSFallback, v);
|
|
final newValue = mainGetBoolOptionSync(
|
|
kOptionAllowInsecureTLSFallback);
|
|
setState(() {
|
|
_allowInsecureTlsFallback = newValue;
|
|
});
|
|
},
|
|
),
|
|
if (isAndroid && !outgoingOnly && !_isUsingPublicServer)
|
|
SettingsTile.switchTile(
|
|
title: Text(translate('Disable UDP')),
|
|
initialValue: _disableUdp,
|
|
onToggle: isOptionFixed(kOptionDisableUdp)
|
|
? null
|
|
: (v) async {
|
|
await bind.mainSetOption(
|
|
key: kOptionDisableUdp, value: v ? 'Y' : 'N');
|
|
final newValue =
|
|
bind.mainGetOptionSync(key: kOptionDisableUdp) == 'Y';
|
|
setState(() {
|
|
_disableUdp = newValue;
|
|
});
|
|
},
|
|
),
|
|
if (!incomingOnly)
|
|
SettingsTile.switchTile(
|
|
title: Text(translate('Enable TCP hole punching')),
|
|
initialValue: _enableTcpPunch,
|
|
onToggle: isOptionFixed(kOptionEnableTcpPunch)
|
|
? null
|
|
: (v) async {
|
|
await mainSetLocalBoolOption(kOptionEnableTcpPunch, v);
|
|
final newValue =
|
|
mainGetLocalBoolOptionSync(kOptionEnableTcpPunch);
|
|
setState(() {
|
|
_enableTcpPunch = newValue;
|
|
});
|
|
},
|
|
),
|
|
if (!incomingOnly)
|
|
SettingsTile.switchTile(
|
|
title: Text(translate('Enable UDP hole punching')),
|
|
initialValue: _enableUdpPunch,
|
|
onToggle: isOptionFixed(kOptionEnableUdpPunch)
|
|
? null
|
|
: (v) async {
|
|
await mainSetLocalBoolOption(kOptionEnableUdpPunch, v);
|
|
final newValue =
|
|
mainGetLocalBoolOptionSync(kOptionEnableUdpPunch);
|
|
setState(() {
|
|
_enableUdpPunch = newValue;
|
|
});
|
|
},
|
|
),
|
|
if (!incomingOnly)
|
|
SettingsTile.switchTile(
|
|
title: Text(translate('Enable IPv6 P2P connection')),
|
|
initialValue: _enableIpv6Punch,
|
|
onToggle: isOptionFixed(kOptionEnableIpv6Punch)
|
|
? null
|
|
: (v) async {
|
|
await mainSetLocalBoolOption(kOptionEnableIpv6Punch, v);
|
|
final newValue =
|
|
mainGetLocalBoolOptionSync(kOptionEnableIpv6Punch);
|
|
setState(() {
|
|
_enableIpv6Punch = newValue;
|
|
});
|
|
},
|
|
),
|
|
if (!incomingOnly)
|
|
SettingsTile.switchTile(
|
|
title: Text(translate('Enable WebRTC P2P connection')),
|
|
initialValue: _enableWebrtc,
|
|
onToggle: isOptionFixed(kOptionEnableWebrtc)
|
|
? null
|
|
: (v) async {
|
|
await mainSetLocalBoolOption(kOptionEnableWebrtc, v);
|
|
final newValue =
|
|
mainGetLocalBoolOptionSync(kOptionEnableWebrtc);
|
|
setState(() {
|
|
_enableWebrtc = newValue;
|
|
});
|
|
},
|
|
),
|
|
SettingsTile(
|
|
title: Text(translate('Language')),
|
|
leading: Icon(Icons.translate),
|
|
onPressed: (context) {
|
|
showLanguageSettings(gFFI.dialogManager);
|
|
}),
|
|
SettingsTile(
|
|
title: Text(translate(
|
|
Theme.of(context).brightness == Brightness.light
|
|
? 'Light Theme'
|
|
: 'Dark Theme')),
|
|
leading: Icon(Theme.of(context).brightness == Brightness.light
|
|
? Icons.dark_mode
|
|
: Icons.light_mode),
|
|
onPressed: (context) {
|
|
showThemeSettings(gFFI.dialogManager);
|
|
},
|
|
),
|
|
if (!disabledSettings)
|
|
SettingsTile.navigation(
|
|
leading: Icon(Icons.keyboard_outlined),
|
|
title: Text(translate('Keyboard shortcuts')),
|
|
description: Text(ShortcutModel.isEnabled()
|
|
? translate('On')
|
|
: translate('Off')),
|
|
trailing: Icon(Icons.arrow_forward_ios),
|
|
onPressed: (context) {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (_) => const MobileKeyboardShortcutsPage(),
|
|
)).then((_) {
|
|
if (mounted) setState(() {});
|
|
});
|
|
},
|
|
),
|
|
if (!bind.isDisableAccount())
|
|
SettingsTile.switchTile(
|
|
title: Text(translate('note-at-conn-end-tip')),
|
|
initialValue: _allowAskForNoteAtEndOfConnection,
|
|
onToggle: (v) async {
|
|
if (v && !gFFI.userModel.isLogin) {
|
|
final res = await loginDialog();
|
|
if (res != true) return;
|
|
}
|
|
await mainSetLocalBoolOption(
|
|
kOptionAllowAskForNoteAtEndOfConnection, v);
|
|
final newValue = mainGetLocalBoolOptionSync(
|
|
kOptionAllowAskForNoteAtEndOfConnection);
|
|
setState(() {
|
|
_allowAskForNoteAtEndOfConnection = newValue;
|
|
});
|
|
},
|
|
),
|
|
if (!incomingOnly)
|
|
SettingsTile.switchTile(
|
|
title:
|
|
Text(translate('keep-awake-during-outgoing-sessions-label')),
|
|
initialValue: _preventSleepWhileConnected,
|
|
onToggle: (v) async {
|
|
await mainSetLocalBoolOption(
|
|
kOptionKeepAwakeDuringOutgoingSessions, v);
|
|
setState(() {
|
|
_preventSleepWhileConnected = v;
|
|
});
|
|
},
|
|
),
|
|
]),
|
|
if (isAndroid)
|
|
SettingsSection(title: Text(translate('Hardware Codec')), tiles: [
|
|
SettingsTile.switchTile(
|
|
title: Text(translate('Enable hardware codec')),
|
|
initialValue: _enableHardwareCodec,
|
|
onToggle: isOptionFixed(kOptionEnableHwcodec)
|
|
? null
|
|
: (v) async {
|
|
await mainSetBoolOption(kOptionEnableHwcodec, v);
|
|
final newValue =
|
|
await mainGetBoolOption(kOptionEnableHwcodec);
|
|
setState(() {
|
|
_enableHardwareCodec = newValue;
|
|
});
|
|
},
|
|
),
|
|
]),
|
|
if (isAndroid)
|
|
SettingsSection(
|
|
title: Text(translate("Recording")),
|
|
tiles: [
|
|
if (!outgoingOnly)
|
|
SettingsTile.switchTile(
|
|
title:
|
|
Text(translate('Automatically record incoming sessions')),
|
|
initialValue: _autoRecordIncomingSession,
|
|
onToggle: isOptionFixed(kOptionAllowAutoRecordIncoming)
|
|
? null
|
|
: (v) async {
|
|
await bind.mainSetOption(
|
|
key: kOptionAllowAutoRecordIncoming,
|
|
value: bool2option(
|
|
kOptionAllowAutoRecordIncoming, v));
|
|
final newValue = option2bool(
|
|
kOptionAllowAutoRecordIncoming,
|
|
await bind.mainGetOption(
|
|
key: kOptionAllowAutoRecordIncoming));
|
|
setState(() {
|
|
_autoRecordIncomingSession = newValue;
|
|
});
|
|
},
|
|
),
|
|
if (!incomingOnly)
|
|
SettingsTile.switchTile(
|
|
title:
|
|
Text(translate('Automatically record outgoing sessions')),
|
|
initialValue: _autoRecordOutgoingSession,
|
|
onToggle: isOptionFixed(kOptionAllowAutoRecordOutgoing)
|
|
? null
|
|
: (v) async {
|
|
await bind.mainSetLocalOption(
|
|
key: kOptionAllowAutoRecordOutgoing,
|
|
value: bool2option(
|
|
kOptionAllowAutoRecordOutgoing, v));
|
|
final newValue = option2bool(
|
|
kOptionAllowAutoRecordOutgoing,
|
|
bind.mainGetLocalOption(
|
|
key: kOptionAllowAutoRecordOutgoing));
|
|
setState(() {
|
|
_autoRecordOutgoingSession = newValue;
|
|
});
|
|
},
|
|
),
|
|
SettingsTile(
|
|
title: Text(translate("Directory")),
|
|
description: Text(bind.mainVideoSaveDirectory(root: false)),
|
|
),
|
|
],
|
|
),
|
|
if (isAndroid &&
|
|
!disabledSettings &&
|
|
!outgoingOnly &&
|
|
!hideSecuritySettings)
|
|
SettingsSection(title: Text('2FA'), tiles: tfaTiles),
|
|
if (isAndroid &&
|
|
!disabledSettings &&
|
|
!outgoingOnly &&
|
|
!hideSecuritySettings)
|
|
SettingsSection(
|
|
title: Text(translate("Share screen")),
|
|
tiles: shareScreenTiles,
|
|
),
|
|
if (!bind.isIncomingOnly()) defaultDisplaySection(),
|
|
if (isAndroid &&
|
|
!disabledSettings &&
|
|
!outgoingOnly &&
|
|
!hideSecuritySettings)
|
|
SettingsSection(
|
|
title: Text(translate("Enhancements")),
|
|
tiles: enhancementsTiles,
|
|
),
|
|
SettingsSection(
|
|
title: Text(translate("About")),
|
|
tiles: [
|
|
SettingsTile(
|
|
onPressed: (context) async {
|
|
await launchUrl(Uri.parse(url));
|
|
},
|
|
title: Text(translate("Version: ") + version),
|
|
value: Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 8),
|
|
child: Text('rustdesk.com',
|
|
style: TextStyle(
|
|
decoration: TextDecoration.underline,
|
|
)),
|
|
),
|
|
leading: Icon(Icons.info)),
|
|
SettingsTile(
|
|
title: Text(translate("Build Date")),
|
|
value: Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 8),
|
|
child: Text(_buildDate),
|
|
),
|
|
leading: Icon(Icons.query_builder)),
|
|
if (isAndroid)
|
|
SettingsTile(
|
|
onPressed: (context) => onCopyFingerprint(_fingerprint),
|
|
title: Text(translate("Fingerprint")),
|
|
value: Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 8),
|
|
child: Text(_fingerprint),
|
|
),
|
|
leading: Icon(Icons.fingerprint)),
|
|
SettingsTile(
|
|
onPressed: (context) => onCopyId(_myId),
|
|
title: Text(translate("ID")),
|
|
value: Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 8),
|
|
child: Text(_myId),
|
|
),
|
|
leading: Icon(Icons.perm_identity)),
|
|
SettingsTile(
|
|
title: Text(translate("Privacy Statement")),
|
|
onPressed: (context) =>
|
|
launchUrlString('https://rustdesk.com/privacy.html'),
|
|
leading: Icon(Icons.privacy_tip),
|
|
)
|
|
],
|
|
),
|
|
],
|
|
);
|
|
return settings;
|
|
}
|
|
|
|
Future<bool> canStartOnBoot() async {
|
|
// start on boot depends on ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS and SYSTEM_ALERT_WINDOW
|
|
if (_hasIgnoreBattery && !_ignoreBatteryOpt) {
|
|
return false;
|
|
}
|
|
if (!await AndroidPermissionManager.check(kSystemAlertWindow)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
defaultDisplaySection() {
|
|
return SettingsSection(
|
|
title: Text(translate("Display Settings")),
|
|
tiles: [
|
|
SettingsTile(
|
|
title: Text(translate('Display Settings')),
|
|
leading: Icon(Icons.desktop_windows_outlined),
|
|
trailing: Icon(Icons.arrow_forward_ios),
|
|
onPressed: (context) {
|
|
Navigator.push(context, MaterialPageRoute(builder: (context) {
|
|
return _DisplayPage();
|
|
}));
|
|
})
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
void showLanguageSettings(OverlayDialogManager dialogManager) async {
|
|
try {
|
|
final langs = json.decode(await bind.mainGetLangs()) as List<dynamic>;
|
|
var lang = bind.mainGetLocalOption(key: kCommConfKeyLang);
|
|
dialogManager.show((setState, close, context) {
|
|
setLang(v) async {
|
|
if (lang != v) {
|
|
setState(() {
|
|
lang = v;
|
|
});
|
|
await bind.mainSetLocalOption(key: kCommConfKeyLang, value: v);
|
|
HomePage.homeKey.currentState?.refreshPages();
|
|
Future.delayed(Duration(milliseconds: 200), close);
|
|
}
|
|
}
|
|
|
|
final isOptFixed = isOptionFixed(kCommConfKeyLang);
|
|
return CustomAlertDialog(
|
|
content: Column(
|
|
children: [
|
|
getRadio(Text(translate('Default')), defaultOptionLang, lang,
|
|
isOptFixed ? null : setLang),
|
|
Divider(color: MyTheme.border),
|
|
] +
|
|
langs.map((e) {
|
|
final key = e[0] as String;
|
|
final name = e[1] as String;
|
|
return getRadio(Text(translate(name)), key, lang,
|
|
isOptFixed ? null : setLang);
|
|
}).toList(),
|
|
),
|
|
);
|
|
}, backDismiss: true, clickMaskDismiss: true);
|
|
} catch (e) {
|
|
//
|
|
}
|
|
}
|
|
|
|
void showThemeSettings(OverlayDialogManager dialogManager) async {
|
|
var themeMode = MyTheme.getThemeModePreference();
|
|
|
|
dialogManager.show((setState, close, context) {
|
|
setTheme(v) {
|
|
if (themeMode != v) {
|
|
setState(() {
|
|
themeMode = v;
|
|
});
|
|
MyTheme.changeDarkMode(themeMode);
|
|
Future.delayed(Duration(milliseconds: 200), close);
|
|
}
|
|
}
|
|
|
|
final isOptFixed = isOptionFixed(kCommConfKeyTheme);
|
|
return CustomAlertDialog(
|
|
content: Column(children: [
|
|
getRadio(Text(translate('Light')), ThemeMode.light, themeMode,
|
|
isOptFixed ? null : setTheme),
|
|
getRadio(Text(translate('Dark')), ThemeMode.dark, themeMode,
|
|
isOptFixed ? null : setTheme),
|
|
getRadio(Text(translate('Follow System')), ThemeMode.system, themeMode,
|
|
isOptFixed ? null : setTheme)
|
|
]),
|
|
);
|
|
}, backDismiss: true, clickMaskDismiss: true);
|
|
}
|
|
|
|
void showAbout(OverlayDialogManager dialogManager) {
|
|
dialogManager.show((setState, close, context) {
|
|
return CustomAlertDialog(
|
|
title: Text(translate('About RustDesk')),
|
|
content: Wrap(direction: Axis.vertical, spacing: 12, children: [
|
|
Text('Version: $version'),
|
|
InkWell(
|
|
onTap: () async {
|
|
const url = 'https://rustdesk.com/';
|
|
await launchUrl(Uri.parse(url));
|
|
},
|
|
child: Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 8),
|
|
child: Text('rustdesk.com',
|
|
style: TextStyle(
|
|
decoration: TextDecoration.underline,
|
|
)),
|
|
)),
|
|
]),
|
|
actions: [],
|
|
);
|
|
}, clickMaskDismiss: true, backDismiss: true);
|
|
}
|
|
|
|
class ScanButton extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return IconButton(
|
|
icon: Icon(Icons.qr_code_scanner),
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (BuildContext context) => ScanPage(),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class _DisplayPage extends StatefulWidget {
|
|
const _DisplayPage();
|
|
|
|
@override
|
|
State<_DisplayPage> createState() => __DisplayPageState();
|
|
}
|
|
|
|
class __DisplayPageState extends State<_DisplayPage> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final Map codecsJson = jsonDecode(bind.mainSupportedHwdecodings());
|
|
final h264 = codecsJson['h264'] ?? false;
|
|
final h265 = codecsJson['h265'] ?? false;
|
|
var codecList = [
|
|
_RadioEntry('Auto', 'auto'),
|
|
_RadioEntry('VP8', 'vp8'),
|
|
_RadioEntry('VP9', 'vp9'),
|
|
_RadioEntry('AV1', 'av1'),
|
|
if (h264) _RadioEntry('H264', 'h264'),
|
|
if (h265) _RadioEntry('H265', 'h265')
|
|
];
|
|
RxBool showCustomImageQuality = false.obs;
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
leading: IconButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
icon: Icon(Icons.arrow_back_ios)),
|
|
title: Text(translate('Display Settings')),
|
|
centerTitle: true,
|
|
),
|
|
body: SettingsList(sections: [
|
|
SettingsSection(
|
|
tiles: [
|
|
_getPopupDialogRadioEntry(
|
|
title: 'Default View Style',
|
|
list: [
|
|
_RadioEntry('Scale original', kRemoteViewStyleOriginal),
|
|
_RadioEntry('Scale adaptive', kRemoteViewStyleAdaptive)
|
|
],
|
|
getter: () =>
|
|
bind.mainGetUserDefaultOption(key: kOptionViewStyle),
|
|
asyncSetter: isOptionFixed(kOptionViewStyle)
|
|
? null
|
|
: (value) async {
|
|
await bind.mainSetUserDefaultOption(
|
|
key: kOptionViewStyle, value: value);
|
|
},
|
|
),
|
|
_getPopupDialogRadioEntry(
|
|
title: 'Default Image Quality',
|
|
list: [
|
|
_RadioEntry('Good image quality', kRemoteImageQualityBest),
|
|
_RadioEntry('Balanced', kRemoteImageQualityBalanced),
|
|
_RadioEntry('Optimize reaction time', kRemoteImageQualityLow),
|
|
_RadioEntry('Custom', kRemoteImageQualityCustom),
|
|
],
|
|
getter: () {
|
|
final v =
|
|
bind.mainGetUserDefaultOption(key: kOptionImageQuality);
|
|
showCustomImageQuality.value = v == kRemoteImageQualityCustom;
|
|
return v;
|
|
},
|
|
asyncSetter: isOptionFixed(kOptionImageQuality)
|
|
? null
|
|
: (value) async {
|
|
await bind.mainSetUserDefaultOption(
|
|
key: kOptionImageQuality, value: value);
|
|
showCustomImageQuality.value =
|
|
value == kRemoteImageQualityCustom;
|
|
},
|
|
tail: customImageQualitySetting(),
|
|
showTail: showCustomImageQuality,
|
|
notCloseValue: kRemoteImageQualityCustom,
|
|
),
|
|
_getPopupDialogRadioEntry(
|
|
title: 'Default Codec',
|
|
list: codecList,
|
|
getter: () =>
|
|
bind.mainGetUserDefaultOption(key: kOptionCodecPreference),
|
|
asyncSetter: isOptionFixed(kOptionCodecPreference)
|
|
? null
|
|
: (value) async {
|
|
await bind.mainSetUserDefaultOption(
|
|
key: kOptionCodecPreference, value: value);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
SettingsSection(
|
|
title: Text(translate('Other Default Options')),
|
|
tiles:
|
|
otherDefaultSettings().map((e) => otherRow(e.$1, e.$2)).toList(),
|
|
),
|
|
]),
|
|
);
|
|
}
|
|
|
|
SettingsTile otherRow(String label, String key) {
|
|
final value = getOtherDefaultSettingOption(key) == 'Y';
|
|
final isOptFixed = isOtherDefaultSettingReadOnly(key);
|
|
return SettingsTile.switchTile(
|
|
initialValue: value,
|
|
title: Text(translate(label)),
|
|
onToggle: isOptFixed
|
|
? null
|
|
: (b) async {
|
|
await setOtherDefaultSettingOption(
|
|
key,
|
|
b ? 'Y' : defaultOptionNo,
|
|
);
|
|
setState(() {});
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ManageTrustedDevices extends StatefulWidget {
|
|
const _ManageTrustedDevices();
|
|
|
|
@override
|
|
State<_ManageTrustedDevices> createState() => __ManageTrustedDevicesState();
|
|
}
|
|
|
|
class __ManageTrustedDevicesState extends State<_ManageTrustedDevices> {
|
|
RxList<TrustedDevice> trustedDevices = RxList.empty(growable: true);
|
|
RxList<Uint8List> selectedDevices = RxList.empty();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(translate('Manage trusted devices')),
|
|
centerTitle: true,
|
|
actions: [
|
|
Obx(() => IconButton(
|
|
icon: Icon(Icons.delete, color: Colors.white),
|
|
onPressed: selectedDevices.isEmpty
|
|
? null
|
|
: () {
|
|
confrimDeleteTrustedDevicesDialog(
|
|
trustedDevices, selectedDevices);
|
|
}))
|
|
],
|
|
),
|
|
body: FutureBuilder(
|
|
future: TrustedDevice.get(),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return Center(child: CircularProgressIndicator());
|
|
}
|
|
if (snapshot.hasError) {
|
|
return Center(child: Text('Error: ${snapshot.error}'));
|
|
}
|
|
final devices = snapshot.data as List<TrustedDevice>;
|
|
trustedDevices = devices.obs;
|
|
return trustedDevicesTable(trustedDevices, selectedDevices);
|
|
}),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _RadioEntry {
|
|
final String label;
|
|
final String value;
|
|
_RadioEntry(this.label, this.value);
|
|
}
|
|
|
|
typedef _RadioEntryGetter = String Function();
|
|
typedef _RadioEntrySetter = Future<void> Function(String);
|
|
|
|
SettingsTile _getPopupDialogRadioEntry({
|
|
required String title,
|
|
required List<_RadioEntry> list,
|
|
required _RadioEntryGetter getter,
|
|
required _RadioEntrySetter? asyncSetter,
|
|
Widget? tail,
|
|
RxBool? showTail,
|
|
String? notCloseValue,
|
|
}) {
|
|
RxString groupValue = ''.obs;
|
|
RxString valueText = ''.obs;
|
|
|
|
init() {
|
|
groupValue.value = getter();
|
|
final e = list.firstWhereOrNull((e) => e.value == groupValue.value);
|
|
if (e != null) {
|
|
valueText.value = e.label;
|
|
}
|
|
}
|
|
|
|
init();
|
|
|
|
void showDialog() async {
|
|
gFFI.dialogManager.show((setState, close, context) {
|
|
final onChanged = asyncSetter == null
|
|
? null
|
|
: (String? value) async {
|
|
if (value == null) return;
|
|
await asyncSetter(value);
|
|
init();
|
|
if (value != notCloseValue) {
|
|
close();
|
|
}
|
|
};
|
|
|
|
return CustomAlertDialog(
|
|
content: Obx(
|
|
() => Column(children: [
|
|
...list
|
|
.map((e) => getRadio(Text(translate(e.label)), e.value,
|
|
groupValue.value, onChanged))
|
|
.toList(),
|
|
Offstage(
|
|
offstage:
|
|
!(tail != null && showTail != null && showTail.value == true),
|
|
child: tail,
|
|
),
|
|
]),
|
|
));
|
|
}, backDismiss: true, clickMaskDismiss: true);
|
|
}
|
|
|
|
return SettingsTile(
|
|
title: Text(translate(title)),
|
|
onPressed: asyncSetter == null ? null : (context) => showDialog(),
|
|
value: Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 8),
|
|
child: Obx(() => Text(translate(valueText.value))),
|
|
),
|
|
);
|
|
}
|