mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-01-18 07:43:01 +08:00
Merge pull request #1037 from Kingtous/flutter_desktop
add: card, address book, fav ui, new AbModel
This commit is contained in:
commit
2e494ba772
@ -325,4 +325,6 @@ Future<void> initGlobalFFI() async {
|
||||
// after `put`, can also be globally found by Get.find<FFI>();
|
||||
Get.put(_globalFFI, permanent: true);
|
||||
await _globalFFI.ffiModel.init();
|
||||
// trigger connection status updater
|
||||
await _globalFFI.bind.mainCheckConnectStatus();
|
||||
}
|
@ -1,8 +1,12 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
import '../../common.dart';
|
||||
import '../../mobile/pages/home_page.dart';
|
||||
@ -10,6 +14,8 @@ import '../../mobile/pages/scan_page.dart';
|
||||
import '../../mobile/pages/settings_page.dart';
|
||||
import '../../models/model.dart';
|
||||
|
||||
enum RemoteType { recently, favorite, discovered, addressBook }
|
||||
|
||||
/// Connection page for connecting to a remote peer.
|
||||
class ConnectionPage extends StatefulWidget implements PageShape {
|
||||
ConnectionPage({Key? key}) : super(key: key);
|
||||
@ -36,18 +42,22 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
var _updateUrl = '';
|
||||
var _menuPos;
|
||||
|
||||
Timer? _updateTimer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_updateTimer = Timer.periodic(Duration(seconds: 1), (timer) {
|
||||
updateStatus();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Provider.of<FfiModel>(context);
|
||||
if (_idController.text.isEmpty) _idController.text = gFFI.getId();
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: MyTheme.grayBg
|
||||
color: MyTheme.grayBg
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
@ -62,7 +72,65 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
).marginOnly(top: 16.0, left: 16.0),
|
||||
SizedBox(height: 12),
|
||||
Divider(thickness: 1,),
|
||||
getPeers(),
|
||||
Expanded(
|
||||
child: DefaultTabController(
|
||||
length: 4,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TabBar(
|
||||
labelColor: Colors.black87,
|
||||
isScrollable: true,
|
||||
indicatorSize: TabBarIndicatorSize.label,
|
||||
tabs: [
|
||||
Tab(child: Text(translate("Recent Sessions")),),
|
||||
Tab(child: Text(translate("Favorites")),),
|
||||
Tab(child: Text(translate("Discovered")),),
|
||||
Tab(child: Text(translate("Address Book")),),
|
||||
]),
|
||||
Expanded(child: TabBarView(children: [
|
||||
FutureBuilder<Widget>(future: getPeers(rType: RemoteType.recently),
|
||||
builder: (context, snapshot){
|
||||
if (snapshot.hasData) {
|
||||
return snapshot.data!;
|
||||
} else {
|
||||
return Offstage();
|
||||
}
|
||||
}),
|
||||
FutureBuilder<Widget>(
|
||||
future: getPeers(rType: RemoteType.favorite),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return snapshot.data!;
|
||||
} else {
|
||||
return Offstage();
|
||||
}
|
||||
}),
|
||||
FutureBuilder<Widget>(
|
||||
future: getPeers(rType: RemoteType.discovered),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return snapshot.data!;
|
||||
} else {
|
||||
return Offstage();
|
||||
}
|
||||
}),
|
||||
FutureBuilder<Widget>(
|
||||
future: buildAddressBook(context),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return snapshot.data!;
|
||||
} else {
|
||||
return Offstage();
|
||||
}
|
||||
}),
|
||||
]).paddingSymmetric(horizontal: 12.0, vertical: 4.0))
|
||||
],
|
||||
)),
|
||||
),
|
||||
Divider(),
|
||||
SizedBox(height: 50, child: Obx(() => buildStatus()))
|
||||
.paddingSymmetric(horizontal: 12.0)
|
||||
]),
|
||||
);
|
||||
}
|
||||
@ -96,20 +164,20 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
return _updateUrl.isEmpty
|
||||
? SizedBox(height: 0)
|
||||
: InkWell(
|
||||
onTap: () async {
|
||||
final url = _updateUrl + '.apk';
|
||||
if (await canLaunch(url)) {
|
||||
await launch(url);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
alignment: AlignmentDirectional.center,
|
||||
width: double.infinity,
|
||||
color: Colors.pinkAccent,
|
||||
padding: EdgeInsets.symmetric(vertical: 12),
|
||||
child: Text(translate('Download new version'),
|
||||
style: TextStyle(
|
||||
color: Colors.white, fontWeight: FontWeight.bold))));
|
||||
onTap: () async {
|
||||
final url = _updateUrl + '.apk';
|
||||
if (await canLaunch(url)) {
|
||||
await launch(url);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
alignment: AlignmentDirectional.center,
|
||||
width: double.infinity,
|
||||
color: Colors.pinkAccent,
|
||||
padding: EdgeInsets.symmetric(vertical: 12),
|
||||
child: Text(translate('Download new version'),
|
||||
style: TextStyle(
|
||||
color: Colors.white, fontWeight: FontWeight.bold))));
|
||||
}
|
||||
|
||||
/// UI for the search bar.
|
||||
@ -221,6 +289,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
@override
|
||||
void dispose() {
|
||||
_idController.dispose();
|
||||
_updateTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@ -230,73 +299,173 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
if (platform == 'mac os')
|
||||
platform = 'mac';
|
||||
else if (platform != 'linux' && platform != 'android') platform = 'win';
|
||||
return Image.asset('assets/$platform.png', width: 24, height: 24);
|
||||
return Image.asset('assets/$platform.png', height: 50);
|
||||
}
|
||||
|
||||
/// Get all the saved peers.
|
||||
Widget getPeers() {
|
||||
final size = MediaQuery.of(context).size;
|
||||
Future<Widget> getPeers({RemoteType rType = RemoteType.recently}) async {
|
||||
final space = 8.0;
|
||||
var width = size.width - 2 * space;
|
||||
final minWidth = 320.0;
|
||||
if (size.width > minWidth + 2 * space) {
|
||||
final n = (size.width / (minWidth + 2 * space)).floor();
|
||||
width = size.width / n - 2 * space;
|
||||
}
|
||||
final cards = <Widget>[];
|
||||
var peers = gFFI.peers();
|
||||
var 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:
|
||||
await gFFI.abModel.getAb();
|
||||
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(Container(
|
||||
width: width,
|
||||
width: 225,
|
||||
height: 150,
|
||||
child: Card(
|
||||
child: GestureDetector(
|
||||
onTap: !isWebDesktop ? () => connect('${p.id}') : null,
|
||||
onDoubleTap: isWebDesktop ? () => connect('${p.id}') : null,
|
||||
onLongPressStart: (details) {
|
||||
final x = details.globalPosition.dx;
|
||||
final y = details.globalPosition.dy;
|
||||
_menuPos = RelativeRect.fromLTRB(x, y, x, y);
|
||||
showPeerMenu(context, p.id);
|
||||
},
|
||||
child: ListTile(
|
||||
contentPadding: const EdgeInsets.only(left: 12),
|
||||
subtitle: Text('${p.username}@${p.hostname}'),
|
||||
title: Text('${p.id}'),
|
||||
leading: Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: getPlatformImage('${p.platform}'),
|
||||
color: str2color('${p.id}${p.platform}', 0x7f)),
|
||||
trailing: InkWell(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
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);
|
||||
}),
|
||||
)))));
|
||||
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 Wrap(children: cards, spacing: space, runSpacing: space);
|
||||
return SingleChildScrollView(
|
||||
child: Wrap(children: cards, spacing: space, runSpacing: space));
|
||||
}
|
||||
|
||||
/// Show the peer menu and handle user's choice.
|
||||
/// User might remove the peer or send a file to the peer.
|
||||
void showPeerMenu(BuildContext context, String id) async {
|
||||
void showPeerMenu(BuildContext context, String id, RemoteType rType) async {
|
||||
var items = [
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Connect')), value: 'connect'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Transfer File')), value: 'file'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('TCP Tunneling')), value: 'tcp-tunnel'),
|
||||
PopupMenuItem<String>(child: Text(translate('Rename')), value: 'rename'),
|
||||
PopupMenuItem<String>(child: Text(translate('Remove')), value: 'remove'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Unremember Password')),
|
||||
value: 'unremember-password'),
|
||||
];
|
||||
if (rType == RemoteType.favorite) {
|
||||
items.add(PopupMenuItem<String>(
|
||||
child: Text(translate('Remove from Favorites')),
|
||||
value: 'remove-fav'));
|
||||
} else
|
||||
items.add(PopupMenuItem<String>(
|
||||
child: Text(translate('Add to Favorites')), value: 'add-fav'));
|
||||
var value = await showMenu(
|
||||
context: context,
|
||||
position: this._menuPos,
|
||||
items: [
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Remove')), value: 'remove')
|
||||
] +
|
||||
([
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Transfer File')), value: 'file')
|
||||
]),
|
||||
items: items,
|
||||
elevation: 8,
|
||||
);
|
||||
if (value == 'remove') {
|
||||
@ -306,7 +475,200 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
}();
|
||||
} else if (value == 'file') {
|
||||
connect(id, isFileTransfer: true);
|
||||
} else if (value == 'add-fav') {}
|
||||
}
|
||||
|
||||
var svcStopped = false.obs;
|
||||
var svcStatusCode = 0.obs;
|
||||
var svcIsUsingPublicServer = true.obs;
|
||||
|
||||
Widget buildStatus() {
|
||||
final light = Container(
|
||||
height: 8,
|
||||
width: 8,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: Colors.green,
|
||||
),
|
||||
).paddingSymmetric(horizontal: 8.0);
|
||||
if (svcStopped.value) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [light, Text(translate("Service is not running"))],
|
||||
);
|
||||
} else {
|
||||
if (svcStatusCode.value == 0) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [light, Text(translate("connecting_status"))],
|
||||
);
|
||||
} else if (svcStatusCode.value == -1) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [light, Text(translate("not_ready_status"))],
|
||||
);
|
||||
}
|
||||
}
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
light,
|
||||
Text("${translate('Ready')}"),
|
||||
svcIsUsingPublicServer.value
|
||||
? InkWell(
|
||||
onTap: onUsePublicServerGuide,
|
||||
child: Text(
|
||||
', ${translate('setup_server_tip')}',
|
||||
style: TextStyle(decoration: TextDecoration.underline),
|
||||
),
|
||||
)
|
||||
: Offstage()
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void onUsePublicServerGuide() {
|
||||
final url = "https://rustdesk.com/blog/id-relay-set/";
|
||||
canLaunchUrlString(url).then((can) {
|
||||
if (can) {
|
||||
launchUrlString(url);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
updateStatus() async {
|
||||
svcStopped.value = gFFI.getOption("stop-service") == "Y";
|
||||
final status = jsonDecode(await gFFI.bind.mainGetConnectStatus())
|
||||
as Map<String, dynamic>;
|
||||
svcStatusCode.value = status["status_num"];
|
||||
svcIsUsingPublicServer.value = await gFFI.bind.mainIsUsingPublicServer();
|
||||
}
|
||||
|
||||
handleLogin() {}
|
||||
|
||||
Future<Widget> buildAddressBook(BuildContext context) async {
|
||||
final token = await gFFI.getLocalOption('access_token');
|
||||
if (token.trim().isEmpty) {
|
||||
return Center(
|
||||
child: InkWell(
|
||||
onTap: handleLogin,
|
||||
child: Text(
|
||||
translate("Login"),
|
||||
style: TextStyle(decoration: TextDecoration.underline),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
final model = gFFI.abModel;
|
||||
return FutureBuilder(
|
||||
future: model.getAb(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return _buildAddressBook(context);
|
||||
} else {
|
||||
if (model.abLoading) {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
} else if (model.abError.isNotEmpty) {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
} else {
|
||||
return Offstage();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildAddressBook(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
Card(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
side: BorderSide(color: MyTheme.grayBg)),
|
||||
color: Colors.white,
|
||||
child: Container(
|
||||
width: 200,
|
||||
height: double.infinity,
|
||||
padding: EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(translate('Tags')),
|
||||
InkWell(
|
||||
child: PopupMenuButton(
|
||||
itemBuilder: (context) => [],
|
||||
child: Icon(Icons.more_vert_outlined)),
|
||||
)
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: MyTheme.darkGray)),
|
||||
child: Wrap(
|
||||
children:
|
||||
gFFI.abModel.tags.map((e) => buildTag(e)).toList(),
|
||||
),
|
||||
).marginSymmetric(vertical: 8.0),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
).marginOnly(right: 8.0),
|
||||
Column(
|
||||
children: [
|
||||
FutureBuilder<Widget>(
|
||||
future: getPeers(rType: RemoteType.addressBook),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return snapshot.data!;
|
||||
} else {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
}),
|
||||
],
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildTag(String tagName) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: MyTheme.darkGray),
|
||||
borderRadius: BorderRadius.circular(10)),
|
||||
margin: EdgeInsets.symmetric(horizontal: 4.0, vertical: 8.0),
|
||||
padding: EdgeInsets.symmetric(vertical: 2.0, horizontal: 8.0),
|
||||
child: Text(tagName),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AddressBookPage extends StatefulWidget {
|
||||
const AddressBookPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<AddressBookPage> createState() => _AddressBookPageState();
|
||||
}
|
||||
|
||||
class _AddressBookPageState extends State<AddressBookPage> {
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
final ab = gFFI.abModel.getAb();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container();
|
||||
}
|
||||
}
|
||||
|
||||
@ -324,13 +686,13 @@ class _WebMenuState extends State<WebMenu> {
|
||||
icon: Icon(Icons.more_vert),
|
||||
itemBuilder: (context) {
|
||||
return (isIOS
|
||||
? [
|
||||
PopupMenuItem(
|
||||
child: Icon(Icons.qr_code_scanner, color: Colors.black),
|
||||
value: "scan",
|
||||
)
|
||||
]
|
||||
: <PopupMenuItem<String>>[]) +
|
||||
? [
|
||||
PopupMenuItem(
|
||||
child: Icon(Icons.qr_code_scanner, color: Colors.black),
|
||||
value: "scan",
|
||||
)
|
||||
]
|
||||
: <PopupMenuItem<String>>[]) +
|
||||
[
|
||||
PopupMenuItem(
|
||||
child: Text(translate('ID/Relay Server')),
|
||||
@ -340,13 +702,13 @@ class _WebMenuState extends State<WebMenu> {
|
||||
(getUrl().contains('admin.rustdesk.com')
|
||||
? <PopupMenuItem<String>>[]
|
||||
: [
|
||||
PopupMenuItem(
|
||||
child: Text(username == null
|
||||
? translate("Login")
|
||||
: translate("Logout") + ' ($username)'),
|
||||
value: "login",
|
||||
)
|
||||
]) +
|
||||
PopupMenuItem(
|
||||
child: Text(username == null
|
||||
? translate("Login")
|
||||
: translate("Logout") + ' ($username)'),
|
||||
value: "login",
|
||||
)
|
||||
]) +
|
||||
[
|
||||
PopupMenuItem(
|
||||
child: Text(translate('About') + ' RustDesk'),
|
||||
|
56
flutter/lib/models/ab_model.dart
Normal file
56
flutter/lib/models/ab_model.dart
Normal file
@ -0,0 +1,56 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/models/model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class AbModel with ChangeNotifier {
|
||||
var abLoading = false;
|
||||
var abError = "";
|
||||
var tags = [];
|
||||
var peers = [];
|
||||
|
||||
WeakReference<FFI> parent;
|
||||
|
||||
AbModel(this.parent);
|
||||
|
||||
FFI? get _ffi => parent.target;
|
||||
|
||||
Future<dynamic> getAb() async {
|
||||
abLoading = true;
|
||||
notifyListeners();
|
||||
// request
|
||||
final api = "${await getApiServer()}/api/ab/get";
|
||||
debugPrint("request $api with post ${await _getHeaders()}");
|
||||
final resp = await http.post(Uri.parse(api), headers: await _getHeaders());
|
||||
abLoading = false;
|
||||
Map<String, dynamic> json = jsonDecode(resp.body);
|
||||
if (json.containsKey('error')) {
|
||||
abError = json['error'];
|
||||
} else if (json.containsKey('data')) {
|
||||
// {"tags":["aaa","bbb"],
|
||||
// "peers":[{"id":"aa1234","username":"selfd",
|
||||
// "hostname":"PC","platform":"Windows","tags":["aaa"]}]}
|
||||
final data = jsonDecode(json['data']);
|
||||
tags = data['tags'];
|
||||
peers = data['peers'];
|
||||
}
|
||||
print(json);
|
||||
notifyListeners();
|
||||
return resp.body;
|
||||
}
|
||||
|
||||
Future<String> getApiServer() async {
|
||||
return await _ffi?.bind.mainGetApiServer() ?? "";
|
||||
}
|
||||
|
||||
void reset() {
|
||||
tags.clear();
|
||||
peers.clear();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<Map<String, String>>? _getHeaders() {
|
||||
return _ffi?.getHttpHeaders();
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ import 'dart:ui' as ui;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hbb/generated_bridge.dart';
|
||||
import 'package:flutter_hbb/models/ab_model.dart';
|
||||
import 'package:flutter_hbb/models/chat_model.dart';
|
||||
import 'package:flutter_hbb/models/file_model.dart';
|
||||
import 'package:flutter_hbb/models/server_model.dart';
|
||||
@ -809,6 +810,7 @@ class FFI {
|
||||
late final ServerModel serverModel;
|
||||
late final ChatModel chatModel;
|
||||
late final FileModel fileModel;
|
||||
late final AbModel abModel;
|
||||
|
||||
FFI() {
|
||||
this.imageModel = ImageModel(WeakReference(this));
|
||||
@ -818,6 +820,7 @@ class FFI {
|
||||
this.serverModel = ServerModel(WeakReference(this)); // use global FFI
|
||||
this.chatModel = ChatModel(WeakReference(this));
|
||||
this.fileModel = FileModel(WeakReference(this));
|
||||
this.abModel = AbModel(WeakReference(this));
|
||||
}
|
||||
|
||||
static FFI newFFI() {
|
||||
@ -995,9 +998,17 @@ class FFI {
|
||||
return ffiModel.platformFFI.getByName("option", name);
|
||||
}
|
||||
|
||||
Future<String> getLocalOption(String name) {
|
||||
return bind.mainGetLocalOption(key: name);
|
||||
}
|
||||
|
||||
Future<void> setLocalOption(String key, String value) {
|
||||
return bind.mainSetLocalOption(key: key, value: value);
|
||||
}
|
||||
|
||||
void setOption(String name, String value) {
|
||||
Map<String, String> res = Map()
|
||||
..["name"] = name
|
||||
..["name"] = name
|
||||
..["value"] = value;
|
||||
return ffiModel.platformFFI.setByName('option', jsonEncode(res));
|
||||
}
|
||||
@ -1087,9 +1098,13 @@ class FFI {
|
||||
return input;
|
||||
}
|
||||
|
||||
void setDefaultAudioInput(String input){
|
||||
void setDefaultAudioInput(String input) {
|
||||
setOption('audio-input', input);
|
||||
}
|
||||
|
||||
Future<Map<String, String>> getHttpHeaders() async {
|
||||
return {"Authorization": "Bearer " + await getLocalOption("access_token")};
|
||||
}
|
||||
}
|
||||
|
||||
class Peer {
|
||||
|
@ -5,7 +5,7 @@ use std::{
|
||||
};
|
||||
|
||||
use flutter_rust_bridge::{StreamSink, SyncReturn, ZeroCopyBuffer};
|
||||
use serde_json::{Number, Value};
|
||||
use serde_json::{json, Number, Value};
|
||||
|
||||
use hbb_common::ResultType;
|
||||
use hbb_common::{
|
||||
@ -20,8 +20,11 @@ use crate::flutter::{self, Session, SESSIONS};
|
||||
use crate::start_server;
|
||||
use crate::ui_interface;
|
||||
use crate::ui_interface::{
|
||||
change_id, get_app_name, get_async_job_status, get_license, get_options, get_socks,
|
||||
get_sound_inputs, get_version, is_ok_change_id, set_options, set_socks, test_if_valid_server,
|
||||
change_id, check_connect_status, get_api_server, get_app_name, get_async_job_status,
|
||||
get_connect_status, get_fav, get_lan_peers, get_license, get_local_option, get_options,
|
||||
get_peer, get_socks, get_sound_inputs, get_version, has_rendezvous_service, is_ok_change_id,
|
||||
post_request, set_local_option, set_options, set_socks, store_fav, test_if_valid_server,
|
||||
using_public_server,
|
||||
};
|
||||
|
||||
fn initialize(app_dir: &str) {
|
||||
@ -429,6 +432,62 @@ pub fn main_get_version() -> String {
|
||||
get_version()
|
||||
}
|
||||
|
||||
pub fn main_get_fav() -> Vec<String> {
|
||||
get_fav()
|
||||
}
|
||||
|
||||
pub fn main_store_fav(favs: Vec<String>) {
|
||||
store_fav(favs)
|
||||
}
|
||||
|
||||
pub fn main_get_peers(id: String) -> String {
|
||||
let conf = get_peer(id);
|
||||
serde_json::to_string(&conf).unwrap_or("".to_string())
|
||||
}
|
||||
|
||||
pub fn main_get_lan_peers() -> String {
|
||||
get_lan_peers()
|
||||
}
|
||||
|
||||
pub fn main_get_connect_status() -> String {
|
||||
let status = get_connect_status();
|
||||
// (status_num, key_confirmed, mouse_time, id)
|
||||
let mut m = serde_json::Map::new();
|
||||
m.insert("status_num".to_string(), json!(status.0));
|
||||
m.insert("key_confirmed".to_string(), json!(status.1));
|
||||
m.insert("mouse_time".to_string(), json!(status.2));
|
||||
m.insert("id".to_string(), json!(status.3));
|
||||
serde_json::to_string(&m).unwrap_or("".to_string())
|
||||
}
|
||||
|
||||
pub fn main_check_connect_status() {
|
||||
check_connect_status(true);
|
||||
}
|
||||
|
||||
pub fn main_is_using_public_server() -> bool {
|
||||
using_public_server()
|
||||
}
|
||||
|
||||
pub fn main_has_rendezvous_service() -> bool {
|
||||
has_rendezvous_service()
|
||||
}
|
||||
|
||||
pub fn main_get_api_server() -> String {
|
||||
get_api_server()
|
||||
}
|
||||
|
||||
pub fn main_post_request(url: String, body: String, header: String) {
|
||||
post_request(url, body, header)
|
||||
}
|
||||
|
||||
pub fn main_get_local_option(key: String) -> String {
|
||||
get_local_option(key)
|
||||
}
|
||||
|
||||
pub fn main_set_local_option(key: String, value: String) {
|
||||
set_local_option(key, value)
|
||||
}
|
||||
|
||||
/// FFI for **get** commands which are idempotent.
|
||||
/// Return result in c string.
|
||||
///
|
||||
|
21
src/ipc.rs
21
src/ipc.rs
@ -1,4 +1,12 @@
|
||||
use crate::rendezvous_mediator::RendezvousMediator;
|
||||
use std::{collections::HashMap, sync::atomic::Ordering};
|
||||
#[cfg(not(windows))]
|
||||
use std::{fs::File, io::prelude::*};
|
||||
|
||||
use parity_tokio_ipc::{
|
||||
Connection as Conn, ConnectionClient as ConnClient, Endpoint, Incoming, SecurityAttributes,
|
||||
};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
pub use clipboard::ClipbaordFile;
|
||||
use hbb_common::{
|
||||
@ -12,13 +20,8 @@ use hbb_common::{
|
||||
tokio_util::codec::Framed,
|
||||
ResultType,
|
||||
};
|
||||
use parity_tokio_ipc::{
|
||||
Connection as Conn, ConnectionClient as ConnClient, Endpoint, Incoming, SecurityAttributes,
|
||||
};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::{collections::HashMap, sync::atomic::Ordering};
|
||||
#[cfg(not(windows))]
|
||||
use std::{fs::File, io::prelude::*};
|
||||
|
||||
use crate::rendezvous_mediator::RendezvousMediator;
|
||||
|
||||
// State with timestamp, because std::time::Instant cannot be serialized
|
||||
#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
|
||||
@ -73,7 +76,7 @@ pub enum FS {
|
||||
WriteOffset {
|
||||
id: i32,
|
||||
file_num: i32,
|
||||
offset_blk: u32
|
||||
offset_blk: u32,
|
||||
},
|
||||
CheckDigest {
|
||||
id: i32,
|
||||
|
@ -630,7 +630,7 @@ pub fn check_zombie(childs: Childs) {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_connect_status(reconnect: bool) -> mpsc::UnboundedSender<ipc::Data> {
|
||||
pub(crate) fn check_connect_status(reconnect: bool) -> mpsc::UnboundedSender<ipc::Data> {
|
||||
let (tx, rx) = mpsc::unbounded_channel::<ipc::Data>();
|
||||
std::thread::spawn(move || check_connect_status_(reconnect, rx));
|
||||
tx
|
||||
|
Loading…
Reference in New Issue
Block a user