2022-07-27 14:29:47 +08:00
|
|
|
import 'dart:async';
|
2022-06-02 16:23:20 +08:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
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-08-13 12:43:35 +08:00
|
|
|
import 'package:flutter_hbb/desktop/pages/desktop_setting_page.dart';
|
2022-09-02 13:36:40 +08:00
|
|
|
import 'package:flutter_hbb/desktop/widgets/popup_menu.dart';
|
|
|
|
import 'package:flutter_hbb/desktop/widgets/material_mod_popup_menu.dart'
|
|
|
|
as mod_menu;
|
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
|
|
|
|
2022-09-16 21:52:08 +08:00
|
|
|
import '../../common/widgets/dialog.dart';
|
|
|
|
|
2022-09-07 12:20:53 +08:00
|
|
|
class _MenubarTheme {
|
2022-09-06 17:08:59 +08:00
|
|
|
static const Color commonColor = MyTheme.accent;
|
|
|
|
// kMinInteractiveDimension
|
|
|
|
static const double height = 25.0;
|
2022-09-07 12:20:53 +08:00
|
|
|
static const double dividerHeight = 12.0;
|
2022-09-06 17:08:59 +08:00
|
|
|
}
|
|
|
|
|
2022-05-23 16:44:23 +08:00
|
|
|
class DesktopHomePage extends StatefulWidget {
|
2022-09-06 17:08:59 +08:00
|
|
|
const DesktopHomePage({Key? key}) : super(key: key);
|
2022-05-23 16:44:23 +08:00
|
|
|
|
|
|
|
@override
|
2022-09-07 12:20:53 +08:00
|
|
|
State<DesktopHomePage> createState() => _DesktopHomePageState();
|
2022-05-23 16:44:23 +08:00
|
|
|
}
|
|
|
|
|
2022-05-29 19:55:50 +08:00
|
|
|
const borderColor = Color(0xFF2F65BA);
|
|
|
|
|
2022-08-09 20:36:52 +08:00
|
|
|
class _DesktopHomePageState extends State<DesktopHomePage>
|
2022-08-13 12:43:35 +08:00
|
|
|
with TrayListener, WindowListener, AutomaticKeepAliveClientMixin {
|
|
|
|
@override
|
|
|
|
bool get wantKeepAlive => true;
|
|
|
|
|
2022-08-09 13:39:30 +08:00
|
|
|
@override
|
|
|
|
void onWindowClose() async {
|
|
|
|
super.onWindowClose();
|
|
|
|
// close all sub windows
|
|
|
|
if (await windowManager.isPreventClose()) {
|
|
|
|
try {
|
2022-09-16 12:14:03 +08:00
|
|
|
await Future.wait([
|
|
|
|
saveWindowPosition(WindowType.Main),
|
|
|
|
rustDeskWinManager.closeAllSubWindows()
|
|
|
|
]);
|
2022-08-09 13:39:30 +08:00
|
|
|
} 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-08-20 19:57:16 +08:00
|
|
|
super.build(context);
|
2022-08-11 16:03:04 +08:00
|
|
|
return Row(
|
|
|
|
children: [
|
2022-08-20 19:57:16 +08:00
|
|
|
buildServerInfo(context),
|
2022-09-03 18:19:50 +08:00
|
|
|
const VerticalDivider(
|
2022-08-20 19:57:16 +08:00
|
|
|
width: 1,
|
|
|
|
thickness: 1,
|
2022-08-11 16:03:04 +08:00
|
|
|
),
|
2022-08-20 19:57:16 +08:00
|
|
|
Expanded(
|
2022-08-11 16:03:04 +08:00
|
|
|
child: buildServerBoard(context),
|
|
|
|
),
|
|
|
|
],
|
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(
|
2022-08-20 19:57:16 +08:00
|
|
|
width: 200,
|
|
|
|
color: MyTheme.color(context).bg,
|
2022-05-29 10:25:36 +08:00
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
buildTip(context),
|
|
|
|
buildIDBoard(context),
|
|
|
|
buildPasswordBoard(context),
|
|
|
|
],
|
|
|
|
),
|
2022-05-25 00:28:59 +08:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildServerBoard(BuildContext context) {
|
2022-08-20 19:57:16 +08:00
|
|
|
return Container(
|
|
|
|
color: MyTheme.color(context).grayBg,
|
2022-09-07 12:20:53 +08:00
|
|
|
child: ConnectionPage(),
|
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(
|
2022-09-04 20:57:57 +08:00
|
|
|
margin: const EdgeInsets.only(left: 20, right: 11),
|
|
|
|
height: 57,
|
2022-05-29 10:25:36 +08:00
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.baseline,
|
|
|
|
textBaseline: TextBaseline.alphabetic,
|
|
|
|
children: [
|
|
|
|
Container(
|
2022-08-20 19:57:16 +08:00
|
|
|
width: 2,
|
2022-09-03 18:19:50 +08:00
|
|
|
decoration: const BoxDecoration(color: MyTheme.accent),
|
2022-09-04 20:57:57 +08:00
|
|
|
).marginOnly(top: 5),
|
2022-05-29 10:25:36 +08:00
|
|
|
Expanded(
|
|
|
|
child: Padding(
|
2022-09-04 20:57:57 +08:00
|
|
|
padding: const EdgeInsets.only(left: 7),
|
2022-05-29 10:25:36 +08:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2022-09-07 12:20:53 +08:00
|
|
|
Container(
|
2022-08-24 11:01:58 +08:00
|
|
|
height: 25,
|
2022-08-20 19:57:16 +08:00
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
2022-08-24 11:01:58 +08:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2022-08-20 19:57:16 +08:00
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
translate("ID"),
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14,
|
|
|
|
color: MyTheme.color(context).lightText),
|
2022-09-04 20:57:57 +08:00
|
|
|
).marginOnly(top: 5),
|
2022-08-20 19:57:16 +08:00
|
|
|
buildPopupMenu(context)
|
|
|
|
],
|
|
|
|
),
|
2022-05-29 10:25:36 +08:00
|
|
|
),
|
2022-08-20 19:57:16 +08:00
|
|
|
Flexible(
|
|
|
|
child: GestureDetector(
|
2022-08-03 09:08:10 +08:00
|
|
|
onDoubleTap: () {
|
|
|
|
Clipboard.setData(
|
|
|
|
ClipboardData(text: model.serverId.text));
|
2022-08-15 14:39:31 +08:00
|
|
|
showToast(translate("Copied"));
|
2022-08-03 09:08:10 +08:00
|
|
|
},
|
|
|
|
child: TextFormField(
|
|
|
|
controller: model.serverId,
|
|
|
|
readOnly: true,
|
2022-09-07 12:20:53 +08:00
|
|
|
decoration: InputDecoration(
|
2022-08-20 19:57:16 +08:00
|
|
|
border: InputBorder.none,
|
2022-09-04 20:57:57 +08:00
|
|
|
contentPadding: EdgeInsets.only(bottom: 20),
|
2022-08-20 19:57:16 +08:00
|
|
|
),
|
2022-09-07 12:20:53 +08:00
|
|
|
style: TextStyle(
|
2022-08-20 19:57:16 +08:00
|
|
|
fontSize: 22,
|
|
|
|
),
|
2022-08-22 17:58:48 +08:00
|
|
|
),
|
2022-08-20 19:57:16 +08:00
|
|
|
),
|
|
|
|
)
|
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-09 20:36:52 +08:00
|
|
|
Widget buildPopupMenu(BuildContext context) {
|
2022-09-07 12:20:53 +08:00
|
|
|
var position;
|
2022-08-20 19:57:16 +08:00
|
|
|
RxBool hover = false.obs;
|
|
|
|
return InkWell(
|
|
|
|
onTapDown: (detail) {
|
|
|
|
final x = detail.globalPosition.dx;
|
|
|
|
final y = detail.globalPosition.dy;
|
|
|
|
position = RelativeRect.fromLTRB(x, y, x, y);
|
|
|
|
},
|
|
|
|
onTap: () async {
|
2022-09-07 12:20:53 +08:00
|
|
|
final userName = await gFFI.userModel.getUserName();
|
|
|
|
final enabledInput = await bind.mainGetOption(key: 'enable-audio');
|
|
|
|
final defaultInput = await gFFI.getDefaultAudioInput();
|
|
|
|
var menu = <PopupMenuEntry>[
|
|
|
|
await genEnablePopupMenuItem(
|
|
|
|
translate("Enable Keyboard/Mouse"),
|
|
|
|
'enable-keyboard',
|
|
|
|
),
|
|
|
|
await genEnablePopupMenuItem(
|
|
|
|
translate("Enable Clipboard"),
|
|
|
|
'enable-clipboard',
|
|
|
|
),
|
|
|
|
await genEnablePopupMenuItem(
|
|
|
|
translate("Enable File Transfer"),
|
|
|
|
'enable-file-transfer',
|
|
|
|
),
|
|
|
|
await genEnablePopupMenuItem(
|
|
|
|
translate("Enable TCP Tunneling"),
|
|
|
|
'enable-tunnel',
|
|
|
|
),
|
|
|
|
genAudioInputPopupMenuItem(enabledInput != "N", defaultInput),
|
|
|
|
PopupMenuDivider(),
|
|
|
|
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',
|
|
|
|
),
|
|
|
|
PopupMenuDivider(),
|
|
|
|
await genEnablePopupMenuItem(
|
|
|
|
translate("Enable Service"),
|
|
|
|
'stop-service',
|
|
|
|
),
|
|
|
|
// TODO: direct server
|
|
|
|
await genEnablePopupMenuItem(
|
|
|
|
translate("Always connected via relay"),
|
|
|
|
'allow-always-relay',
|
|
|
|
),
|
|
|
|
await genEnablePopupMenuItem(
|
|
|
|
translate("Start ID/relay service"),
|
|
|
|
'stop-rendezvous-service',
|
|
|
|
),
|
|
|
|
PopupMenuDivider(),
|
|
|
|
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',
|
|
|
|
),
|
|
|
|
PopupMenuDivider(),
|
|
|
|
await 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);
|
|
|
|
}
|
2022-08-20 19:57:16 +08:00
|
|
|
},
|
|
|
|
child: Obx(
|
2022-08-24 11:01:58 +08:00
|
|
|
() => CircleAvatar(
|
2022-09-04 20:57:57 +08:00
|
|
|
radius: 15,
|
2022-08-24 11:01:58 +08:00
|
|
|
backgroundColor: hover.value
|
|
|
|
? MyTheme.color(context).grayBg!
|
|
|
|
: MyTheme.color(context).bg!,
|
|
|
|
child: Icon(
|
|
|
|
Icons.more_vert_outlined,
|
|
|
|
size: 20,
|
|
|
|
color: hover.value
|
|
|
|
? MyTheme.color(context).text
|
|
|
|
: MyTheme.color(context).lightText,
|
2022-08-20 19:57:16 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onHover: (value) => hover.value = value,
|
|
|
|
);
|
2022-07-27 14:29:47 +08:00
|
|
|
}
|
|
|
|
|
2022-05-29 10:25:36 +08:00
|
|
|
buildPasswordBoard(BuildContext context) {
|
2022-06-13 21:07:26 +08:00
|
|
|
final model = gFFI.serverModel;
|
2022-08-20 19:57:16 +08:00
|
|
|
RxBool refreshHover = false.obs;
|
2022-05-29 10:25:36 +08:00
|
|
|
return Container(
|
2022-08-22 17:58:48 +08:00
|
|
|
margin: EdgeInsets.only(left: 20.0, right: 16, top: 13, bottom: 13),
|
2022-05-29 10:25:36 +08:00
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.baseline,
|
|
|
|
textBaseline: TextBaseline.alphabetic,
|
|
|
|
children: [
|
|
|
|
Container(
|
2022-08-20 19:57:16 +08:00
|
|
|
width: 2,
|
|
|
|
height: 52,
|
2022-05-29 10:25:36 +08:00
|
|
|
decoration: BoxDecoration(color: MyTheme.accent),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Padding(
|
2022-09-04 20:57:57 +08:00
|
|
|
padding: const EdgeInsets.only(left: 7),
|
2022-05-29 10:25:36 +08:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
translate("Password"),
|
2022-08-20 19:57:16 +08:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14, color: MyTheme.color(context).lightText),
|
2022-05-29 10:25:36 +08:00
|
|
|
),
|
2022-08-01 20:42:30 +08:00
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
2022-08-03 09:08:10 +08:00
|
|
|
child: GestureDetector(
|
|
|
|
onDoubleTap: () {
|
2022-08-11 21:29:43 +08:00
|
|
|
if (model.verificationMethod !=
|
|
|
|
kUsePermanentPassword) {
|
|
|
|
Clipboard.setData(
|
|
|
|
ClipboardData(text: model.serverPasswd.text));
|
2022-08-15 14:39:31 +08:00
|
|
|
showToast(translate("Copied"));
|
2022-08-11 21:29:43 +08:00
|
|
|
}
|
2022-08-03 09:08:10 +08:00
|
|
|
},
|
|
|
|
child: TextFormField(
|
|
|
|
controller: model.serverPasswd,
|
|
|
|
readOnly: true,
|
2022-08-20 19:57:16 +08:00
|
|
|
decoration: InputDecoration(
|
|
|
|
border: InputBorder.none,
|
2022-09-04 20:57:57 +08:00
|
|
|
contentPadding: EdgeInsets.only(bottom: 2),
|
2022-08-20 19:57:16 +08:00
|
|
|
),
|
|
|
|
style: TextStyle(fontSize: 15),
|
2022-08-03 09:08:10 +08:00
|
|
|
),
|
2022-08-01 20:42:30 +08:00
|
|
|
),
|
|
|
|
),
|
2022-08-20 19:57:16 +08:00
|
|
|
InkWell(
|
|
|
|
child: Obx(
|
|
|
|
() => Icon(
|
|
|
|
Icons.refresh,
|
|
|
|
color: refreshHover.value
|
|
|
|
? MyTheme.color(context).text
|
|
|
|
: Color(0xFFDDDDDD),
|
|
|
|
size: 22,
|
2022-09-04 20:57:57 +08:00
|
|
|
).marginOnly(right: 8, bottom: 2),
|
2022-08-20 19:57:16 +08:00
|
|
|
),
|
|
|
|
onTap: () => bind.mainUpdateTemporaryPassword(),
|
|
|
|
onHover: (value) => refreshHover.value = value,
|
2022-08-01 20:42:30 +08:00
|
|
|
),
|
2022-09-07 12:20:53 +08:00
|
|
|
const _PasswordPopupMenu(),
|
2022-08-01 20:42:30 +08:00
|
|
|
],
|
2022-08-22 17:58:48 +08:00
|
|
|
),
|
2022-05-29 10:25:36 +08:00
|
|
|
],
|
2022-05-25 00:28:59 +08:00
|
|
|
),
|
|
|
|
),
|
2022-05-29 10:25:36 +08:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildTip(BuildContext context) {
|
|
|
|
return Padding(
|
2022-08-22 17:58:48 +08:00
|
|
|
padding:
|
2022-09-04 20:57:57 +08:00
|
|
|
const EdgeInsets.only(left: 20.0, right: 16, top: 16.0, bottom: 5),
|
2022-05-29 10:25:36 +08:00
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
translate("Your Desktop"),
|
2022-08-20 19:57:16 +08:00
|
|
|
style: TextStyle(fontWeight: FontWeight.normal, fontSize: 19),
|
2022-05-29 10:25:36 +08:00
|
|
|
),
|
|
|
|
SizedBox(
|
2022-08-22 17:58:48 +08:00
|
|
|
height: 10.0,
|
2022-05-29 10:25:36 +08:00
|
|
|
),
|
|
|
|
Text(
|
|
|
|
translate("desk_tip"),
|
|
|
|
overflow: TextOverflow.clip,
|
2022-08-20 19:57:16 +08:00
|
|
|
style: TextStyle(
|
2022-08-22 17:58:48 +08:00
|
|
|
fontSize: 12,
|
|
|
|
color: MyTheme.color(context).lighterText,
|
|
|
|
height: 1.25),
|
2022-05-29 10:25:36 +08:00
|
|
|
)
|
|
|
|
],
|
2022-05-25 00:28:59 +08:00
|
|
|
),
|
|
|
|
);
|
2022-05-23 16:44:23 +08:00
|
|
|
}
|
2022-06-02 16:23:20 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
void onTrayMenuItemClick(MenuItem menuItem) {
|
2022-09-13 21:59:06 +08:00
|
|
|
print('click ${menuItem.key}');
|
2022-06-02 16:23:20 +08:00
|
|
|
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-09 21:12:55 +08:00
|
|
|
Get.forceAppUpdate();
|
2022-07-29 16:47:24 +08:00
|
|
|
}
|
|
|
|
|
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-08-09 21:12:55 +08:00
|
|
|
if (key == "allow-darktheme") 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-09-08 21:40:43 +08:00
|
|
|
changeIdDialog();
|
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-09 20:36:52 +08:00
|
|
|
Future<PopupMenuItem<String>> genEnablePopupMenuItem(
|
|
|
|
String label, String key) async {
|
|
|
|
final v = await bind.mainGetOption(key: key);
|
2022-08-09 20:50:45 +08:00
|
|
|
bool enable;
|
|
|
|
if (key == "stop-service") {
|
|
|
|
enable = v != "Y";
|
2022-08-09 21:12:55 +08:00
|
|
|
} else if (key.startsWith("allow-")) {
|
|
|
|
enable = v == "Y";
|
2022-08-09 20:50:45 +08:00
|
|
|
} else {
|
|
|
|
enable = v != "N";
|
|
|
|
}
|
2022-08-08 17:53:51 +08:00
|
|
|
|
2022-07-18 18:20:00 +08:00
|
|
|
return PopupMenuItem(
|
2022-08-09 20:36:52 +08:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Icon(Icons.check,
|
|
|
|
color: enable ? null : MyTheme.accent.withAlpha(00)),
|
|
|
|
Text(
|
|
|
|
label,
|
|
|
|
style: genTextStyle(enable),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-08-08 17:53:51 +08:00
|
|
|
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
|
|
|
|
2022-07-18 18:20:00 +08:00
|
|
|
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-09-03 18:19:50 +08:00
|
|
|
const linkStyle = TextStyle(decoration: TextDecoration.underline);
|
2022-08-12 18:42:02 +08:00
|
|
|
gFFI.dialogManager.show((setState, close) {
|
2022-07-18 18:20:00 +08:00
|
|
|
return CustomAlertDialog(
|
|
|
|
title: Text("About $appName"),
|
|
|
|
content: ConstrainedBox(
|
2022-09-03 18:19:50 +08:00
|
|
|
constraints: const BoxConstraints(minWidth: 500),
|
2022-07-18 18:20:00 +08:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2022-09-03 18:19:50 +08:00
|
|
|
const SizedBox(
|
2022-07-18 18:20:00 +08:00
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Text("Version: $version").marginSymmetric(vertical: 4.0),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
launchUrlString("https://rustdesk.com/privacy");
|
|
|
|
},
|
2022-09-03 18:19:50 +08:00
|
|
|
child: const Text(
|
2022-07-27 14:29:47 +08:00
|
|
|
"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");
|
|
|
|
},
|
2022-09-03 18:19:50 +08:00
|
|
|
child: const Text(
|
2022-07-27 14:29:47 +08:00
|
|
|
"Website",
|
|
|
|
style: linkStyle,
|
|
|
|
).marginSymmetric(vertical: 4.0)),
|
2022-07-18 18:20:00 +08:00
|
|
|
Container(
|
2022-09-03 18:19:50 +08:00
|
|
|
decoration: const BoxDecoration(color: Color(0xFF2c8cff)),
|
|
|
|
padding:
|
|
|
|
const EdgeInsets.symmetric(vertical: 24, horizontal: 8),
|
2022-07-18 18:20:00 +08:00
|
|
|
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",
|
2022-09-03 18:19:50 +08:00
|
|
|
style: const TextStyle(color: Colors.white),
|
2022-07-27 14:29:47 +08:00
|
|
|
),
|
2022-09-03 18:19:50 +08:00
|
|
|
const Text(
|
2022-07-27 14:29:47 +08:00
|
|
|
"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: [
|
2022-09-03 18:19:50 +08:00
|
|
|
TextButton(onPressed: close, child: Text(translate("OK"))),
|
2022-07-18 18:20:00 +08:00
|
|
|
],
|
2022-09-03 18:19:50 +08:00
|
|
|
onSubmit: close,
|
|
|
|
onCancel: close,
|
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 = "";
|
2022-08-28 21:43:18 +08:00
|
|
|
var userContontroller = TextEditingController(text: userName);
|
|
|
|
var pwdController = TextEditingController(text: pass);
|
2022-07-27 14:29:47 +08:00
|
|
|
|
|
|
|
var isInProgress = false;
|
|
|
|
var completer = Completer<bool>();
|
2022-08-12 18:42:02 +08:00
|
|
|
gFFI.dialogManager.show((setState, close) {
|
2022-09-03 18:19:50 +08:00
|
|
|
submit() async {
|
|
|
|
setState(() {
|
|
|
|
userNameMsg = "";
|
|
|
|
passMsg = "";
|
|
|
|
isInProgress = true;
|
|
|
|
});
|
|
|
|
cancel() {
|
|
|
|
setState(() {
|
|
|
|
isInProgress = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
userName = userContontroller.text;
|
|
|
|
pass = pwdController.text;
|
|
|
|
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) {
|
|
|
|
// ignore: avoid_print
|
|
|
|
print(err.toString());
|
|
|
|
cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
cancel() {
|
|
|
|
completer.complete(false);
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2022-07-27 14:29:47 +08:00
|
|
|
return CustomAlertDialog(
|
|
|
|
title: Text(translate("Login")),
|
|
|
|
content: ConstrainedBox(
|
2022-09-03 18:19:50 +08:00
|
|
|
constraints: const BoxConstraints(minWidth: 500),
|
2022-07-27 14:29:47 +08:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2022-09-03 18:19:50 +08:00
|
|
|
const SizedBox(
|
2022-07-27 14:29:47 +08:00
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
2022-09-03 18:19:50 +08:00
|
|
|
constraints: const BoxConstraints(minWidth: 100),
|
2022-07-27 14:29:47 +08:00
|
|
|
child: Text(
|
|
|
|
"${translate('Username')}:",
|
|
|
|
textAlign: TextAlign.start,
|
|
|
|
).marginOnly(bottom: 16.0)),
|
2022-09-03 18:19:50 +08:00
|
|
|
const SizedBox(
|
2022-07-27 14:29:47 +08:00
|
|
|
width: 24.0,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
decoration: InputDecoration(
|
2022-09-03 18:19:50 +08:00
|
|
|
border: const OutlineInputBorder(),
|
2022-07-27 14:29:47 +08:00
|
|
|
errorText: userNameMsg.isNotEmpty ? userNameMsg : null),
|
2022-08-28 21:43:18 +08:00
|
|
|
controller: userContontroller,
|
2022-09-03 18:19:50 +08:00
|
|
|
focusNode: FocusNode()..requestFocus(),
|
2022-07-27 14:29:47 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-09-03 18:19:50 +08:00
|
|
|
const SizedBox(
|
2022-07-27 14:29:47 +08:00
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
2022-09-03 18:19:50 +08:00
|
|
|
constraints: const BoxConstraints(minWidth: 100),
|
2022-07-27 14:29:47 +08:00
|
|
|
child: Text("${translate('Password')}:")
|
|
|
|
.marginOnly(bottom: 16.0)),
|
2022-09-03 18:19:50 +08:00
|
|
|
const SizedBox(
|
2022-07-27 14:29:47 +08:00
|
|
|
width: 24.0,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
obscureText: true,
|
|
|
|
decoration: InputDecoration(
|
2022-09-03 18:19:50 +08:00
|
|
|
border: const OutlineInputBorder(),
|
2022-07-27 14:29:47 +08:00
|
|
|
errorText: passMsg.isNotEmpty ? passMsg : null),
|
2022-08-28 21:43:18 +08:00
|
|
|
controller: pwdController,
|
2022-07-27 14:29:47 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-09-03 18:19:50 +08:00
|
|
|
const SizedBox(
|
2022-07-27 14:29:47 +08:00
|
|
|
height: 4.0,
|
|
|
|
),
|
2022-09-03 18:19:50 +08:00
|
|
|
Offstage(
|
|
|
|
offstage: !isInProgress, child: const LinearProgressIndicator())
|
2022-07-27 14:29:47 +08:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: [
|
2022-09-03 18:19:50 +08:00
|
|
|
TextButton(onPressed: cancel, child: Text(translate("Cancel"))),
|
|
|
|
TextButton(onPressed: submit, child: Text(translate("OK"))),
|
2022-07-27 14:29:47 +08:00
|
|
|
],
|
2022-09-03 18:19:50 +08:00
|
|
|
onSubmit: submit,
|
|
|
|
onCancel: cancel,
|
2022-07-27 14:29:47 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
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 = "";
|
|
|
|
|
2022-08-12 18:42:02 +08:00
|
|
|
gFFI.dialogManager.show((setState, close) {
|
2022-09-03 18:19:50 +08:00
|
|
|
submit() {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
bind.mainSetPermanentPassword(password: pass);
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2022-08-01 20:42:30 +08:00
|
|
|
return CustomAlertDialog(
|
|
|
|
title: Text(translate("Set Password")),
|
|
|
|
content: ConstrainedBox(
|
2022-09-03 18:19:50 +08:00
|
|
|
constraints: const BoxConstraints(minWidth: 500),
|
2022-08-01 20:42:30 +08:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2022-09-03 18:19:50 +08:00
|
|
|
const SizedBox(
|
2022-08-01 20:42:30 +08:00
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
2022-09-03 18:19:50 +08:00
|
|
|
constraints: const BoxConstraints(minWidth: 100),
|
2022-08-01 20:42:30 +08:00
|
|
|
child: Text(
|
|
|
|
"${translate('Password')}:",
|
|
|
|
textAlign: TextAlign.start,
|
|
|
|
).marginOnly(bottom: 16.0)),
|
2022-09-03 18:19:50 +08:00
|
|
|
const SizedBox(
|
2022-08-01 20:42:30 +08:00
|
|
|
width: 24.0,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
obscureText: true,
|
|
|
|
decoration: InputDecoration(
|
2022-09-03 18:19:50 +08:00
|
|
|
border: const OutlineInputBorder(),
|
2022-08-01 20:42:30 +08:00
|
|
|
errorText: errMsg0.isNotEmpty ? errMsg0 : null),
|
|
|
|
controller: p0,
|
2022-09-03 18:19:50 +08:00
|
|
|
focusNode: FocusNode()..requestFocus(),
|
2022-08-01 20:42:30 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-09-03 18:19:50 +08:00
|
|
|
const SizedBox(
|
2022-08-01 20:42:30 +08:00
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
ConstrainedBox(
|
2022-09-03 18:19:50 +08:00
|
|
|
constraints: const BoxConstraints(minWidth: 100),
|
2022-08-01 20:42:30 +08:00
|
|
|
child: Text("${translate('Confirmation')}:")
|
|
|
|
.marginOnly(bottom: 16.0)),
|
2022-09-03 18:19:50 +08:00
|
|
|
const SizedBox(
|
2022-08-01 20:42:30 +08:00
|
|
|
width: 24.0,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
obscureText: true,
|
|
|
|
decoration: InputDecoration(
|
2022-09-03 18:19:50 +08:00
|
|
|
border: const OutlineInputBorder(),
|
2022-08-01 20:42:30 +08:00
|
|
|
errorText: errMsg1.isNotEmpty ? errMsg1 : null),
|
|
|
|
controller: p1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: [
|
2022-09-03 18:19:50 +08:00
|
|
|
TextButton(onPressed: close, child: Text(translate("Cancel"))),
|
|
|
|
TextButton(onPressed: submit, child: Text(translate("OK"))),
|
2022-08-01 20:42:30 +08:00
|
|
|
],
|
2022-09-03 18:19:50 +08:00
|
|
|
onSubmit: submit,
|
|
|
|
onCancel: close,
|
2022-08-01 20:42:30 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2022-09-07 12:20:53 +08:00
|
|
|
|
|
|
|
class _PasswordPopupMenu extends StatefulWidget {
|
|
|
|
const _PasswordPopupMenu({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<_PasswordPopupMenu> createState() => _PasswordPopupMenuState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PasswordPopupMenuState extends State<_PasswordPopupMenu> {
|
|
|
|
final RxBool _tempEnabled = true.obs;
|
|
|
|
final RxBool _permEnabled = true.obs;
|
|
|
|
|
|
|
|
List<MenuEntryBase<String>> _buildMenus() {
|
|
|
|
return <MenuEntryBase<String>>[
|
|
|
|
MenuEntryRadios<String>(
|
|
|
|
text: translate('Password type'),
|
|
|
|
optionsGetter: () => [
|
|
|
|
MenuEntryRadioOption(
|
|
|
|
text: translate('Use temporary password'),
|
|
|
|
value: kUseTemporaryPassword),
|
|
|
|
MenuEntryRadioOption(
|
|
|
|
text: translate('Use permanent password'),
|
|
|
|
value: kUsePermanentPassword),
|
|
|
|
MenuEntryRadioOption(
|
|
|
|
text: translate('Use both passwords'),
|
|
|
|
value: kUseBothPasswords),
|
|
|
|
],
|
|
|
|
curOptionGetter: () async {
|
|
|
|
return gFFI.serverModel.verificationMethod;
|
|
|
|
},
|
|
|
|
optionSetter: (String oldValue, String newValue) async {
|
|
|
|
await bind.mainSetOption(
|
|
|
|
key: "verification-method", value: newValue);
|
|
|
|
await gFFI.serverModel.updatePasswordModel();
|
|
|
|
setState(() {
|
|
|
|
_tempEnabled.value =
|
|
|
|
gFFI.serverModel.verificationMethod != kUsePermanentPassword;
|
|
|
|
_permEnabled.value =
|
|
|
|
gFFI.serverModel.verificationMethod != kUseTemporaryPassword;
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
MenuEntryDivider(),
|
|
|
|
MenuEntryButton<String>(
|
|
|
|
enabled: _permEnabled,
|
|
|
|
childBuilder: (TextStyle? style) => Text(
|
|
|
|
translate('Set permanent password'),
|
|
|
|
style: style,
|
|
|
|
),
|
|
|
|
proc: () {
|
|
|
|
setPasswordDialog();
|
|
|
|
},
|
|
|
|
dismissOnClicked: true,
|
|
|
|
),
|
|
|
|
MenuEntrySubMenu(
|
|
|
|
enabled: _tempEnabled,
|
|
|
|
text: translate('Set temporary password length'),
|
|
|
|
entries: [
|
|
|
|
MenuEntryRadios<String>(
|
|
|
|
enabled: _tempEnabled,
|
|
|
|
text: translate(''),
|
|
|
|
optionsGetter: () => [
|
|
|
|
MenuEntryRadioOption(
|
|
|
|
text: translate('6'),
|
|
|
|
value: '6',
|
|
|
|
enabled: _tempEnabled,
|
|
|
|
),
|
|
|
|
MenuEntryRadioOption(
|
|
|
|
text: translate('8'),
|
|
|
|
value: '8',
|
|
|
|
enabled: _tempEnabled,
|
|
|
|
),
|
|
|
|
MenuEntryRadioOption(
|
|
|
|
text: translate('10'),
|
|
|
|
value: '10',
|
|
|
|
enabled: _tempEnabled,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
curOptionGetter: () async {
|
|
|
|
return gFFI.serverModel.temporaryPasswordLength;
|
|
|
|
},
|
|
|
|
optionSetter: (String oldValue, String newValue) async {
|
|
|
|
if (oldValue != newValue) {
|
|
|
|
await gFFI.serverModel.setTemporaryPasswordLength(newValue);
|
|
|
|
await gFFI.serverModel.updatePasswordModel();
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
])
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final editHover = false.obs;
|
|
|
|
return mod_menu.PopupMenuButton(
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
onHover: (v) => editHover.value = v,
|
|
|
|
tooltip: translate(''),
|
|
|
|
position: mod_menu.PopupMenuPosition.overSide,
|
|
|
|
itemBuilder: (BuildContext context) => _buildMenus()
|
|
|
|
.map((entry) => entry.build(
|
|
|
|
context,
|
|
|
|
const MenuConfig(
|
|
|
|
commonColor: _MenubarTheme.commonColor,
|
|
|
|
height: _MenubarTheme.height,
|
|
|
|
dividerHeight: _MenubarTheme.dividerHeight,
|
|
|
|
)))
|
|
|
|
.expand((i) => i)
|
|
|
|
.toList(),
|
|
|
|
child: Obx(() => Icon(Icons.edit,
|
|
|
|
size: 22,
|
|
|
|
color: editHover.value
|
|
|
|
? MyTheme.color(context).text
|
|
|
|
: const Color(0xFFDDDDDD))
|
|
|
|
.marginOnly(bottom: 2)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|