Skip to content

Commit

Permalink
Merge pull request #9 from rustdesk/master
Browse files Browse the repository at this point in the history
sync master
  • Loading branch information
eltorio authored Mar 28, 2024
2 parents 21064ac + 6186b41 commit 4c04b54
Show file tree
Hide file tree
Showing 29 changed files with 410 additions and 183 deletions.
81 changes: 53 additions & 28 deletions flutter/lib/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import '../consts.dart';
import 'common/widgets/overlay.dart';
import 'mobile/pages/file_manager_page.dart';
import 'mobile/pages/remote_page.dart';
import 'desktop/pages/remote_page.dart' as desktop_remote;
import 'package:flutter_hbb/desktop/widgets/remote_toolbar.dart';
import 'models/input_model.dart';
import 'models/model.dart';
import 'models/platform_model.dart';
Expand All @@ -48,7 +50,7 @@ final isMacOS = isMacOS_;
final isLinux = isLinux_;
final isDesktop = isDesktop_;
final isWeb = isWeb_;
var isWebDesktop = false;
final isWebDesktop = isWebDesktop_;
var isMobile = isAndroid || isIOS;
var version = '';
int androidVersion = 0;
Expand All @@ -60,6 +62,8 @@ DesktopType? desktopType;
bool get isMainDesktopWindow =>
desktopType == DesktopType.main || desktopType == DesktopType.cm;

String get screenInfo => screenInfo_;

