From ce1a504e9fdc564a1d42ec8034f01f9baf05f5a3 Mon Sep 17 00:00:00 2001 From: fufesou Date: Wed, 31 Aug 2022 23:02:02 -0700 Subject: [PATCH] flutter_desktop: custom image quality Signed-off-by: fufesou --- flutter/.gitignore | 2 +- flutter/lib/common.dart | 14 +++--- .../lib/desktop/widgets/remote_menubar.dart | 45 ++++++++++--------- flutter/pubspec.yaml | 1 + 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/flutter/.gitignore b/flutter/.gitignore index e5db34d22..ec3fef74e 100644 --- a/flutter/.gitignore +++ b/flutter/.gitignore @@ -48,7 +48,7 @@ lib/generated_bridge.dart lib/generated_bridge.freezed.dart # Flutter Generated Files -**/flutter/GeneratedPluginRegistrant.swift +**/GeneratedPluginRegistrant.swift **/flutter/generated_plugin_registrant.cc **/flutter/generated_plugin_registrant.h **/flutter/generated_plugins.cmake diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index e8632caaa..75328c840 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -432,7 +432,7 @@ void msgBox( if (type != "connecting" && type != "success" && !type.contains("nook")) { buttons.insert( 0, - getMsgBoxButton(translate('OK'), () { + msgBoxButton(translate('OK'), () { dialogManager.dismissAll(); // https://github.com/fufesou/rustdesk/blob/5e9a31340b899822090a3731769ae79c6bf5f3e5/src/ui/common.tis#L263 if (!type.contains("custom")) { @@ -446,7 +446,7 @@ void msgBox( if (hasCancel) { buttons.insert( 0, - getMsgBoxButton(translate('Cancel'), () { + msgBoxButton(translate('Cancel'), () { dialogManager.dismissAll(); })); } @@ -454,17 +454,17 @@ void msgBox( if (type.contains("hasclose")) { buttons.insert( 0, - getMsgBoxButton(translate('Close'), () { + msgBoxButton(translate('Close'), () { dialogManager.dismissAll(); })); } dialogManager.show((setState, close) => CustomAlertDialog( - title: Text(translate(title), style: TextStyle(fontSize: 21)), + title: _msgBoxTitle(title), content: Text(translate(text), style: TextStyle(fontSize: 15)), actions: buttons)); } -Widget getMsgBoxButton(String text, void Function() onPressed) { +Widget msgBoxButton(String text, void Function() onPressed) { return ButtonTheme( padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10), materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, @@ -479,11 +479,13 @@ Widget getMsgBoxButton(String text, void Function() onPressed) { Text(translate(text), style: TextStyle(color: MyTheme.accent)))); } +Widget _msgBoxTitle(String title) => Text(translate(title), style: TextStyle(fontSize: 21)); + void msgBoxCommon(OverlayDialogManager dialogManager, String title, Widget content, List buttons) { dialogManager.dismissAll(); dialogManager.show((setState, close) => CustomAlertDialog( - title: Text(translate(title), style: TextStyle(fontSize: 21)), + title: _msgBoxTitle(title), content: content, actions: buttons)); } diff --git a/flutter/lib/desktop/widgets/remote_menubar.dart b/flutter/lib/desktop/widgets/remote_menubar.dart index 26789ac4f..66edb7a96 100644 --- a/flutter/lib/desktop/widgets/remote_menubar.dart +++ b/flutter/lib/desktop/widgets/remote_menubar.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_hbb/models/chat_model.dart'; import 'package:get/get.dart'; -import 'package:tuple/tuple.dart'; +import 'package:rxdart/rxdart.dart' as rxdart; import '../../common.dart'; import '../../mobile/widgets/dialog.dart'; @@ -467,7 +467,7 @@ class _RemoteMenubarState extends State { } if (newValue == 'custom') { - final btnCancel = getMsgBoxButton(translate('Cancel'), () { + final btnCancel = msgBoxButton(translate('Close'), () { widget.ffi.dialogManager.dismissAll(); }); final quality = @@ -475,26 +475,29 @@ class _RemoteMenubarState extends State { final double initValue = quality != null && quality.isNotEmpty ? quality[0].toDouble() : 50.0; - // final slider = _ImageCustomQualitySlider( - // id: widget.id, v: RxDouble(initValue)); final RxDouble sliderValue = RxDouble(initValue); - final slider = Obx(() => Slider( - value: sliderValue.value, - max: 100, - label: sliderValue.value.round().toString(), - onChanged: (double value) { - () async { - await bind.sessionSetCustomImageQuality( - id: widget.id, value: value.toInt()); - final quality = await bind.sessionGetCustomImageQuality( - id: widget.id); - sliderValue.value = - quality != null && quality.isNotEmpty - ? quality[0].toDouble() - : 50.0; - }(); - }, - )); + final rxReplay = rxdart.ReplaySubject(); + rxReplay + .throttleTime(const Duration(milliseconds: 1000), + trailing: true, leading: false) + .listen((double v) { + () async { + await bind.sessionSetCustomImageQuality( + id: widget.id, value: v.toInt()); + }(); + }); + final slider = Obx(() { + return Slider( + value: sliderValue.value, + max: 100, + divisions: 100, + label: sliderValue.value.round().toString(), + onChanged: (double value) { + sliderValue.value = value; + rxReplay.add(value); + }, + ); + }); msgBoxCommon(widget.ffi.dialogManager, 'Custom Image Quality', slider, [btnCancel]); } diff --git a/flutter/pubspec.yaml b/flutter/pubspec.yaml index a35f1c872..b6ce5d20b 100644 --- a/flutter/pubspec.yaml +++ b/flutter/pubspec.yaml @@ -73,6 +73,7 @@ dependencies: contextmenu: ^3.0.0 desktop_drop: ^0.3.3 scroll_pos: ^0.3.0 + rxdart: ^0.27.5 dev_dependencies: flutter_launcher_icons: ^0.9.1