mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-01-18 07:43:01 +08:00
Merge pull request #1108 from Kingtous/flutter_desktop
feat: unremember password & initial dark theme & rename
This commit is contained in:
commit
e35f0d84be
@ -4,6 +4,7 @@ import 'package:flutter/gestures.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/instance_manager.dart';
|
import 'package:get/instance_manager.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
import 'models/model.dart';
|
import 'models/model.dart';
|
||||||
|
|
||||||
@ -38,6 +39,24 @@ class MyTheme {
|
|||||||
static const Color idColor = Color(0xFF00B6F0);
|
static const Color idColor = Color(0xFF00B6F0);
|
||||||
static const Color darkGray = Color(0xFFB9BABC);
|
static const Color darkGray = Color(0xFFB9BABC);
|
||||||
static const Color dark = Colors.black87;
|
static const Color dark = Colors.black87;
|
||||||
|
|
||||||
|
static ThemeData lightTheme = ThemeData(
|
||||||
|
brightness: Brightness.light,
|
||||||
|
primarySwatch: Colors.blue,
|
||||||
|
visualDensity: VisualDensity.adaptivePlatformDensity,
|
||||||
|
tabBarTheme: TabBarTheme(labelColor: Colors.black87),
|
||||||
|
);
|
||||||
|
static ThemeData darkTheme = ThemeData(
|
||||||
|
brightness: Brightness.dark,
|
||||||
|
primarySwatch: Colors.blue,
|
||||||
|
visualDensity: VisualDensity.adaptivePlatformDensity,
|
||||||
|
tabBarTheme: TabBarTheme(labelColor: Colors.white70));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isDarkTheme() {
|
||||||
|
final isDark = "Y" == Get.find<SharedPreferences>().getString("darkTheme");
|
||||||
|
debugPrint("current is dark theme: $isDark");
|
||||||
|
return isDark;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ButtonStyle flatButtonStyle = TextButton.styleFrom(
|
final ButtonStyle flatButtonStyle = TextButton.styleFrom(
|
||||||
@ -327,4 +346,6 @@ Future<void> initGlobalFFI() async {
|
|||||||
await _globalFFI.ffiModel.init();
|
await _globalFFI.ffiModel.init();
|
||||||
// trigger connection status updater
|
// trigger connection status updater
|
||||||
await _globalFFI.bind.mainCheckConnectStatus();
|
await _globalFFI.bind.mainCheckConnectStatus();
|
||||||
|
// global shared preference
|
||||||
|
await Get.putAsync(() => SharedPreferences.getInstance());
|
||||||
}
|
}
|
@ -16,7 +16,6 @@ import '../../mobile/pages/home_page.dart';
|
|||||||
import '../../mobile/pages/scan_page.dart';
|
import '../../mobile/pages/scan_page.dart';
|
||||||
import '../../mobile/pages/settings_page.dart';
|
import '../../mobile/pages/settings_page.dart';
|
||||||
import '../../models/model.dart';
|
import '../../models/model.dart';
|
||||||
import '../../models/peer_model.dart';
|
|
||||||
|
|
||||||
enum RemoteType { recently, favorite, discovered, addressBook }
|
enum RemoteType { recently, favorite, discovered, addressBook }
|
||||||
|
|
||||||
@ -60,7 +59,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (_idController.text.isEmpty) _idController.text = gFFI.getId();
|
if (_idController.text.isEmpty) _idController.text = gFFI.getId();
|
||||||
return Container(
|
return Container(
|
||||||
decoration: BoxDecoration(color: MyTheme.grayBg),
|
decoration: BoxDecoration(color: isDarkTheme() ? null : MyTheme.grayBg),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.max,
|
mainAxisSize: MainAxisSize.max,
|
||||||
@ -83,7 +82,6 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
TabBar(
|
TabBar(
|
||||||
labelColor: Colors.black87,
|
|
||||||
isScrollable: true,
|
isScrollable: true,
|
||||||
indicatorSize: TabBarIndicatorSize.label,
|
indicatorSize: TabBarIndicatorSize.label,
|
||||||
tabs: [
|
tabs: [
|
||||||
@ -105,7 +103,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
RecentPeerWidget(),
|
RecentPeerWidget(),
|
||||||
FavoritePeerWidget(),
|
FavoritePeerWidget(),
|
||||||
DiscoveredPeerWidget(),
|
DiscoveredPeerWidget(),
|
||||||
AddressBookPeerWidget(),
|
// AddressBookPeerWidget(),
|
||||||
// FutureBuilder<Widget>(
|
// FutureBuilder<Widget>(
|
||||||
// future: getPeers(rType: RemoteType.recently),
|
// future: getPeers(rType: RemoteType.recently),
|
||||||
// builder: (context, snapshot) {
|
// builder: (context, snapshot) {
|
||||||
@ -133,15 +131,15 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
// return Offstage();
|
// return Offstage();
|
||||||
// }
|
// }
|
||||||
// }),
|
// }),
|
||||||
// FutureBuilder<Widget>(
|
FutureBuilder<Widget>(
|
||||||
// future: buildAddressBook(context),
|
future: buildAddressBook(context),
|
||||||
// builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
// if (snapshot.hasData) {
|
if (snapshot.hasData) {
|
||||||
// return snapshot.data!;
|
return snapshot.data!;
|
||||||
// } else {
|
} else {
|
||||||
// return Offstage();
|
return Offstage();
|
||||||
// }
|
}
|
||||||
// }),
|
}),
|
||||||
]).paddingSymmetric(horizontal: 12.0, vertical: 4.0))
|
]).paddingSymmetric(horizontal: 12.0, vertical: 4.0))
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
@ -205,7 +203,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
width: 500,
|
width: 500,
|
||||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 24),
|
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 24),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: MyTheme.white,
|
color: isDarkTheme() ? null : MyTheme.white,
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(13)),
|
borderRadius: const BorderRadius.all(Radius.circular(13)),
|
||||||
),
|
),
|
||||||
child: Ink(
|
child: Ink(
|
||||||
@ -235,13 +233,11 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
helperStyle: TextStyle(
|
helperStyle: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
color: MyTheme.dark,
|
|
||||||
),
|
),
|
||||||
labelStyle: TextStyle(
|
labelStyle: TextStyle(
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
fontSize: 26,
|
fontSize: 26,
|
||||||
letterSpacing: 0.2,
|
letterSpacing: 0.2,
|
||||||
color: MyTheme.dark,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
controller: _idController,
|
controller: _idController,
|
||||||
@ -269,7 +265,6 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
translate(
|
translate(
|
||||||
"Transfer File",
|
"Transfer File",
|
||||||
),
|
),
|
||||||
style: TextStyle(color: MyTheme.dark),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -334,154 +329,6 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get all the saved peers.
|
|
||||||
Future<Widget> getPeers({RemoteType rType = RemoteType.recently}) async {
|
|
||||||
final space = 8.0;
|
|
||||||
final cards = <Widget>[];
|
|
||||||
List<Peer> peers;
|
|
||||||
switch (rType) {
|
|
||||||
case RemoteType.recently:
|
|
||||||
peers = gFFI.peers();
|
|
||||||
break;
|
|
||||||
case RemoteType.favorite:
|
|
||||||
peers = await gFFI.bind.mainGetFav().then((peers) async {
|
|
||||||
final peersEntities = await Future.wait(peers
|
|
||||||
.map((id) => gFFI.bind.mainGetPeers(id: id))
|
|
||||||
.toList(growable: false))
|
|
||||||
.then((peers_str) {
|
|
||||||
final len = peers_str.length;
|
|
||||||
final ps = List<Peer>.empty(growable: true);
|
|
||||||
for (var i = 0; i < len; i++) {
|
|
||||||
print("${peers[i]}: ${peers_str[i]}");
|
|
||||||
ps.add(Peer.fromJson(peers[i], jsonDecode(peers_str[i])['info']));
|
|
||||||
}
|
|
||||||
return ps;
|
|
||||||
});
|
|
||||||
return peersEntities;
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case RemoteType.discovered:
|
|
||||||
peers = await gFFI.bind.mainGetLanPeers().then((peers_string) {
|
|
||||||
print(peers_string);
|
|
||||||
return [];
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case RemoteType.addressBook:
|
|
||||||
peers = gFFI.abModel.peers.map((e) {
|
|
||||||
return Peer.fromJson(e['id'], e);
|
|
||||||
}).toList();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
peers.forEach((p) {
|
|
||||||
var deco = Rx<BoxDecoration?>(BoxDecoration(
|
|
||||||
border: Border.all(color: Colors.transparent, width: 1.0),
|
|
||||||
borderRadius: BorderRadius.circular(20)));
|
|
||||||
cards.add(Obx(
|
|
||||||
() => Offstage(
|
|
||||||
offstage: !hitTag(gFFI.abModel.selectedTags, p.tags) &&
|
|
||||||
rType == RemoteType.addressBook,
|
|
||||||
child: Container(
|
|
||||||
width: 225,
|
|
||||||
height: 150,
|
|
||||||
child: Card(
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(20)),
|
|
||||||
child: MouseRegion(
|
|
||||||
onEnter: (evt) {
|
|
||||||
deco.value = BoxDecoration(
|
|
||||||
border: Border.all(color: Colors.blue, width: 1.0),
|
|
||||||
borderRadius: BorderRadius.circular(20));
|
|
||||||
},
|
|
||||||
onExit: (evt) {
|
|
||||||
deco.value = BoxDecoration(
|
|
||||||
border:
|
|
||||||
Border.all(color: Colors.transparent, width: 1.0),
|
|
||||||
borderRadius: BorderRadius.circular(20));
|
|
||||||
},
|
|
||||||
child: Obx(
|
|
||||||
() => Container(
|
|
||||||
decoration: deco.value,
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color:
|
|
||||||
str2color('${p.id}${p.platform}', 0x7f),
|
|
||||||
borderRadius: BorderRadius.only(
|
|
||||||
topLeft: Radius.circular(20),
|
|
||||||
topRight: Radius.circular(20),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment:
|
|
||||||
CrossAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.all(6),
|
|
||||||
child: getPlatformImage(
|
|
||||||
'${p.platform}'),
|
|
||||||
),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Tooltip(
|
|
||||||
message:
|
|
||||||
'${p.username}@${p.hostname}',
|
|
||||||
child: Text(
|
|
||||||
'${p.username}@${p.hostname}',
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.white70,
|
|
||||||
fontSize: 12),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
overflow:
|
|
||||||
TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
).paddingAll(4.0),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Text("${p.id}"),
|
|
||||||
InkWell(
|
|
||||||
child: Icon(Icons.more_vert),
|
|
||||||
onTapDown: (e) {
|
|
||||||
final x = e.globalPosition.dx;
|
|
||||||
final y = e.globalPosition.dy;
|
|
||||||
_menuPos =
|
|
||||||
RelativeRect.fromLTRB(x, y, x, y);
|
|
||||||
},
|
|
||||||
onTap: () {
|
|
||||||
showPeerMenu(context, p.id, rType);
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
).paddingSymmetric(vertical: 8.0, horizontal: 12.0)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
))),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
});
|
|
||||||
return SingleChildScrollView(
|
|
||||||
child: Wrap(children: cards, spacing: space, runSpacing: space));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Show the peer menu and handle user's choice.
|
/// Show the peer menu and handle user's choice.
|
||||||
/// User might remove the peer or send a file to the peer.
|
/// User might remove the peer or send a file to the peer.
|
||||||
void showPeerMenu(BuildContext context, String id, RemoteType rType) async {
|
void showPeerMenu(BuildContext context, String id, RemoteType rType) async {
|
||||||
@ -676,7 +523,6 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
side: BorderSide(color: MyTheme.grayBg)),
|
side: BorderSide(color: MyTheme.grayBg)),
|
||||||
color: Colors.white,
|
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 200,
|
width: 200,
|
||||||
height: double.infinity,
|
height: double.infinity,
|
||||||
@ -736,24 +582,8 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
),
|
),
|
||||||
).marginOnly(right: 8.0),
|
).marginOnly(right: 8.0),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: FutureBuilder<Widget>(
|
child: Align(
|
||||||
future: getPeers(rType: RemoteType.addressBook),
|
alignment: Alignment.topLeft, child: AddressBookPeerWidget()),
|
||||||
builder: (context, snapshot) {
|
|
||||||
if (snapshot.hasData) {
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [Expanded(child: snapshot.data!)],
|
|
||||||
);
|
|
||||||
} else if (snapshot.hasError) {
|
|
||||||
return Container(
|
|
||||||
alignment: Alignment.center,
|
|
||||||
child: Text('${snapshot.error}'));
|
|
||||||
} else {
|
|
||||||
return Container(
|
|
||||||
alignment: Alignment.center,
|
|
||||||
child: CircularProgressIndicator());
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
@ -10,6 +10,7 @@ import 'package:flutter_hbb/desktop/widgets/titlebar_widget.dart';
|
|||||||
import 'package:flutter_hbb/models/model.dart';
|
import 'package:flutter_hbb/models/model.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:tray_manager/tray_manager.dart';
|
import 'package:tray_manager/tray_manager.dart';
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
|
|
||||||
@ -64,7 +65,6 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener {
|
|||||||
return ChangeNotifierProvider.value(
|
return ChangeNotifierProvider.value(
|
||||||
value: gFFI.serverModel,
|
value: gFFI.serverModel,
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(color: MyTheme.white),
|
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
buildTip(context),
|
buildTip(context),
|
||||||
@ -339,13 +339,24 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void changeTheme(String choice) async {
|
||||||
|
if (choice == "Y") {
|
||||||
|
Get.changeTheme(MyTheme.darkTheme);
|
||||||
|
} else {
|
||||||
|
Get.changeTheme(MyTheme.lightTheme);
|
||||||
|
}
|
||||||
|
Get.find<SharedPreferences>().setString("darkTheme", choice);
|
||||||
|
}
|
||||||
|
|
||||||
void onSelectMenu(String value) {
|
void onSelectMenu(String value) {
|
||||||
if (value.startsWith('enable-')) {
|
if (value.startsWith('enable-')) {
|
||||||
final option = gFFI.getOption(value);
|
final option = gFFI.getOption(value);
|
||||||
gFFI.setOption(value, option == "N" ? "" : "N");
|
gFFI.setOption(value, option == "N" ? "" : "N");
|
||||||
} else if (value.startsWith('allow-')) {
|
} else if (value.startsWith('allow-')) {
|
||||||
final option = gFFI.getOption(value);
|
final option = gFFI.getOption(value);
|
||||||
gFFI.setOption(value, option == "Y" ? "" : "Y");
|
final choice = option == "Y" ? "" : "Y";
|
||||||
|
gFFI.setOption(value, choice);
|
||||||
|
changeTheme(choice);
|
||||||
} else if (value == "stop-service") {
|
} else if (value == "stop-service") {
|
||||||
final option = gFFI.getOption(value);
|
final option = gFFI.getOption(value);
|
||||||
gFFI.setOption(value, option == "Y" ? "" : "Y");
|
gFFI.setOption(value, option == "Y" ? "" : "Y");
|
||||||
@ -367,9 +378,8 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PopupMenuItem<String> genEnablePopupMenuItem(String label, String value) {
|
PopupMenuItem<String> genEnablePopupMenuItem(String label, String value) {
|
||||||
final isEnable = label.startsWith('enable-')
|
final v = gFFI.getOption(value);
|
||||||
? gFFI.getOption(value) != "N"
|
final isEnable = value.startsWith('enable-') ? v != "N" : v == "Y";
|
||||||
: gFFI.getOption(value) != "Y";
|
|
||||||
return PopupMenuItem(
|
return PopupMenuItem(
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
@ -72,7 +72,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
backgroundColor: MyTheme.grayBg,
|
backgroundColor: isDarkTheme() ? MyTheme.dark : MyTheme.grayBg,
|
||||||
body: Row(
|
body: Row(
|
||||||
children: [
|
children: [
|
||||||
Flexible(flex: 3, child: body(isLocal: true)),
|
Flexible(flex: 3, child: body(isLocal: true)),
|
||||||
|
@ -1,19 +1,24 @@
|
|||||||
|
import 'package:contextmenu/contextmenu.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:contextmenu/contextmenu.dart';
|
|
||||||
|
|
||||||
import '../../common.dart';
|
import '../../common.dart';
|
||||||
import '../../models/model.dart';
|
import '../../models/model.dart';
|
||||||
import '../../models/peer_model.dart';
|
import '../../models/peer_model.dart';
|
||||||
|
|
||||||
typedef PopupMenuItemsFunc = Future<List<PopupMenuItem<String>>> Function();
|
typedef PopupMenuItemsFunc = Future<List<PopupMenuItem<String>>> Function();
|
||||||
|
enum PeerType { recent, fav, discovered, ab }
|
||||||
|
|
||||||
class _PeerCard extends StatefulWidget {
|
class _PeerCard extends StatefulWidget {
|
||||||
final Peer peer;
|
final Peer peer;
|
||||||
final PopupMenuItemsFunc popupMenuItemsFunc;
|
final PopupMenuItemsFunc popupMenuItemsFunc;
|
||||||
|
final PeerType type;
|
||||||
|
|
||||||
_PeerCard({required this.peer, required this.popupMenuItemsFunc, Key? key})
|
_PeerCard({required this.peer,
|
||||||
|
required this.popupMenuItemsFunc,
|
||||||
|
Key? key,
|
||||||
|
required this.type})
|
||||||
: super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -21,11 +26,13 @@ class _PeerCard extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// State for the connection page.
|
/// State for the connection page.
|
||||||
class _PeerCardState extends State<_PeerCard> {
|
class _PeerCardState extends State<_PeerCard>
|
||||||
|
with AutomaticKeepAliveClientMixin {
|
||||||
var _menuPos;
|
var _menuPos;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
super.build(context);
|
||||||
final peer = super.widget.peer;
|
final peer = super.widget.peer;
|
||||||
var deco = Rx<BoxDecoration?>(BoxDecoration(
|
var deco = Rx<BoxDecoration?>(BoxDecoration(
|
||||||
border: Border.all(color: Colors.transparent, width: 1.0),
|
border: Border.all(color: Colors.transparent, width: 1.0),
|
||||||
@ -47,8 +54,7 @@ class _PeerCardState extends State<_PeerCard> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildPeerTile(
|
Widget _buildPeerTile(BuildContext context, Peer peer, Rx<BoxDecoration?> deco) {
|
||||||
BuildContext context, Peer peer, Rx<BoxDecoration?> deco) {
|
|
||||||
return Obx(
|
return Obx(
|
||||||
() => Container(
|
() => Container(
|
||||||
decoration: deco.value,
|
decoration: deco.value,
|
||||||
@ -78,15 +84,37 @@ class _PeerCardState extends State<_PeerCard> {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Tooltip(
|
child: FutureBuilder<String>(
|
||||||
message: '${peer.username}@${peer.hostname}',
|
future: gFFI.getPeerOption(peer.id, 'alias'),
|
||||||
|
builder: (_, snapshot) {
|
||||||
|
if (snapshot.hasData) {
|
||||||
|
final name = snapshot.data!.isEmpty
|
||||||
|
? '${peer.username}@${peer.hostname}'
|
||||||
|
: snapshot.data!;
|
||||||
|
return Tooltip(
|
||||||
|
message: name,
|
||||||
child: Text(
|
child: Text(
|
||||||
'${peer.username}@${peer.hostname}',
|
name,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.white70, fontSize: 12),
|
color: Colors.white70,
|
||||||
|
fontSize: 12),
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// alias has not arrived
|
||||||
|
return Center(
|
||||||
|
child: Text(
|
||||||
|
'${peer.username}@${peer.hostname}',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white70,
|
||||||
|
fontSize: 12),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -160,8 +188,7 @@ class _PeerCardState extends State<_PeerCard> {
|
|||||||
}();
|
}();
|
||||||
} else if (value == 'file') {
|
} else if (value == 'file') {
|
||||||
_connect(id, isFileTransfer: true);
|
_connect(id, isFileTransfer: true);
|
||||||
} else if (value == 'add-fav') {
|
} else if (value == 'add-fav') {} else if (value == 'connect') {
|
||||||
} else if (value == 'connect') {
|
|
||||||
_connect(id, isFileTransfer: false);
|
_connect(id, isFileTransfer: false);
|
||||||
} else if (value == 'ab-delete') {
|
} else if (value == 'ab-delete') {
|
||||||
gFFI.abModel.deletePeer(id);
|
gFFI.abModel.deletePeer(id);
|
||||||
@ -169,6 +196,10 @@ class _PeerCardState extends State<_PeerCard> {
|
|||||||
setState(() {});
|
setState(() {});
|
||||||
} else if (value == 'ab-edit-tag') {
|
} else if (value == 'ab-edit-tag') {
|
||||||
_abEditTag(id);
|
_abEditTag(id);
|
||||||
|
} else if (value == 'rename') {
|
||||||
|
_rename(id);
|
||||||
|
} else if (value == 'unremember-password') {
|
||||||
|
await gFFI.bind.mainForgetPassword(id: id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,15 +296,104 @@ class _PeerCardState extends State<_PeerCard> {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _rename(String id) async {
|
||||||
|
var isInProgress = false;
|
||||||
|
var name = await gFFI.getPeerOption(id, 'alias');
|
||||||
|
if (widget.type == PeerType.ab) {
|
||||||
|
final peer = gFFI.abModel.peers.firstWhere((p) => id == p['id']);
|
||||||
|
if (peer == null) {
|
||||||
|
// this should not happen
|
||||||
|
} else {
|
||||||
|
name = peer['alias'] ?? "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final k = GlobalKey<FormState>();
|
||||||
|
DialogManager.show((setState, close) {
|
||||||
|
return CustomAlertDialog(
|
||||||
|
title: Text(translate("Rename")),
|
||||||
|
content: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||||
|
child: Form(
|
||||||
|
key: k,
|
||||||
|
child: TextFormField(
|
||||||
|
controller: TextEditingController(text: name),
|
||||||
|
decoration: InputDecoration(border: OutlineInputBorder()),
|
||||||
|
onChanged: (newStr) {
|
||||||
|
name = newStr;
|
||||||
|
},
|
||||||
|
validator: (s) {
|
||||||
|
if (s == null || s.isEmpty) {
|
||||||
|
return translate("Empty");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
onSaved: (s) {
|
||||||
|
name = s ?? "unnamed";
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Offstage(offstage: !isInProgress, child: LinearProgressIndicator())
|
||||||
|
],
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
close();
|
||||||
|
},
|
||||||
|
child: Text(translate("Cancel"))),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
setState(() {
|
||||||
|
isInProgress = true;
|
||||||
|
});
|
||||||
|
if (k.currentState != null) {
|
||||||
|
if (k.currentState!.validate()) {
|
||||||
|
k.currentState!.save();
|
||||||
|
await gFFI.setPeerOption(id, 'alias', name);
|
||||||
|
if (widget.type == PeerType.ab) {
|
||||||
|
gFFI.abModel.setPeerOption(id, 'alias', name);
|
||||||
|
await gFFI.abModel.updateAb();
|
||||||
|
} else {
|
||||||
|
Future.delayed(Duration.zero, () {
|
||||||
|
this.setState(() {});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
isInProgress = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: Text(translate("OK"))),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get wantKeepAlive => true;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class BasePeerCard extends StatelessWidget {
|
abstract class BasePeerCard extends StatelessWidget {
|
||||||
final Peer peer;
|
final Peer peer;
|
||||||
BasePeerCard({required this.peer, Key? key}) : super(key: key);
|
final PeerType type;
|
||||||
|
|
||||||
|
BasePeerCard({required this.peer, required this.type, Key? key})
|
||||||
|
: super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return _PeerCard(peer: peer, popupMenuItemsFunc: _getPopupMenuItems);
|
return _PeerCard(
|
||||||
|
peer: peer,
|
||||||
|
popupMenuItemsFunc: _getPopupMenuItems,
|
||||||
|
type: type,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@protected
|
@protected
|
||||||
@ -281,7 +401,8 @@ abstract class BasePeerCard extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class RecentPeerCard extends BasePeerCard {
|
class RecentPeerCard extends BasePeerCard {
|
||||||
RecentPeerCard({required Peer peer, Key? key}) : super(peer: peer, key: key);
|
RecentPeerCard({required Peer peer, Key? key})
|
||||||
|
: super(peer: peer, key: key, type: PeerType.recent);
|
||||||
|
|
||||||
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
|
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
|
||||||
debugPrint("call RecentPeerCard _getPopupMenuItems");
|
debugPrint("call RecentPeerCard _getPopupMenuItems");
|
||||||
@ -297,15 +418,13 @@ class RecentPeerCard extends BasePeerCard {
|
|||||||
PopupMenuItem<String>(
|
PopupMenuItem<String>(
|
||||||
child: Text(translate('Unremember Password')),
|
child: Text(translate('Unremember Password')),
|
||||||
value: 'unremember-password'),
|
value: 'unremember-password'),
|
||||||
PopupMenuItem<String>(
|
|
||||||
child: Text(translate('Edit Tag')), value: 'ab-edit-tag'),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FavoritePeerCard extends BasePeerCard {
|
class FavoritePeerCard extends BasePeerCard {
|
||||||
FavoritePeerCard({required Peer peer, Key? key})
|
FavoritePeerCard({required Peer peer, Key? key})
|
||||||
: super(peer: peer, key: key);
|
: super(peer: peer, key: key, type: PeerType.fav);
|
||||||
|
|
||||||
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
|
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
|
||||||
debugPrint("call FavoritePeerCard _getPopupMenuItems");
|
debugPrint("call FavoritePeerCard _getPopupMenuItems");
|
||||||
@ -329,7 +448,7 @@ class FavoritePeerCard extends BasePeerCard {
|
|||||||
|
|
||||||
class DiscoveredPeerCard extends BasePeerCard {
|
class DiscoveredPeerCard extends BasePeerCard {
|
||||||
DiscoveredPeerCard({required Peer peer, Key? key})
|
DiscoveredPeerCard({required Peer peer, Key? key})
|
||||||
: super(peer: peer, key: key);
|
: super(peer: peer, key: key, type: PeerType.discovered);
|
||||||
|
|
||||||
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
|
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
|
||||||
debugPrint("call DiscoveredPeerCard _getPopupMenuItems");
|
debugPrint("call DiscoveredPeerCard _getPopupMenuItems");
|
||||||
@ -345,15 +464,13 @@ class DiscoveredPeerCard extends BasePeerCard {
|
|||||||
PopupMenuItem<String>(
|
PopupMenuItem<String>(
|
||||||
child: Text(translate('Unremember Password')),
|
child: Text(translate('Unremember Password')),
|
||||||
value: 'unremember-password'),
|
value: 'unremember-password'),
|
||||||
PopupMenuItem<String>(
|
|
||||||
child: Text(translate('Edit Tag')), value: 'ab-edit-tag'),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AddressBookPeerCard extends BasePeerCard {
|
class AddressBookPeerCard extends BasePeerCard {
|
||||||
AddressBookPeerCard({required Peer peer, Key? key})
|
AddressBookPeerCard({required Peer peer, Key? key})
|
||||||
: super(peer: peer, key: key);
|
: super(peer: peer, key: key, type: PeerType.ab);
|
||||||
|
|
||||||
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
|
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
|
||||||
debugPrint("call AddressBookPeerCard _getPopupMenuItems");
|
debugPrint("call AddressBookPeerCard _getPopupMenuItems");
|
||||||
@ -372,6 +489,8 @@ class AddressBookPeerCard extends BasePeerCard {
|
|||||||
value: 'unremember-password'),
|
value: 'unremember-password'),
|
||||||
PopupMenuItem<String>(
|
PopupMenuItem<String>(
|
||||||
child: Text(translate('Add to Favorites')), value: 'add-fav'),
|
child: Text(translate('Add to Favorites')), value: 'add-fav'),
|
||||||
|
PopupMenuItem<String>(
|
||||||
|
child: Text(translate('Edit Tag')), value: 'ab-edit-tag'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import 'package:flutter_hbb/desktop/screen/desktop_file_transfer_screen.dart';
|
|||||||
import 'package:flutter_hbb/desktop/screen/desktop_remote_screen.dart';
|
import 'package:flutter_hbb/desktop/screen/desktop_remote_screen.dart';
|
||||||
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
import 'package:get/route_manager.dart';
|
import 'package:get/route_manager.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
@ -32,6 +33,10 @@ Future<Null> main(List<String> args) async {
|
|||||||
runRustDeskApp(args);
|
runRustDeskApp(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ThemeData getCurrentTheme() {
|
||||||
|
return isDarkTheme() ? MyTheme.darkTheme : MyTheme.darkTheme;
|
||||||
|
}
|
||||||
|
|
||||||
void runRustDeskApp(List<String> args) async {
|
void runRustDeskApp(List<String> args) async {
|
||||||
if (!isDesktop) {
|
if (!isDesktop) {
|
||||||
runApp(App());
|
runApp(App());
|
||||||
@ -47,12 +52,17 @@ void runRustDeskApp(List<String> args) async {
|
|||||||
WindowType wType = type.windowType;
|
WindowType wType = type.windowType;
|
||||||
switch (wType) {
|
switch (wType) {
|
||||||
case WindowType.RemoteDesktop:
|
case WindowType.RemoteDesktop:
|
||||||
runApp(DesktopRemoteScreen(
|
runApp(GetMaterialApp(
|
||||||
|
theme: getCurrentTheme(),
|
||||||
|
home: DesktopRemoteScreen(
|
||||||
params: argument,
|
params: argument,
|
||||||
|
),
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
case WindowType.FileTransfer:
|
case WindowType.FileTransfer:
|
||||||
runApp(DesktopFileTransferScreen(params: argument));
|
runApp(GetMaterialApp(
|
||||||
|
theme: getCurrentTheme(),
|
||||||
|
home: DesktopFileTransferScreen(params: argument)));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -85,10 +95,7 @@ class App extends StatelessWidget {
|
|||||||
navigatorKey: globalKey,
|
navigatorKey: globalKey,
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
title: 'RustDesk',
|
title: 'RustDesk',
|
||||||
theme: ThemeData(
|
theme: getCurrentTheme(),
|
||||||
primarySwatch: Colors.blue,
|
|
||||||
visualDensity: VisualDensity.adaptivePlatformDensity,
|
|
||||||
),
|
|
||||||
home: isDesktop
|
home: isDesktop
|
||||||
? DesktopHomePage()
|
? DesktopHomePage()
|
||||||
: !isAndroid
|
: !isAndroid
|
||||||
|
@ -141,6 +141,16 @@ class AbModel with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setPeerOption(String id, String key, String value) {
|
||||||
|
final it = peers.where((p0) => p0['id'] == id);
|
||||||
|
if (it.isEmpty) {
|
||||||
|
debugPrint("${id} is not exists");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
it.first[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
peers.clear();
|
peers.clear();
|
||||||
tags.clear();
|
tags.clear();
|
||||||
|
@ -1010,6 +1010,14 @@ class FFI {
|
|||||||
return bind.mainSetLocalOption(key: key, value: value);
|
return bind.mainSetLocalOption(key: key, value: value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<String> getPeerOption(String id, String key) {
|
||||||
|
return bind.mainGetPeerOption(id: id, key: key);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setPeerOption(String id, String key, String value) {
|
||||||
|
return bind.mainSetPeerOption(id: id, key: key, value: value);
|
||||||
|
}
|
||||||
|
|
||||||
void setOption(String name, String value) {
|
void setOption(String name, String value) {
|
||||||
Map<String, String> res = Map()
|
Map<String, String> res = Map()
|
||||||
..["name"] = name
|
..["name"] = name
|
||||||
|
@ -20,11 +20,11 @@ use crate::flutter::{self, Session, SESSIONS};
|
|||||||
use crate::start_server;
|
use crate::start_server;
|
||||||
use crate::ui_interface;
|
use crate::ui_interface;
|
||||||
use crate::ui_interface::{
|
use crate::ui_interface::{
|
||||||
change_id, check_connect_status, get_api_server, get_app_name, get_async_job_status,
|
change_id, check_connect_status, forget_password, get_api_server, get_app_name,
|
||||||
get_connect_status, get_fav, get_id, get_lan_peers, get_license, get_local_option, get_options,
|
get_async_job_status, get_connect_status, get_fav, get_id, get_lan_peers, get_license,
|
||||||
get_peer, get_socks, get_sound_inputs, get_uuid, get_version, has_rendezvous_service,
|
get_local_option, get_options, get_peer, get_peer_option, get_socks, get_sound_inputs,
|
||||||
is_ok_change_id, post_request, set_local_option, set_options, set_socks, store_fav,
|
get_uuid, get_version, has_rendezvous_service, is_ok_change_id, post_request, set_local_option,
|
||||||
test_if_valid_server, using_public_server,
|
set_options, set_peer_option, set_socks, store_fav, test_if_valid_server, using_public_server,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn initialize(app_dir: &str) {
|
fn initialize(app_dir: &str) {
|
||||||
@ -496,6 +496,18 @@ pub fn main_get_uuid() -> String {
|
|||||||
get_uuid()
|
get_uuid()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn main_get_peer_option(id: String, key: String) -> String {
|
||||||
|
get_peer_option(id, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main_set_peer_option(id: String, key: String, value: String) {
|
||||||
|
set_peer_option(id, key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main_forget_password(id: String) {
|
||||||
|
forget_password(id)
|
||||||
|
}
|
||||||
|
|
||||||
/// FFI for **get** commands which are idempotent.
|
/// FFI for **get** commands which are idempotent.
|
||||||
/// Return result in c string.
|
/// Return result in c string.
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user