Merge pull request #1302 from Kingtous/flutter_desktop
opt: optimize cm ui & prepare custom titlebar
This commit is contained in:
commit
58b471e26b
flutter
@ -10,8 +10,8 @@ import 'desktop/pages/server_page.dart';
|
|||||||
void main(List<String> args) async {
|
void main(List<String> args) async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await windowManager.ensureInitialized();
|
await windowManager.ensureInitialized();
|
||||||
await initEnv(kAppTypeConnectionManager);
|
|
||||||
runApp(GetMaterialApp(theme: getCurrentTheme(), home: DesktopServerPage()));
|
|
||||||
await windowManager.setSize(Size(400, 600));
|
await windowManager.setSize(Size(400, 600));
|
||||||
await windowManager.setAlignment(Alignment.topRight);
|
await windowManager.setAlignment(Alignment.topRight);
|
||||||
|
await initEnv(kAppTypeConnectionManager);
|
||||||
|
runApp(GetMaterialApp(theme: getCurrentTheme(), home: DesktopServerPage()));
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,15 @@ final ButtonStyle flatButtonStyle = TextButton.styleFrom(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
String formatDurationToTime(Duration duration) {
|
||||||
|
var totalTime = duration.inSeconds;
|
||||||
|
final secs = totalTime % 60;
|
||||||
|
totalTime = (totalTime - secs) ~/ 60;
|
||||||
|
final mins = totalTime % 60;
|
||||||
|
totalTime = (totalTime - mins) ~/ 60;
|
||||||
|
return "${totalTime.toString().padLeft(2, "0")}:${mins.toString().padLeft(2, "0")}:${secs.toString().padLeft(2, "0")}";
|
||||||
|
}
|
||||||
|
|
||||||
closeConnection({String? id}) {
|
closeConnection({String? id}) {
|
||||||
if (isAndroid || isIOS) {
|
if (isAndroid || isIOS) {
|
||||||
Navigator.popUntil(globalKey.currentContext!, ModalRoute.withName("/"));
|
Navigator.popUntil(globalKey.currentContext!, ModalRoute.withName("/"));
|
||||||
@ -440,12 +449,18 @@ class PermissionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Future<bool> check(String type) {
|
static Future<bool> check(String type) {
|
||||||
|
if (isDesktop) {
|
||||||
|
return Future.value(true);
|
||||||
|
}
|
||||||
if (!permissions.contains(type))
|
if (!permissions.contains(type))
|
||||||
return Future.error("Wrong permission!$type");
|
return Future.error("Wrong permission!$type");
|
||||||
return gFFI.invokeMethod("check_permission", type);
|
return gFFI.invokeMethod("check_permission", type);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<bool> request(String type) {
|
static Future<bool> request(String type) {
|
||||||
|
if (isDesktop) {
|
||||||
|
return Future.value(true);
|
||||||
|
}
|
||||||
if (!permissions.contains(type))
|
if (!permissions.contains(type))
|
||||||
return Future.error("Wrong permission!$type");
|
return Future.error("Wrong permission!$type");
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
// import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
// import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
@ -136,9 +139,9 @@ class ConnectionManager extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final serverModel = Provider.of<ServerModel>(context);
|
final serverModel = Provider.of<ServerModel>(context);
|
||||||
// test case:
|
// test case:
|
||||||
serverModel.clients.clear();
|
// serverModel.clients.clear();
|
||||||
serverModel.clients[0] = Client(
|
// serverModel.clients[0] = Client(
|
||||||
false, false, "Readmi-M21sdfsdf", "123123123", true, false, false);
|
// false, false, "Readmi-M21sdfsdf", "123123123", true, false, false);
|
||||||
return serverModel.clients.isEmpty
|
return serverModel.clients.isEmpty
|
||||||
? Center(
|
? Center(
|
||||||
child: Text(translate("Waiting")),
|
child: Text(translate("Waiting")),
|
||||||
@ -170,9 +173,10 @@ class ConnectionManager extends StatelessWidget {
|
|||||||
Widget buildConnectionCard(MapEntry<int, Client> entry) {
|
Widget buildConnectionCard(MapEntry<int, Client> entry) {
|
||||||
final client = entry.value;
|
final client = entry.value;
|
||||||
return Column(
|
return Column(
|
||||||
|
key: ValueKey(entry.key),
|
||||||
children: [
|
children: [
|
||||||
_CmHeader(client: client),
|
_CmHeader(client: client),
|
||||||
_PrivilegeBoard(client: client),
|
client.isFileTransfer ? Offstage() : _PrivilegeBoard(client: client),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Align(
|
child: Align(
|
||||||
alignment: Alignment.bottomCenter,
|
alignment: Alignment.bottomCenter,
|
||||||
@ -200,13 +204,39 @@ class ConnectionManager extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CmHeader extends StatelessWidget {
|
class _CmHeader extends StatefulWidget {
|
||||||
final Client client;
|
final Client client;
|
||||||
|
|
||||||
const _CmHeader({Key? key, required this.client}) : super(key: key);
|
const _CmHeader({Key? key, required this.client}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_CmHeader> createState() => _CmHeaderState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CmHeaderState extends State<_CmHeader>
|
||||||
|
with AutomaticKeepAliveClientMixin {
|
||||||
|
Client get client => widget.client;
|
||||||
|
|
||||||
|
var _time = 0.obs;
|
||||||
|
Timer? _timer;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_timer = Timer.periodic(Duration(seconds: 1), (_) {
|
||||||
|
_time.value = _time.value + 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_timer?.cancel();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
super.build(context);
|
||||||
return Row(
|
return Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
@ -242,13 +272,13 @@ class _CmHeader extends StatelessWidget {
|
|||||||
SizedBox(
|
SizedBox(
|
||||||
height: 16.0,
|
height: 16.0,
|
||||||
),
|
),
|
||||||
Offstage(
|
Row(
|
||||||
offstage: !client.authorized,
|
|
||||||
child: Row(
|
|
||||||
children: [
|
children: [
|
||||||
Text("${translate("Connected")}"),
|
Text("${translate("Connected")}").marginOnly(right: 8.0),
|
||||||
|
Obx(() => Text(
|
||||||
|
"${formatDurationToTime(Duration(seconds: _time.value))}"))
|
||||||
],
|
],
|
||||||
))
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -264,6 +294,9 @@ class _CmHeader extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void handleSendMsg() {}
|
void handleSendMsg() {}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get wantKeepAlive => true;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PrivilegeBoard extends StatelessWidget {
|
class _PrivilegeBoard extends StatelessWidget {
|
||||||
|
@ -117,9 +117,23 @@ void runFileTransferScreen(Map<String, dynamic> argument) async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void runConnectionManagerScreen() async {
|
void runConnectionManagerScreen() async {
|
||||||
await initEnv(kAppTypeConnectionManager);
|
// initialize window
|
||||||
await windowManager.setSize(Size(400, 600));
|
WindowOptions windowOptions = WindowOptions(
|
||||||
|
size: Size(300, 400),
|
||||||
|
center: true,
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
skipTaskbar: false,
|
||||||
|
titleBarStyle: TitleBarStyle.normal,
|
||||||
|
);
|
||||||
|
await Future.wait([
|
||||||
|
initEnv(kAppTypeConnectionManager),
|
||||||
|
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||||
await windowManager.setAlignment(Alignment.topRight);
|
await windowManager.setAlignment(Alignment.topRight);
|
||||||
|
await windowManager.show();
|
||||||
|
await windowManager.focus();
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
;
|
||||||
runApp(GetMaterialApp(theme: getCurrentTheme(), home: DesktopServerPage()));
|
runApp(GetMaterialApp(theme: getCurrentTheme(), home: DesktopServerPage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,6 +342,10 @@ class ServerModel with ChangeNotifier {
|
|||||||
var res = await bind.mainGetClientsState();
|
var res = await bind.mainGetClientsState();
|
||||||
try {
|
try {
|
||||||
final List clientsJson = jsonDecode(res);
|
final List clientsJson = jsonDecode(res);
|
||||||
|
if (isDesktop && clientsJson.isEmpty && _clients.isNotEmpty) {
|
||||||
|
// exit cm when >1 peers to no peers
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
_clients.clear();
|
_clients.clear();
|
||||||
for (var clientJson in clientsJson) {
|
for (var clientJson in clientsJson) {
|
||||||
final client = Client.fromJson(clientJson);
|
final client = Client.fromJson(clientJson);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include "my_application.h"
|
#include "my_application.h"
|
||||||
|
|
||||||
#include <flutter_linux/flutter_linux.h>
|
#include <flutter_linux/flutter_linux.h>
|
||||||
// #include <bitsdojo_window_linux/bitsdojo_window_plugin.h>
|
|
||||||
#ifdef GDK_WINDOWING_X11
|
#ifdef GDK_WINDOWING_X11
|
||||||
#include <gdk/gdkx.h>
|
#include <gdk/gdkx.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -66,7 +66,6 @@ dependencies:
|
|||||||
git:
|
git:
|
||||||
url: https://github.com/Kingtous/rustdesk_desktop_multi_window
|
url: https://github.com/Kingtous/rustdesk_desktop_multi_window
|
||||||
ref: 2b1176d53f195cc55e8d37151bb3d9f6bd52fad3
|
ref: 2b1176d53f195cc55e8d37151bb3d9f6bd52fad3
|
||||||
# bitsdojo_window: ^0.1.2
|
|
||||||
freezed_annotation: ^2.0.3
|
freezed_annotation: ^2.0.3
|
||||||
tray_manager: 0.1.7
|
tray_manager: 0.1.7
|
||||||
get: ^4.6.5
|
get: ^4.6.5
|
||||||
|
Loading…
x
Reference in New Issue
Block a user