From ec4a95f906bbb8ece21e429fc66893ed01092893 Mon Sep 17 00:00:00 2001 From: NicKoehler Date: Thu, 18 May 2023 11:41:16 +0200 Subject: [PATCH] replaced buttons with switches --- flutter/lib/consts.dart | 3 +- flutter/lib/desktop/pages/server_page.dart | 38 +++++++++++----------- flutter/lib/main.dart | 10 +++--- flutter/lib/models/chat_model.dart | 5 +-- flutter/test/cm_test.dart | 6 ++-- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/flutter/lib/consts.dart b/flutter/lib/consts.dart index 827fd3b3f..1facf4e4b 100644 --- a/flutter/lib/consts.dart +++ b/flutter/lib/consts.dart @@ -76,7 +76,8 @@ extension StringExtension on String { String get nonBreaking => replaceAll(' ', String.fromCharCode($nbsp)); } -const Size kConnectionManagerWindowSize = Size(300, 400); +const Size kConnectionManagerWindowSizeClosedChat = Size(300, 500); +const Size kConnectionManagerWindowSizeOpenChat = Size(600, 500); // Tabbar transition duration, now we remove the duration const Duration kTabTransitionDuration = Duration.zero; const double kEmptyMarginTop = 50; diff --git a/flutter/lib/desktop/pages/server_page.dart b/flutter/lib/desktop/pages/server_page.dart index 45591b79b..ff35fa69f 100644 --- a/flutter/lib/desktop/pages/server_page.dart +++ b/flutter/lib/desktop/pages/server_page.dart @@ -408,17 +408,12 @@ class _PrivilegeBoard extends StatefulWidget { class _PrivilegeBoardState extends State<_PrivilegeBoard> { late final client = widget.client; - Widget buildPermissionIcon( - bool enabled, ImageProvider icon, Function(bool)? onTap, String tooltip) { - return Tooltip( - message: tooltip, - child: Ink( - decoration: - BoxDecoration(color: enabled ? MyTheme.accent80 : Colors.grey), - padding: EdgeInsets.all(4.0), - child: InkWell( - onTap: () => - checkClickTime(widget.client.id, () => onTap?.call(!enabled)), + Widget buildPermissionTile(bool enabled, ImageProvider icon, + Function(bool)? onTap, String tooltipText) { + return Row( + children: [ + Tooltip( + message: tooltipText, child: Image( image: icon, width: 50, @@ -426,7 +421,12 @@ class _PrivilegeBoardState extends State<_PrivilegeBoard> { fit: BoxFit.scaleDown, ), ), - ).marginSymmetric(horizontal: 4.0), + Switch( + value: enabled, + onChanged: (v) => + checkClickTime(widget.client.id, () => onTap?.call(v)), + ), + ], ); } @@ -445,44 +445,44 @@ class _PrivilegeBoardState extends State<_PrivilegeBoard> { height: 8.0, ), FittedBox( - child: Row( + child: Column( children: [ - buildPermissionIcon(client.keyboard, iconKeyboard, (enabled) { + buildPermissionTile(client.keyboard, iconKeyboard, (enabled) { bind.cmSwitchPermission( connId: client.id, name: "keyboard", enabled: enabled); setState(() { client.keyboard = enabled; }); }, translate('Allow using keyboard and mouse')), - buildPermissionIcon(client.clipboard, iconClipboard, (enabled) { + buildPermissionTile(client.clipboard, iconClipboard, (enabled) { bind.cmSwitchPermission( connId: client.id, name: "clipboard", enabled: enabled); setState(() { client.clipboard = enabled; }); }, translate('Allow using clipboard')), - buildPermissionIcon(client.audio, iconAudio, (enabled) { + buildPermissionTile(client.audio, iconAudio, (enabled) { bind.cmSwitchPermission( connId: client.id, name: "audio", enabled: enabled); setState(() { client.audio = enabled; }); }, translate('Allow hearing sound')), - buildPermissionIcon(client.file, iconFile, (enabled) { + buildPermissionTile(client.file, iconFile, (enabled) { bind.cmSwitchPermission( connId: client.id, name: "file", enabled: enabled); setState(() { client.file = enabled; }); }, translate('Allow file copy and paste')), - buildPermissionIcon(client.restart, iconRestart, (enabled) { + buildPermissionTile(client.restart, iconRestart, (enabled) { bind.cmSwitchPermission( connId: client.id, name: "restart", enabled: enabled); setState(() { client.restart = enabled; }); }, translate('Allow remote restart')), - buildPermissionIcon(client.recording, iconRecording, (enabled) { + buildPermissionTile(client.recording, iconRecording, (enabled) { bind.cmSwitchPermission( connId: client.id, name: "recording", enabled: enabled); setState(() { diff --git a/flutter/lib/main.dart b/flutter/lib/main.dart index 318f9c2cc..3dca92a2e 100644 --- a/flutter/lib/main.dart +++ b/flutter/lib/main.dart @@ -233,21 +233,21 @@ void runConnectionManagerScreen(bool hide) async { } void showCmWindow() { - WindowOptions windowOptions = - getHiddenTitleBarWindowOptions(size: kConnectionManagerWindowSize); + WindowOptions windowOptions = getHiddenTitleBarWindowOptions( + size: kConnectionManagerWindowSizeClosedChat); windowManager.waitUntilReadyToShow(windowOptions, () async { bind.mainHideDocker(); await windowManager.show(); await Future.wait([windowManager.focus(), windowManager.setOpacity(1)]); // ensure initial window size to be changed await windowManager.setSizeAlignment( - kConnectionManagerWindowSize, Alignment.topRight); + kConnectionManagerWindowSizeClosedChat, Alignment.topRight); }); } void hideCmWindow() { - WindowOptions windowOptions = - getHiddenTitleBarWindowOptions(size: kConnectionManagerWindowSize); + WindowOptions windowOptions = getHiddenTitleBarWindowOptions( + size: kConnectionManagerWindowSizeClosedChat); windowManager.setOpacity(0); windowManager.waitUntilReadyToShow(windowOptions, () async { bind.mainHideDocker(); diff --git a/flutter/lib/models/chat_model.dart b/flutter/lib/models/chat_model.dart index 9db5a1571..99ffcd220 100644 --- a/flutter/lib/models/chat_model.dart +++ b/flutter/lib/models/chat_model.dart @@ -203,11 +203,12 @@ class ChatModel with ChangeNotifier { notifyListeners(); await windowManager.show(); await windowManager.setSizeAlignment( - kConnectionManagerWindowSize, Alignment.topRight); + kConnectionManagerWindowSizeClosedChat, Alignment.topRight); } else { requestChatInputFocus(); await windowManager.show(); - await windowManager.setSizeAlignment(Size(600, 400), Alignment.topRight); + await windowManager.setSizeAlignment( + kConnectionManagerWindowSizeOpenChat, Alignment.topRight); _isShowCMChatPage = !_isShowCMChatPage; notifyListeners(); } diff --git a/flutter/test/cm_test.dart b/flutter/test/cm_test.dart index 2c037c7b0..fca9d8cee 100644 --- a/flutter/test/cm_test.dart +++ b/flutter/test/cm_test.dart @@ -45,12 +45,12 @@ void main(List args) async { ], supportedLocales: supportedLocales, home: const DesktopServerPage())); - WindowOptions windowOptions = - getHiddenTitleBarWindowOptions(size: kConnectionManagerWindowSize); + WindowOptions windowOptions = getHiddenTitleBarWindowOptions( + size: kConnectionManagerWindowSizeClosedChat); windowManager.waitUntilReadyToShow(windowOptions, () async { await windowManager.show(); // ensure initial window size to be changed - await windowManager.setSize(kConnectionManagerWindowSize); + await windowManager.setSize(kConnectionManagerWindowSizeClosedChat); await Future.wait([ windowManager.setAlignment(Alignment.topRight), windowManager.focus(),