/// Check if the app is running with single view mode.
bool isSingleViewApp() {
return desktopType == DesktopType.cm;
Expand Down Expand Up @@ -233,11 +237,13 @@ class MyTheme {
);

static SwitchThemeData switchTheme() {
return SwitchThemeData(splashRadius: isDesktop ? 0 : kRadialReactionRadius);
return SwitchThemeData(
splashRadius: (isDesktop || isWebDesktop) ? 0 : kRadialReactionRadius);
}

static RadioThemeData radioTheme() {
return RadioThemeData(splashRadius: isDesktop ? 0 : kRadialReactionRadius);
return RadioThemeData(
splashRadius: (isDesktop || isWebDesktop) ? 0 : kRadialReactionRadius);
}

// Checkbox
Expand Down Expand Up @@ -286,20 +292,20 @@ class MyTheme {
static EdgeInsets dialogContentPadding({bool actions = true}) {
final double p = dialogPadding;

return isDesktop
return (isDesktop || isWebDesktop)
? EdgeInsets.fromLTRB(p, p, p, actions ? (p - 4) : p)
: EdgeInsets.fromLTRB(p, p, p, actions ? (p / 2) : p);
}

static EdgeInsets dialogActionsPadding() {
final double p = dialogPadding;

return isDesktop
return (isDesktop || isWebDesktop)
? EdgeInsets.fromLTRB(p, 0, p, (p - 4))
: EdgeInsets.fromLTRB(p, 0, (p - mobileTextButtonPaddingLR), (p / 2));
}

static EdgeInsets dialogButtonPadding = isDesktop
static EdgeInsets dialogButtonPadding = (isDesktop || isWebDesktop)
? EdgeInsets.only(left: dialogPadding)
: EdgeInsets.only(left: dialogPadding / 3);

Expand Down Expand Up @@ -371,10 +377,10 @@ class MyTheme {
labelColor: Colors.black87,
),
tooltipTheme: tooltipTheme(),
splashColor: isDesktop ? Colors.transparent : null,
highlightColor: isDesktop ? Colors.transparent : null,
splashFactory: isDesktop ? NoSplash.splashFactory : null,
textButtonTheme: isDesktop
splashColor: (isDesktop || isWebDesktop) ? Colors.transparent : null,
highlightColor: (isDesktop || isWebDesktop) ? Colors.transparent : null,
splashFactory: (isDesktop || isWebDesktop) ? NoSplash.splashFactory : null,
textButtonTheme: (isDesktop || isWebDesktop)
? TextButtonThemeData(
style: TextButton.styleFrom(
splashFactory: NoSplash.splashFactory,
Expand Down Expand Up @@ -414,7 +420,9 @@ class MyTheme {
color: Colors.white,
shape: RoundedRectangleBorder(
side: BorderSide(
color: isDesktop ? Color(0xFFECECEC) : Colors.transparent),
color: (isDesktop || isWebDesktop)
? Color(0xFFECECEC)
: Colors.transparent),
borderRadius: BorderRadius.all(Radius.circular(8.0)),
)),
).copyWith(
Expand All @@ -440,7 +448,7 @@ class MyTheme {
),
),
scrollbarTheme: scrollbarThemeDark,
inputDecorationTheme: isDesktop
inputDecorationTheme: (isDesktop || isWebDesktop)
? InputDecorationTheme(
fillColor: Color(0xFF24252B),
filled: true,
Expand All @@ -467,10 +475,10 @@ class MyTheme {
labelColor: Colors.white70,
),
tooltipTheme: tooltipTheme(),
splashColor: isDesktop ? Colors.transparent : null,
highlightColor: isDesktop ? Colors.transparent : null,
splashFactory: isDesktop ? NoSplash.splashFactory : null,
textButtonTheme: isDesktop
splashColor: (isDesktop || isWebDesktop) ? Colors.transparent : null,
highlightColor: (isDesktop || isWebDesktop) ? Colors.transparent : null,
splashFactory: (isDesktop || isWebDesktop) ? NoSplash.splashFactory : null,
textButtonTheme: (isDesktop || isWebDesktop)
? TextButtonThemeData(
style: TextButton.styleFrom(
splashFactory: NoSplash.splashFactory,
Expand Down Expand Up @@ -818,7 +826,7 @@ class OverlayDialogManager {
Offstage(
offstage: !showCancel,
child: Center(
child: isDesktop
child: (isDesktop || isWebDesktop)
? dialogButton('Cancel', onPressed: cancel)
: TextButton(
style: flatButtonStyle,
Expand Down Expand Up @@ -1293,7 +1301,7 @@ class AndroidPermissionManager {
}

static Future<bool> check(String type) {
if (isDesktop) {
if (isDesktop || isWeb) {
return Future.value(true);
}
return gFFI.invokeMethod("check_permission", type);
Expand All @@ -1307,7 +1315,7 @@ class AndroidPermissionManager {
/// We use XXPermissions to request permissions,
/// for supported types, see https://github.com/getActivity/XXPermissions/blob/e46caea32a64ad7819df62d448fb1c825481cd28/library/src/main/java/com/hjq/permissions/Permission.java
static Future<bool> request(String type) {
if (isDesktop) {
if (isDesktop || isWeb) {
return Future.value(true);
}

Expand Down Expand Up @@ -1863,7 +1871,8 @@ Future<bool> initUniLinks() async {
// check cold boot
try {
final initialLink = await getInitialLink();
if (initialLink == null) {
print("initialLink: $initialLink");
if (initialLink == null || initialLink.isEmpty) {
return false;
}
return handleUriLink(uriString: initialLink);
Expand Down Expand Up @@ -2196,13 +2205,29 @@ connect(BuildContext context, String id,
),
);
} else {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => RemotePage(
id: id, password: password, isSharedPassword: isSharedPassword),
),
);
if (isWebDesktop) {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => desktop_remote.RemotePage(
key: ValueKey(id),
id: id,
toolbarState: ToolbarState(),
password: password,
forceRelay: forceRelay,
isSharedPassword: isSharedPassword,
),
),
);
} else {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => RemotePage(
id: id, password: password, isSharedPassword: isSharedPassword),
),
);
}
}
}

Expand Down Expand Up @@ -2397,7 +2422,7 @@ Widget dialogButton(String text,
Widget? icon,
TextStyle? style,
ButtonStyle? buttonStyle}) {
if (isDesktop) {
if (isDesktop || isWebDesktop) {
if (isOutline) {
return icon == null
? OutlinedButton(
Expand Down
8 changes: 6 additions & 2 deletions flutter/lib/common/widgets/address_book.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class _AddressBookState extends State<AddressBook> {
} else {
return Column(
children: [
// NOT use Offstage to wrap LinearProgressIndicator
if (gFFI.abModel.currentAbLoading.value &&
gFFI.abModel.currentAbEmpty)
const LinearProgressIndicator(),
buildErrorBanner(context,
loading: gFFI.abModel.currentAbLoading,
err: gFFI.abModel.currentAbPullError,
Expand All @@ -59,7 +63,7 @@ class _AddressBookState extends State<AddressBook> {
retry: null, // remove retry
close: () => gFFI.abModel.currentAbPushError.value = ''),
Expanded(
child: isDesktop
child: (isDesktop || isWebDesktop)
? _buildAddressBookDesktop()
: _buildAddressBookMobile())
],
Expand Down Expand Up @@ -307,7 +311,7 @@ class _AddressBookState extends State<AddressBook> {
return tagBuilder(e);
});
final maxHeight = max(MediaQuery.of(context).size.height / 6, 100.0);
return isDesktop
return (isDesktop || isWebDesktop)
? gridView
: LimitedBox(maxHeight: maxHeight, child: gridView);
});
Expand Down
9 changes: 4 additions & 5 deletions flutter/lib/common/widgets/dialog.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -81,7 +80,7 @@ void changeIdDialog() {
final Iterable violations = rules.where((r) => !r.validate(newId));
if (violations.isNotEmpty) {
setState(() {
msg = isDesktop
msg = (isDesktop || isWebDesktop)
? '${translate('Prompt')}: ${violations.map((r) => r.name).join(', ')}'
: violations.map((r) => r.name).join(', ');
});
Expand All @@ -106,7 +105,7 @@ void changeIdDialog() {
}
setState(() {
isInProgress = false;
msg = isDesktop
msg = (isDesktop || isWebDesktop)
? '${translate('Prompt')}: ${translate(status)}'
: translate(status);
});
Expand Down Expand Up @@ -143,7 +142,7 @@ void changeIdDialog() {
const SizedBox(
height: 8.0,
),
isDesktop
(isDesktop || isWebDesktop)
? Obx(() => Wrap(
runSpacing: 8,
spacing: 4,
Expand Down Expand Up @@ -1109,7 +1108,7 @@ void showRequestElevationDialog(
errorText: errPwd.isEmpty ? null : errPwd.value,
),
],
).marginOnly(left: isDesktop ? 35 : 0),
).marginOnly(left: (isDesktop || isWebDesktop) ? 35 : 0),
).marginOnly(top: 10),
],
),
Expand Down
7 changes: 5 additions & 2 deletions flutter/lib/common/widgets/my_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class _MyGroupState extends State<MyGroup> {
err: gFFI.groupModel.groupLoadError,
retry: null,
close: () => gFFI.groupModel.groupLoadError.value = ''),
Expanded(child: isDesktop ? _buildDesktop() : _buildMobile())
Expanded(
child: (isDesktop || isWebDesktop)
? _buildDesktop()
: _buildMobile())
],
);
});
Expand Down Expand Up @@ -164,7 +167,7 @@ class _MyGroupState extends State<MyGroup> {
itemCount: items.length,
itemBuilder: (context, index) => _buildUserItem(items[index]));
var maxHeight = max(MediaQuery.of(context).size.height / 6, 100.0);
return isDesktop
return (isDesktop || isWebDesktop)
? listView
: LimitedBox(maxHeight: maxHeight, child: listView);
});
Expand Down
2 changes: 1 addition & 1 deletion flutter/lib/common/widgets/overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DraggableChatWindow extends StatelessWidget {
resizeToAvoidBottomInset: false,
appBar: CustomAppBar(
onPanUpdate: onPanUpdate,
appBar: isDesktop
appBar: (isDesktop || isWebDesktop)
? _buildDesktopAppBar(context)
: _buildMobileAppBar(context),
),
Expand Down
26 changes: 13 additions & 13 deletions flutter/lib/common/widgets/peer_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hbb/common/widgets/dialog.dart';
import 'package:flutter_hbb/consts.dart';
import 'package:flutter_hbb/models/ab_model.dart';
import 'package:flutter_hbb/models/peer_tab_model.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -52,7 +51,7 @@ class _PeerCardState extends State<_PeerCard>
@override
Widget build(BuildContext context) {
super.build(context);
if (isDesktop) {
if (isDesktop || isWebDesktop) {
return _buildDesktop();
} else {
return _buildMobile();
Expand Down Expand Up @@ -883,8 +882,7 @@ class RecentPeerCard extends BasePeerCard {
menuItems.add(_createShortCutAction(peer.id));
}
menuItems.add(MenuEntryDivider());
if (!isWeb) {
// TODO: support web version
if (isDesktop || isWebDesktop) {
menuItems.add(_renameAction(peer.id));
}
if (await bind.mainPeerHasPassword(id: peer.id)) {
Expand Down Expand Up @@ -940,8 +938,7 @@ class FavoritePeerCard extends BasePeerCard {
menuItems.add(_createShortCutAction(peer.id));
}
menuItems.add(MenuEntryDivider());
if (!isWeb) {
// TODO: support web version
if (isDesktop || isWebDesktop) {
menuItems.add(_renameAction(peer.id));
}
if (await bind.mainPeerHasPassword(id: peer.id)) {
Expand Down Expand Up @@ -1046,8 +1043,7 @@ class AddressBookPeerCard extends BasePeerCard {
}
if (gFFI.abModel.current.canWrite()) {
menuItems.add(MenuEntryDivider());
if (!isWeb) {
// TODO: support web version
if (isDesktop || isWebDesktop) {
menuItems.add(_renameAction(peer.id));
}
if (gFFI.abModel.current.isPersonal() && peer.hash.isNotEmpty) {
Expand Down Expand Up @@ -1249,7 +1245,7 @@ void _rdpDialog(String id) async {
).marginOnly(bottom: isDesktop ? 8 : 0),
Row(
children: [
isDesktop
(isDesktop || isWebDesktop)
? ConstrainedBox(
constraints: const BoxConstraints(minWidth: 140),
child: Text(
Expand All @@ -1260,15 +1256,17 @@ void _rdpDialog(String id) async {
Expanded(
child: TextField(
decoration: InputDecoration(
labelText: isDesktop ? null : translate('Username')),
labelText: (isDesktop || isWebDesktop)
? null
: translate('Username')),
controller: userController,
),
),
],
).marginOnly(bottom: isDesktop ? 8 : 0),
).marginOnly(bottom: (isDesktop || isWebDesktop) ? 8 : 0),
Row(
children: [
isDesktop
(isDesktop || isWebDesktop)
? ConstrainedBox(
constraints: const BoxConstraints(minWidth: 140),
child: Text(
Expand All @@ -1280,7 +1278,9 @@ void _rdpDialog(String id) async {
child: Obx(() => TextField(
obscureText: secure.value,
decoration: InputDecoration(
labelText: isDesktop ? null : translate('Password'),
labelText: (isDesktop || isWebDesktop)
? null
: translate('Password'),
suffixIcon: IconButton(
onPressed: () => secure.value = !secure.value,
icon: Icon(secure.value
Expand Down
Loading

0 comments on commit 4c04b54

Please sign in to comment.