mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-06-11 12:43:12 +08:00
feat: add single/multi window manager wrapper & fix issue causing input twice
This commit is contained in:
parent
24a6846f03
commit
708801bdf6
4
flutter/lib/common/formatter/id_formatter.dart
Normal file
4
flutter/lib/common/formatter/id_formatter.dart
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// TODO: Divide every 3 number to display ID
|
||||||
|
class IdFormController extends TextEditingController {}
|
@ -1,15 +1,14 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hbb/mobile/pages/file_manager_page.dart';
|
import 'package:flutter_hbb/mobile/pages/file_manager_page.dart';
|
||||||
|
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
import 'dart:async';
|
|
||||||
import '../../common.dart';
|
import '../../common.dart';
|
||||||
import '../../models/model.dart';
|
|
||||||
import '../../mobile/pages/home_page.dart';
|
import '../../mobile/pages/home_page.dart';
|
||||||
import '../../mobile/pages/remote_page.dart';
|
|
||||||
import '../../mobile/pages/settings_page.dart';
|
|
||||||
import '../../mobile/pages/scan_page.dart';
|
import '../../mobile/pages/scan_page.dart';
|
||||||
import '../../models/server_model.dart';
|
import '../../mobile/pages/settings_page.dart';
|
||||||
|
import '../../models/model.dart';
|
||||||
|
|
||||||
/// Connection page for connecting to a remote peer.
|
/// Connection page for connecting to a remote peer.
|
||||||
class ConnectionPage extends StatefulWidget implements PageShape {
|
class ConnectionPage extends StatefulWidget implements PageShape {
|
||||||
@ -46,7 +45,6 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Provider.of<FfiModel>(context);
|
Provider.of<FfiModel>(context);
|
||||||
if (_idController.text.isEmpty) _idController.text = FFI.getId();
|
if (_idController.text.isEmpty) _idController.text = FFI.getId();
|
||||||
FFI.serverModel.startService();
|
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
@ -55,7 +53,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
getUpdateUI(),
|
getUpdateUI(),
|
||||||
getSearchBarUI(),
|
getSearchBarUI(),
|
||||||
Container(height: 12),
|
SizedBox(height: 12),
|
||||||
getPeers(),
|
getPeers(),
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
@ -86,12 +84,15 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
Navigator.push(
|
// single window
|
||||||
context,
|
// Navigator.push(
|
||||||
MaterialPageRoute(
|
// context,
|
||||||
builder: (BuildContext context) => RemotePage(id: id),
|
// MaterialPageRoute(
|
||||||
),
|
// builder: (BuildContext context) => RemotePage(id: id),
|
||||||
);
|
// ),
|
||||||
|
// );
|
||||||
|
// multi window
|
||||||
|
await rustDeskWinManager.new_remote_desktop(id);
|
||||||
}
|
}
|
||||||
FocusScopeNode currentFocus = FocusScope.of(context);
|
FocusScopeNode currentFocus = FocusScope.of(context);
|
||||||
if (!currentFocus.hasPrimaryFocus) {
|
if (!currentFocus.hasPrimaryFocus) {
|
||||||
|
66
flutter/lib/desktop/pages/connection_tab_page.dart
Normal file
66
flutter/lib/desktop/pages/connection_tab_page.dart
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_hbb/desktop/pages/remote_page.dart';
|
||||||
|
import 'package:flutter_hbb/models/model.dart';
|
||||||
|
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
||||||
|
|
||||||
|
class ConnectionTabPage extends StatefulWidget {
|
||||||
|
final Map<String, dynamic> params;
|
||||||
|
|
||||||
|
const ConnectionTabPage({Key? key, required this.params}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ConnectionTabPage> createState() => _ConnectionTabPageState(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ConnectionTabPageState extends State<ConnectionTabPage>
|
||||||
|
with SingleTickerProviderStateMixin {
|
||||||
|
// refactor List<int> when using multi-tab
|
||||||
|
// this singleton is only for test
|
||||||
|
late String connectionId;
|
||||||
|
late TabController tabController;
|
||||||
|
|
||||||
|
_ConnectionTabPageState(Map<String, dynamic> params) {
|
||||||
|
connectionId = params['id'] ?? "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
rustDeskWinManager.setMethodHandler((call, fromWindowId) async {
|
||||||
|
print(
|
||||||
|
"call ${call.method} with args ${call.arguments} from window ${fromWindowId}");
|
||||||
|
// for simplify, just replace connectionId
|
||||||
|
if (call.method == "new_remote_desktop") {
|
||||||
|
setState(() {
|
||||||
|
FFI.close();
|
||||||
|
connectionId = jsonDecode(call.arguments)["id"];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tabController = TabController(length: 1, vsync: this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
TabBar(
|
||||||
|
controller: tabController,
|
||||||
|
isScrollable: true,
|
||||||
|
labelColor: Colors.black87,
|
||||||
|
physics: NeverScrollableScrollPhysics(),
|
||||||
|
tabs: [
|
||||||
|
Tab(
|
||||||
|
text: connectionId,
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
Expanded(
|
||||||
|
child: TabBarView(controller: tabController, children: [
|
||||||
|
RemotePage(key: ValueKey(connectionId), id: connectionId)
|
||||||
|
]))
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -55,8 +55,8 @@ class _DesktopHomePageState extends State<DesktopHomePage> {
|
|||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
buildControlPanel(context),
|
// buildControlPanel(context),
|
||||||
buildRecentSession(context),
|
// buildRecentSession(context),
|
||||||
ConnectionPage()
|
ConnectionPage()
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
1364
flutter/lib/desktop/pages/remote_page.dart
Normal file
1364
flutter/lib/desktop/pages/remote_page.dart
Normal file
File diff suppressed because it is too large
Load Diff
46
flutter/lib/desktop/screen/desktop_remote_screen.dart
Normal file
46
flutter/lib/desktop/screen/desktop_remote_screen.dart
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_hbb/common.dart';
|
||||||
|
import 'package:flutter_hbb/desktop/pages/connection_tab_page.dart';
|
||||||
|
import 'package:flutter_hbb/models/model.dart';
|
||||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
/// multi-tab desktop remote screen
|
||||||
|
class DesktopRemoteScreen extends StatelessWidget {
|
||||||
|
final Map<String, dynamic> params;
|
||||||
|
|
||||||
|
const DesktopRemoteScreen({Key? key, required this.params}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MultiProvider(
|
||||||
|
providers: [
|
||||||
|
ChangeNotifierProvider.value(value: FFI.ffiModel),
|
||||||
|
ChangeNotifierProvider.value(value: FFI.imageModel),
|
||||||
|
ChangeNotifierProvider.value(value: FFI.cursorModel),
|
||||||
|
ChangeNotifierProvider.value(value: FFI.canvasModel),
|
||||||
|
],
|
||||||
|
child: MaterialApp(
|
||||||
|
navigatorKey: globalKey,
|
||||||
|
debugShowCheckedModeBanner: false,
|
||||||
|
title: 'RustDesk - Remote Desktop',
|
||||||
|
theme: ThemeData(
|
||||||
|
primarySwatch: Colors.blue,
|
||||||
|
visualDensity: VisualDensity.adaptivePlatformDensity,
|
||||||
|
),
|
||||||
|
home: ConnectionTabPage(
|
||||||
|
params: params,
|
||||||
|
),
|
||||||
|
navigatorObservers: [
|
||||||
|
// FirebaseAnalyticsObserver(analytics: analytics),
|
||||||
|
FlutterSmartDialog.observer
|
||||||
|
],
|
||||||
|
builder: FlutterSmartDialog.init(
|
||||||
|
builder: isAndroid
|
||||||
|
? (_, child) => AccessibilityListener(
|
||||||
|
child: child,
|
||||||
|
)
|
||||||
|
: null)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,12 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hbb/desktop/pages/desktop_home_page.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_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';
|
||||||
|
import 'package:window_manager/window_manager.dart';
|
||||||
|
|
||||||
import 'common.dart';
|
import 'common.dart';
|
||||||
import 'mobile/pages/home_page.dart';
|
import 'mobile/pages/home_page.dart';
|
||||||
@ -9,7 +14,9 @@ import 'mobile/pages/server_page.dart';
|
|||||||
import 'mobile/pages/settings_page.dart';
|
import 'mobile/pages/settings_page.dart';
|
||||||
import 'models/model.dart';
|
import 'models/model.dart';
|
||||||
|
|
||||||
Future<Null> main() async {
|
int? windowId;
|
||||||
|
|
||||||
|
Future<Null> main(List<String> args) async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await FFI.ffiModel.init();
|
await FFI.ffiModel.init();
|
||||||
// await Firebase.initializeApp();
|
// await Firebase.initializeApp();
|
||||||
@ -17,11 +24,49 @@ Future<Null> main() async {
|
|||||||
toAndroidChannelInit();
|
toAndroidChannelInit();
|
||||||
}
|
}
|
||||||
refreshCurrentUser();
|
refreshCurrentUser();
|
||||||
if (isDesktop) {
|
runRustDeskApp(args);
|
||||||
print("desktop mode: starting service");
|
}
|
||||||
FFI.serverModel.startService();
|
|
||||||
|
void runRustDeskApp(List<String> args) async {
|
||||||
|
if (!isDesktop) {
|
||||||
|
runApp(App());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (args.isNotEmpty && args.first == 'multi_window') {
|
||||||
|
windowId = int.parse(args[1]);
|
||||||
|
final argument = args[2].isEmpty
|
||||||
|
? Map<String, dynamic>()
|
||||||
|
: jsonDecode(args[2]) as Map<String, dynamic>;
|
||||||
|
int type = argument['type'] ?? -1;
|
||||||
|
WindowType wType = type.windowType;
|
||||||
|
switch (wType) {
|
||||||
|
case WindowType.RemoteDesktop:
|
||||||
|
runApp(DesktopRemoteScreen(
|
||||||
|
params: argument,
|
||||||
|
));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// main window
|
||||||
|
await windowManager.ensureInitialized();
|
||||||
|
// start service
|
||||||
|
FFI.serverModel.startService();
|
||||||
|
WindowOptions windowOptions = WindowOptions(
|
||||||
|
size: Size(1280, 720),
|
||||||
|
center: true,
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
skipTaskbar: false,
|
||||||
|
titleBarStyle: TitleBarStyle.normal,
|
||||||
|
);
|
||||||
|
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||||
|
await windowManager.show();
|
||||||
|
await windowManager.focus();
|
||||||
|
});
|
||||||
|
|
||||||
|
runApp(App());
|
||||||
}
|
}
|
||||||
runApp(App());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class App extends StatelessWidget {
|
class App extends StatelessWidget {
|
||||||
@ -46,8 +91,8 @@ class App extends StatelessWidget {
|
|||||||
home: isDesktop
|
home: isDesktop
|
||||||
? DesktopHomePage()
|
? DesktopHomePage()
|
||||||
: !isAndroid
|
: !isAndroid
|
||||||
? WebHomePage()
|
? WebHomePage()
|
||||||
: HomePage(),
|
: HomePage(),
|
||||||
navigatorObservers: [
|
navigatorObservers: [
|
||||||
// FirebaseAnalyticsObserver(analytics: analytics),
|
// FirebaseAnalyticsObserver(analytics: analytics),
|
||||||
FlutterSmartDialog.observer
|
FlutterSmartDialog.observer
|
||||||
@ -55,8 +100,8 @@ class App extends StatelessWidget {
|
|||||||
builder: FlutterSmartDialog.init(
|
builder: FlutterSmartDialog.init(
|
||||||
builder: isAndroid
|
builder: isAndroid
|
||||||
? (_, child) => AccessibilityListener(
|
? (_, child) => AccessibilityListener(
|
||||||
child: child,
|
child: child,
|
||||||
)
|
)
|
||||||
: null)),
|
: null)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hbb/models/chat_model.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_hbb/mobile/widgets/gesture_help.dart';
|
import 'package:flutter_hbb/mobile/widgets/gesture_help.dart';
|
||||||
|
import 'package:flutter_hbb/models/chat_model.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';
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'dart:ui' as ui;
|
|
||||||
import 'dart:async';
|
|
||||||
import 'package:wakelock/wakelock.dart';
|
import 'package:wakelock/wakelock.dart';
|
||||||
|
|
||||||
import '../../common.dart';
|
import '../../common.dart';
|
||||||
import '../widgets/gestures.dart';
|
|
||||||
import '../../models/model.dart';
|
import '../../models/model.dart';
|
||||||
import '../widgets/dialog.dart';
|
import '../widgets/dialog.dart';
|
||||||
|
import '../widgets/gestures.dart';
|
||||||
import '../widgets/overlay.dart';
|
import '../widgets/overlay.dart';
|
||||||
|
|
||||||
final initText = '\1' * 1024;
|
final initText = '\1' * 1024;
|
||||||
@ -122,10 +124,10 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
oldValue = oldValue.substring(j + 1);
|
oldValue = oldValue.substring(j + 1);
|
||||||
var common = 0;
|
var common = 0;
|
||||||
for (;
|
for (;
|
||||||
common < oldValue.length &&
|
common < oldValue.length &&
|
||||||
common < newValue.length &&
|
common < newValue.length &&
|
||||||
newValue[common] == oldValue[common];
|
newValue[common] == oldValue[common];
|
||||||
++common);
|
++common);
|
||||||
for (i = 0; i < oldValue.length - common; ++i) {
|
for (i = 0; i < oldValue.length - common; ++i) {
|
||||||
FFI.inputKey('VK_BACK');
|
FFI.inputKey('VK_BACK');
|
||||||
}
|
}
|
||||||
@ -228,26 +230,26 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
child: getRawPointerAndKeyBody(
|
child: getRawPointerAndKeyBody(
|
||||||
keyboard,
|
keyboard,
|
||||||
Scaffold(
|
Scaffold(
|
||||||
// resizeToAvoidBottomInset: true,
|
// resizeToAvoidBottomInset: true,
|
||||||
floatingActionButton: !showActionButton
|
floatingActionButton: !showActionButton
|
||||||
? null
|
? null
|
||||||
: FloatingActionButton(
|
: FloatingActionButton(
|
||||||
mini: !hideKeyboard,
|
mini: !hideKeyboard,
|
||||||
child: Icon(
|
child: Icon(
|
||||||
hideKeyboard ? Icons.expand_more : Icons.expand_less),
|
hideKeyboard ? Icons.expand_more : Icons.expand_less),
|
||||||
backgroundColor: MyTheme.accent,
|
backgroundColor: MyTheme.accent,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (hideKeyboard) {
|
if (hideKeyboard) {
|
||||||
_showEdit = false;
|
_showEdit = false;
|
||||||
FFI.invokeMethod("enable_soft_keyboard", false);
|
FFI.invokeMethod("enable_soft_keyboard", false);
|
||||||
_mobileFocusNode.unfocus();
|
_mobileFocusNode.unfocus();
|
||||||
_physicalFocusNode.requestFocus();
|
_physicalFocusNode.requestFocus();
|
||||||
} else {
|
} else {
|
||||||
_showBar = !_showBar;
|
_showBar = !_showBar;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
bottomNavigationBar: _showBar && pi.displays.length > 0
|
bottomNavigationBar: _showBar && pi.displays.length > 0
|
||||||
? getBottomAppBar(keyboard)
|
? getBottomAppBar(keyboard)
|
||||||
: null,
|
: null,
|
||||||
@ -259,11 +261,11 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
child: isWebDesktop
|
child: isWebDesktop
|
||||||
? getBodyForDesktopWithListener(keyboard)
|
? getBodyForDesktopWithListener(keyboard)
|
||||||
: SafeArea(
|
: SafeArea(
|
||||||
child: Container(
|
child: Container(
|
||||||
color: MyTheme.canvasColor,
|
color: MyTheme.canvasColor,
|
||||||
child: _isPhysicalMouse
|
child: _isPhysicalMouse
|
||||||
? getBodyForMobile()
|
? getBodyForMobile()
|
||||||
: getBodyForMobileWithGesture())));
|
: getBodyForMobileWithGesture())));
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
))),
|
))),
|
||||||
@ -379,14 +381,14 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Row(
|
Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
IconButton(
|
IconButton(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
icon: Icon(Icons.clear),
|
icon: Icon(Icons.clear),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
clientClose();
|
clientClose();
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
] +
|
] +
|
||||||
<Widget>[
|
<Widget>[
|
||||||
IconButton(
|
IconButton(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
@ -400,45 +402,45 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
(isWebDesktop
|
(isWebDesktop
|
||||||
? []
|
? []
|
||||||
: FFI.ffiModel.isPeerAndroid
|
: FFI.ffiModel.isPeerAndroid
|
||||||
? [
|
? [
|
||||||
IconButton(
|
IconButton(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
icon: Icon(Icons.build),
|
icon: Icon(Icons.build),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (mobileActionsOverlayEntry == null) {
|
if (mobileActionsOverlayEntry == null) {
|
||||||
showMobileActionsOverlay();
|
showMobileActionsOverlay();
|
||||||
} else {
|
} else {
|
||||||
hideMobileActionsOverlay();
|
hideMobileActionsOverlay();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
: [
|
: [
|
||||||
IconButton(
|
IconButton(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
icon: Icon(Icons.keyboard),
|
icon: Icon(Icons.keyboard),
|
||||||
onPressed: openKeyboard),
|
onPressed: openKeyboard),
|
||||||
IconButton(
|
IconButton(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
icon: Icon(FFI.ffiModel.touchMode
|
icon: Icon(FFI.ffiModel.touchMode
|
||||||
? Icons.touch_app
|
? Icons.touch_app
|
||||||
: Icons.mouse),
|
: Icons.mouse),
|
||||||
onPressed: changeTouchMode,
|
onPressed: changeTouchMode,
|
||||||
),
|
),
|
||||||
]) +
|
]) +
|
||||||
(isWeb
|
(isWeb
|
||||||
? []
|
? []
|
||||||
: <Widget>[
|
: <Widget>[
|
||||||
IconButton(
|
IconButton(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
icon: Icon(Icons.message),
|
icon: Icon(Icons.message),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
FFI.chatModel
|
FFI.chatModel
|
||||||
.changeCurrentID(ChatModel.clientModeID);
|
.changeCurrentID(ChatModel.clientModeID);
|
||||||
toggleChatOverlay();
|
toggleChatOverlay();
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
]) +
|
]) +
|
||||||
[
|
[
|
||||||
IconButton(
|
IconButton(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
@ -547,15 +549,15 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
onThreeFingerVerticalDragUpdate: FFI.ffiModel.isPeerAndroid
|
onThreeFingerVerticalDragUpdate: FFI.ffiModel.isPeerAndroid
|
||||||
? null
|
? null
|
||||||
: (d) {
|
: (d) {
|
||||||
_mouseScrollIntegral += d.delta.dy / 4;
|
_mouseScrollIntegral += d.delta.dy / 4;
|
||||||
if (_mouseScrollIntegral > 1) {
|
if (_mouseScrollIntegral > 1) {
|
||||||
FFI.scroll(1);
|
FFI.scroll(1);
|
||||||
_mouseScrollIntegral = 0;
|
_mouseScrollIntegral = 0;
|
||||||
} else if (_mouseScrollIntegral < -1) {
|
} else if (_mouseScrollIntegral < -1) {
|
||||||
FFI.scroll(-1);
|
FFI.scroll(-1);
|
||||||
_mouseScrollIntegral = 0;
|
_mouseScrollIntegral = 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget getBodyForMobile() {
|
Widget getBodyForMobile() {
|
||||||
@ -571,17 +573,17 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
child: !_showEdit
|
child: !_showEdit
|
||||||
? Container()
|
? Container()
|
||||||
: TextFormField(
|
: TextFormField(
|
||||||
textInputAction: TextInputAction.newline,
|
textInputAction: TextInputAction.newline,
|
||||||
autocorrect: false,
|
autocorrect: false,
|
||||||
enableSuggestions: false,
|
enableSuggestions: false,
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
focusNode: _mobileFocusNode,
|
focusNode: _mobileFocusNode,
|
||||||
maxLines: null,
|
maxLines: null,
|
||||||
initialValue: _value,
|
initialValue: _value,
|
||||||
// trick way to make backspace work always
|
// trick way to make backspace work always
|
||||||
keyboardType: TextInputType.multiline,
|
keyboardType: TextInputType.multiline,
|
||||||
onChanged: handleInput,
|
onChanged: handleInput,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
@ -597,6 +599,7 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int lastMouseDownButtons = 0;
|
int lastMouseDownButtons = 0;
|
||||||
|
|
||||||
Map<String, dynamic> getEvent(PointerEvent evt, String type) {
|
Map<String, dynamic> getEvent(PointerEvent evt, String type) {
|
||||||
final Map<String, dynamic> out = {};
|
final Map<String, dynamic> out = {};
|
||||||
out['type'] = type;
|
out['type'] = type;
|
||||||
@ -630,16 +633,16 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
more.add(PopupMenuItem<String>(
|
more.add(PopupMenuItem<String>(
|
||||||
child: Row(
|
child: Row(
|
||||||
children: ([
|
children: ([
|
||||||
Container(width: 100.0, child: Text(translate('OS Password'))),
|
Container(width: 100.0, child: Text(translate('OS Password'))),
|
||||||
TextButton(
|
TextButton(
|
||||||
style: flatButtonStyle,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
showSetOSPassword(false);
|
showSetOSPassword(false);
|
||||||
},
|
},
|
||||||
child: Icon(Icons.edit, color: MyTheme.accent),
|
child: Icon(Icons.edit, color: MyTheme.accent),
|
||||||
)
|
)
|
||||||
])),
|
])),
|
||||||
value: 'enter_os_password'));
|
value: 'enter_os_password'));
|
||||||
if (!isWebDesktop) {
|
if (!isWebDesktop) {
|
||||||
if (perms['keyboard'] != false && perms['clipboard'] != false) {
|
if (perms['keyboard'] != false && perms['clipboard'] != false) {
|
||||||
@ -665,7 +668,7 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
value: 'block-input'));
|
value: 'block-input'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
() async {
|
() async {
|
||||||
var value = await showMenu(
|
var value = await showMenu(
|
||||||
context: context,
|
context: context,
|
||||||
position: RelativeRect.fromLTRB(x, y, x, y),
|
position: RelativeRect.fromLTRB(x, y, x, y),
|
||||||
@ -683,7 +686,7 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
} else if (value == 'refresh') {
|
} else if (value == 'refresh') {
|
||||||
FFI.setByName('refresh');
|
FFI.setByName('refresh');
|
||||||
} else if (value == 'paste') {
|
} else if (value == 'paste') {
|
||||||
() async {
|
() async {
|
||||||
ClipboardData? data = await Clipboard.getData(Clipboard.kTextPlain);
|
ClipboardData? data = await Clipboard.getData(Clipboard.kTextPlain);
|
||||||
if (data != null && data.text != null) {
|
if (data != null && data.text != null) {
|
||||||
FFI.setByName('input_string', '${data.text}');
|
FFI.setByName('input_string', '${data.text}');
|
||||||
@ -749,7 +752,7 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
child: icon != null
|
child: icon != null
|
||||||
? Icon(icon, size: 17, color: Colors.white)
|
? Icon(icon, size: 17, color: Colors.white)
|
||||||
: Text(translate(text),
|
: Text(translate(text),
|
||||||
style: TextStyle(color: Colors.white, fontSize: 11)),
|
style: TextStyle(color: Colors.white, fontSize: 11)),
|
||||||
onPressed: onPressed);
|
onPressed: onPressed);
|
||||||
};
|
};
|
||||||
final pi = FFI.ffiModel.pi;
|
final pi = FFI.ffiModel.pi;
|
||||||
@ -771,25 +774,25 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
final keys = <Widget>[
|
final keys = <Widget>[
|
||||||
wrap(
|
wrap(
|
||||||
' Fn ',
|
' Fn ',
|
||||||
() => setState(
|
() => setState(
|
||||||
() {
|
() {
|
||||||
_fn = !_fn;
|
_fn = !_fn;
|
||||||
if (_fn) {
|
if (_fn) {
|
||||||
_more = false;
|
_more = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
_fn),
|
_fn),
|
||||||
wrap(
|
wrap(
|
||||||
' ... ',
|
' ... ',
|
||||||
() => setState(
|
() => setState(
|
||||||
() {
|
() {
|
||||||
_more = !_more;
|
_more = !_more;
|
||||||
if (_more) {
|
if (_more) {
|
||||||
_fn = false;
|
_fn = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
_more),
|
_more),
|
||||||
];
|
];
|
||||||
final fn = <Widget>[
|
final fn = <Widget>[
|
||||||
@ -920,8 +923,7 @@ class ImagePainter extends CustomPainter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckboxListTile getToggle(
|
CheckboxListTile getToggle(void Function(void Function()) setState, option, name) {
|
||||||
void Function(void Function()) setState, option, name) {
|
|
||||||
return CheckboxListTile(
|
return CheckboxListTile(
|
||||||
value: FFI.getByName('toggle_option', option) == 'true',
|
value: FFI.getByName('toggle_option', option) == 'true',
|
||||||
onChanged: (v) {
|
onChanged: (v) {
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:math';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_hbb/models/chat_model.dart';
|
import 'package:flutter_hbb/models/chat_model.dart';
|
||||||
import 'package:flutter_hbb/models/file_model.dart';
|
import 'package:flutter_hbb/models/file_model.dart';
|
||||||
import 'package:flutter_hbb/models/server_model.dart';
|
import 'package:flutter_hbb/models/server_model.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'dart:math';
|
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
import 'dart:ui' as ui;
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:tuple/tuple.dart';
|
import 'package:tuple/tuple.dart';
|
||||||
import 'dart:async';
|
|
||||||
import '../common.dart';
|
import '../common.dart';
|
||||||
import '../mobile/widgets/dialog.dart';
|
import '../mobile/widgets/dialog.dart';
|
||||||
import '../mobile/widgets/overlay.dart';
|
import '../mobile/widgets/overlay.dart';
|
||||||
@ -596,17 +598,17 @@ class CursorModel with ChangeNotifier {
|
|||||||
final rgba = Uint8List.fromList(colors.map((s) => s as int).toList());
|
final rgba = Uint8List.fromList(colors.map((s) => s as int).toList());
|
||||||
var pid = FFI.id;
|
var pid = FFI.id;
|
||||||
ui.decodeImageFromPixels(rgba, width, height, ui.PixelFormat.rgba8888,
|
ui.decodeImageFromPixels(rgba, width, height, ui.PixelFormat.rgba8888,
|
||||||
(image) {
|
(image) {
|
||||||
if (FFI.id != pid) return;
|
if (FFI.id != pid) return;
|
||||||
_image = image;
|
_image = image;
|
||||||
_images[id] = Tuple3(image, _hotx, _hoty);
|
_images[id] = Tuple3(image, _hotx, _hoty);
|
||||||
try {
|
try {
|
||||||
// my throw exception, because the listener maybe already dispose
|
// my throw exception, because the listener maybe already dispose
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('notify cursor: $e');
|
print('notify cursor: $e');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateCursorId(Map<String, dynamic> evt) {
|
void updateCursorId(Map<String, dynamic> evt) {
|
||||||
@ -635,8 +637,7 @@ class CursorModel with ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateDisplayOriginWithCursor(
|
void updateDisplayOriginWithCursor(double x, double y, double xCursor, double yCursor) {
|
||||||
double x, double y, double xCursor, double yCursor) {
|
|
||||||
_displayOriginX = x;
|
_displayOriginX = x;
|
||||||
_displayOriginY = y;
|
_displayOriginY = y;
|
||||||
_x = xCursor;
|
_x = xCursor;
|
||||||
@ -734,13 +735,17 @@ class FFI {
|
|||||||
/// [press] indicates a click event(down and up).
|
/// [press] indicates a click event(down and up).
|
||||||
static void inputKey(String name, {bool? down, bool? press}) {
|
static void inputKey(String name, {bool? down, bool? press}) {
|
||||||
if (!ffiModel.keyboard()) return;
|
if (!ffiModel.keyboard()) return;
|
||||||
setByName(
|
final Map<String, String> out = Map();
|
||||||
'input_key',
|
out['name'] = name;
|
||||||
json.encode(modify({
|
// default: down = false
|
||||||
'name': name,
|
if (down == true) {
|
||||||
'down': (down ?? false).toString(),
|
out['down'] = "true";
|
||||||
'press': (press ?? true).toString()
|
}
|
||||||
})));
|
// default: press = true
|
||||||
|
if (press != false) {
|
||||||
|
out['press'] = "true";
|
||||||
|
}
|
||||||
|
setByName('input_key', json.encode(modify(out)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send mouse movement event with distance in [x] and [y].
|
/// Send mouse movement event with distance in [x] and [y].
|
||||||
@ -760,7 +765,7 @@ class FFI {
|
|||||||
return peers
|
return peers
|
||||||
.map((s) => s as List<dynamic>)
|
.map((s) => s as List<dynamic>)
|
||||||
.map((s) =>
|
.map((s) =>
|
||||||
Peer.fromJson(s[0] as String, s[1] as Map<String, dynamic>))
|
Peer.fromJson(s[0] as String, s[1] as Map<String, dynamic>))
|
||||||
.toList();
|
.toList();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('peers(): $e');
|
print('peers(): $e');
|
||||||
|
93
flutter/lib/utils/multi_window_manager.dart
Normal file
93
flutter/lib/utils/multi_window_manager.dart
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:ui';
|
||||||
|
|
||||||
|
import 'package:desktop_multi_window/desktop_multi_window.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
/// must keep the order
|
||||||
|
enum WindowType { Main, RemoteDesktop, FileTransfer, PortForward, Unknown }
|
||||||
|
|
||||||
|
extension Index on int {
|
||||||
|
WindowType get windowType {
|
||||||
|
switch (this) {
|
||||||
|
case 0:
|
||||||
|
return WindowType.Main;
|
||||||
|
case 1:
|
||||||
|
return WindowType.RemoteDesktop;
|
||||||
|
case 2:
|
||||||
|
return WindowType.FileTransfer;
|
||||||
|
case 3:
|
||||||
|
return WindowType.PortForward;
|
||||||
|
default:
|
||||||
|
return WindowType.Unknown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Window Manager
|
||||||
|
/// mainly use it in `Main Window`
|
||||||
|
/// use it in sub window is not recommended
|
||||||
|
class RustDeskMultiWindowManager {
|
||||||
|
RustDeskMultiWindowManager._();
|
||||||
|
|
||||||
|
static final instance = RustDeskMultiWindowManager._();
|
||||||
|
|
||||||
|
int? _remoteDesktopWindowId;
|
||||||
|
|
||||||
|
Future<dynamic> new_remote_desktop(String remote_id) async {
|
||||||
|
final msg =
|
||||||
|
jsonEncode({"type": WindowType.RemoteDesktop.index, "id": remote_id});
|
||||||
|
|
||||||
|
try {
|
||||||
|
final ids = await DesktopMultiWindow.getAllSubWindowIds();
|
||||||
|
if (!ids.contains(_remoteDesktopWindowId)) {
|
||||||
|
_remoteDesktopWindowId = null;
|
||||||
|
}
|
||||||
|
} on Error {
|
||||||
|
_remoteDesktopWindowId = null;
|
||||||
|
}
|
||||||
|
if (_remoteDesktopWindowId == null) {
|
||||||
|
final remoteDesktopController =
|
||||||
|
await DesktopMultiWindow.createWindow(msg);
|
||||||
|
remoteDesktopController
|
||||||
|
..setFrame(const Offset(0, 0) & const Size(1280, 720))
|
||||||
|
..center()
|
||||||
|
..setTitle("rustdesk - remote desktop")
|
||||||
|
..show();
|
||||||
|
_remoteDesktopWindowId = remoteDesktopController.windowId;
|
||||||
|
} else {
|
||||||
|
return call(WindowType.RemoteDesktop, "new_remote_desktop", msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<dynamic> call(WindowType type, String methodName, dynamic args) async {
|
||||||
|
int? windowId = findWindowByType(type);
|
||||||
|
if (windowId == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return await DesktopMultiWindow.invokeMethod(windowId, methodName, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
int? findWindowByType(WindowType type) {
|
||||||
|
switch (type) {
|
||||||
|
case WindowType.Main:
|
||||||
|
break;
|
||||||
|
case WindowType.RemoteDesktop:
|
||||||
|
return _remoteDesktopWindowId;
|
||||||
|
case WindowType.FileTransfer:
|
||||||
|
break;
|
||||||
|
case WindowType.PortForward:
|
||||||
|
break;
|
||||||
|
case WindowType.Unknown:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMethodHandler(
|
||||||
|
Future<dynamic> Function(MethodCall call, int fromWindowId)? handler) {
|
||||||
|
DesktopMultiWindow.setMethodHandler(handler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final rustDeskWinManager = RustDeskMultiWindowManager.instance;
|
@ -85,6 +85,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.16"
|
version: "1.1.16"
|
||||||
|
desktop_multi_window:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: desktop_multi_window
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.0.2"
|
||||||
device_info:
|
device_info:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -751,6 +758,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.5.2"
|
version: "2.5.2"
|
||||||
|
window_manager:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: window_manager
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.2.3"
|
||||||
xdg_directories:
|
xdg_directories:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -55,6 +55,8 @@ dependencies:
|
|||||||
image: ^3.1.3
|
image: ^3.1.3
|
||||||
flutter_smart_dialog: ^4.3.1
|
flutter_smart_dialog: ^4.3.1
|
||||||
flutter_rust_bridge: ^1.30.0
|
flutter_rust_bridge: ^1.30.0
|
||||||
|
window_manager: ^0.2.3
|
||||||
|
desktop_multi_window: ^0.0.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_launcher_icons: ^0.9.1
|
flutter_launcher_icons: ^0.9.1
|
||||||
|
Loading…
Reference in New Issue
Block a user