mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
@@ -24,7 +24,5 @@ void main(List<String> args) async {
|
||||
gFFI.serverModel.clients
|
||||
.add(Client(3, false, false, "UserD", "441123123", true, false, false));
|
||||
runApp(GetMaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: getCurrentTheme(),
|
||||
home: DesktopServerPage()));
|
||||
debugShowCheckedModeBanner: false, home: DesktopServerPage()));
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ var isWeb = false;
|
||||
var isWebDesktop = false;
|
||||
var version = "";
|
||||
int androidVersion = 0;
|
||||
late final DesktopType? desktopType;
|
||||
|
||||
typedef F = String Function(String);
|
||||
typedef FMethod = String Function(String, dynamic);
|
||||
@@ -42,6 +43,15 @@ late final iconFile = MemoryImage(Uint8List.fromList(base64Decode(
|
||||
late final iconRestart = MemoryImage(Uint8List.fromList(base64Decode(
|
||||
'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAB7BAAAewQHDaVRTAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAbhJREFUWIXVlrFqFGEUhb+7UYxaWCQKlrKKxaZSQVGDJih2tj6MD2DnMwiWvoAIRnENIpZiYxEro6IooiS7SPwsMgNLkk3mjmYmnmb45/73nMNwz/x/qH3gMu2gH6rAU+Blw+Lngau4jpmGxVF7qp1iPWjaQKnZ2WnXbuP/NqAeUPc3ZkA9XDwvqc+BVWCgPlJ7tRwUKThZce819b46VH+pfXVRXVO/q2cSul3VOgZUl0ejq86r39TXI8mqZKDuDEwCw3IREQvAbWAGmMsQZQ0sAl3gHPB1Q+0e8BuYzRDuy2yOiFVgaUxtRf0ETGc4syk4rc6PqU0Cx9j8Zf6dAeAK8Fi9sUXtFjABvEgxJlNwRP2svlNPjbw/q35U36oTFbnyMSwabxb/gB/qA3VBHagrauV7RW0DRfP1IvMlXqkXkhz1DYyQTKtHa/Z2VVMx3IiI+PI3/bCHjuOpFrSnAMpL6QfgTcMGesDx0kBr2BMzsNyi/vtQu8CJlgwsRbZDnWP90NkKaxHxJMOXMqAeAn5u0ydwMCKGY+qbkB3C2W3EKWoXk5zVoHbUZ+6Mh7tl4G4F8RJ3qvL+AfV3r5Vdpj70AAAAAElFTkSuQmCC')));
|
||||
|
||||
enum DesktopType {
|
||||
main,
|
||||
remote,
|
||||
fileTransfer,
|
||||
cm,
|
||||
portForward,
|
||||
rdp,
|
||||
}
|
||||
|
||||
class IconFont {
|
||||
static const _family1 = 'Tabbar';
|
||||
static const _family2 = 'PeerSearchbar';
|
||||
@@ -182,6 +192,32 @@ class MyTheme {
|
||||
],
|
||||
);
|
||||
|
||||
static changeTo(bool dark) {
|
||||
if (Get.isDarkMode != dark) {
|
||||
Get.find<SharedPreferences>().setString("darkTheme", dark ? "Y" : "");
|
||||
Get.changeThemeMode(dark ? ThemeMode.dark : ThemeMode.light);
|
||||
if (desktopType == DesktopType.main) {
|
||||
bind.mainChangeTheme(dark: dark);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool _themeInitialed = false;
|
||||
|
||||
static ThemeMode initialThemeMode({bool mainPage = false}) {
|
||||
bool dark;
|
||||
// Brightnesss is always light on windows, Flutter 3.0.5
|
||||
if (_themeInitialed || !mainPage || Platform.isWindows) {
|
||||
dark = "Y" == Get.find<SharedPreferences>().getString("darkTheme");
|
||||
} else {
|
||||
dark = WidgetsBinding.instance.platformDispatcher.platformBrightness ==
|
||||
Brightness.dark;
|
||||
Get.find<SharedPreferences>().setString("darkTheme", dark ? "Y" : "");
|
||||
}
|
||||
_themeInitialed = true;
|
||||
return dark ? ThemeMode.dark : ThemeMode.light;
|
||||
}
|
||||
|
||||
static ColorThemeExtension color(BuildContext context) {
|
||||
return Theme.of(context).extension<ColorThemeExtension>()!;
|
||||
}
|
||||
@@ -192,8 +228,7 @@ class MyTheme {
|
||||
}
|
||||
|
||||
bool isDarkTheme() {
|
||||
final isDark = "Y" == Get.find<SharedPreferences>().getString("darkTheme");
|
||||
return isDark;
|
||||
return Get.isDarkMode;
|
||||
}
|
||||
|
||||
final ButtonStyle flatButtonStyle = TextButton.styleFrom(
|
||||
@@ -478,7 +513,9 @@ void msgBox(
|
||||
submit() {
|
||||
dialogManager.dismissAll();
|
||||
// https://github.com/fufesou/rustdesk/blob/5e9a31340b899822090a3731769ae79c6bf5f3e5/src/ui/common.tis#L263
|
||||
if (!type.contains("custom")) {
|
||||
if (!type.contains("custom") &&
|
||||
!(desktopType == DesktopType.portForward ||
|
||||
desktopType == DesktopType.rdp)) {
|
||||
closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ const String kAppTypeMain = "main";
|
||||
const String kAppTypeDesktopRemote = "remote";
|
||||
const String kAppTypeDesktopFileTransfer = "file transfer";
|
||||
const String kAppTypeDesktopPortForward = "port forward";
|
||||
const String kAppTypeDesktopRDP = "rdp";
|
||||
|
||||
const String kTabLabelHomePage = "Home";
|
||||
const String kTabLabelSettingPage = "Settings";
|
||||
|
||||
|
||||
@@ -218,27 +218,25 @@ class _UserInterfaceState extends State<_UserInterface>
|
||||
onChanged: (key) async {
|
||||
await bind.mainSetLocalOption(key: "lang", value: key);
|
||||
Get.forceAppUpdate();
|
||||
bind.mainChangeLanguage(lang: key);
|
||||
},
|
||||
).marginOnly(left: _kContentHMargin);
|
||||
});
|
||||
}
|
||||
|
||||
Widget theme() {
|
||||
var change = () {
|
||||
bool dark = !isDarkTheme();
|
||||
Get.changeTheme(dark ? MyTheme.darkTheme : MyTheme.lightTheme);
|
||||
Get.find<SharedPreferences>().setString("darkTheme", dark ? "Y" : "");
|
||||
Get.forceAppUpdate();
|
||||
};
|
||||
change() {
|
||||
MyTheme.changeTo(!isDarkTheme());
|
||||
}
|
||||
|
||||
return GestureDetector(
|
||||
onTap: change,
|
||||
child: Row(
|
||||
children: [
|
||||
Checkbox(value: isDarkTheme(), onChanged: (_) => change()),
|
||||
Expanded(child: Text(translate('Dark Theme'))),
|
||||
],
|
||||
).marginOnly(left: _kCheckBoxLeftMargin),
|
||||
onTap: change,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ class _DesktopTabPageState extends State<DesktopTabPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final dark = isDarkTheme();
|
||||
RxBool fullscreen = false.obs;
|
||||
Get.put(fullscreen, tag: 'fullscreen');
|
||||
return Obx(() => DragToResizeArea(
|
||||
|
||||
@@ -70,45 +70,38 @@ class _PortForwardPageState extends State<PortForwardPage>
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return Overlay(initialEntries: [
|
||||
OverlayEntry(builder: (context) {
|
||||
_ffi.dialogManager.setOverlayState(Overlay.of(context));
|
||||
return Scaffold(
|
||||
backgroundColor: MyTheme.color(context).grayBg,
|
||||
body: FutureBuilder(future: () async {
|
||||
if (!isRdp) {
|
||||
refreshTunnelConfig();
|
||||
}
|
||||
}(), builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
width: 20, color: MyTheme.color(context).grayBg!)),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
buildPrompt(context),
|
||||
Flexible(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: MyTheme.color(context).bg,
|
||||
border:
|
||||
Border.all(width: 1, color: MyTheme.border)),
|
||||
child: widget.isRDP
|
||||
? buildRdp(context)
|
||||
: buildTunnel(context),
|
||||
),
|
||||
),
|
||||
],
|
||||
return Scaffold(
|
||||
backgroundColor: MyTheme.color(context).grayBg,
|
||||
body: FutureBuilder(future: () async {
|
||||
if (!isRdp) {
|
||||
refreshTunnelConfig();
|
||||
}
|
||||
}(), builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
width: 20, color: MyTheme.color(context).grayBg!)),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
buildPrompt(context),
|
||||
Flexible(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: MyTheme.color(context).bg,
|
||||
border: Border.all(width: 1, color: MyTheme.border)),
|
||||
child:
|
||||
widget.isRDP ? buildRdp(context) : buildTunnel(context),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return const Offstage();
|
||||
}),
|
||||
);
|
||||
})
|
||||
]);
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return const Offstage();
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
buildPrompt(BuildContext context) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/consts.dart';
|
||||
import 'package:flutter_hbb/desktop/widgets/tabbar_widget.dart';
|
||||
import 'package:flutter_hbb/mobile/pages/chat_page.dart';
|
||||
import 'package:flutter_hbb/models/chat_model.dart';
|
||||
@@ -63,20 +64,15 @@ class _DesktopServerPageState extends State<DesktopServerPage>
|
||||
border: Border.all(color: MyTheme.color(context).border!)),
|
||||
child: Scaffold(
|
||||
backgroundColor: MyTheme.color(context).bg,
|
||||
body: Overlay(initialEntries: [
|
||||
OverlayEntry(builder: (context) {
|
||||
gFFI.dialogManager.setOverlayState(Overlay.of(context));
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(child: ConnectionManager()),
|
||||
SizedBox.fromSize(size: Size(0, 15.0)),
|
||||
],
|
||||
),
|
||||
);
|
||||
})
|
||||
]),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(child: ConnectionManager()),
|
||||
SizedBox.fromSize(size: Size(0, 15.0)),
|
||||
],
|
||||
),
|
||||
),
|
||||
))));
|
||||
}
|
||||
|
||||
@@ -111,7 +107,7 @@ class ConnectionManagerState extends State<ConnectionManager> {
|
||||
return serverModel.clients.isEmpty
|
||||
? Column(
|
||||
children: [
|
||||
buildTitleBar(Offstage()),
|
||||
buildTitleBar(),
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: Text(translate("Waiting")),
|
||||
@@ -134,20 +130,27 @@ class ConnectionManagerState extends State<ConnectionManager> {
|
||||
]));
|
||||
}
|
||||
|
||||
Widget buildTitleBar(Widget middle) {
|
||||
return GestureDetector(
|
||||
onPanDown: (d) {
|
||||
windowManager.startDragging();
|
||||
},
|
||||
Widget buildTitleBar() {
|
||||
return SizedBox(
|
||||
height: kDesktopRemoteTabBarHeight,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
_AppIcon(),
|
||||
Expanded(child: middle),
|
||||
const _AppIcon(),
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onPanStart: (d) {
|
||||
windowManager.startDragging();
|
||||
},
|
||||
child: Container(
|
||||
color: MyTheme.color(context).bg,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 4.0,
|
||||
),
|
||||
_CloseButton()
|
||||
const _CloseButton()
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -209,15 +212,16 @@ class _CloseButton extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Ink(
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
windowManager.close();
|
||||
},
|
||||
child: Icon(
|
||||
Icons.close,
|
||||
size: 30,
|
||||
)),
|
||||
return IconButton(
|
||||
onPressed: () {
|
||||
windowManager.close();
|
||||
},
|
||||
icon: const Icon(
|
||||
IconFont.close,
|
||||
size: 18,
|
||||
),
|
||||
splashColor: Colors.transparent,
|
||||
hoverColor: Colors.transparent,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,12 +43,16 @@ Future<Null> main(List<String> args) async {
|
||||
WindowType wType = type.windowType;
|
||||
switch (wType) {
|
||||
case WindowType.RemoteDesktop:
|
||||
desktopType = DesktopType.remote;
|
||||
runRemoteScreen(argument);
|
||||
break;
|
||||
case WindowType.FileTransfer:
|
||||
desktopType = DesktopType.fileTransfer;
|
||||
runFileTransferScreen(argument);
|
||||
break;
|
||||
case WindowType.PortForward:
|
||||
desktopType =
|
||||
argument['isRDP'] ? DesktopType.rdp : DesktopType.portForward;
|
||||
runPortForwardScreen(argument);
|
||||
break;
|
||||
default:
|
||||
@@ -56,19 +60,17 @@ Future<Null> main(List<String> args) async {
|
||||
}
|
||||
} else if (args.isNotEmpty && args.first == '--cm') {
|
||||
print("--cm started");
|
||||
desktopType = DesktopType.cm;
|
||||
await windowManager.ensureInitialized();
|
||||
runConnectionManagerScreen();
|
||||
} else {
|
||||
desktopType = DesktopType.main;
|
||||
await windowManager.ensureInitialized();
|
||||
windowManager.setPreventClose(true);
|
||||
runMainApp(true);
|
||||
}
|
||||
}
|
||||
|
||||
ThemeData getCurrentTheme() {
|
||||
return isDarkTheme() ? MyTheme.darkTheme : MyTheme.lightTheme;
|
||||
}
|
||||
|
||||
Future<void> initEnv(String appType) async {
|
||||
await platformFFI.init(appType);
|
||||
// global FFI, use this **ONLY** for global configuration
|
||||
@@ -77,6 +79,7 @@ Future<void> initEnv(String appType) async {
|
||||
await initGlobalFFI();
|
||||
// await Firebase.initializeApp();
|
||||
refreshCurrentUser();
|
||||
_registerEventHandler();
|
||||
}
|
||||
|
||||
void runMainApp(bool startService) async {
|
||||
@@ -111,7 +114,9 @@ void runRemoteScreen(Map<String, dynamic> argument) async {
|
||||
navigatorKey: globalKey,
|
||||
debugShowCheckedModeBanner: false,
|
||||
title: 'RustDesk - Remote Desktop',
|
||||
theme: getCurrentTheme(),
|
||||
theme: MyTheme.lightTheme,
|
||||
darkTheme: MyTheme.darkTheme,
|
||||
themeMode: MyTheme.initialThemeMode(),
|
||||
home: DesktopRemoteScreen(
|
||||
params: argument,
|
||||
),
|
||||
@@ -129,7 +134,9 @@ void runFileTransferScreen(Map<String, dynamic> argument) async {
|
||||
navigatorKey: globalKey,
|
||||
debugShowCheckedModeBanner: false,
|
||||
title: 'RustDesk - File Transfer',
|
||||
theme: getCurrentTheme(),
|
||||
theme: MyTheme.lightTheme,
|
||||
darkTheme: MyTheme.darkTheme,
|
||||
themeMode: MyTheme.initialThemeMode(),
|
||||
home: DesktopFileTransferScreen(params: argument),
|
||||
navigatorObservers: [
|
||||
// FirebaseAnalyticsObserver(analytics: analytics),
|
||||
@@ -146,7 +153,9 @@ void runPortForwardScreen(Map<String, dynamic> argument) async {
|
||||
navigatorKey: globalKey,
|
||||
debugShowCheckedModeBanner: false,
|
||||
title: 'RustDesk - Port Forward',
|
||||
theme: getCurrentTheme(),
|
||||
theme: MyTheme.lightTheme,
|
||||
darkTheme: MyTheme.darkTheme,
|
||||
themeMode: MyTheme.initialThemeMode(),
|
||||
home: DesktopPortForwardScreen(params: argument),
|
||||
navigatorObservers: [
|
||||
// FirebaseAnalyticsObserver(analytics: analytics),
|
||||
@@ -170,7 +179,9 @@ void runConnectionManagerScreen() async {
|
||||
]);
|
||||
runApp(GetMaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: getCurrentTheme(),
|
||||
theme: MyTheme.lightTheme,
|
||||
darkTheme: MyTheme.darkTheme,
|
||||
themeMode: MyTheme.initialThemeMode(),
|
||||
home: DesktopServerPage(),
|
||||
builder: _keepScaleBuilder()));
|
||||
}
|
||||
@@ -185,7 +196,26 @@ WindowOptions getHiddenTitleBarWindowOptions(Size size) {
|
||||
);
|
||||
}
|
||||
|
||||
class App extends StatelessWidget {
|
||||
class App extends StatefulWidget {
|
||||
@override
|
||||
State<App> createState() => _AppState();
|
||||
}
|
||||
|
||||
class _AppState extends State<App> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.window.onPlatformBrightnessChanged = () {
|
||||
WidgetsBinding.instance.handlePlatformBrightnessChanged();
|
||||
var system =
|
||||
WidgetsBinding.instance.platformDispatcher.platformBrightness;
|
||||
var current = isDarkTheme() ? Brightness.dark : Brightness.light;
|
||||
if (current != system) {
|
||||
MyTheme.changeTo(system == Brightness.dark);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// final analytics = FirebaseAnalytics.instance;
|
||||
@@ -204,7 +234,9 @@ class App extends StatelessWidget {
|
||||
navigatorKey: globalKey,
|
||||
debugShowCheckedModeBanner: false,
|
||||
title: 'RustDesk',
|
||||
theme: getCurrentTheme(),
|
||||
theme: MyTheme.lightTheme,
|
||||
darkTheme: MyTheme.darkTheme,
|
||||
themeMode: MyTheme.initialThemeMode(mainPage: true),
|
||||
home: isDesktop
|
||||
? const DesktopTabPage()
|
||||
: !isAndroid
|
||||
@@ -238,3 +270,17 @@ _keepScaleBuilder() {
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
_registerEventHandler() {
|
||||
if (desktopType != DesktopType.main) {
|
||||
platformFFI.registerEventHandler('theme', 'theme', (evt) {
|
||||
String? dark = evt['dark'];
|
||||
if (dark != null) {
|
||||
MyTheme.changeTo(dark == 'true');
|
||||
}
|
||||
});
|
||||
platformFFI.registerEventHandler('language', 'language', (_) {
|
||||
Get.forceAppUpdate();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user