2022-07-27 14:29:47 +08:00
|
|
|
import 'dart:async';
|
2022-07-18 18:20:00 +08:00
|
|
|
import 'dart:convert';
|
2022-06-02 16:23:20 +08:00
|
|
|
import 'dart:io';
|
|
|
|
|
2022-08-09 13:39:30 +08:00
|
|
|
import 'package:desktop_multi_window/desktop_multi_window.dart';
|
2022-06-02 16:23:20 +08:00
|
|
|
import 'package:flutter/material.dart' hide MenuItem;
|
2022-07-14 12:32:01 +08:00
|
|
|
import 'package:flutter/services.dart';
|
2022-05-25 00:28:59 +08:00
|
|
|
import 'package:flutter_hbb/common.dart';
|
2022-05-29 04:39:12 +08:00
|
|
|
import 'package:flutter_hbb/desktop/pages/connection_page.dart';
|
2022-05-29 19:55:50 +08:00
|
|
|
import 'package:flutter_hbb/desktop/widgets/titlebar_widget.dart';
|
2022-08-03 22:03:31 +08:00
|
|
|
import 'package:flutter_hbb/models/platform_model.dart';
|
2022-08-01 20:42:30 +08:00
|
|
|
import 'package:flutter_hbb/models/server_model.dart';
|
2022-08-09 09:01:06 +08:00
|
|
|
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
2022-07-14 12:32:01 +08:00
|
|
|
import 'package:get/get.dart';
|
2022-05-25 00:28:59 +08:00
|
|
|
import 'package:provider/provider.dart';
|
2022-07-29 16:47:24 +08:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2022-06-02 16:23:20 +08:00
|
|
|
import 'package:tray_manager/tray_manager.dart';
|
2022-07-18 18:20:00 +08:00
|
|
|
import 'package:url_launcher/url_launcher_string.dart';
|
2022-08-09 13:39:30 +08:00
|
|
|
import 'package:window_manager/window_manager.dart';
|
2022-05-23 16:44:23 +08:00
|
|
|
|
|
|
|
class DesktopHomePage extends StatefulWidget {
|
|
|
|
DesktopHomePage({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _DesktopHomePageState();
|
|
|
|
}
|
|
|
|
|
2022-05-29 19:55:50 +08:00
|
|
|
const borderColor = Color(0xFF2F65BA);
|
|
|
|
|
2022-08-09 13:39:30 +08:00
|
|
|
class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener, WindowListener {
|
|
|
|
|
|
|
|
@override
|
|
|
|
void onWindowClose() async {
|
|
|
|
super.onWindowClose();
|
|
|
|
// close all sub windows
|
|
|
|
if (await windowManager.isPreventClose()) {
|
|
|
|
try {
|
|
|
|
await rustDeskWinManager.closeAllSubWindows();
|
|
|
|
} catch (err) {
|
|
|
|
debugPrint("$err");
|
|
|
|
} finally {
|
|
|
|
await windowManager.setPreventClose(false);
|
|
|
|
await windowManager.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-23 16:44:23 +08:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-05-25 00:28:59 +08:00
|
|
|
return Scaffold(
|
2022-05-29 19:55:50 +08:00
|
|
|
body: Column(
|
|
|
|
children: [
|
2022-06-02 14:51:09 +08:00
|
|
|
DesktopTitleBar(
|
|
|
|
child: Center(
|
|
|
|
child: Text(
|
|
|
|
"RustDesk",
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.white,
|
|
|
|
fontSize: 20,
|
|
|
|
fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
),
|
2022-05-29 19:55:50 +08:00
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Flexible(
|
|
|
|
child: buildServerInfo(context),
|
|
|
|
flex: 1,
|
|
|
|
),
|
|
|
|
Flexible(
|
|
|
|
child: buildServerBoard(context),
|
|
|
|
flex: 4,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-05-25 00:28:59 +08:00
|
|
|
),
|
2022-05-29 19:55:50 +08:00
|
|
|
),
|
|
|
|
],
|
2022-05-25 00:28:59 +08:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildServerInfo(BuildContext context) {
|
|
|
|
return ChangeNotifierProvider.value(
|
2022-06-13 21:07:26 +08:00
|
|
|
value: gFFI.serverModel,
|
2022-05-29 10:25:36 +08:00
|
|
|
child: Container(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
buildTip(context),
|
|
|
|
buildIDBoard(context),
|
|
|
|
buildPasswordBoard(context),
|
|
|
|
],
|
|
|
|
),
|
2022-05-25 00:28:59 +08:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildServerBoard(BuildContext context) {
|
2022-05-29 10:25:36 +08:00
|
|
|
return Column(
|
|
|
|
children: [
|
2022-07-14 12:32:01 +08:00
|
|
|
Expanded(child: ConnectionPage()),
|
2022-05-29 10:25:36 +08:00
|
|
|
],
|
2022-05-25 00:28:59 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildIDBoard(BuildContext context) {
|
2022-06-13 21:07:26 +08:00
|
|
|
final model = gFFI.serverModel;
|
2022-05-29 10:25:36 +08:00
|
|
|
return Container(
|
|
|
|
margin: EdgeInsets.symmetric(vertical: 4.0, horizontal: 16.0),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.baseline,
|
|
|
|
textBaseline: TextBaseline.alphabetic,
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
width: 3,
|
|
|
|
height: 70,
|
|
|
|
decoration: BoxDecoration(color: MyTheme.accent),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2022-07-14 12:32:01 +08:00
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
translate("ID"),
|
2022-07-18 18:20:00 +08:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 18, fontWeight: FontWeight.w500),
|
2022-07-14 12:32:01 +08:00
|
|
|
),
|
2022-07-27 14:29:47 +08:00
|
|
|
FutureBuilder<Widget>(
|
|
|
|
future: buildPopupMenu(context),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasError) {
|
|
|
|
print("${snapshot.error}");
|
|
|
|
}
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
return snapshot.data!;
|
|
|
|
} else {
|
|
|
|
return Offstage();
|
|
|
|
}
|
|
|
|
})
|
2022-07-14 12:32:01 +08:00
|
|
|
],
|
2022-05-29 10:25:36 +08:00
|
|
|
),
|
2022-08-03 09:08:10 +08:00
|
|
|
GestureDetector(
|
|
|
|
onDoubleTap: () {
|
|
|
|
Clipboard.setData(
|
|
|
|
ClipboardData(text: model.serverId.text));
|
|
|
|
showToast(translate("Copied"));
|
|
|
|
},
|
|
|
|
child: TextFormField(
|
|
|
|
controller: model.serverId,
|
|
|
|
readOnly: true,
|
|
|
|
)),
|
2022-05-29 10:25:36 +08:00
|
|
|
],
|
|
|
|
),
|
2022-05-25 00:28:59 +08:00
|
|
|
),
|
2022-05-29 10:25:36 +08:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-27 14:29:47 +08:00
|
|
|
Future<Widget> buildPopupMenu(BuildContext context) async {
|
|
|
|
var position;
|
|
|
|
return GestureDetector(
|
|
|
|
onTapDown: (detail) {
|
|
|
|
final x = detail.globalPosition.dx;
|
|
|
|
final y = detail.globalPosition.dy;
|
|
|
|
position = RelativeRect.fromLTRB(x, y, x, y);
|
|
|
|
},
|
|
|
|
onTap: () async {
|
|
|
|
final userName = await gFFI.userModel.getUserName();
|
2022-08-08 17:53:51 +08:00
|
|
|
final enabledInput = await bind.mainGetOption(key: 'enable-audio');
|
|
|
|
final defaultInput = await gFFI.getDefaultAudioInput();
|
2022-08-03 09:08:10 +08:00
|
|
|
var menu = <PopupMenuEntry>[
|
2022-07-27 14:29:47 +08:00
|
|
|
genEnablePopupMenuItem(
|
|
|
|
translate("Enable Keyboard/Mouse"),
|
|
|
|
'enable-keyboard',
|
|
|
|
),
|
|
|
|
genEnablePopupMenuItem(
|
|
|
|
translate("Enable Clipboard"),
|
|
|
|
'enable-clipboard',
|
|
|
|
),
|
|
|
|
genEnablePopupMenuItem(
|
|
|
|
translate("Enable File Transfer"),
|
|
|
|
'enable-file-transfer',
|
|
|
|
),
|
|
|
|
genEnablePopupMenuItem(
|
|
|
|
translate("Enable TCP Tunneling"),
|
|
|
|
'enable-tunnel',
|
|
|
|
),
|
2022-08-08 17:53:51 +08:00
|
|
|
genAudioInputPopupMenuItem(enabledInput != "N", defaultInput),
|
2022-08-03 09:08:10 +08:00
|
|
|
PopupMenuDivider(),
|
2022-07-27 14:29:47 +08:00
|
|
|
PopupMenuItem(
|
|
|
|
child: Text(translate("ID/Relay Server")),
|
|
|
|
value: 'custom-server',
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
child: Text(translate("IP Whitelisting")),
|
|
|
|
value: 'whitelist',
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
child: Text(translate("Socks5 Proxy")),
|
|
|
|
value: 'socks5-proxy',
|
|
|
|
),
|
2022-08-03 09:08:10 +08:00
|
|
|
PopupMenuDivider(),
|
2022-07-27 14:29:47 +08:00
|
|
|
genEnablePopupMenuItem(
|
|
|
|
translate("Enable Service"),
|
|
|
|
'stop-service',
|
|
|
|
),
|
|
|
|
// TODO: direct server
|
|
|
|
genEnablePopupMenuItem(
|
|
|
|
translate("Always connected via relay"),
|
|
|
|
'allow-always-relay',
|
|
|
|
),
|
|
|
|
genEnablePopupMenuItem(
|
|
|
|
translate("Start ID/relay service"),
|
|
|
|
'stop-rendezvous-service',
|
|
|
|
),
|
2022-08-03 09:08:10 +08:00
|
|
|
PopupMenuDivider(),
|
2022-07-27 14:29:47 +08:00
|
|
|
userName.isEmpty
|
|
|
|
? PopupMenuItem(
|
|
|
|
child: Text(translate("Login")),
|
|
|
|
value: 'login',
|
|
|
|
)
|
|
|
|
: PopupMenuItem(
|
|
|
|
child: Text("${translate("Logout")} $userName"),
|
|
|
|
value: 'logout',
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
child: Text(translate("Change ID")),
|
|
|
|
value: 'change-id',
|
|
|
|
),
|
2022-08-03 09:08:10 +08:00
|
|
|
PopupMenuDivider(),
|
2022-07-27 14:29:47 +08:00
|
|
|
genEnablePopupMenuItem(
|
|
|
|
translate("Dark Theme"),
|
|
|
|
'allow-darktheme',
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
child: Text(translate("About")),
|
|
|
|
value: 'about',
|
|
|
|
),
|
|
|
|
];
|
|
|
|
final v =
|
|
|
|
await showMenu(context: context, position: position, items: menu);
|
|
|
|
if (v != null) {
|
|
|
|
onSelectMenu(v);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Icon(Icons.more_vert_outlined));
|
|
|
|
}
|
|
|
|
|
2022-05-29 10:25:36 +08:00
|
|
|
buildPasswordBoard(BuildContext context) {
|
2022-06-13 21:07:26 +08:00
|
|
|
final model = gFFI.serverModel;
|
2022-05-29 10:25:36 +08:00
|
|
|
return Container(
|
|
|
|
margin: EdgeInsets.symmetric(vertical: 4.0, horizontal: 16.0),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.baseline,
|
|
|
|
textBaseline: TextBaseline.alphabetic,
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
width: 3,
|
|
|
|
height: 70,
|
|
|
|
decoration: BoxDecoration(color: MyTheme.accent),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
translate("Password"),
|
|
|
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
|
|
|
|
),
|
2022-08-01 20:42:30 +08:00
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
2022-08-03 09:08:10 +08:00
|
|
|
child: GestureDetector(
|
|
|
|
onDoubleTap: () {
|
|
|
|
Clipboard.setData(
|
|
|
|
ClipboardData(text: model.serverPasswd.text));
|
|
|
|
showToast(translate("Copied"));
|
|
|
|
},
|
|
|
|
child: TextFormField(
|
|
|
|
controller: model.serverPasswd,
|
|
|
|
readOnly: true,
|
|
|
|
),
|
2022-08-01 20:42:30 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.refresh),
|
2022-08-08 22:27:27 +08:00
|
|
|
onPressed: () => bind.mainUpdateTemporaryPassword(),
|
2022-08-01 20:42:30 +08:00
|
|
|
),
|
|
|
|
FutureBuilder<Widget>(
|
|
|
|
future: buildPasswordPopupMenu(context),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasError) {
|
|
|
|
print("${snapshot.error}");
|
|
|
|
}
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
return snapshot.data!;
|
|
|
|
} else {
|
|
|
|
return Offstage();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
],
|
2022-05-29 10:25:36 +08:00
|
|
|
),
|
|
|
|
],
|
2022-05-25 00:28:59 +08:00
|
|
|
),
|
|
|
|
),
|
2022-05-29 10:25:36 +08:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-08-01 20:42:30 +08:00
|
|
|
Future<Widget> buildPasswordPopupMenu(BuildContext context) async {
|
|
|
|
var position;
|
|
|
|
return GestureDetector(
|
|
|
|
onTapDown: (detail) {
|
|
|
|
final x = detail.globalPosition.dx;
|
|
|
|
final y = detail.globalPosition.dy;
|
|
|
|
position = RelativeRect.fromLTRB(x, y, x, y);
|
|
|
|
},
|
|
|
|
onTap: () async {
|
|
|
|
var method = (String text, String value) => PopupMenuItem(
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Offstage(
|
|
|
|
offstage: gFFI.serverModel.verificationMethod != value,
|
|
|
|
child: Icon(Icons.check)),
|
|
|
|
Text(
|
|
|
|
text,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
onTap: () => gFFI.serverModel.verificationMethod = value,
|
|
|
|
);
|
|
|
|
final temporary_enabled =
|
|
|
|
gFFI.serverModel.verificationMethod != kUsePermanentPassword;
|
2022-08-03 09:08:10 +08:00
|
|
|
var menu = <PopupMenuEntry>[
|
2022-08-01 20:42:30 +08:00
|
|
|
method(translate("Use temporary password"), kUseTemporaryPassword),
|
|
|
|
method(translate("Use permanent password"), kUsePermanentPassword),
|
|
|
|
method(translate("Use both passwords"), kUseBothPasswords),
|
2022-08-03 09:08:10 +08:00
|
|
|
PopupMenuDivider(),
|
2022-08-01 20:42:30 +08:00
|
|
|
PopupMenuItem(
|
|
|
|
child: Text(translate("Set permanent password")),
|
|
|
|
value: 'set-permanent-password',
|
|
|
|
enabled: gFFI.serverModel.verificationMethod !=
|
|
|
|
kUseTemporaryPassword),
|
|
|
|
PopupMenuItem(
|
|
|
|
child: PopupMenuButton(
|
2022-08-03 09:08:10 +08:00
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
child: Text(
|
|
|
|
translate("Set temporary password length"),
|
|
|
|
),
|
2022-08-01 20:42:30 +08:00
|
|
|
itemBuilder: (context) => ["6", "8", "10"]
|
|
|
|
.map((e) => PopupMenuItem(
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Offstage(
|
|
|
|
offstage: gFFI.serverModel
|
|
|
|
.temporaryPasswordLength !=
|
|
|
|
e,
|
|
|
|
child: Icon(Icons.check)),
|
|
|
|
Text(
|
|
|
|
e,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
if (gFFI.serverModel.temporaryPasswordLength !=
|
|
|
|
e) {
|
|
|
|
gFFI.serverModel.temporaryPasswordLength = e;
|
2022-08-08 22:27:27 +08:00
|
|
|
bind.mainUpdateTemporaryPassword();
|
2022-08-01 20:42:30 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
))
|
|
|
|
.toList(),
|
|
|
|
enabled: temporary_enabled,
|
|
|
|
),
|
|
|
|
enabled: temporary_enabled),
|
|
|
|
];
|
|
|
|
final v =
|
|
|
|
await showMenu(context: context, position: position, items: menu);
|
2022-08-03 09:08:10 +08:00
|
|
|
if (v == "set-permanent-password") {
|
|
|
|
setPasswordDialog();
|
2022-08-01 20:42:30 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Icon(Icons.edit));
|
|
|
|
}
|
|
|
|
|
2022-05-29 10:25:36 +08:00
|
|
|
buildTip(BuildContext context) {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
translate("Your Desktop"),
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
translate("desk_tip"),
|
|
|
|
overflow: TextOverflow.clip,
|
|
|
|
style: TextStyle(fontSize: 14),
|
|
|
|
)
|
|
|
|
],
|
2022-05-25 00:28:59 +08:00
|
|
|
),
|
|
|
|
);
|
2022-05-23 16:44:23 +08:00
|
|
|
}
|
2022-05-29 10:25:36 +08:00
|
|
|
|
|
|
|
buildControlPanel(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(10), color: MyTheme.white),
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(translate("Control Remote Desktop")),
|
|
|
|
Form(
|
|
|
|
child: Column(
|
2022-08-01 20:42:30 +08:00
|
|
|
children: [
|
|
|
|
TextFormField(
|
|
|
|
controller: TextEditingController(),
|
|
|
|
inputFormatters: [
|
|
|
|
FilteringTextInputFormatter.allow(RegExp(r"[0-9]"))
|
2022-07-14 12:32:01 +08:00
|
|
|
],
|
2022-08-01 20:42:30 +08:00
|
|
|
)
|
|
|
|
],
|
|
|
|
))
|
2022-05-29 10:25:36 +08:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildRecentSession(BuildContext context) {
|
|
|
|
return Center(child: Text("waiting implementation"));
|
|
|
|
}
|
2022-06-02 16:23:20 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
void onTrayMenuItemClick(MenuItem menuItem) {
|
|
|
|
print("click ${menuItem.key}");
|
|
|
|
switch (menuItem.key) {
|
|
|
|
case "quit":
|
|
|
|
exit(0);
|
|
|
|
case "show":
|
2022-08-01 20:42:30 +08:00
|
|
|
// windowManager.show();
|
2022-06-02 16:23:20 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
trayManager.addListener(this);
|
2022-08-09 13:39:30 +08:00
|
|
|
windowManager.addListener(this);
|
2022-08-09 09:01:06 +08:00
|
|
|
rustDeskWinManager.setMethodHandler((call, fromWindowId) async {
|
|
|
|
print(
|
|
|
|
"call ${call.method} with args ${call.arguments} from window ${fromWindowId}");
|
|
|
|
if (call.method == "main_window_on_top") {
|
2022-08-09 19:32:19 +08:00
|
|
|
window_on_top(null);
|
2022-08-09 09:01:06 +08:00
|
|
|
}
|
|
|
|
});
|
2022-06-02 16:23:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
trayManager.removeListener(this);
|
2022-08-09 13:39:30 +08:00
|
|
|
windowManager.removeListener(this);
|
2022-06-02 16:23:20 +08:00
|
|
|
super.dispose();
|
|
|
|
}
|
2022-07-14 12:32:01 +08:00
|
|
|
|
2022-07-29 16:47:24 +08:00
|
|
|
void changeTheme(String choice) async {
|
|
|
|
if (choice == "Y") {
|
|
|
|
Get.changeTheme(MyTheme.darkTheme);
|
|
|
|
} else {
|
|
|
|
Get.changeTheme(MyTheme.lightTheme);
|
|
|
|
}
|
|
|
|
Get.find<SharedPreferences>().setString("darkTheme", choice);
|
|
|
|
}
|
|
|
|
|
2022-08-08 17:53:51 +08:00
|
|
|
void onSelectMenu(String key) async {
|
|
|
|
if (key.startsWith('enable-')) {
|
|
|
|
final option = await bind.mainGetOption(key: key);
|
|
|
|
bind.mainSetOption(key: key, value: option == "N" ? "" : "N");
|
|
|
|
} else if (key.startsWith('allow-')) {
|
|
|
|
final option = await bind.mainGetOption(key: key);
|
2022-07-29 16:47:24 +08:00
|
|
|
final choice = option == "Y" ? "" : "Y";
|
2022-08-08 17:53:51 +08:00
|
|
|
bind.mainSetOption(key: key, value: choice);
|
2022-07-29 16:47:24 +08:00
|
|
|
changeTheme(choice);
|
2022-08-08 17:53:51 +08:00
|
|
|
} else if (key == "stop-service") {
|
|
|
|
final option = await bind.mainGetOption(key: key);
|
|
|
|
bind.mainSetOption(key: key, value: option == "Y" ? "" : "Y");
|
|
|
|
} else if (key == "change-id") {
|
2022-07-15 17:00:37 +08:00
|
|
|
changeId();
|
2022-08-08 17:53:51 +08:00
|
|
|
} else if (key == "custom-server") {
|
2022-07-18 18:20:00 +08:00
|
|
|
changeServer();
|
2022-08-08 17:53:51 +08:00
|
|
|
} else if (key == "whitelist") {
|
2022-07-18 18:20:00 +08:00
|
|
|
changeWhiteList();
|
2022-08-08 17:53:51 +08:00
|
|
|
} else if (key == "socks5-proxy") {
|
2022-07-18 18:20:00 +08:00
|
|
|
changeSocks5Proxy();
|
2022-08-08 17:53:51 +08:00
|
|
|
} else if (key == "about") {
|
2022-07-18 18:20:00 +08:00
|
|
|
about();
|
2022-08-08 17:53:51 +08:00
|
|
|
} else if (key == "logout") {
|
2022-07-27 14:29:47 +08:00
|
|
|
logOut();
|
2022-08-08 17:53:51 +08:00
|
|
|
} else if (key == "login") {
|
2022-07-27 14:29:47 +08:00
|
|
|
login();
|
2022-07-14 12:32:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-08 17:53:51 +08:00
|
|
|
PopupMenuItem<String> genEnablePopupMenuItem(String label, String key) {
|
|
|
|
Future<bool> getOptionEnable(String key) async {
|
|
|
|
final v = await bind.mainGetOption(key: key);
|
|
|
|
return key.startsWith('enable-') ? v != "N" : v == "Y";
|
|
|
|
}
|
|
|
|
|
2022-07-18 18:20:00 +08:00
|
|
|
return PopupMenuItem(
|
2022-08-08 17:53:51 +08:00
|
|
|
child: FutureBuilder<bool>(
|
|
|
|
future: getOptionEnable(key),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
var enable = false;
|
|
|
|
if (snapshot.hasData && snapshot.data!) {
|
|
|
|
enable = true;
|
|
|
|
}
|
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
Offstage(offstage: !enable, child: Icon(Icons.check)),
|
|
|
|
Text(
|
|
|
|
label,
|
|
|
|
style: genTextStyle(enable),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
value: key,
|
2022-07-18 18:20:00 +08:00
|
|
|
);
|
2022-07-14 12:32:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TextStyle genTextStyle(bool isPositive) {
|
2022-07-18 18:20:00 +08:00
|
|
|
return isPositive
|
|
|
|
? TextStyle()
|
|
|
|
: TextStyle(
|
2022-08-01 20:42:30 +08:00
|
|
|
color: Colors.redAccent, decoration: TextDecoration.lineThrough);
|
2022-07-14 12:32:01 +08:00
|
|
|
}
|
|
|
|
|
2022-08-08 17:53:51 +08:00
|
|
|
PopupMenuItem<String> genAudioInputPopupMenuItem(
|
|
|
|
bool enableInput, String defaultAudioInput) {
|
|
|
|
final defaultInput = defaultAudioInput.obs;
|
|
|
|
final enabled = enableInput.obs;
|
|
|
|
|
2022-07-18 18:20:00 +08:00
|
|
|
return PopupMenuItem(
|
|
|
|
child: FutureBuilder<List<String>>(
|
|
|
|
future: gFFI.getAudioInputs(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
2022-08-01 20:42:30 +08:00
|
|
|
final inputs = snapshot.data!.toList();
|
2022-07-18 18:20:00 +08:00
|
|
|
if (Platform.isWindows) {
|
|
|
|
inputs.insert(0, translate("System Sound"));
|
|
|
|
}
|
|
|
|
var inputList = inputs
|
|
|
|
.map((e) => PopupMenuItem(
|
2022-08-01 20:42:30 +08:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Obx(() => Offstage(
|
|
|
|
offstage: defaultInput.value != e,
|
|
|
|
child: Icon(Icons.check))),
|
|
|
|
Expanded(
|
|
|
|
child: Tooltip(
|
|
|
|
message: e,
|
|
|
|
child: Text(
|
|
|
|
"$e",
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
))),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
value: e,
|
|
|
|
))
|
2022-07-18 18:20:00 +08:00
|
|
|
.toList();
|
|
|
|
inputList.insert(
|
|
|
|
0,
|
|
|
|
PopupMenuItem(
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Obx(() => Offstage(
|
|
|
|
offstage: enabled.value, child: Icon(Icons.check))),
|
|
|
|
Expanded(child: Text(translate("Mute"))),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
value: "Mute",
|
|
|
|
));
|
|
|
|
return PopupMenuButton<String>(
|
2022-07-14 12:32:01 +08:00
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
child: Container(
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: Text(translate("Audio Input"))),
|
|
|
|
itemBuilder: (context) => inputList,
|
2022-08-08 17:53:51 +08:00
|
|
|
onSelected: (dev) async {
|
2022-07-18 18:20:00 +08:00
|
|
|
if (dev == "Mute") {
|
2022-08-08 17:53:51 +08:00
|
|
|
await bind.mainSetOption(
|
|
|
|
key: 'enable-audio', value: enabled.value ? '' : 'N');
|
|
|
|
enabled.value =
|
|
|
|
await bind.mainGetOption(key: 'enable-audio') != 'N';
|
|
|
|
} else if (dev != await gFFI.getDefaultAudioInput()) {
|
2022-07-18 18:20:00 +08:00
|
|
|
gFFI.setDefaultAudioInput(dev);
|
|
|
|
defaultInput.value = dev;
|
|
|
|
}
|
2022-07-14 12:32:01 +08:00
|
|
|
},
|
2022-07-18 18:20:00 +08:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Text("...");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
value: 'audio-input',
|
|
|
|
);
|
2022-07-14 12:32:01 +08:00
|
|
|
}
|
2022-07-15 17:00:37 +08:00
|
|
|
|
|
|
|
/// change local ID
|
|
|
|
void changeId() {
|
|
|
|
var newId = "";
|
|
|
|
var msg = "";
|
|
|
|
var isInProgress = false;
|
2022-07-18 18:20:00 +08:00
|
|
|
DialogManager.show((setState, close) {
|
2022-07-15 17:00:37 +08:00
|
|
|
return CustomAlertDialog(
|
|
|
|
title: Text(translate("Change ID")),
|
|
|
|
content: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(translate("id_change_tip")),
|
2022-07-18 18:20:00 +08:00
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
2022-07-15 17:00:37 +08:00
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Text("ID:").marginOnly(bottom: 16.0),
|
2022-07-18 18:20:00 +08:00
|
|
|
SizedBox(
|
|
|
|
width: 24.0,
|
|
|
|
),
|
2022-07-15 17:00:37 +08:00
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
onChanged: (s) {
|
|
|
|
newId = s;
|
|
|
|
},
|
|
|
|
decoration: InputDecoration(
|
2022-07-18 18:20:00 +08:00
|
|
|
border: OutlineInputBorder(),
|
|
|
|
errorText: msg.isEmpty ? null : translate(msg)),
|
2022-07-15 17:00:37 +08:00
|
|
|
inputFormatters: [
|
|
|
|
LengthLimitingTextInputFormatter(16),
|
|
|
|
// FilteringTextInputFormatter(RegExp(r"[a-zA-z][a-zA-z0-9\_]*"), allow: true)
|
|
|
|
],
|
|
|
|
maxLength: 16,
|
|
|
|
),
|
|
|
|
),
|
2022-07-15 17:00:37 +08:00
|
|
|
],
|
|
|
|
),
|
2022-07-18 18:20:00 +08:00
|
|
|
SizedBox(
|
|
|
|
height: 4.0,
|
|
|
|
),
|
|
|
|
Offstage(offstage: !isInProgress, child: LinearProgressIndicator())
|
2022-07-15 17:00:37 +08:00
|
|
|
],
|
2022-07-18 18:20:00 +08:00
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
close();
|
|
|
|
},
|
|
|
|
child: Text(translate("Cancel"))),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
|
|
|
setState(() {
|
|
|
|
msg = "";
|
|
|
|
isInProgress = true;
|
2022-08-03 22:03:31 +08:00
|
|
|
bind.mainChangeId(newId: newId);
|
2022-07-18 18:20:00 +08:00
|
|
|
});
|
2022-07-15 17:00:37 +08:00
|
|
|
|
2022-08-03 22:03:31 +08:00
|
|
|
var status = await bind.mainGetAsyncStatus();
|
2022-07-18 18:20:00 +08:00
|
|
|
while (status == " ") {
|
|
|
|
await Future.delayed(Duration(milliseconds: 100));
|
2022-08-03 22:03:31 +08:00
|
|
|
status = await bind.mainGetAsyncStatus();
|
2022-07-18 18:20:00 +08:00
|
|
|
}
|
|
|
|
if (status.isEmpty) {
|
|
|
|
// ok
|
|
|
|
close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setState(() {
|
|
|
|
isInProgress = false;
|
|
|
|
msg = translate(status);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Text(translate("OK"))),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void changeServer() async {
|
2022-08-03 22:03:31 +08:00
|
|
|
Map<String, dynamic> oldOptions = jsonDecode(await bind.mainGetOptions());
|
2022-07-18 18:20:00 +08:00
|
|
|
print("${oldOptions}");
|
|
|
|
String idServer = oldOptions['custom-rendezvous-server'] ?? "";
|
|
|
|
var idServerMsg = "";
|
|
|
|
String relayServer = oldOptions['relay-server'] ?? "";
|
|
|
|
var relayServerMsg = "";
|
|
|
|
String apiServer = oldOptions['api-server'] ?? "";
|
|
|
|
var apiServerMsg = "";
|
|
|
|
var key = oldOptions['key'] ?? "";
|
|
|
|
|
|
|
|
var isInProgress = false;
|
|
|
|
DialogManager.show((setState, close) {
|
|
|
|
return CustomAlertDialog(
|
|
|
|
title: Text(translate("ID/Relay Server")),
|
|
|
|
content: ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 500),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 100),
|
|
|
|
child: Text("${translate('ID Server')}:")
|
|
|
|
.marginOnly(bottom: 16.0)),
|
|
|
|
SizedBox(
|
|
|
|
width: 24.0,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
onChanged: (s) {
|
|
|
|
idServer = s;
|
|
|
|
},
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
errorText:
|
2022-08-01 20:42:30 +08:00
|
|
|
idServerMsg.isNotEmpty ? idServerMsg : null),
|
2022-07-18 18:20:00 +08:00
|
|
|
controller: TextEditingController(text: idServer),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 100),
|
|
|
|
child: Text("${translate('Relay Server')}:")
|
|
|
|
.marginOnly(bottom: 16.0)),
|
|
|
|
SizedBox(
|
|
|
|
width: 24.0,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
onChanged: (s) {
|
|
|
|
relayServer = s;
|
|
|
|
},
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
errorText: relayServerMsg.isNotEmpty
|
|
|
|
? relayServerMsg
|
|
|
|
: null),
|
|
|
|
controller: TextEditingController(text: relayServer),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 100),
|
|
|
|
child: Text("${translate('API Server')}:")
|
|
|
|
.marginOnly(bottom: 16.0)),
|
|
|
|
SizedBox(
|
|
|
|
width: 24.0,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
onChanged: (s) {
|
|
|
|
apiServer = s;
|
|
|
|
},
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
errorText:
|
2022-08-01 20:42:30 +08:00
|
|
|
apiServerMsg.isNotEmpty ? apiServerMsg : null),
|
2022-07-18 18:20:00 +08:00
|
|
|
controller: TextEditingController(text: apiServer),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 100),
|
|
|
|
child: Text("${translate('Key')}:")
|
|
|
|
.marginOnly(bottom: 16.0)),
|
|
|
|
SizedBox(
|
|
|
|
width: 24.0,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
onChanged: (s) {
|
|
|
|
key = s;
|
|
|
|
},
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
),
|
|
|
|
controller: TextEditingController(text: key),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 4.0,
|
|
|
|
),
|
|
|
|
Offstage(
|
|
|
|
offstage: !isInProgress, child: LinearProgressIndicator())
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
close();
|
|
|
|
},
|
|
|
|
child: Text(translate("Cancel"))),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
|
|
|
setState(() {
|
|
|
|
[idServerMsg, relayServerMsg, apiServerMsg]
|
|
|
|
.forEach((element) {
|
|
|
|
element = "";
|
|
|
|
});
|
|
|
|
isInProgress = true;
|
|
|
|
});
|
|
|
|
final cancel = () {
|
|
|
|
setState(() {
|
|
|
|
isInProgress = false;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
idServer = idServer.trim();
|
|
|
|
relayServer = relayServer.trim();
|
|
|
|
apiServer = apiServer.trim();
|
|
|
|
key = key.trim();
|
|
|
|
|
|
|
|
if (idServer.isNotEmpty) {
|
|
|
|
idServerMsg = translate(
|
2022-08-03 22:03:31 +08:00
|
|
|
await bind.mainTestIfValidServer(server: idServer));
|
2022-07-18 18:20:00 +08:00
|
|
|
if (idServerMsg.isEmpty) {
|
|
|
|
oldOptions['custom-rendezvous-server'] = idServer;
|
|
|
|
} else {
|
|
|
|
cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
oldOptions['custom-rendezvous-server'] = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (relayServer.isNotEmpty) {
|
2022-08-03 22:03:31 +08:00
|
|
|
relayServerMsg = translate(
|
|
|
|
await bind.mainTestIfValidServer(server: relayServer));
|
2022-07-18 18:20:00 +08:00
|
|
|
if (relayServerMsg.isEmpty) {
|
|
|
|
oldOptions['relay-server'] = relayServer;
|
|
|
|
} else {
|
|
|
|
cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
oldOptions['relay-server'] = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (apiServer.isNotEmpty) {
|
|
|
|
if (apiServer.startsWith('http://') ||
|
|
|
|
apiServer.startsWith("https://")) {
|
|
|
|
oldOptions['api-server'] = apiServer;
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
apiServerMsg = translate("invalid_http");
|
|
|
|
cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
oldOptions['api-server'] = "";
|
|
|
|
}
|
|
|
|
// ok
|
|
|
|
oldOptions['key'] = key;
|
2022-08-03 22:03:31 +08:00
|
|
|
await bind.mainSetOptions(json: jsonEncode(oldOptions));
|
2022-07-18 18:20:00 +08:00
|
|
|
close();
|
|
|
|
},
|
|
|
|
child: Text(translate("OK"))),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void changeWhiteList() async {
|
2022-08-03 22:03:31 +08:00
|
|
|
Map<String, dynamic> oldOptions = jsonDecode(await bind.mainGetOptions());
|
2022-07-18 18:20:00 +08:00
|
|
|
var newWhiteList = ((oldOptions['whitelist'] ?? "") as String).split(',');
|
|
|
|
var newWhiteListField = newWhiteList.join('\n');
|
|
|
|
var msg = "";
|
|
|
|
var isInProgress = false;
|
|
|
|
DialogManager.show((setState, close) {
|
|
|
|
return CustomAlertDialog(
|
|
|
|
title: Text(translate("IP Whitelisting")),
|
|
|
|
content: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(translate("whitelist_sep")),
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
onChanged: (s) {
|
|
|
|
newWhiteListField = s;
|
|
|
|
},
|
|
|
|
maxLines: null,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
errorText: msg.isEmpty ? null : translate(msg),
|
|
|
|
),
|
|
|
|
controller: TextEditingController(text: newWhiteListField),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 4.0,
|
|
|
|
),
|
|
|
|
Offstage(offstage: !isInProgress, child: LinearProgressIndicator())
|
|
|
|
],
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
close();
|
|
|
|
},
|
|
|
|
child: Text(translate("Cancel"))),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
|
|
|
setState(() {
|
|
|
|
msg = "";
|
|
|
|
isInProgress = true;
|
|
|
|
});
|
|
|
|
newWhiteListField = newWhiteListField.trim();
|
|
|
|
var newWhiteList = "";
|
|
|
|
if (newWhiteListField.isEmpty) {
|
|
|
|
// pass
|
|
|
|
} else {
|
|
|
|
final ips =
|
2022-08-01 20:42:30 +08:00
|
|
|
newWhiteListField.trim().split(RegExp(r"[\s,;\n]+"));
|
2022-07-18 18:20:00 +08:00
|
|
|
// test ip
|
|
|
|
final ipMatch = RegExp(r"^\d+\.\d+\.\d+\.\d+$");
|
|
|
|
for (final ip in ips) {
|
|
|
|
if (!ipMatch.hasMatch(ip)) {
|
|
|
|
msg = translate("Invalid IP") + " $ip";
|
|
|
|
setState(() {
|
|
|
|
isInProgress = false;
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
newWhiteList = ips.join(',');
|
|
|
|
}
|
|
|
|
oldOptions['whitelist'] = newWhiteList;
|
2022-08-03 22:03:31 +08:00
|
|
|
await bind.mainSetOptions(json: jsonEncode(oldOptions));
|
2022-07-18 18:20:00 +08:00
|
|
|
close();
|
|
|
|
},
|
|
|
|
child: Text(translate("OK"))),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void changeSocks5Proxy() async {
|
2022-08-03 22:03:31 +08:00
|
|
|
var socks = await bind.mainGetSocks();
|
2022-07-18 18:20:00 +08:00
|
|
|
|
|
|
|
String proxy = "";
|
|
|
|
String proxyMsg = "";
|
|
|
|
String username = "";
|
|
|
|
String password = "";
|
|
|
|
if (socks.length == 3) {
|
|
|
|
proxy = socks[0];
|
|
|
|
username = socks[1];
|
|
|
|
password = socks[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
var isInProgress = false;
|
|
|
|
DialogManager.show((setState, close) {
|
|
|
|
return CustomAlertDialog(
|
|
|
|
title: Text(translate("Socks5 Proxy")),
|
|
|
|
content: ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 500),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 100),
|
|
|
|
child: Text("${translate('Hostname')}:")
|
|
|
|
.marginOnly(bottom: 16.0)),
|
|
|
|
SizedBox(
|
|
|
|
width: 24.0,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
onChanged: (s) {
|
|
|
|
proxy = s;
|
|
|
|
},
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: OutlineInputBorder(),
|
2022-07-27 14:29:47 +08:00
|
|
|
errorText: proxyMsg.isNotEmpty ? proxyMsg : null),
|
2022-07-18 18:20:00 +08:00
|
|
|
controller: TextEditingController(text: proxy),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 100),
|
|
|
|
child: Text("${translate('Username')}:")
|
|
|
|
.marginOnly(bottom: 16.0)),
|
|
|
|
SizedBox(
|
|
|
|
width: 24.0,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
onChanged: (s) {
|
|
|
|
username = s;
|
|
|
|
},
|
|
|
|
decoration: InputDecoration(
|
2022-07-27 14:29:47 +08:00
|
|
|
border: OutlineInputBorder(),
|
|
|
|
),
|
2022-07-18 18:20:00 +08:00
|
|
|
controller: TextEditingController(text: username),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 100),
|
|
|
|
child: Text("${translate('Password')}:")
|
|
|
|
.marginOnly(bottom: 16.0)),
|
|
|
|
SizedBox(
|
|
|
|
width: 24.0,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
onChanged: (s) {
|
|
|
|
password = s;
|
|
|
|
},
|
|
|
|
decoration: InputDecoration(
|
2022-07-27 14:29:47 +08:00
|
|
|
border: OutlineInputBorder(),
|
|
|
|
),
|
2022-07-18 18:20:00 +08:00
|
|
|
controller: TextEditingController(text: password),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Offstage(
|
|
|
|
offstage: !isInProgress, child: LinearProgressIndicator())
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
close();
|
|
|
|
},
|
|
|
|
child: Text(translate("Cancel"))),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
|
|
|
setState(() {
|
|
|
|
proxyMsg = "";
|
|
|
|
isInProgress = true;
|
|
|
|
});
|
|
|
|
final cancel = () {
|
|
|
|
setState(() {
|
|
|
|
isInProgress = false;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
proxy = proxy.trim();
|
|
|
|
username = username.trim();
|
|
|
|
password = password.trim();
|
|
|
|
|
|
|
|
if (proxy.isNotEmpty) {
|
|
|
|
proxyMsg = translate(
|
2022-08-03 22:03:31 +08:00
|
|
|
await bind.mainTestIfValidServer(server: proxy));
|
2022-07-18 18:20:00 +08:00
|
|
|
if (proxyMsg.isEmpty) {
|
|
|
|
// ignore
|
|
|
|
} else {
|
|
|
|
cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-08-03 22:03:31 +08:00
|
|
|
await bind.mainSetSocks(
|
2022-08-01 20:42:30 +08:00
|
|
|
proxy: proxy, username: username, password: password);
|
2022-07-18 18:20:00 +08:00
|
|
|
close();
|
|
|
|
},
|
|
|
|
child: Text(translate("OK"))),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void about() async {
|
2022-08-03 22:03:31 +08:00
|
|
|
final appName = await bind.mainGetAppName();
|
|
|
|
final license = await bind.mainGetLicense();
|
|
|
|
final version = await bind.mainGetVersion();
|
2022-07-27 14:29:47 +08:00
|
|
|
final linkStyle = TextStyle(decoration: TextDecoration.underline);
|
2022-07-18 18:20:00 +08:00
|
|
|
DialogManager.show((setState, close) {
|
|
|
|
return CustomAlertDialog(
|
|
|
|
title: Text("About $appName"),
|
|
|
|
content: ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 500),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Text("Version: $version").marginSymmetric(vertical: 4.0),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
launchUrlString("https://rustdesk.com/privacy");
|
|
|
|
},
|
2022-07-27 14:29:47 +08:00
|
|
|
child: Text(
|
|
|
|
"Privacy Statement",
|
|
|
|
style: linkStyle,
|
|
|
|
).marginSymmetric(vertical: 4.0)),
|
2022-07-18 18:20:00 +08:00
|
|
|
InkWell(
|
2022-07-27 14:29:47 +08:00
|
|
|
onTap: () {
|
|
|
|
launchUrlString("https://rustdesk.com");
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
"Website",
|
|
|
|
style: linkStyle,
|
|
|
|
).marginSymmetric(vertical: 4.0)),
|
2022-07-18 18:20:00 +08:00
|
|
|
Container(
|
2022-07-27 14:29:47 +08:00
|
|
|
decoration: BoxDecoration(color: Color(0xFF2c8cff)),
|
2022-07-18 18:20:00 +08:00
|
|
|
padding: EdgeInsets.symmetric(vertical: 24, horizontal: 8),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2022-07-27 14:29:47 +08:00
|
|
|
Text(
|
|
|
|
"Copyright © 2022 Purslane Ltd.\n$license",
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"Made with heart in this chaotic world!",
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.w800,
|
|
|
|
color: Colors.white),
|
|
|
|
)
|
2022-07-18 18:20:00 +08:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
).marginSymmetric(vertical: 4.0)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
|
|
|
close();
|
|
|
|
},
|
|
|
|
child: Text(translate("OK"))),
|
|
|
|
],
|
2022-07-15 17:00:37 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2022-07-27 14:29:47 +08:00
|
|
|
|
|
|
|
void login() {
|
|
|
|
loginDialog().then((success) {
|
|
|
|
if (success) {
|
|
|
|
// refresh frame
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void logOut() {
|
|
|
|
gFFI.userModel.logOut().then((_) => {setState(() {})});
|
|
|
|
}
|
2022-05-23 16:44:23 +08:00
|
|
|
}
|
2022-07-27 14:29:47 +08:00
|
|
|
|
|
|
|
/// common login dialog for desktop
|
|
|
|
/// call this directly
|
|
|
|
Future<bool> loginDialog() async {
|
|
|
|
String userName = "";
|
|
|
|
var userNameMsg = "";
|
|
|
|
String pass = "";
|
|
|
|
var passMsg = "";
|
|
|
|
|
|
|
|
var isInProgress = false;
|
|
|
|
var completer = Completer<bool>();
|
|
|
|
DialogManager.show((setState, close) {
|
|
|
|
return CustomAlertDialog(
|
|
|
|
title: Text(translate("Login")),
|
|
|
|
content: ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 500),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 100),
|
|
|
|
child: Text(
|
|
|
|
"${translate('Username')}:",
|
|
|
|
textAlign: TextAlign.start,
|
|
|
|
).marginOnly(bottom: 16.0)),
|
|
|
|
SizedBox(
|
|
|
|
width: 24.0,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
onChanged: (s) {
|
|
|
|
userName = s;
|
|
|
|
},
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
errorText: userNameMsg.isNotEmpty ? userNameMsg : null),
|
|
|
|
controller: TextEditingController(text: userName),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 100),
|
|
|
|
child: Text("${translate('Password')}:")
|
|
|
|
.marginOnly(bottom: 16.0)),
|
|
|
|
SizedBox(
|
|
|
|
width: 24.0,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
obscureText: true,
|
|
|
|
onChanged: (s) {
|
|
|
|
pass = s;
|
|
|
|
},
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
errorText: passMsg.isNotEmpty ? passMsg : null),
|
|
|
|
controller: TextEditingController(text: pass),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 4.0,
|
|
|
|
),
|
|
|
|
Offstage(offstage: !isInProgress, child: LinearProgressIndicator())
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
completer.complete(false);
|
|
|
|
close();
|
|
|
|
},
|
|
|
|
child: Text(translate("Cancel"))),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
|
|
|
setState(() {
|
|
|
|
userNameMsg = "";
|
|
|
|
passMsg = "";
|
|
|
|
isInProgress = true;
|
|
|
|
});
|
|
|
|
final cancel = () {
|
|
|
|
setState(() {
|
|
|
|
isInProgress = false;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
userName = userName;
|
|
|
|
pass = pass;
|
|
|
|
if (userName.isEmpty) {
|
|
|
|
userNameMsg = translate("Username missed");
|
|
|
|
cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pass.isEmpty) {
|
|
|
|
passMsg = translate("Password missed");
|
|
|
|
cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
final resp = await gFFI.userModel.login(userName, pass);
|
|
|
|
if (resp.containsKey('error')) {
|
|
|
|
passMsg = resp['error'];
|
|
|
|
cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// {access_token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJndWlkIjoiMDFkZjQ2ZjgtZjg3OS00MDE0LTk5Y2QtMGMwYzM2MmViZGJlIiwiZXhwIjoxNjYxNDg2NzYwfQ.GZpe1oI8TfM5yTYNrpcwbI599P4Z_-b2GmnwNl2Lr-w,
|
|
|
|
// token_type: Bearer, user: {id: , name: admin, email: null, note: null, status: null, grp: null, is_admin: true}}
|
|
|
|
debugPrint("$resp");
|
|
|
|
completer.complete(true);
|
|
|
|
} catch (err) {
|
|
|
|
print(err.toString());
|
|
|
|
cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
close();
|
|
|
|
},
|
|
|
|
child: Text(translate("OK"))),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
return completer.future;
|
2022-08-01 20:42:30 +08:00
|
|
|
}
|
|
|
|
|
2022-08-08 22:27:27 +08:00
|
|
|
void setPasswordDialog() async {
|
|
|
|
final pw = await bind.mainGetPermanentPassword();
|
2022-08-01 20:42:30 +08:00
|
|
|
final p0 = TextEditingController(text: pw);
|
|
|
|
final p1 = TextEditingController(text: pw);
|
|
|
|
var errMsg0 = "";
|
|
|
|
var errMsg1 = "";
|
|
|
|
|
|
|
|
DialogManager.show((setState, close) {
|
|
|
|
return CustomAlertDialog(
|
|
|
|
title: Text(translate("Set Password")),
|
|
|
|
content: ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 500),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 100),
|
|
|
|
child: Text(
|
|
|
|
"${translate('Password')}:",
|
|
|
|
textAlign: TextAlign.start,
|
|
|
|
).marginOnly(bottom: 16.0)),
|
|
|
|
SizedBox(
|
|
|
|
width: 24.0,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
obscureText: true,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
errorText: errMsg0.isNotEmpty ? errMsg0 : null),
|
|
|
|
controller: p0,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minWidth: 100),
|
|
|
|
child: Text("${translate('Confirmation')}:")
|
|
|
|
.marginOnly(bottom: 16.0)),
|
|
|
|
SizedBox(
|
|
|
|
width: 24.0,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
obscureText: true,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
errorText: errMsg1.isNotEmpty ? errMsg1 : null),
|
|
|
|
controller: p1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
close();
|
|
|
|
},
|
|
|
|
child: Text(translate("Cancel"))),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
setState(() {
|
|
|
|
errMsg0 = "";
|
|
|
|
errMsg1 = "";
|
|
|
|
});
|
|
|
|
final pass = p0.text.trim();
|
|
|
|
if (pass.length < 6) {
|
|
|
|
setState(() {
|
|
|
|
errMsg0 = translate("Too short, at least 6 characters.");
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (p1.text.trim() != pass) {
|
|
|
|
setState(() {
|
|
|
|
errMsg1 = translate("The confirmation is not identical.");
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2022-08-08 22:27:27 +08:00
|
|
|
bind.mainSetPermanentPassword(password: pass);
|
2022-08-01 20:42:30 +08:00
|
|
|
close();
|
|
|
|
},
|
|
|
|
child: Text(translate("OK"))),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|