Skip to content

Commit cd247e0

Browse files
committed
2 parents 815a249 + 29b01e9 commit cd247e0

File tree

8 files changed

+128
-113
lines changed

8 files changed

+128
-113
lines changed

Diff for: flutter/lib/common.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -2383,7 +2383,7 @@ connect(BuildContext context, String id,
23832383
),
23842384
);
23852385
} else {
2386-
if (isWebDesktop) {
2386+
if (isWeb) {
23872387
Navigator.push(
23882388
context,
23892389
MaterialPageRoute(

Diff for: flutter/lib/common/widgets/peer_card.dart

+91-89
Original file line numberDiff line numberDiff line change
@@ -58,35 +58,40 @@ class _PeerCardState extends State<_PeerCard>
5858
stateGlobal.isPortrait.isTrue ? _buildPortrait() : _buildLandscape());
5959
}
6060

61+
Widget gestureDetector({required Widget child}) {
62+
final PeerTabModel peerTabModel = Provider.of(context);
63+
final peer = super.widget.peer;
64+
return GestureDetector(
65+
onDoubleTap: peerTabModel.multiSelectionMode
66+
? null
67+
: () => widget.connect(context, peer.id),
68+
onTap: () {
69+
if (peerTabModel.multiSelectionMode) {
70+
peerTabModel.select(peer);
71+
} else {
72+
if (isMobile) {
73+
widget.connect(context, peer.id);
74+
} else {
75+
peerTabModel.select(peer);
76+
}
77+
}
78+
},
79+
onLongPress: () => peerTabModel.select(peer),
80+
child: child);
81+
}
82+
6183
Widget _buildPortrait() {
6284
final peer = super.widget.peer;
63-
final PeerTabModel peerTabModel = Provider.of(context);
6485
return Card(
6586
margin: EdgeInsets.symmetric(horizontal: 2),
66-
child: GestureDetector(
67-
onTap: () {
68-
if (peerTabModel.multiSelectionMode) {
69-
peerTabModel.select(peer);
70-
} else {
71-
if (!isWebDesktop) {
72-
connectInPeerTab(context, peer, widget.tab);
73-
}
74-
}
75-
},
76-
onDoubleTap: isWebDesktop
77-
? () => connectInPeerTab(context, peer, widget.tab)
78-
: null,
79-
onLongPress: () {
80-
peerTabModel.select(peer);
81-
},
87+
child: gestureDetector(
8288
child: Container(
8389
padding: EdgeInsets.only(left: 12, top: 8, bottom: 8),
8490
child: _buildPeerTile(context, peer, null)),
8591
));
8692
}
8793

8894
Widget _buildLandscape() {
89-
final PeerTabModel peerTabModel = Provider.of(context);
9095
final peer = super.widget.peer;
9196
var deco = Rx<BoxDecoration?>(
9297
BoxDecoration(
@@ -115,30 +120,21 @@ class _PeerCardState extends State<_PeerCard>
115120
),
116121
);
117122
},
118-
child: GestureDetector(
119-
onDoubleTap:
120-
peerTabModel.multiSelectionMode || peerTabModel.isShiftDown
121-
? null
122-
: () => widget.connect(context, peer.id),
123-
onTap: () => peerTabModel.select(peer),
124-
onLongPress: () => peerTabModel.select(peer),
123+
child: gestureDetector(
125124
child: Obx(() => peerCardUiType.value == PeerUiType.grid
126125
? _buildPeerCard(context, peer, deco)
127126
: _buildPeerTile(context, peer, deco))),
128127
);
129128
}
130129

131-
Widget _buildPeerTile(
132-
BuildContext context, Peer peer, Rx<BoxDecoration?>? deco) {
133-
hideUsernameOnCard ??=
134-
bind.mainGetBuildinOption(key: kHideUsernameOnCard) == 'Y';
130+
makeChild(bool isPortrait, Peer peer) {
135131
final name = hideUsernameOnCard == true
136132
? peer.hostname
137133
: '${peer.username}${peer.username.isNotEmpty && peer.hostname.isNotEmpty ? '@' : ''}${peer.hostname}';
138134
final greyStyle = TextStyle(
139135
fontSize: 11,
140136
color: Theme.of(context).textTheme.titleLarge?.color?.withOpacity(0.6));
141-
makeChild(bool isPortrait) => Row(
137+
return Row(
142138
mainAxisSize: MainAxisSize.max,
143139
children: [
144140
Container(
@@ -210,6 +206,12 @@ class _PeerCardState extends State<_PeerCard>
210206
)
211207
],
212208
);
209+
}
210+
211+
Widget _buildPeerTile(
212+
BuildContext context, Peer peer, Rx<BoxDecoration?>? deco) {
213+
hideUsernameOnCard ??=
214+
bind.mainGetBuildinOption(key: kHideUsernameOnCard) == 'Y';
213215
final colors = _frontN(peer.tags, 25)
214216
.map((e) => gFFI.abModel.getCurrentAbTagColor(e))
215217
.toList();
@@ -220,21 +222,22 @@ class _PeerCardState extends State<_PeerCard>
220222
? '${translate('Tags')}: ${peer.tags.join(', ')}'
221223
: '',
222224
child: Stack(children: [
223-
Obx(() => deco == null
224-
? makeChild(stateGlobal.isPortrait.isTrue)
225-
: Container(
225+
Obx(
226+
() => deco == null
227+
? makeChild(stateGlobal.isPortrait.isTrue, peer)
228+
: Container(
226229
foregroundDecoration: deco.value,
227-
child: makeChild(stateGlobal.isPortrait.isTrue),
230+
child: makeChild(stateGlobal.isPortrait.isTrue, peer),
228231
),
229-
),
232+
),
230233
if (colors.isNotEmpty)
231-
Obx(()=> Positioned(
232-
top: 2,
233-
right: stateGlobal.isPortrait.isTrue ? 20 : 10,
234-
child: CustomPaint(
235-
painter: TagPainter(radius: 3, colors: colors),
236-
),
237-
))
234+
Obx(() => Positioned(
235+
top: 2,
236+
right: stateGlobal.isPortrait.isTrue ? 20 : 10,
237+
child: CustomPaint(
238+
painter: TagPainter(radius: 3, colors: colors),
239+
),
240+
))
238241
]),
239242
);
240243
}
@@ -1259,54 +1262,53 @@ void _rdpDialog(String id) async {
12591262
],
12601263
).marginOnly(bottom: isDesktop ? 8 : 0),
12611264
Obx(() => Row(
1262-
children: [
1263-
stateGlobal.isPortrait.isFalse
1264-
? ConstrainedBox(
1265-
constraints: const BoxConstraints(minWidth: 140),
1266-
child: Text(
1267-
"${translate('Username')}:",
1268-
textAlign: TextAlign.right,
1269-
).marginOnly(right: 10))
1270-
: SizedBox.shrink(),
1271-
Expanded(
1272-
child: TextField(
1273-
decoration: InputDecoration(
1274-
labelText: isDesktop
1275-
? null
1276-
: translate('Username')),
1277-
controller: userController,
1278-
),
1279-
),
1280-
],
1281-
).marginOnly(bottom: stateGlobal.isPortrait.isFalse ? 8 : 0)),
1282-
Obx(() => Row(
1283-
children: [
1284-
stateGlobal.isPortrait.isFalse
1285-
? ConstrainedBox(
1286-
constraints: const BoxConstraints(minWidth: 140),
1287-
child: Text(
1288-
"${translate('Password')}:",
1289-
textAlign: TextAlign.right,
1290-
).marginOnly(right: 10))
1291-
: SizedBox.shrink(),
1292-
Expanded(
1293-
child: Obx(() => TextField(
1294-
obscureText: secure.value,
1295-
maxLength: maxLength,
1265+
children: [
1266+
stateGlobal.isPortrait.isFalse
1267+
? ConstrainedBox(
1268+
constraints: const BoxConstraints(minWidth: 140),
1269+
child: Text(
1270+
"${translate('Username')}:",
1271+
textAlign: TextAlign.right,
1272+
).marginOnly(right: 10))
1273+
: SizedBox.shrink(),
1274+
Expanded(
1275+
child: TextField(
12961276
decoration: InputDecoration(
1297-
labelText: isDesktop
1298-
? null
1299-
: translate('Password'),
1300-
suffixIcon: IconButton(
1301-
onPressed: () => secure.value = !secure.value,
1302-
icon: Icon(secure.value
1303-
? Icons.visibility_off
1304-
: Icons.visibility))),
1305-
controller: passwordController,
1306-
)),
1307-
),
1308-
],
1309-
))
1277+
labelText:
1278+
isDesktop ? null : translate('Username')),
1279+
controller: userController,
1280+
),
1281+
),
1282+
],
1283+
).marginOnly(bottom: stateGlobal.isPortrait.isFalse ? 8 : 0)),
1284+
Obx(() => Row(
1285+
children: [
1286+
stateGlobal.isPortrait.isFalse
1287+
? ConstrainedBox(
1288+
constraints: const BoxConstraints(minWidth: 140),
1289+
child: Text(
1290+
"${translate('Password')}:",
1291+
textAlign: TextAlign.right,
1292+
).marginOnly(right: 10))
1293+
: SizedBox.shrink(),
1294+
Expanded(
1295+
child: Obx(() => TextField(
1296+
obscureText: secure.value,
1297+
maxLength: maxLength,
1298+
decoration: InputDecoration(
1299+
labelText:
1300+
isDesktop ? null : translate('Password'),
1301+
suffixIcon: IconButton(
1302+
onPressed: () =>
1303+
secure.value = !secure.value,
1304+
icon: Icon(secure.value
1305+
? Icons.visibility_off
1306+
: Icons.visibility))),
1307+
controller: passwordController,
1308+
)),
1309+
),
1310+
],
1311+
))
13101312
],
13111313
),
13121314
),

