mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-27 23:19:02 +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_hbb/mobile/pages/file_manager_page.dart';
|
||||
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'dart:async';
|
||||
|
||||
import '../../common.dart';
|
||||
import '../../models/model.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 '../../models/server_model.dart';
|
||||
import '../../mobile/pages/settings_page.dart';
|
||||
import '../../models/model.dart';
|
||||
|
||||
/// Connection page for connecting to a remote peer.
|
||||
class ConnectionPage extends StatefulWidget implements PageShape {
|
||||
@ -46,7 +45,6 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
Widget build(BuildContext context) {
|
||||
Provider.of<FfiModel>(context);
|
||||
if (_idController.text.isEmpty) _idController.text = FFI.getId();
|
||||
FFI.serverModel.startService();
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
@ -55,7 +53,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
children: <Widget>[
|
||||
getUpdateUI(),
|
||||
getSearchBarUI(),
|
||||
Container(height: 12),
|
||||
SizedBox(height: 12),
|
||||
getPeers(),
|
||||
]),
|
||||
);
|
||||
@ -86,12 +84,15 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
),
|
||||
);
|
||||
} else {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) => RemotePage(id: id),
|
||||
),
|
||||
);
|
||||
// single window
|
||||
// Navigator.push(
|
||||
// context,
|
||||
// MaterialPageRoute(
|
||||
// builder: (BuildContext context) => RemotePage(id: id),
|
||||
// ),
|
||||
// );
|
||||
// multi window
|
||||
await rustDeskWinManager.new_remote_desktop(id);
|
||||
}
|
||||
FocusScopeNode currentFocus = FocusScope.of(context);
|
||||
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(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
buildControlPanel(context),
|
||||
buildRecentSession(context),
|
||||
// buildControlPanel(context),
|
||||
// buildRecentSession(context),
|
||||
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_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:provider/provider.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
import 'common.dart';
|
||||
import 'mobile/pages/home_page.dart';
|
||||
@ -9,7 +14,9 @@ import 'mobile/pages/server_page.dart';
|
||||
import 'mobile/pages/settings_page.dart';
|
||||
import 'models/model.dart';
|
||||
|
||||
Future<Null> main() async {
|
||||
int? windowId;
|
||||
|
||||
Future<Null> main(List<String> args) async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await FFI.ffiModel.init();
|
||||
// await Firebase.initializeApp();
|
||||
@ -17,11 +24,49 @@ Future<Null> main() async {
|
||||
toAndroidChannelInit();
|
||||
}
|
||||
refreshCurrentUser();
|
||||
if (isDesktop) {
|
||||
print("desktop mode: starting service");
|
||||
FFI.serverModel.startService();
|
||||
runRustDeskApp(args);
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -46,8 +91,8 @@ class App extends StatelessWidget {
|
||||
home: isDesktop
|
||||
? DesktopHomePage()
|
||||
: !isAndroid
|
||||
? WebHomePage()
|
||||
: HomePage(),
|
||||
? WebHomePage()
|
||||
: HomePage(),
|
||||
navigatorObservers: [
|
||||
// FirebaseAnalyticsObserver(analytics: analytics),
|
||||
FlutterSmartDialog.observer
|
||||
@ -55,8 +100,8 @@ class App extends StatelessWidget {
|
||||
builder: FlutterSmartDialog.init(
|
||||
builder: isAndroid
|
||||
? (_, child) => AccessibilityListener(
|
||||
child: child,
|
||||
)
|
||||
child: child,
|
||||
)
|
||||
: null)),
|
||||
);
|
||||
}
|
||||
|
@ -1,17 +1,19 @@
|
||||
import 'dart:async';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/gestures.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/models/chat_model.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.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 '../../common.dart';
|
||||
import '../widgets/gestures.dart';
|
||||
import '../../models/model.dart';
|
||||
import '../widgets/dialog.dart';
|
||||
import '../widgets/gestures.dart';
|
||||
import '../widgets/overlay.dart';
|
||||
|
||||
final initText = '\1' * 1024;
|
||||
@ -122,10 +124,10 @@ class _RemotePageState extends State<RemotePage> {
|
||||
oldValue = oldValue.substring(j + 1);
|
||||
var common = 0;
|
||||
for (;
|
||||
common < oldValue.length &&
|
||||
common < newValue.length &&
|
||||
newValue[common] == oldValue[common];
|
||||
++common);
|
||||
common < oldValue.length &&
|
||||
common < newValue.length &&
|
||||
newValue[common] == oldValue[common];
|
||||
++common);
|
||||
for (i = 0; i < oldValue.length - common; ++i) {
|
||||
FFI.inputKey('VK_BACK');
|
||||
}
|
||||
@ -228,26 +230,26 @@ class _RemotePageState extends State<RemotePage> {
|
||||
child: getRawPointerAndKeyBody(
|
||||
keyboard,
|
||||
Scaffold(
|
||||
// resizeToAvoidBottomInset: true,
|
||||
// resizeToAvoidBottomInset: true,
|
||||
floatingActionButton: !showActionButton
|
||||
? null
|
||||
: FloatingActionButton(
|
||||
mini: !hideKeyboard,
|
||||
child: Icon(
|
||||
hideKeyboard ? Icons.expand_more : Icons.expand_less),
|
||||
backgroundColor: MyTheme.accent,
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
if (hideKeyboard) {
|
||||
_showEdit = false;
|
||||
FFI.invokeMethod("enable_soft_keyboard", false);
|
||||
_mobileFocusNode.unfocus();
|
||||
_physicalFocusNode.requestFocus();
|
||||
} else {
|
||||
_showBar = !_showBar;
|
||||
}
|
||||
});
|
||||
}),
|
||||
mini: !hideKeyboard,
|
||||
child: Icon(
|
||||
hideKeyboard ? Icons.expand_more : Icons.expand_less),
|
||||
backgroundColor: MyTheme.accent,
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
if (hideKeyboard) {
|
||||
_showEdit = false;
|
||||
FFI.invokeMethod("enable_soft_keyboard", false);
|
||||
_mobileFocusNode.unfocus();
|
||||
_physicalFocusNode.requestFocus();
|
||||
} else {
|
||||
_showBar = !_showBar;
|
||||
}
|
||||
});
|
||||
}),
|
||||
bottomNavigationBar: _showBar && pi.displays.length > 0
|
||||
? getBottomAppBar(keyboard)
|
||||
: null,
|
||||
@ -259,11 +261,11 @@ class _RemotePageState extends State<RemotePage> {
|
||||
child: isWebDesktop
|
||||
? getBodyForDesktopWithListener(keyboard)
|
||||
: SafeArea(
|
||||
child: Container(
|
||||
color: MyTheme.canvasColor,
|
||||
child: _isPhysicalMouse
|
||||
? getBodyForMobile()
|
||||
: getBodyForMobileWithGesture())));
|
||||
child: Container(
|
||||
color: MyTheme.canvasColor,
|
||||
child: _isPhysicalMouse
|
||||
? getBodyForMobile()
|
||||
: getBodyForMobileWithGesture())));
|
||||
})
|
||||
],
|
||||
))),
|
||||
@ -379,14 +381,14 @@ class _RemotePageState extends State<RemotePage> {
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
icon: Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
clientClose();
|
||||
},
|
||||
)
|
||||
] +
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
icon: Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
clientClose();
|
||||
},
|
||||
)
|
||||
] +
|
||||
<Widget>[
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
@ -400,45 +402,45 @@ class _RemotePageState extends State<RemotePage> {
|
||||
(isWebDesktop
|
||||
? []
|
||||
: FFI.ffiModel.isPeerAndroid
|
||||
? [
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
icon: Icon(Icons.build),
|
||||
onPressed: () {
|
||||
if (mobileActionsOverlayEntry == null) {
|
||||
showMobileActionsOverlay();
|
||||
} else {
|
||||
hideMobileActionsOverlay();
|
||||
}
|
||||
},
|
||||
)
|
||||
]
|
||||
: [
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
icon: Icon(Icons.keyboard),
|
||||
onPressed: openKeyboard),
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
icon: Icon(FFI.ffiModel.touchMode
|
||||
? Icons.touch_app
|
||||
: Icons.mouse),
|
||||
onPressed: changeTouchMode,
|
||||
),
|
||||
]) +
|
||||
? [
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
icon: Icon(Icons.build),
|
||||
onPressed: () {
|
||||
if (mobileActionsOverlayEntry == null) {
|
||||
showMobileActionsOverlay();
|
||||
} else {
|
||||
hideMobileActionsOverlay();
|
||||
}
|
||||
},
|
||||
)
|
||||
]
|
||||
: [
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
icon: Icon(Icons.keyboard),
|
||||
onPressed: openKeyboard),
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
icon: Icon(FFI.ffiModel.touchMode
|
||||
? Icons.touch_app
|
||||
: Icons.mouse),
|
||||
onPressed: changeTouchMode,
|
||||
),
|
||||
]) +
|
||||
(isWeb
|
||||
? []
|
||||
: <Widget>[
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
icon: Icon(Icons.message),
|
||||
onPressed: () {
|
||||
FFI.chatModel
|
||||
.changeCurrentID(ChatModel.clientModeID);
|
||||
toggleChatOverlay();
|
||||
},
|
||||
)
|
||||
]) +
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
icon: Icon(Icons.message),
|
||||
onPressed: () {
|
||||
FFI.chatModel
|
||||
.changeCurrentID(ChatModel.clientModeID);
|
||||
toggleChatOverlay();
|
||||
},
|
||||
)
|
||||
]) +
|
||||
[
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
@ -547,15 +549,15 @@ class _RemotePageState extends State<RemotePage> {
|
||||
onThreeFingerVerticalDragUpdate: FFI.ffiModel.isPeerAndroid
|
||||
? null
|
||||
: (d) {
|
||||
_mouseScrollIntegral += d.delta.dy / 4;
|
||||
if (_mouseScrollIntegral > 1) {
|
||||
FFI.scroll(1);
|
||||
_mouseScrollIntegral = 0;
|
||||
} else if (_mouseScrollIntegral < -1) {
|
||||
FFI.scroll(-1);
|
||||
_mouseScrollIntegral = 0;
|
||||
}
|
||||
});
|
||||
_mouseScrollIntegral += d.delta.dy / 4;
|
||||
if (_mouseScrollIntegral > 1) {
|
||||
FFI.scroll(1);
|
||||
_mouseScrollIntegral = 0;
|
||||
} else if (_mouseScrollIntegral < -1) {
|
||||
FFI.scroll(-1);
|
||||
_mouseScrollIntegral = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Widget getBodyForMobile() {
|
||||
@ -571,17 +573,17 @@ class _RemotePageState extends State<RemotePage> {
|
||||
child: !_showEdit
|
||||
? Container()
|
||||
: TextFormField(
|
||||
textInputAction: TextInputAction.newline,
|
||||
autocorrect: false,
|
||||
enableSuggestions: false,
|
||||
autofocus: true,
|
||||
focusNode: _mobileFocusNode,
|
||||
maxLines: null,
|
||||
initialValue: _value,
|
||||
// trick way to make backspace work always
|
||||
keyboardType: TextInputType.multiline,
|
||||
onChanged: handleInput,
|
||||
),
|
||||
textInputAction: TextInputAction.newline,
|
||||
autocorrect: false,
|
||||
enableSuggestions: false,
|
||||
autofocus: true,
|
||||
focusNode: _mobileFocusNode,
|
||||
maxLines: null,
|
||||
initialValue: _value,
|
||||
// trick way to make backspace work always
|
||||
keyboardType: TextInputType.multiline,
|
||||
onChanged: handleInput,
|
||||
),
|
||||
),
|
||||
]));
|
||||
}
|
||||
@ -597,6 +599,7 @@ class _RemotePageState extends State<RemotePage> {
|
||||
}
|
||||
|
||||
int lastMouseDownButtons = 0;
|
||||
|
||||
Map<String, dynamic> getEvent(PointerEvent evt, String type) {
|
||||
final Map<String, dynamic> out = {};
|
||||
out['type'] = type;
|
||||
@ -630,16 +633,16 @@ class _RemotePageState extends State<RemotePage> {
|
||||
more.add(PopupMenuItem<String>(
|
||||
child: Row(
|
||||
children: ([
|
||||
Container(width: 100.0, child: Text(translate('OS Password'))),
|
||||
TextButton(
|
||||
style: flatButtonStyle,
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
showSetOSPassword(false);
|
||||
},
|
||||
child: Icon(Icons.edit, color: MyTheme.accent),
|
||||
)
|
||||
])),
|
||||
Container(width: 100.0, child: Text(translate('OS Password'))),
|
||||
TextButton(
|
||||
style: flatButtonStyle,
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
showSetOSPassword(false);
|
||||
},
|
||||
child: Icon(Icons.edit, color: MyTheme.accent),
|
||||
)
|
||||
])),
|
||||
value: 'enter_os_password'));
|
||||
if (!isWebDesktop) {
|
||||
if (perms['keyboard'] != false && perms['clipboard'] != false) {
|
||||
@ -665,7 +668,7 @@ class _RemotePageState extends State<RemotePage> {
|
||||
value: 'block-input'));
|
||||
}
|
||||
}
|
||||
() async {
|
||||
() async {
|
||||
var value = await showMenu(
|
||||
context: context,
|
||||
position: RelativeRect.fromLTRB(x, y, x, y),
|
||||
@ -683,7 +686,7 @@ class _RemotePageState extends State<RemotePage> {
|
||||
} else if (value == 'refresh') {
|
||||
FFI.setByName('refresh');
|
||||
} else if (value == 'paste') {
|
||||
() async {
|
||||
() async {
|
||||
ClipboardData? data = await Clipboard.getData(Clipboard.kTextPlain);
|
||||
if (data != null && data.text != null) {
|
||||
FFI.setByName('input_string', '${data.text}');
|
||||
@ -749,7 +752,7 @@ class _RemotePageState extends State<RemotePage> {
|
||||
child: icon != null
|
||||
? Icon(icon, size: 17, color: Colors.white)
|
||||
: Text(translate(text),
|
||||
style: TextStyle(color: Colors.white, fontSize: 11)),
|
||||
style: TextStyle(color: Colors.white, fontSize: 11)),
|
||||
onPressed: onPressed);
|
||||
};
|
||||
final pi = FFI.ffiModel.pi;
|
||||
@ -771,25 +774,25 @@ class _RemotePageState extends State<RemotePage> {
|
||||
final keys = <Widget>[
|
||||
wrap(
|
||||
' Fn ',
|
||||
() => setState(
|
||||
() => setState(
|
||||
() {
|
||||
_fn = !_fn;
|
||||
if (_fn) {
|
||||
_more = false;
|
||||
}
|
||||
},
|
||||
),
|
||||
_fn = !_fn;
|
||||
if (_fn) {
|
||||
_more = false;
|
||||
}
|
||||
},
|
||||
),
|
||||
_fn),
|
||||
wrap(
|
||||
' ... ',
|
||||
() => setState(
|
||||
() => setState(
|
||||
() {
|
||||
_more = !_more;
|
||||
if (_more) {
|
||||
_fn = false;
|
||||
}
|
||||
},
|
||||
),
|
||||
_more = !_more;
|
||||
if (_more) {
|
||||
_fn = false;
|
||||
}
|
||||
},
|
||||
),
|
||||
_more),
|
||||
];
|
||||
final fn = <Widget>[
|
||||
@ -920,8 +923,7 @@ class ImagePainter extends CustomPainter {
|
||||
}
|
||||
}
|
||||
|
||||
CheckboxListTile getToggle(
|
||||
void Function(void Function()) setState, option, name) {
|
||||
CheckboxListTile getToggle(void Function(void Function()) setState, option, name) {
|
||||
return CheckboxListTile(
|
||||
value: FFI.getByName('toggle_option', option) == 'true',
|
||||
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_hbb/models/chat_model.dart';
|
||||
import 'package:flutter_hbb/models/file_model.dart';
|
||||
import 'package:flutter_hbb/models/server_model.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.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 'dart:async';
|
||||
|
||||
import '../common.dart';
|
||||
import '../mobile/widgets/dialog.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());
|
||||
var pid = FFI.id;
|
||||
ui.decodeImageFromPixels(rgba, width, height, ui.PixelFormat.rgba8888,
|
||||
(image) {
|
||||
if (FFI.id != pid) return;
|
||||
_image = image;
|
||||
_images[id] = Tuple3(image, _hotx, _hoty);
|
||||
try {
|
||||
// my throw exception, because the listener maybe already dispose
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
print('notify cursor: $e');
|
||||
}
|
||||
});
|
||||
(image) {
|
||||
if (FFI.id != pid) return;
|
||||
_image = image;
|
||||
_images[id] = Tuple3(image, _hotx, _hoty);
|
||||
try {
|
||||
// my throw exception, because the listener maybe already dispose
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
print('notify cursor: $e');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void updateCursorId(Map<String, dynamic> evt) {
|
||||
@ -635,8 +637,7 @@ class CursorModel with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void updateDisplayOriginWithCursor(
|
||||
double x, double y, double xCursor, double yCursor) {
|
||||
void updateDisplayOriginWithCursor(double x, double y, double xCursor, double yCursor) {
|
||||
_displayOriginX = x;
|
||||
_displayOriginY = y;
|
||||
_x = xCursor;
|
||||
@ -734,13 +735,17 @@ class FFI {
|
||||
/// [press] indicates a click event(down and up).
|
||||
static void inputKey(String name, {bool? down, bool? press}) {
|
||||
if (!ffiModel.keyboard()) return;
|
||||
setByName(
|
||||
'input_key',
|
||||
json.encode(modify({
|
||||
'name': name,
|
||||
'down': (down ?? false).toString(),
|
||||
'press': (press ?? true).toString()
|
||||
})));
|
||||
final Map<String, String> out = Map();
|
||||
out['name'] = name;
|
||||
// default: down = false
|
||||
if (down == true) {
|
||||
out['down'] = "true";
|
||||
}
|
||||
// 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].
|
||||
@ -760,7 +765,7 @@ class FFI {
|
||||
return peers
|
||||
.map((s) => s as List<dynamic>)
|
||||
.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();
|
||||
} catch (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"
|
||||
source: hosted
|
||||
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:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -751,6 +758,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
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:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -55,6 +55,8 @@ dependencies:
|
||||
image: ^3.1.3
|
||||
flutter_smart_dialog: ^4.3.1
|
||||
flutter_rust_bridge: ^1.30.0
|
||||
window_manager: ^0.2.3
|
||||
desktop_multi_window: ^0.0.2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_launcher_icons: ^0.9.1
|
||||
|
Loading…
Reference in New Issue
Block a user