fix: desktop, remote toolbar, remember collapse (#8349)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
parent
12f7fc3d33
commit
07e0b5ac10
@ -496,6 +496,7 @@ class _RemotePageState extends State<RemotePage>
|
||||
() => _ffi.ffiModel.pi.isSet.isFalse
|
||||
? Container(color: Colors.transparent)
|
||||
: Obx(() {
|
||||
widget.toolbarState.initShow(sessionId);
|
||||
_ffi.textureModel.updateCurrentDisplay(peerDisplay.value);
|
||||
return ImagePaint(
|
||||
id: widget.id,
|
||||
|
@ -46,7 +46,6 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
||||
static const IconData selectedIcon = Icons.desktop_windows_sharp;
|
||||
static const IconData unselectedIcon = Icons.desktop_windows_outlined;
|
||||
|
||||
late ToolbarState _toolbarState;
|
||||
String? peerId;
|
||||
bool _isScreenRectSet = false;
|
||||
int? _display;
|
||||
@ -54,7 +53,6 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
||||
var connectionMap = RxList<Widget>.empty(growable: true);
|
||||
|
||||
_ConnectionTabPageState(Map<String, dynamic> params) {
|
||||
_toolbarState = ToolbarState();
|
||||
RemoteCountState.init();
|
||||
peerId = params['id'];
|
||||
final sessionId = params['session_id'];
|
||||
@ -91,7 +89,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
||||
display: display,
|
||||
displays: displays?.cast<int>(),
|
||||
password: params['password'],
|
||||
toolbarState: _toolbarState,
|
||||
toolbarState: ToolbarState(),
|
||||
tabController: tabController,
|
||||
switchUuid: params['switch_uuid'],
|
||||
forceRelay: params['forceRelay'],
|
||||
@ -126,7 +124,6 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_toolbarState.save();
|
||||
}
|
||||
|
||||
@override
|
||||
@ -251,15 +248,16 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
||||
final pi = ffi.ffiModel.pi;
|
||||
final perms = ffi.ffiModel.permissions;
|
||||
final sessionId = ffi.sessionId;
|
||||
final toolbarState = remotePage.toolbarState;
|
||||
menu.addAll([
|
||||
MenuEntryButton<String>(
|
||||
childBuilder: (TextStyle? style) => Obx(() => Text(
|
||||
translate(
|
||||
_toolbarState.show.isTrue ? 'Hide Toolbar' : 'Show Toolbar'),
|
||||
toolbarState.show.isTrue ? 'Hide Toolbar' : 'Show Toolbar'),
|
||||
style: style,
|
||||
)),
|
||||
proc: () {
|
||||
_toolbarState.switchShow();
|
||||
toolbarState.switchShow(sessionId);
|
||||
cancelFunc();
|
||||
},
|
||||
padding: padding,
|
||||
@ -426,8 +424,6 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
||||
});
|
||||
});
|
||||
ConnectionTypeState.init(id);
|
||||
_toolbarState.setShow(
|
||||
bind.mainGetUserDefaultOption(key: kOptionCollapseToolbar) != 'Y');
|
||||
tabController.add(TabInfo(
|
||||
key: id,
|
||||
label: id,
|
||||
@ -442,7 +438,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
||||
display: display,
|
||||
displays: displays?.cast<int>(),
|
||||
password: args['password'],
|
||||
toolbarState: _toolbarState,
|
||||
toolbarState: ToolbarState(),
|
||||
tabController: tabController,
|
||||
switchUuid: switchUuid,
|
||||
forceRelay: args['forceRelay'],
|
||||
|
@ -26,45 +26,42 @@ import './popup_menu.dart';
|
||||
import './kb_layout_type_chooser.dart';
|
||||
|
||||
class ToolbarState {
|
||||
late RxBool show;
|
||||
late RxBool _pin;
|
||||
|
||||
bool isShowInited = false;
|
||||
RxBool show = false.obs;
|
||||
|
||||
ToolbarState() {
|
||||
_pin = RxBool(false);
|
||||
final s = bind.getLocalFlutterOption(k: kOptionRemoteMenubarState);
|
||||
if (s.isEmpty) {
|
||||
_initSet(false, false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final m = jsonDecode(s);
|
||||
if (m == null) {
|
||||
_initSet(false, false);
|
||||
} else {
|
||||
_initSet(m['pin'] ?? false, m['pin'] ?? false);
|
||||
if (m != null) {
|
||||
_pin = RxBool(m['pin'] ?? false);
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Failed to decode toolbar state ${e.toString()}');
|
||||
_initSet(false, false);
|
||||
}
|
||||
}
|
||||
|
||||
_initSet(bool s, bool p) {
|
||||
// Show remubar when connection is established.
|
||||
show = RxBool(
|
||||
bind.mainGetUserDefaultOption(key: kOptionCollapseToolbar) != 'Y');
|
||||
_pin = RxBool(p);
|
||||
}
|
||||
|
||||
bool get pin => _pin.value;
|
||||
|
||||
switchShow() async {
|
||||
switchShow(SessionID sessionId) async {
|
||||
bind.sessionToggleOption(
|
||||
sessionId: sessionId, value: kOptionCollapseToolbar);
|
||||
show.value = !show.value;
|
||||
}
|
||||
|
||||
setShow(bool v) async {
|
||||
if (show.value != v) {
|
||||
show.value = v;
|
||||
initShow(SessionID sessionId) async {
|
||||
if (!isShowInited) {
|
||||
show.value = !(await bind.sessionGetToggleOption(
|
||||
sessionId: sessionId, arg: kOptionCollapseToolbar) ??
|
||||
false);
|
||||
isShowInited = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,10 +83,6 @@ class ToolbarState {
|
||||
bind.setLocalFlutterOption(
|
||||
k: kOptionRemoteMenubarState, v: jsonEncode({'pin': _pin.value}));
|
||||
}
|
||||
|
||||
save() async {
|
||||
await _savePin();
|
||||
}
|
||||
}
|
||||
|
||||
class _ToolbarTheme {
|
||||
@ -446,7 +439,7 @@ class _RemoteToolbarState extends State<RemoteToolbar> {
|
||||
sessionId: widget.ffi.sessionId,
|
||||
dragging: _dragging,
|
||||
fractionX: _fractionX,
|
||||
show: show,
|
||||
toolbarState: widget.state,
|
||||
setFullscreen: _setFullscreen,
|
||||
setMinimize: _minimize,
|
||||
borderRadius: borderRadius,
|
||||
@ -2343,7 +2336,7 @@ class _DraggableShowHide extends StatefulWidget {
|
||||
final SessionID sessionId;
|
||||
final RxDouble fractionX;
|
||||
final RxBool dragging;
|
||||
final RxBool show;
|
||||
final ToolbarState toolbarState;
|
||||
final BorderRadius borderRadius;
|
||||
|
||||
final Function(bool) setFullscreen;
|
||||
@ -2354,7 +2347,7 @@ class _DraggableShowHide extends StatefulWidget {
|
||||
required this.sessionId,
|
||||
required this.fractionX,
|
||||
required this.dragging,
|
||||
required this.show,
|
||||
required this.toolbarState,
|
||||
required this.setFullscreen,
|
||||
required this.setMinimize,
|
||||
required this.borderRadius,
|
||||
@ -2370,6 +2363,8 @@ class _DraggableShowHideState extends State<_DraggableShowHide> {
|
||||
double left = 0.0;
|
||||
double right = 1.0;
|
||||
|
||||
RxBool get show => widget.toolbarState.show;
|
||||
|
||||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
@ -2473,13 +2468,13 @@ class _DraggableShowHideState extends State<_DraggableShowHide> {
|
||||
)),
|
||||
TextButton(
|
||||
onPressed: () => setState(() {
|
||||
widget.show.value = !widget.show.value;
|
||||
widget.toolbarState.switchShow(widget.sessionId);
|
||||
}),
|
||||
child: Obx((() => Tooltip(
|
||||
message: translate(
|
||||
widget.show.isTrue ? 'Hide Toolbar' : 'Show Toolbar'),
|
||||
message:
|
||||
translate(show.isTrue ? 'Hide Toolbar' : 'Show Toolbar'),
|
||||
child: Icon(
|
||||
widget.show.isTrue ? Icons.expand_less : Icons.expand_more,
|
||||
show.isTrue ? Icons.expand_less : Icons.expand_more,
|
||||
size: iconSize,
|
||||
),
|
||||
))),
|
||||
|
@ -1284,6 +1284,7 @@ impl PeerConfig {
|
||||
keys::OPTION_TOUCH_MODE,
|
||||
keys::OPTION_I444,
|
||||
keys::OPTION_SWAP_LEFT_RIGHT_MOUSE,
|
||||
keys::OPTION_COLLAPSE_TOOLBAR,
|
||||
]
|
||||
.map(|key| {
|
||||
mp.insert(key.to_owned(), UserDefaultConfig::read(key));
|
||||
|
Loading…
x
Reference in New Issue
Block a user