Skip to content

Commit

Permalink
Merge branch 'rustdesk:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangbo8418 authored Feb 18, 2024
2 parents 7d5de37 + 0f44de7 commit f959d34
Show file tree
Hide file tree
Showing 25 changed files with 525 additions and 454 deletions.
80 changes: 80 additions & 0 deletions flutter/lib/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2990,3 +2990,83 @@ ColorFilter? svgColor(Color? color) {
return ColorFilter.mode(color, BlendMode.srcIn);
}
}

// ignore: must_be_immutable
class ComboBox extends StatelessWidget {
late final List<String> keys;
late final List<String> values;
late final String initialKey;
late final Function(String key) onChanged;
late final bool enabled;
late String current;

ComboBox({
Key? key,
required this.keys,
required this.values,
required this.initialKey,
required this.onChanged,
this.enabled = true,
}) : super(key: key);

@override
Widget build(BuildContext context) {
var index = keys.indexOf(initialKey);
if (index < 0) {
index = 0;
}
var ref = values[index].obs;
current = keys[index];
return Container(
decoration: BoxDecoration(
border: Border.all(
color: enabled
? MyTheme.color(context).border2 ?? MyTheme.border
: MyTheme.border,
),
borderRadius:
BorderRadius.circular(8), //border raiuds of dropdown button
),
height: 42, // should be the height of a TextField
child: Obx(() => DropdownButton<String>(
isExpanded: true,
value: ref.value,
elevation: 16,
underline: Container(),
style: TextStyle(
color: enabled
? Theme.of(context).textTheme.titleMedium?.color
: disabledTextColor(context, enabled)),
icon: const Icon(
Icons.expand_more_sharp,
size: 20,
).marginOnly(right: 15),
onChanged: enabled
? (String? newValue) {
if (newValue != null && newValue != ref.value) {
ref.value = newValue;
current = newValue;
onChanged(keys[values.indexOf(newValue)]);
}
}
: null,
items: values.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style: const TextStyle(fontSize: 15),
overflow: TextOverflow.ellipsis,
).marginOnly(left: 15),
);
}).toList(),
)),
).marginOnly(bottom: 5);
}
}

Color? disabledTextColor(BuildContext context, bool enabled) {
return enabled
? null
: Theme.of(context).textTheme.titleLarge?.color?.withOpacity(0.6);
}
105 changes: 25 additions & 80 deletions flutter/lib/common/widgets/dialog.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:flutter/material.dart';
Expand Down Expand Up @@ -1862,6 +1863,7 @@ void enter2FaDialog(
});
}

// This dialog should not be dismissed, otherwise it will be black screen, have not reproduced this.
void showWindowsSessionsDialog(
String type,
String title,
Expand All @@ -1870,97 +1872,40 @@ void showWindowsSessionsDialog(
SessionID sessionId,
String peerId,
String sessions) {
List<String> sessionsList = sessions.split(',');
Map<String, String> sessionMap = {};
List<dynamic> sessionsList = [];
try {
sessionsList = json.decode(sessions);
} catch (e) {
print(e);
}
List<String> sids = [];
List<String> names = [];
for (var session in sessionsList) {
var sessionInfo = session.split('-');
if (sessionInfo.isNotEmpty) {
sessionMap[sessionInfo[0]] = sessionInfo[1];
}
sids.add(session['sid']);
names.add(session['name']);
}
String selectedUserValue = sessionMap.keys.first;
String selectedUserValue = sids.first;
dialogManager.dismissAll();
dialogManager.show((setState, close, context) {
onConnect() {
bind.sessionReconnect(
sessionId: sessionId,
forceRelay: false,
userSessionId: selectedUserValue);
dialogManager.dismissAll();
dialogManager.showLoading(translate('Connecting...'),
onCancel: closeConnection);
submit() {
bind.sessionSendSelectedSessionId(
sessionId: sessionId, sid: selectedUserValue);
close();
}

return CustomAlertDialog(
title: null,
content: msgboxContent(type, title, text),
actions: [
SessionsDropdown(peerId, sessionId, sessionMap, (value) {
setState(() {
selectedUserValue = value;
});
}),
dialogButton('Connect', onPressed: onConnect, isOutline: false),
ComboBox(
keys: sids,
values: names,
initialKey: selectedUserValue,
onChanged: (value) {
selectedUserValue = value;
}),
dialogButton('Connect', onPressed: submit, isOutline: false),
],
);
});
}

class SessionsDropdown extends StatefulWidget {
final String peerId;
final SessionID sessionId;
final Map<String, String> sessions;
final Function(String) onValueChanged;

SessionsDropdown(
this.peerId, this.sessionId, this.sessions, this.onValueChanged);

@override
_SessionsDropdownState createState() => _SessionsDropdownState();
}

class _SessionsDropdownState extends State<SessionsDropdown> {
late String selectedValue;
@override
void initState() {
super.initState();
selectedValue = widget.sessions.keys.first;
}

@override
Widget build(BuildContext context) {
return Container(
width: 300,
child: DropdownButton<String>(
value: selectedValue,
isExpanded: true,
borderRadius: BorderRadius.circular(8),
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 5),
items: widget.sessions.entries.map((entry) {
return DropdownMenuItem(
value: entry.key,
child: Text(
entry.value,
style: TextStyle(
color: MyTheme.currentThemeMode() == ThemeMode.dark
? Colors.white
: MyTheme.dark,
),
),
);
}).toList(),
onChanged: (value) {
if (value != null) {
setState(() {
selectedValue = value;
});
widget.onValueChanged(value);
}
},
style: TextStyle(
fontSize: 16.0,
),
),
);
}
}
Loading

0 comments on commit f959d34

Please sign in to comment.