Diff for: flutter/lib/main.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ class _AppState extends State<App> with WidgetsBindingObserver {
475475
: (context, child) {
476476
child = _keepScaleBuilder(context, child);
477477
child = botToastBuilder(context, child);
478-
if (isDesktop && desktopType == DesktopType.main) {
478+
if ((isDesktop && desktopType == DesktopType.main) ||
479+
isWebDesktop) {
479480
child = keyListenerBuilder(context, child);
480481
}
481482
if (isLinux) {

Diff for: flutter/lib/models/model.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ class FfiModel with ChangeNotifier {
372372
} else if (name == 'plugin_option') {
373373
handleOption(evt);
374374
} else if (name == "sync_peer_hash_password_to_personal_ab") {
375-
if (desktopType == DesktopType.main) {
375+
if (desktopType == DesktopType.main || isWeb) {
376376
final id = evt['id'];
377377
final hash = evt['hash'];
378378
if (id != null && hash != null) {

Diff for: flutter/lib/models/peer_tab_model.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class PeerTabModel with ChangeNotifier {
152152
// https://github.com/flutter/flutter/issues/101275#issuecomment-1604541700
153153
// After onTap, the shift key should be pressed for a while when not in multiselection mode,
154154
// because onTap is delayed when onDoubleTap is not null
155-
if (isDesktop && !_isShiftDown) return;
155+
if (isDesktop || isWebDesktop) return;
156156
_multiSelectionMode = true;
157157
}
158158
final cached = _currentTabCachedPeers.map((e) => e.id).toList();

Diff for: flutter/lib/models/web_model.dart

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// ignore_for_file: avoid_web_libraries_in_flutter
22

33
import 'dart:convert';
4+
import 'dart:js_interop';
45
import 'dart:typed_data';
56
import 'dart:js';
67
import 'dart:html';
@@ -107,6 +108,10 @@ class PlatformFFI {
107108
sessionId: sessionId, display: display, ptr: ptr);
108109

109110
Future<void> init(String appType) async {
111+
Completer completer = Completer();
112+
context["onInitFinished"] = () {
113+
completer.complete();
114+
};
110115
context.callMethod('init');
111116
version = getByName('version');
112117
window.onContextMenu.listen((event) {
@@ -121,6 +126,7 @@ class PlatformFFI {
121126
print('json.decode fail(): $e');
122127
}
123128
};
129+
return completer.future;
124130
}
125131

126132
void setEventCallback(void Function(Map<String, dynamic>) fun) {

Diff for: flutter/lib/web/bridge.dart

+14-8
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ class RustdeskImpl {
8585
dynamic hint}) {
8686
return js.context.callMethod('setByName', [
8787
'session_add_sync',
88-
jsonEncode({'id': id, 'password': password})
88+
jsonEncode({
89+
'id': id,
90+
'password': password,
91+
'is_shared_password': isSharedPassword
92+
})
8993
]);
9094
}
9195

@@ -1118,7 +1122,8 @@ class RustdeskImpl {
11181122
}
11191123

11201124
Future<void> mainRemovePeer({required String id, dynamic hint}) {
1121-
return Future(() => js.context.callMethod('setByName', ['remove', id]));
1125+
return Future(
1126+
() => js.context.callMethod('setByName', ['remove_peer', id]));
11221127
}
11231128

11241129
bool mainHasHwcodec({dynamic hint}) {
@@ -1146,27 +1151,28 @@ class RustdeskImpl {
11461151
}
11471152

11481153
Future<void> mainSaveAb({required String json, dynamic hint}) {
1149-
throw UnimplementedError();
1154+
return Future(() => js.context.callMethod('setByName', ['save_ab', json]));
11501155
}
11511156

11521157
Future<void> mainClearAb({dynamic hint}) {
1153-
throw UnimplementedError();
1158+
return Future(() => js.context.callMethod('setByName', ['clear_ab']));
11541159
}
11551160

11561161
Future<String> mainLoadAb({dynamic hint}) {
1157-
throw UnimplementedError();
1162+
return Future(() => js.context.callMethod('getByName', ['load_ab']));
11581163
}
11591164

11601165
Future<void> mainSaveGroup({required String json, dynamic hint}) {
1161-
throw UnimplementedError();
1166+
return Future(
1167+
() => js.context.callMethod('setByName', ['save_group', json]));
11621168
}
11631169

11641170
Future<void> mainClearGroup({dynamic hint}) {
1165-
throw UnimplementedError();
1171+
return Future(() => js.context.callMethod('setByName', ['clear_group']));
11661172
}
11671173

11681174
Future<String> mainLoadGroup({dynamic hint}) {
1169-
throw UnimplementedError();
1175+
return Future(() => js.context.callMethod('getByName', ['load_group']));
11701176
}
11711177

11721178
Future<void> sessionSendPointer(

0 commit comments

Comments
 (0)