mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-04-19 00:01:29 +03:00
feat: add local option to main window
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart' hide MenuItem;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hbb/common.dart';
|
||||
import 'package:flutter_hbb/desktop/pages/connection_page.dart';
|
||||
import 'package:flutter_hbb/desktop/widgets/titlebar_widget.dart';
|
||||
import 'package:flutter_hbb/models/model.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tray_manager/tray_manager.dart';
|
||||
|
||||
@@ -42,9 +44,6 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener {
|
||||
child: buildServerInfo(context),
|
||||
flex: 1,
|
||||
),
|
||||
SizedBox(
|
||||
width: 16.0,
|
||||
),
|
||||
Flexible(
|
||||
child: buildServerBoard(context),
|
||||
flex: 4,
|
||||
@@ -76,12 +75,8 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener {
|
||||
|
||||
buildServerBoard(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
// buildControlPanel(context),
|
||||
// buildRecentSession(context),
|
||||
Expanded(child: ConnectionPage())
|
||||
Expanded(child: ConnectionPage()),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -105,9 +100,35 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
translate("ID"),
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
translate("ID"),
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
|
||||
),
|
||||
PopupMenuButton(
|
||||
padding: EdgeInsets.all(4.0),
|
||||
itemBuilder: (context) => [
|
||||
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',),
|
||||
genAudioInputPopupMenuItem(),
|
||||
// TODO: Audio Input
|
||||
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',),
|
||||
// sep
|
||||
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',),
|
||||
PopupMenuItem(child: Text(translate("Change ID")), value: 'change-id',),
|
||||
genEnablePopupMenuItem(translate("Dark Theme"), 'allow-darktheme',),
|
||||
PopupMenuItem(child: Text(translate("About")), value: 'about',),
|
||||
], onSelected: onSelectMenu,)
|
||||
],
|
||||
),
|
||||
TextFormField(
|
||||
controller: model.serverId,
|
||||
@@ -194,7 +215,9 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener {
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: TextEditingController(),
|
||||
inputFormatters: [],
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.allow(RegExp(r"[0-9]"))
|
||||
],
|
||||
)
|
||||
],
|
||||
))
|
||||
@@ -232,4 +255,90 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener {
|
||||
trayManager.removeListener(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void onSelectMenu(String value) {
|
||||
if (value.startsWith('enable-')) {
|
||||
final option = gFFI.getOption(value);
|
||||
gFFI.setOption(value, option == "N" ? "" : "N");
|
||||
} else if (value.startsWith('allow-')) {
|
||||
final option = gFFI.getOption(value);
|
||||
gFFI.setOption(value, option == "Y" ? "" : "Y");
|
||||
} else if (value == "stop-service") {
|
||||
final option = gFFI.getOption(value);
|
||||
gFFI.setOption(value, option == "Y" ? "" : "Y");
|
||||
}
|
||||
}
|
||||
|
||||
PopupMenuItem<String> genEnablePopupMenuItem(String label, String value) {
|
||||
final isEnable =
|
||||
label.startsWith('enable-') ? gFFI.getOption(value) != "N" : gFFI.getOption(value) != "Y";
|
||||
return PopupMenuItem(child: Row(
|
||||
children: [
|
||||
Offstage(offstage: !isEnable, child: Icon(Icons.check)),
|
||||
Text(label, style: genTextStyle(isEnable),),
|
||||
],
|
||||
), value: value,);
|
||||
}
|
||||
|
||||
TextStyle genTextStyle(bool isPositive) {
|
||||
return isPositive ? TextStyle() : TextStyle(
|
||||
color: Colors.redAccent,
|
||||
decoration: TextDecoration.lineThrough
|
||||
);
|
||||
}
|
||||
|
||||
PopupMenuItem<String> genAudioInputPopupMenuItem() {
|
||||
final _enabledInput = gFFI.getOption('enable-audio');
|
||||
var defaultInput = gFFI.getDefaultAudioInput().obs;
|
||||
var enabled = (_enabledInput != "N").obs;
|
||||
return PopupMenuItem(child: FutureBuilder<List<String>>(
|
||||
future: gFFI.getAudioInputs(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
final inputs = snapshot.data!;
|
||||
if (Platform.isWindows) {
|
||||
inputs.insert(0, translate("System Sound"));
|
||||
}
|
||||
var inputList = inputs.map((e) => PopupMenuItem(
|
||||
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,
|
||||
)).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>(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(translate("Audio Input"))),
|
||||
itemBuilder: (context) => inputList,
|
||||
onSelected: (dev) {
|
||||
if (dev == "Mute") {
|
||||
gFFI.setOption('enable-audio', _enabledInput == 'N' ? '': 'N');
|
||||
enabled.value = gFFI.getOption('enable-audio') != 'N';
|
||||
} else if (dev != gFFI.getDefaultAudioInput()) {
|
||||
gFFI.setDefaultAudioInput(dev);
|
||||
defaultInput.value = dev;
|
||||
}
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return Text("...");
|
||||
}
|
||||
},
|
||||
), value: 'audio-input',);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user