Merge pull request #5256 from dignow/refact/separate_remote_window

Refact/separate remote window
This commit is contained in:
RustDesk
2023-08-06 09:31:05 +08:00
committed by GitHub
58 changed files with 727 additions and 320 deletions

View File

@@ -367,7 +367,7 @@ class ChatModel with ChangeNotifier {
// not minisized: add count
if (await WindowController.fromWindowId(stateGlobal.windowId)
.isMinimized()) {
window_on_top(stateGlobal.windowId);
windowOnTop(stateGlobal.windowId);
if (notSelected) {
tabController.jumpTo(index);
}
@@ -386,7 +386,7 @@ class ChatModel with ChangeNotifier {
return;
}
if (isDesktop) {
window_on_top(null);
windowOnTop(null);
// disable auto jumpTo other tab when hasFocus, and mark unread message
final currentSelectedTab =
session.serverModel.tabController.state.value.selectedTabInfo;

View File

@@ -0,0 +1,46 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:texture_rgba_renderer/texture_rgba_renderer.dart';
import '../../common.dart';
import './platform_model.dart';
class RenderTexture {
final RxInt textureId = RxInt(-1);
int _textureKey = -1;
SessionID? _sessionId;
final useTextureRender = bind.mainUseTextureRender();
final textureRenderer = TextureRgbaRenderer();
RenderTexture();
create(SessionID sessionId) {
if (useTextureRender) {
_textureKey = bind.getNextTextureKey();
_sessionId = sessionId;
textureRenderer.createTexture(_textureKey).then((id) async {
debugPrint("id: $id, texture_key: $_textureKey");
if (id != -1) {
final ptr = await textureRenderer.getTexturePtr(_textureKey);
platformFFI.registerTexture(sessionId, ptr);
textureId.value = id;
}
});
}
}
destroy() async {
if (useTextureRender && _textureKey != -1 && _sessionId != null) {
platformFFI.registerTexture(_sessionId!, 0);
await textureRenderer.closeTexture(_textureKey);
_textureKey = -1;
}
}
static final RenderTexture instance = RenderTexture();
}
// Global instance for separate texture
final renderTexture = RenderTexture.instance;

View File

@@ -260,7 +260,7 @@ class FfiModel with ChangeNotifier {
});
break;
default:
window_on_top(null);
windowOnTop(null);
break;
}
}
@@ -1583,6 +1583,7 @@ class FFI {
/// dialogManager use late to ensure init after main page binding [globalKey]
late final dialogManager = OverlayDialogManager();
late final bool isSessionAdded;
late final SessionID sessionId;
late final ImageModel imageModel; // session
late final FfiModel ffiModel; // session
@@ -1600,8 +1601,9 @@ class FFI {
late final InputModel inputModel; // session
late final ElevationModel elevationModel; // session
FFI() {
sessionId = isDesktop ? Uuid().v4obj() : _constSessionId;
FFI(SessionID? sId) {
isSessionAdded = sId != null;
sessionId = sId ?? (isDesktop ? Uuid().v4obj() : _constSessionId);
imageModel = ImageModel(WeakReference(this));
ffiModel = FfiModel(WeakReference(this));
cursorModel = CursorModel(WeakReference(this));
@@ -1641,23 +1643,31 @@ class FFI {
imageModel.id = id;
cursorModel.id = id;
}
// ignore: unused_local_variable
final addRes = bind.sessionAddSync(
sessionId: sessionId,
id: id,
isFileTransfer: isFileTransfer,
isPortForward: isPortForward,
isRdp: isRdp,
switchUuid: switchUuid ?? "",
forceRelay: forceRelay ?? false,
password: password ?? "",
);
if (!isSessionAdded) {
// ignore: unused_local_variable
final addRes = bind.sessionAddSync(
sessionId: sessionId,
id: id,
isFileTransfer: isFileTransfer,
isPortForward: isPortForward,
isRdp: isRdp,
switchUuid: switchUuid ?? '',
forceRelay: forceRelay ?? false,
password: password ?? '',
);
}
final stream = bind.sessionStart(sessionId: sessionId, id: id);
final cb = ffiModel.startEventListener(sessionId, id);
final useTextureRender = bind.mainUseTextureRender();
final SimpleWrapper<bool> isToNewWindowNotified = SimpleWrapper(false);
// Preserved for the rgba data.
stream.listen((message) {
if (closed) return;
if (isSessionAdded && !isToNewWindowNotified.value) {
bind.sessionReadyToNewWindow(sessionId: sessionId);
isToNewWindowNotified.value = true;
}
() async {
if (message is EventToUI_Event) {
if (message.field0 == "close") {
@@ -1717,7 +1727,7 @@ class FFI {
}
/// Close the remote session.
Future<void> close() async {
Future<void> close({bool closeSession = true}) async {
closed = true;
chatModel.close();
if (imageModel.image != null && !isWebDesktop) {
@@ -1735,7 +1745,9 @@ class FFI {
ffiModel.clear();
canvasModel.clear();
inputModel.resetModifiers();
await bind.sessionClose(sessionId: sessionId);
if (closeSession) {
await bind.sessionClose(sessionId: sessionId);
}
debugPrint('model $id closed');
id = '';
}

View File

@@ -473,7 +473,7 @@ class ServerModel with ChangeNotifier {
onTap: () {},
page: desktop.buildConnectionCard(client)));
Future.delayed(Duration.zero, () async {
if (!hideCm) window_on_top(null);
if (!hideCm) windowOnTop(null);
});
// Only do the hidden task when on Desktop.
if (client.authorized && isDesktop) {
@@ -612,7 +612,7 @@ class ServerModel with ChangeNotifier {
if (client.incomingVoiceCall) {
// Has incoming phone call, let's set the window on top.
Future.delayed(Duration.zero, () {
window_on_top(null);
windowOnTop(null);
});
}
notifyListeners();