Merge pull request #686 from Kingtous/flutter_desktop

feat: add tray icon to status bar & fix: multi window injection and titlebar issue
This commit is contained in:
RustDesk 2022-06-02 16:33:58 +08:00 committed by GitHub
commit c94d10782c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 140 additions and 69 deletions

BIN
flutter/assets/logo.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

View File

@ -52,12 +52,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
getUpdateUI(),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
getSearchBarUI(),
],
),
getSearchBarUI(),
SizedBox(height: 12),
getPeers(),
]),

View File

@ -64,37 +64,34 @@ class _ConnectionTabPageState extends State<ConnectionTabPage>
animationDuration: Duration.zero,
child: Column(
children: [
SizedBox(
height: 50,
child: DesktopTitleBar(
child: TabBar(
isScrollable: true,
labelColor: Colors.white,
physics: NeverScrollableScrollPhysics(),
indicatorColor: Colors.white,
tabs: connectionIds
.map((e) => Tab(
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(e),
SizedBox(
width: 4,
),
InkWell(
onTap: () {
onRemoveId(e);
},
child: Icon(
Icons.highlight_remove,
size: 20,
))
],
),
))
.toList()),
),
DesktopTitleBar(
child: TabBar(
isScrollable: true,
labelColor: Colors.white,
physics: NeverScrollableScrollPhysics(),
indicatorColor: Colors.white,
tabs: connectionIds
.map((e) => Tab(
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(e),
SizedBox(
width: 4,
),
InkWell(
onTap: () {
onRemoveId(e);
},
child: Icon(
Icons.highlight_remove,
size: 20,
))
],
),
))
.toList()),
),
Expanded(
child: TabBarView(

View File

@ -1,9 +1,13 @@
import 'package:flutter/material.dart';
import 'dart:io';
import 'package:flutter/material.dart' hide MenuItem;
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:provider/provider.dart';
import 'package:tray_manager/tray_manager.dart';
import 'package:window_manager/window_manager.dart';
class DesktopHomePage extends StatefulWidget {
DesktopHomePage({Key? key}) : super(key: key);
@ -14,26 +18,22 @@ class DesktopHomePage extends StatefulWidget {
const borderColor = Color(0xFF2F65BA);
class _DesktopHomePageState extends State<DesktopHomePage> {
class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Row(
children: [
DesktopTitleBar(
child: Center(
child: Text(
"RustDesk",
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold),
),
),
)
],
DesktopTitleBar(
child: Center(
child: Text(
"RustDesk",
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold),
),
),
),
Expanded(
child: Container(
@ -207,4 +207,30 @@ class _DesktopHomePageState extends State<DesktopHomePage> {
buildRecentSession(BuildContext context) {
return Center(child: Text("waiting implementation"));
}
@override
void onTrayMenuItemClick(MenuItem menuItem) {
print("click ${menuItem.key}");
switch (menuItem.key) {
case "quit":
exit(0);
case "show":
windowManager.show();
break;
default:
break;
}
}
@override
void initState() {
super.initState();
trayManager.addListener(this);
}
@override
void dispose() {
trayManager.removeListener(this);
super.dispose();
}
}

View File

@ -12,16 +12,16 @@ class DesktopTitleBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Expanded(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [backgroundStartColor, backgroundEndColor],
stops: [0.0, 1.0]),
),
child: WindowTitleBarBox(
return Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [backgroundStartColor, backgroundEndColor],
stops: [0.0, 1.0]),
),
child: WindowTitleBarBox(
child: SizedBox(
child: Row(
children: [
Expanded(

View File

@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_hbb/desktop/pages/desktop_home_page.dart';
import 'package:flutter_hbb/desktop/screen/desktop_remote_screen.dart';
import 'package:flutter_hbb/utils/multi_window_manager.dart';
import 'package:flutter_hbb/utils/tray_manager.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:provider/provider.dart';
import 'package:window_manager/window_manager.dart';
@ -52,6 +53,7 @@ void runRustDeskApp(List<String> args) async {
break;
}
} else {
initTray();
FFI.serverModel.startService();
runApp(App());
doWhenWindowReady(() {

View File

@ -0,0 +1,22 @@
import 'dart:io';
import 'package:flutter_hbb/models/model.dart';
import 'package:tray_manager/tray_manager.dart';
Future<void> initTray({List<MenuItem>? extra_item}) async {
List<MenuItem> items = [
MenuItem(key: "show", label: translate("show rustdesk")),
MenuItem.separator(),
MenuItem(key: "quit", label: translate("quit rustdesk")),
];
if (extra_item != null) {
items.insertAll(0, extra_item);
}
await Future.wait([
trayManager
.setIcon(Platform.isWindows ? "assets/logo.ico" : "assets/logo.png"),
trayManager.setContextMenu(Menu(items: items)),
trayManager.setToolTip("rustdesk"),
trayManager.setTitle("rustdesk")
]);
}

View File

@ -222,8 +222,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "4aab101f17f02312dc45311eb3009cc0ea5357c1"
resolved-ref: "4aab101f17f02312dc45311eb3009cc0ea5357c1"
ref: "704718b2853723b615675e048f1f385cbfb209a6"
resolved-ref: "704718b2853723b615675e048f1f385cbfb209a6"
url: "https://github.com/Kingtous/rustdesk_desktop_multi_window"
source: git
version: "0.0.1"
@ -408,7 +408,7 @@ packages:
name: flutter_smart_dialog
url: "https://pub.dartlang.org"
source: hosted
version: "4.3.2"
version: "4.3.2+1"
flutter_test:
dependency: "direct dev"
description: flutter
@ -566,6 +566,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
menu_base:
dependency: transitive
description:
name: menu_base
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.1"
meta:
dependency: transitive
description:
@ -771,6 +778,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
screen_retriever:
dependency: transitive
description:
name: screen_retriever
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
settings_ui:
dependency: "direct main"
description:
@ -848,6 +862,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
shortid:
dependency: transitive
description:
name: shortid
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
sky_engine:
dependency: transitive
description: flutter
@ -930,6 +951,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
tray_manager:
dependency: "direct main"
description:
name: tray_manager
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.7"
tuple:
dependency: "direct main"
description:
@ -1076,7 +1104,7 @@ packages:
name: window_manager
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.3"
version: "0.2.5"
xdg_directories:
dependency: transitive
description:

View File

@ -58,13 +58,14 @@ dependencies:
url: https://github.com/SoLongAndThanksForAllThePizza/flutter_rust_bridge
ref: master
path: frb_dart
window_manager: ^0.2.3
window_manager: ^0.2.5
desktop_multi_window:
git:
url: https://github.com/Kingtous/rustdesk_desktop_multi_window
ref: 4aab101f17f02312dc45311eb3009cc0ea5357c1
ref: 704718b2853723b615675e048f1f385cbfb209a6
bitsdojo_window: ^0.1.2
freezed_annotation: ^2.0.3
tray_manager: 0.1.7
dev_dependencies:
flutter_launcher_icons: ^0.9.1