2022-08-11 18:59:26 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2022-08-17 21:28:36 +08:00
|
|
|
import 'package:get/get.dart';
|
2022-08-15 12:35:10 +08:00
|
|
|
// import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
2022-08-11 18:59:26 +08:00
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
import '../../common.dart';
|
|
|
|
import '../../mobile/pages/home_page.dart';
|
|
|
|
import '../../models/platform_model.dart';
|
|
|
|
import '../../models/server_model.dart';
|
|
|
|
|
|
|
|
class DesktopServerPage extends StatefulWidget implements PageShape {
|
|
|
|
@override
|
|
|
|
final title = translate("Share Screen");
|
|
|
|
|
|
|
|
@override
|
|
|
|
final icon = Icon(Icons.mobile_screen_share);
|
|
|
|
|
|
|
|
@override
|
|
|
|
final appBarActions = [
|
|
|
|
PopupMenuButton<String>(
|
|
|
|
icon: Icon(Icons.more_vert),
|
|
|
|
itemBuilder: (context) {
|
|
|
|
return [
|
|
|
|
PopupMenuItem(
|
|
|
|
child: Text(translate("Change ID")),
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
|
|
|
value: "changeID",
|
|
|
|
enabled: false,
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
child: Text(translate("Set permanent password")),
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
|
|
|
value: "setPermanentPassword",
|
|
|
|
enabled:
|
|
|
|
gFFI.serverModel.verificationMethod != kUseTemporaryPassword,
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
child: Text(translate("Set temporary password length")),
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
|
|
|
value: "setTemporaryPasswordLength",
|
|
|
|
enabled:
|
|
|
|
gFFI.serverModel.verificationMethod != kUsePermanentPassword,
|
|
|
|
),
|
|
|
|
const PopupMenuDivider(),
|
|
|
|
PopupMenuItem(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 0.0),
|
|
|
|
value: kUseTemporaryPassword,
|
|
|
|
child: Container(
|
|
|
|
child: ListTile(
|
|
|
|
title: Text(translate("Use temporary password")),
|
|
|
|
trailing: Icon(
|
|
|
|
Icons.check,
|
|
|
|
color: gFFI.serverModel.verificationMethod ==
|
|
|
|
kUseTemporaryPassword
|
|
|
|
? null
|
|
|
|
: Color(0xFFFFFFFF),
|
|
|
|
))),
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 0.0),
|
|
|
|
value: kUsePermanentPassword,
|
|
|
|
child: ListTile(
|
|
|
|
title: Text(translate("Use permanent password")),
|
|
|
|
trailing: Icon(
|
|
|
|
Icons.check,
|
|
|
|
color: gFFI.serverModel.verificationMethod ==
|
|
|
|
kUsePermanentPassword
|
|
|
|
? null
|
|
|
|
: Color(0xFFFFFFFF),
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 0.0),
|
|
|
|
value: kUseBothPasswords,
|
|
|
|
child: ListTile(
|
|
|
|
title: Text(translate("Use both passwords")),
|
|
|
|
trailing: Icon(
|
|
|
|
Icons.check,
|
|
|
|
color: gFFI.serverModel.verificationMethod !=
|
|
|
|
kUseTemporaryPassword &&
|
|
|
|
gFFI.serverModel.verificationMethod !=
|
|
|
|
kUsePermanentPassword
|
|
|
|
? null
|
|
|
|
: Color(0xFFFFFFFF),
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
},
|
|
|
|
onSelected: (value) {
|
|
|
|
if (value == "changeID") {
|
|
|
|
// TODO
|
|
|
|
} else if (value == "setPermanentPassword") {
|
2022-08-15 12:35:10 +08:00
|
|
|
// setPermanentPasswordDialog();
|
2022-08-11 18:59:26 +08:00
|
|
|
} else if (value == "setTemporaryPasswordLength") {
|
2022-08-15 12:35:10 +08:00
|
|
|
// setTemporaryPasswordLengthDialog();
|
2022-08-11 18:59:26 +08:00
|
|
|
} else if (value == kUsePermanentPassword ||
|
|
|
|
value == kUseTemporaryPassword ||
|
|
|
|
value == kUseBothPasswords) {
|
|
|
|
bind.mainSetOption(key: "verification-method", value: value);
|
|
|
|
gFFI.serverModel.updatePasswordModel();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _DesktopServerPageState();
|
|
|
|
}
|
|
|
|
|
2022-08-17 21:46:56 +08:00
|
|
|
class _DesktopServerPageState extends State<DesktopServerPage>
|
|
|
|
with AutomaticKeepAliveClientMixin {
|
2022-08-11 18:59:26 +08:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-17 21:46:56 +08:00
|
|
|
super.build(context);
|
2022-08-11 18:59:26 +08:00
|
|
|
return ChangeNotifierProvider.value(
|
|
|
|
value: gFFI.serverModel,
|
|
|
|
child: Consumer<ServerModel>(
|
2022-08-17 21:28:36 +08:00
|
|
|
builder: (context, serverModel, child) => Material(
|
2022-08-11 18:59:26 +08:00
|
|
|
child: Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
children: [
|
2022-08-17 21:28:36 +08:00
|
|
|
Expanded(child: ConnectionManager()),
|
2022-08-11 18:59:26 +08:00
|
|
|
SizedBox.fromSize(size: Size(0, 15.0)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)));
|
|
|
|
}
|
2022-08-17 21:46:56 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
bool get wantKeepAlive => true;
|
2022-08-11 18:59:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class ConnectionManager extends StatelessWidget {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final serverModel = Provider.of<ServerModel>(context);
|
2022-08-17 21:28:36 +08:00
|
|
|
// test case:
|
2022-08-17 21:46:56 +08:00
|
|
|
serverModel.clients.clear();
|
|
|
|
serverModel.clients[0] = Client(
|
|
|
|
false, false, "Readmi-M21sdfsdf", "123123123", true, false, false);
|
|
|
|
return serverModel.clients.isEmpty
|
|
|
|
? Center(
|
|
|
|
child: Text(translate("Waiting")),
|
|
|
|
)
|
|
|
|
: DefaultTabController(
|
|
|
|
length: serverModel.clients.length,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: kTextTabBarHeight,
|
|
|
|
child: TabBar(
|
|
|
|
isScrollable: true,
|
|
|
|
tabs: serverModel.clients.entries
|
|
|
|
.map((entry) => buildTab(entry))
|
|
|
|
.toList(growable: false)),
|
2022-08-17 21:28:36 +08:00
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: TabBarView(
|
|
|
|
children: serverModel.clients.entries
|
|
|
|
.map((entry) => buildConnectionCard(entry))
|
|
|
|
.toList(growable: false)),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildConnectionCard(MapEntry<int, Client> entry) {
|
|
|
|
final client = entry.value;
|
2022-08-11 18:59:26 +08:00
|
|
|
return Column(
|
2022-08-17 21:28:36 +08:00
|
|
|
children: [
|
|
|
|
_CmHeader(client: client),
|
|
|
|
_PrivilegeBoard(client: client),
|
|
|
|
Expanded(
|
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
child: _CmControlPanel(client: client),
|
|
|
|
))
|
|
|
|
],
|
|
|
|
).paddingSymmetric(vertical: 8.0, horizontal: 8.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildTab(MapEntry<int, Client> entry) {
|
|
|
|
return Tab(
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
width: 80,
|
|
|
|
child: Text(
|
|
|
|
"${entry.value.name}",
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CmHeader extends StatelessWidget {
|
|
|
|
final Client client;
|
|
|
|
|
|
|
|
const _CmHeader({Key? key, required this.client}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
// icon
|
|
|
|
Container(
|
|
|
|
width: 100,
|
|
|
|
height: 100,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
decoration: BoxDecoration(color: str2color(client.name)),
|
|
|
|
child: Text(
|
|
|
|
"${client.name[0]}",
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold, color: Colors.white, fontSize: 75),
|
|
|
|
),
|
|
|
|
).marginOnly(left: 4.0, right: 8.0),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"${client.name}",
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyTheme.cmIdColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 20,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
maxLines: 1,
|
|
|
|
),
|
|
|
|
Text("(${client.peerId})",
|
|
|
|
style: TextStyle(color: MyTheme.cmIdColor, fontSize: 14)),
|
|
|
|
SizedBox(
|
|
|
|
height: 16.0,
|
|
|
|
),
|
|
|
|
Offstage(
|
|
|
|
offstage: !client.authorized,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Text("${translate("Connected")}"),
|
|
|
|
],
|
|
|
|
))
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Offstage(
|
|
|
|
offstage: client.isFileTransfer,
|
|
|
|
child: IconButton(
|
|
|
|
onPressed: handleSendMsg,
|
|
|
|
icon: Icon(Icons.message_outlined),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleSendMsg() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PrivilegeBoard extends StatelessWidget {
|
|
|
|
final Client client;
|
|
|
|
|
|
|
|
const _PrivilegeBoard({Key? key, required this.client}) : super(key: key);
|
|
|
|
|
|
|
|
Widget buildPermissionIcon(bool enabled, ImageProvider icon,
|
|
|
|
Function(bool)? onTap, String? tooltip) {
|
|
|
|
return Tooltip(
|
|
|
|
message: tooltip ?? "",
|
|
|
|
child: Ink(
|
|
|
|
decoration:
|
|
|
|
BoxDecoration(color: enabled ? MyTheme.accent80 : Colors.grey),
|
|
|
|
padding: EdgeInsets.all(4.0),
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () => onTap?.call(!enabled),
|
|
|
|
child: Image(
|
|
|
|
image: icon,
|
|
|
|
width: 50,
|
|
|
|
height: 50,
|
|
|
|
fit: BoxFit.scaleDown,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
).marginSymmetric(horizontal: 4.0),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
margin: EdgeInsets.only(top: 16.0, bottom: 8.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
translate("Permissions"),
|
|
|
|
style: TextStyle(fontSize: 16),
|
|
|
|
).marginOnly(left: 4.0),
|
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
buildPermissionIcon(
|
|
|
|
client.keyboard, iconKeyboard, (enable) => null, null),
|
|
|
|
buildPermissionIcon(
|
|
|
|
client.clipboard, iconClipboard, (enable) => null, null),
|
|
|
|
buildPermissionIcon(
|
|
|
|
client.audio, iconAudio, (enable) => null, null),
|
|
|
|
// TODO: file transfer
|
|
|
|
buildPermissionIcon(false, iconFile, (enable) => null, null),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
2022-08-11 18:59:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-17 21:28:36 +08:00
|
|
|
class _CmControlPanel extends StatelessWidget {
|
|
|
|
final Client client;
|
|
|
|
|
|
|
|
const _CmControlPanel({Key? key, required this.client}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-17 21:46:56 +08:00
|
|
|
return client.authorized
|
|
|
|
? buildAuthorized(context)
|
|
|
|
: buildUnAuthorized(context);
|
2022-08-17 21:28:36 +08:00
|
|
|
}
|
|
|
|
|
2022-08-17 21:46:56 +08:00
|
|
|
buildAuthorized(BuildContext context) {
|
2022-08-17 21:28:36 +08:00
|
|
|
return Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Ink(
|
|
|
|
width: 200,
|
|
|
|
height: 40,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.redAccent, borderRadius: BorderRadius.circular(10)),
|
|
|
|
child: InkWell(
|
2022-08-17 21:46:56 +08:00
|
|
|
onTap: () => handleDisconnect(context),
|
2022-08-17 21:28:36 +08:00
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
translate("Disconnect"),
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-08-17 21:46:56 +08:00
|
|
|
buildUnAuthorized(BuildContext context) {
|
2022-08-17 21:28:36 +08:00
|
|
|
return Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Ink(
|
|
|
|
width: 100,
|
|
|
|
height: 40,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: MyTheme.accent, borderRadius: BorderRadius.circular(10)),
|
|
|
|
child: InkWell(
|
2022-08-17 21:46:56 +08:00
|
|
|
onTap: () => handleAccept(context),
|
2022-08-17 21:28:36 +08:00
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
translate("Accept"),
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
width: 30,
|
|
|
|
),
|
|
|
|
Ink(
|
|
|
|
width: 100,
|
|
|
|
height: 40,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.transparent,
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
border: Border.all(color: Colors.grey)),
|
|
|
|
child: InkWell(
|
2022-08-17 21:46:56 +08:00
|
|
|
onTap: () => handleDisconnect(context),
|
2022-08-17 21:28:36 +08:00
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
translate("Cancel"),
|
|
|
|
style: TextStyle(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-08-17 21:46:56 +08:00
|
|
|
void handleDisconnect(BuildContext context) {
|
|
|
|
bind.cmCloseConnection(connId: client.id);
|
|
|
|
}
|
2022-08-17 21:28:36 +08:00
|
|
|
|
2022-08-17 21:46:56 +08:00
|
|
|
void handleAccept(BuildContext context) {
|
|
|
|
final model = Provider.of<ServerModel>(context, listen: false);
|
|
|
|
model.sendLoginResponse(client, true);
|
|
|
|
}
|
2022-08-17 21:28:36 +08:00
|
|
|
}
|
|
|
|
|
2022-08-11 18:59:26 +08:00
|
|
|
class PaddingCard extends StatelessWidget {
|
|
|
|
PaddingCard({required this.child, this.title, this.titleIcon});
|
|
|
|
|
|
|
|
final String? title;
|
|
|
|
final IconData? titleIcon;
|
|
|
|
final Widget child;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final children = [child];
|
|
|
|
if (title != null) {
|
|
|
|
children.insert(
|
|
|
|
0,
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 5.0),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
titleIcon != null
|
|
|
|
? Padding(
|
|
|
|
padding: EdgeInsets.only(right: 10),
|
|
|
|
child: Icon(titleIcon,
|
|
|
|
color: MyTheme.accent80, size: 30))
|
|
|
|
: SizedBox.shrink(),
|
|
|
|
Text(
|
|
|
|
title!,
|
|
|
|
style: TextStyle(
|
|
|
|
fontFamily: 'WorkSans',
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 20,
|
|
|
|
color: MyTheme.accent80,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
return Container(
|
|
|
|
width: double.maxFinite,
|
|
|
|
child: Card(
|
|
|
|
margin: EdgeInsets.fromLTRB(15.0, 15.0, 15.0, 0),
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 15.0, horizontal: 30.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: children,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget clientInfo(Client client) {
|
|
|
|
return Padding(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 8),
|
|
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
flex: -1,
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.only(right: 12),
|
|
|
|
child: CircleAvatar(
|
|
|
|
child: Text(client.name[0]),
|
|
|
|
backgroundColor: MyTheme.border))),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text(client.name,
|
|
|
|
style: TextStyle(color: MyTheme.idColor, fontSize: 18)),
|
|
|
|
SizedBox(width: 8),
|
|
|
|
Text(client.peerId,
|
|
|
|
style: TextStyle(color: MyTheme.idColor, fontSize: 10))
|
|
|
|
]))
|
|
|
|
],
|
|
|
|
),
|
|
|
|
]));
|
|
|
|
}
|