Skip to content

Commit

Permalink
Refact. Flutter web, mid commit (rustdesk#7494)
Browse files Browse the repository at this point in the history
Signed-off-by: fufesou <[email protected]>
  • Loading branch information
fufesou authored Mar 24, 2024
1 parent 96e1b5b commit 85cafda
Show file tree
Hide file tree
Showing 33 changed files with 298 additions and 152 deletions.
9 changes: 6 additions & 3 deletions flutter/lib/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,12 @@ closeConnection({String? id}) {
gFFI.chatModel.hideChatOverlay();
Navigator.popUntil(globalKey.currentContext!, ModalRoute.withName("/"));
} else {
final controller = Get.find<DesktopTabController>();
controller.closeBy(id);
if (isWeb) {
Navigator.popUntil(globalKey.currentContext!, ModalRoute.withName("/"));
} else {
final controller = Get.find<DesktopTabController>();
controller.closeBy(id);
}
}
}

Expand Down Expand Up @@ -2980,7 +2984,6 @@ Future<bool> setServerConfig(
await bind.mainSetOption(key: 'relay-server', value: config.relayServer);
await bind.mainSetOption(key: 'api-server', value: config.apiServer);
await bind.mainSetOption(key: 'key', value: config.key);

final newApiServer = await bind.mainGetApiServer();
if (oldApiServer.isNotEmpty &&
oldApiServer != newApiServer &&
Expand Down
4 changes: 2 additions & 2 deletions flutter/lib/common/widgets/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ class _DialogVerificationCodeField extends State<DialogVerificationCodeField> {

// software secure keyboard will take the focus since flutter 3.13
// request focus again when android account password obtain focus
if (Platform.isAndroid && widget.reRequestFocus) {
if (isAndroid && widget.reRequestFocus) {
_focusNode.addListener(() {
if (_focusNode.hasFocus) {
_timerReRequestFocus?.cancel();
Expand Down Expand Up @@ -694,7 +694,7 @@ class _PasswordWidgetState extends State<PasswordWidget> {
}
// software secure keyboard will take the focus since flutter 3.13
// request focus again when android account password obtain focus
if (Platform.isAndroid && widget.reRequestFocus) {
if (isAndroid && widget.reRequestFocus) {
_focusNode.addListener(() {
if (_focusNode.hasFocus) {
_timerReRequestFocus?.cancel();
Expand Down
22 changes: 10 additions & 12 deletions flutter/lib/common/widgets/peer_card.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:io';

import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -875,10 +873,10 @@ class RecentPeerCard extends BasePeerCard {
}
// menuItems.add(await _openNewConnInOptAction(peer.id));
menuItems.add(await _forceAlwaysRelayAction(peer.id));
if (Platform.isWindows && peer.platform == kPeerPlatformWindows) {
if (isWindows && peer.platform == kPeerPlatformWindows) {
menuItems.add(_rdpAction(context, peer.id));
}
if (Platform.isWindows) {
if (isWindows) {
menuItems.add(_createShortCutAction(peer.id));
}
menuItems.add(MenuEntryDivider());
Expand Down Expand Up @@ -927,10 +925,10 @@ class FavoritePeerCard extends BasePeerCard {
}
// menuItems.add(await _openNewConnInOptAction(peer.id));
menuItems.add(await _forceAlwaysRelayAction(peer.id));
if (Platform.isWindows && peer.platform == kPeerPlatformWindows) {
if (isWindows && peer.platform == kPeerPlatformWindows) {
menuItems.add(_rdpAction(context, peer.id));
}
if (Platform.isWindows) {
if (isWindows) {
menuItems.add(_createShortCutAction(peer.id));
}
menuItems.add(MenuEntryDivider());
Expand Down Expand Up @@ -979,11 +977,11 @@ class DiscoveredPeerCard extends BasePeerCard {
}
// menuItems.add(await _openNewConnInOptAction(peer.id));
menuItems.add(await _forceAlwaysRelayAction(peer.id));
if (Platform.isWindows && peer.platform == kPeerPlatformWindows) {
if (isWindows && peer.platform == kPeerPlatformWindows) {
menuItems.add(_rdpAction(context, peer.id));
}
menuItems.add(_wolAction(peer.id));
if (Platform.isWindows) {
if (isWindows) {
menuItems.add(_createShortCutAction(peer.id));
}

Expand Down Expand Up @@ -1027,10 +1025,10 @@ class AddressBookPeerCard extends BasePeerCard {
}
// menuItems.add(await _openNewConnInOptAction(peer.id));
// menuItems.add(await _forceAlwaysRelayAction(peer.id));
if (Platform.isWindows && peer.platform == kPeerPlatformWindows) {
if (isWindows && peer.platform == kPeerPlatformWindows) {
menuItems.add(_rdpAction(context, peer.id));
}
if (Platform.isWindows) {
if (isWindows) {
menuItems.add(_createShortCutAction(peer.id));
}
if (gFFI.abModel.current.canWrite()) {
Expand Down Expand Up @@ -1154,10 +1152,10 @@ class MyGroupPeerCard extends BasePeerCard {
}
// menuItems.add(await _openNewConnInOptAction(peer.id));
// menuItems.add(await _forceAlwaysRelayAction(peer.id));
if (Platform.isWindows && peer.platform == kPeerPlatformWindows) {
if (isWindows && peer.platform == kPeerPlatformWindows) {
menuItems.add(_rdpAction(context, peer.id));
}
if (Platform.isWindows) {
if (isWindows) {
menuItems.add(_createShortCutAction(peer.id));
}
// menuItems.add(MenuEntryDivider());
Expand Down
5 changes: 2 additions & 3 deletions flutter/lib/common/widgets/toolbar.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:convert';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -633,8 +632,8 @@ List<TToggleMenu> toolbarKeyboardToggles(FFI ffi) {

// swap key
if (ffiModel.keyboard &&
((Platform.isMacOS && pi.platform != kPeerPlatformMacOS) ||
(!Platform.isMacOS && pi.platform == kPeerPlatformMacOS))) {
((isMacOS && pi.platform != kPeerPlatformMacOS) ||
(!isMacOS && pi.platform == kPeerPlatformMacOS))) {
final option = 'allow_swap_key';
final value =
bind.sessionGetToggleOptionSync(sessionId: sessionId, arg: option);
Expand Down
10 changes: 5 additions & 5 deletions flutter/lib/consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ const double kDefaultQuality = 50;
const double kMaxQuality = 100;
const double kMaxMoreQuality = 2000;

double kNewWindowOffset = Platform.isWindows
double kNewWindowOffset = isWindows
? 56.0
: Platform.isLinux
: isLinux
? 50.0
: Platform.isMacOS
: isMacOS
? 30.0
: 50.0;

EdgeInsets get kDragToResizeAreaPadding =>
!kUseCompatibleUiMode && Platform.isLinux
!kUseCompatibleUiMode && isLinux
? stateGlobal.fullscreen.isTrue || stateGlobal.isMaximized.value
? EdgeInsets.zero
: EdgeInsets.all(5.0)
Expand Down Expand Up @@ -152,7 +152,7 @@ const kDefaultScrollDuration = Duration(milliseconds: 50);
const kDefaultMouseWheelThrottleDuration = Duration(milliseconds: 50);
const kFullScreenEdgeSize = 0.0;
const kMaximizeEdgeSize = 0.0;
var kWindowEdgeSize = Platform.isWindows ? 1.0 : 5.0;
var kWindowEdgeSize = isWindows ? 1.0 : 5.0;
const kWindowBorderWidth = 1.0;
const kDesktopMenuPadding = EdgeInsets.only(left: 12.0, right: 3.0);

Expand Down
3 changes: 1 addition & 2 deletions flutter/lib/desktop/pages/connection_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -231,7 +230,7 @@ class _ConnectionPageState extends State<ConnectionPage>
if (eventName == 'minimize') {
isWindowMinimized = true;
} else if (eventName == 'maximize' || eventName == 'restore') {
if (isWindowMinimized && Platform.isWindows) {
if (isWindowMinimized && isWindows) {
// windows can't update when minimized.
Get.forceAppUpdate();
}
Expand Down
10 changes: 5 additions & 5 deletions flutter/lib/desktop/pages/desktop_home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
return buildInstallCard("", systemError, "", () {});
}

if (Platform.isWindows && !bind.isDisableInstallation()) {
if (isWindows && !bind.isDisableInstallation()) {
if (!bind.mainIsInstalled()) {
return buildInstallCard(
"", bind.isOutgoingOnly() ? "" : "install_tip", "Install",
Expand All @@ -485,7 +485,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
bind.mainUpdateMe();
});
}
} else if (Platform.isMacOS) {
} else if (isMacOS) {
if (!(bind.isOutgoingOnly() ||
bind.mainIsCanScreenRecording(prompt: false))) {
return buildInstallCard("Permissions", "config_screen", "Configure",
Expand Down Expand Up @@ -521,7 +521,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
// watchIsCanRecordAudio = true;
// });
// }
} else if (Platform.isLinux) {
} else if (isLinux) {
if (bind.isOutgoingOnly()) {
return Container();
}
Expand Down Expand Up @@ -570,7 +570,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
onPressed: () {
SystemNavigator.pop(); // Close the application
// https://github.com/flutter/flutter/issues/66631
if (Platform.isWindows) {
if (isWindows) {
exit(0);
}
},
Expand Down Expand Up @@ -740,7 +740,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
}
}
if (watchIsCanRecordAudio) {
if (Platform.isMacOS) {
if (isMacOS) {
Future.microtask(() async {
if ((await osxCanRecordAudio() ==
PermissionAuthorizeType.authorized)) {
Expand Down
8 changes: 4 additions & 4 deletions flutter/lib/desktop/pages/desktop_setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ class _GeneralState extends State<_General> {
}

String getDefault() {
if (Platform.isWindows) return translate('System Sound');
if (isWindows) return translate('System Sound');
return '';
}

Expand All @@ -434,7 +434,7 @@ class _GeneralState extends State<_General> {

return futureBuilder(future: () async {
List<String> devices = (await bind.mainGetSoundInputs()).toList();
if (Platform.isWindows) {
if (isWindows) {
devices.insert(0, translate('System Sound'));
}
String current = await getValue();
Expand Down Expand Up @@ -705,7 +705,7 @@ class _SafetyState extends State<_Safety> with AutomaticKeepAliveClientMixin {
_OptionCheckBox(
context, 'Enable recording session', 'enable-record-session',
enabled: enabled, fakeValue: fakeValue),
if (Platform.isWindows)
if (isWindows)
_OptionCheckBox(
context, 'Enable blocking user input', 'enable-block-input',
enabled: enabled, fakeValue: fakeValue),
Expand Down Expand Up @@ -845,7 +845,7 @@ class _SafetyState extends State<_Safety> with AutomaticKeepAliveClientMixin {

bool value = bind.mainIsShareRdp();
return Offstage(
offstage: !(Platform.isWindows && bind.mainIsInstalled()),
offstage: !(isWindows && bind.mainIsInstalled()),
child: GestureDetector(
child: Row(
children: [
Expand Down
2 changes: 1 addition & 1 deletion flutter/lib/desktop/pages/desktop_tab_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class _DesktopTabPageState extends State<DesktopTabPage> {
),
),
)));
return Platform.isMacOS || kUseCompatibleUiMode
return isMacOS || kUseCompatibleUiMode
? tabWidget
: Obx(
() => DragToResizeArea(
Expand Down
6 changes: 3 additions & 3 deletions flutter/lib/desktop/pages/file_manager_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class _FileManagerPageState extends State<FileManagerPage>
.showLoading(translate('Connecting...'), onCancel: closeConnection);
});
Get.put(_ffi, tag: 'ft_${widget.id}');
if (!Platform.isLinux) {
if (!isLinux) {
WakelockPlus.enable();
}
debugPrint("File manager page init success with id ${widget.id}");
Expand All @@ -106,7 +106,7 @@ class _FileManagerPageState extends State<FileManagerPage>
model.close().whenComplete(() {
_ffi.close();
_ffi.dialogManager.dismissAll();
if (!Platform.isLinux) {
if (!isLinux) {
WakelockPlus.disable();
}
Get.delete<FFI>(tag: 'ft_${widget.id}');
Expand Down Expand Up @@ -1298,7 +1298,7 @@ class _FileManagerViewState extends State<FileManagerView> {
onPointerSignal: (e) {
if (e is PointerScrollEvent) {
final sc = _breadCrumbScroller;
final scale = Platform.isWindows ? 2 : 4;
final scale = isWindows ? 2 : 4;
sc.jumpTo(sc.offset + e.scrollDelta.dy / scale);
}
},
Expand Down
3 changes: 1 addition & 2 deletions flutter/lib/desktop/pages/file_manager_tab_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:convert';
import 'dart:io';

import 'package:desktop_multi_window/desktop_multi_window.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -104,7 +103,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
labelGetter: DesktopTab.tablabelGetter,
)),
);
return Platform.isMacOS || kUseCompatibleUiMode
return isMacOS || kUseCompatibleUiMode
? tabWidget
: SubWindowDragToResizeArea(
child: tabWidget,
Expand Down
3 changes: 1 addition & 2 deletions flutter/lib/desktop/pages/port_forward_tab_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:convert';
import 'dart:io';

import 'package:desktop_multi_window/desktop_multi_window.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -113,7 +112,7 @@ class _PortForwardTabPageState extends State<PortForwardTabPage> {
labelGetter: DesktopTab.tablabelGetter,
)),
);
return Platform.isMacOS || kUseCompatibleUiMode
return isMacOS || kUseCompatibleUiMode
? tabWidget
: Obx(
() => SubWindowDragToResizeArea(
Expand Down
Loading

0 comments on commit 85cafda

Please sign in to comment.