refact, separate remote window, tmp commit

Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
dignow
2023-08-03 23:14:40 +08:00
parent 902f56c499
commit 1970795093
10 changed files with 115 additions and 52 deletions

View File

@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hbb/common.dart';
import 'package:flutter_hbb/consts.dart';
import 'package:flutter_hbb/utils/multi_window_manager.dart';
import 'package:flutter_hbb/desktop/pages/desktop_home_page.dart';
import 'package:flutter_hbb/desktop/pages/desktop_tab_page.dart';
import 'package:flutter_hbb/models/platform_model.dart';
@@ -248,7 +249,7 @@ class _General extends StatefulWidget {
class _GeneralState extends State<_General> {
final RxBool serviceStop = Get.find<RxBool>(tag: 'stop-service');
RxBool serviceBtnEabled = true.obs;
RxBool serviceBtnEnabled = true.obs;
@override
Widget build(BuildContext context) {
@@ -300,14 +301,14 @@ class _GeneralState extends State<_General> {
return _Card(title: 'Service', children: [
Obx(() => _Button(serviceStop.value ? 'Start' : 'Stop', () {
() async {
serviceBtnEabled.value = false;
serviceBtnEnabled.value = false;
await start_service(serviceStop.value);
// enable the button after 1 second
Future.delayed(const Duration(seconds: 1), () {
serviceBtnEabled.value = true;
serviceBtnEnabled.value = true;
});
}();
}, enabled: serviceBtnEabled.value))
}, enabled: serviceBtnEnabled.value))
]);
}
@@ -318,7 +319,14 @@ class _GeneralState extends State<_General> {
isServer: false),
_OptionCheckBox(context, 'Adaptive Bitrate', 'enable-abr'),
_OptionCheckBox(
context, 'Separate remote window', kOptionSeparateRemoteWindow, isServer: false),
context,
'Separate remote window',
kOptionSeparateRemoteWindow,
isServer: false,
update: () {
rustDeskWinManager.separateWindows();
},
),
];
// though this is related to GUI, but opengl problem affects all users, so put in config rather than local
children.add(Tooltip(
@@ -1678,7 +1686,6 @@ Widget _OptionCheckBox(BuildContext context, String label, String key,
isServer
? await mainSetBoolOption(key, option)
: await mainSetLocalBoolOption(key, option);
;
update?.call();
}
}

View File

@@ -80,7 +80,7 @@ class _FileManagerPageState extends State<FileManagerPage>
@override
void initState() {
super.initState();
_ffi = FFI();
_ffi = FFI(null);
_ffi.start(widget.id,
isFileTransfer: true,
password: widget.password,

View File

@@ -54,7 +54,7 @@ class _PortForwardPageState extends State<PortForwardPage>
@override
void initState() {
super.initState();
_ffi = FFI();
_ffi = FFI(null);
_ffi.start(widget.id,
isPortForward: true,
password: widget.password,

View File

@@ -28,10 +28,13 @@ import '../widgets/tabbar_widget.dart';
final SimpleWrapper<bool> _firstEnterImage = SimpleWrapper(false);
final Map<String, bool> noCloseSessionOnDispose = {};
class RemotePage extends StatefulWidget {
RemotePage({
Key? key,
required this.id,
required this.sessionId,
required this.password,
required this.toolbarState,
required this.tabController,
@@ -40,6 +43,7 @@ class RemotePage extends StatefulWidget {
}) : super(key: key);
final String id;
final SessionID? sessionId;
final String? password;
final ToolbarState toolbarState;
final String? switchUuid;
@@ -91,7 +95,7 @@ class _RemotePageState extends State<RemotePage>
void initState() {
super.initState();
_initStates(widget.id);
_ffi = FFI();
_ffi = FFI(widget.sessionId);
Get.put(_ffi, tag: widget.id);
_ffi.imageModel.addCallbackOnFirstImage((String peerId) {
showKBLayoutTypeChooserIfNeeded(
@@ -199,6 +203,8 @@ class _RemotePageState extends State<RemotePage>
@override
Future<void> dispose() async {
final closeSession = noCloseSessionOnDispose.remove(widget.id) ?? false;
// https://github.com/flutter/flutter/issues/64935
super.dispose();
debugPrint("REMOTE PAGE dispose session $sessionId ${widget.id}");
@@ -209,11 +215,13 @@ class _RemotePageState extends State<RemotePage>
_ffi.dialogManager.hideMobileActionsOverlay();
_ffi.recordingModel.onClose();
_rawKeyFocusNode.dispose();
await _ffi.close();
await _ffi.close(closeSession: closeSession);
_timer?.cancel();
_ffi.dialogManager.dismissAll();
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: SystemUiOverlay.values);
if (closeSession) {
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: SystemUiOverlay.values);
}
if (!Platform.isLinux) {
await Wakelock.disable();
}

View File

@@ -52,6 +52,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
_toolbarState = ToolbarState();
RemoteCountState.init();
final peerId = params['id'];
final sessionId = params['session_id'];
if (peerId != null) {
ConnectionTypeState.init(peerId);
tabController.onSelected = (id) {
@@ -73,6 +74,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
page: RemotePage(
key: ValueKey(peerId),
id: peerId,
sessionId: sessionId == null ? null : SessionID(sessionId),
password: params['password'],
toolbarState: _toolbarState,
tabController: tabController,
@@ -99,6 +101,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
final args = jsonDecode(call.arguments);
final id = args['id'];
final switchUuid = args['switch_uuid'];
final sessionId = args['session_id'];
windowOnTop(windowId());
ConnectionTypeState.init(id);
_toolbarState.setShow(
@@ -112,6 +115,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
page: RemotePage(
key: ValueKey(id),
id: id,
sessionId: sessionId == null ? null : SessionID(sessionId),
password: args['password'],
toolbarState: _toolbarState,
tabController: tabController,
@@ -136,6 +140,15 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
.map((e) => e.key)
.toList()
.join(',');
} else if (call.method == kWindowEventGetSessionIdList) {
return tabController.state.value.tabs
.map((e) => '${e.key},${(e.page as RemotePage).ffi.sessionId}')
.toList()
.join(';');
} else if (call.method == kWindowEventCloseForSeparateWindow) {
final peerId = call.arguments;
noCloseSessionOnDispose[peerId] = true;
tabController.closeBy(peerId);
}
_update_remote_count();
});