Merge pull request #1219 from 21pages/tabbar

switch window, close subwindow
This commit is contained in:
RustDesk 2022-08-09 10:24:19 +08:00 committed by GitHub
commit cf435b0665
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/instance_manager.dart'; import 'package:get/instance_manager.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:window_manager/window_manager.dart';
import 'models/model.dart'; import 'models/model.dart';
import 'models/platform_model.dart'; import 'models/platform_model.dart';
@ -109,6 +110,12 @@ backToHome() {
Navigator.popUntil(globalKey.currentContext!, ModalRoute.withName("/")); Navigator.popUntil(globalKey.currentContext!, ModalRoute.withName("/"));
} }
void window_on_top() {
windowManager.restore();
windowManager.show();
windowManager.focus();
}
typedef DialogBuilder = CustomAlertDialog Function( typedef DialogBuilder = CustomAlertDialog Function(
StateSetter setState, void Function([dynamic]) close); StateSetter setState, void Function([dynamic]) close);

View File

@ -8,6 +8,7 @@ import 'package:flutter_hbb/desktop/pages/remote_page.dart';
import 'package:flutter_hbb/desktop/widgets/tabbar_widget.dart'; import 'package:flutter_hbb/desktop/widgets/tabbar_widget.dart';
import 'package:flutter_hbb/utils/multi_window_manager.dart'; import 'package:flutter_hbb/utils/multi_window_manager.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:window_manager/window_manager.dart';
import '../../models/model.dart'; import '../../models/model.dart';
@ -47,6 +48,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage>
"call ${call.method} with args ${call.arguments} from window ${fromWindowId}"); "call ${call.method} with args ${call.arguments} from window ${fromWindowId}");
// for simplify, just replace connectionId // for simplify, just replace connectionId
if (call.method == "new_remote_desktop") { if (call.method == "new_remote_desktop") {
window_on_top();
final args = jsonDecode(call.arguments); final args = jsonDecode(call.arguments);
final id = args['id']; final id = args['id'];
final indexOf = connectionIds.indexOf(id); final indexOf = connectionIds.indexOf(id);
@ -111,5 +113,8 @@ class _ConnectionTabPageState extends State<ConnectionTabPage>
initialIndex = max(0, initialIndex - 1); initialIndex = max(0, initialIndex - 1);
tabController.value = TabController( tabController.value = TabController(
length: connectionIds.length, vsync: this, initialIndex: initialIndex); length: connectionIds.length, vsync: this, initialIndex: initialIndex);
if (connectionIds.length == 0) {
windowManager.close();
}
} }
} }

View File

@ -9,6 +9,7 @@ import 'package:flutter_hbb/desktop/pages/connection_page.dart';
import 'package:flutter_hbb/desktop/widgets/titlebar_widget.dart'; import 'package:flutter_hbb/desktop/widgets/titlebar_widget.dart';
import 'package:flutter_hbb/models/platform_model.dart'; import 'package:flutter_hbb/models/platform_model.dart';
import 'package:flutter_hbb/models/server_model.dart'; import 'package:flutter_hbb/models/server_model.dart';
import 'package:flutter_hbb/utils/multi_window_manager.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@ -447,6 +448,13 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener {
void initState() { void initState() {
super.initState(); super.initState();
trayManager.addListener(this); trayManager.addListener(this);
rustDeskWinManager.setMethodHandler((call, fromWindowId) async {
print(
"call ${call.method} with args ${call.arguments} from window ${fromWindowId}");
if (call.method == "main_window_on_top") {
window_on_top();
}
});
} }
@override @override

View File

@ -8,6 +8,7 @@ import 'package:flutter_hbb/desktop/widgets/tabbar_widget.dart';
import 'package:flutter_hbb/models/model.dart'; import 'package:flutter_hbb/models/model.dart';
import 'package:flutter_hbb/utils/multi_window_manager.dart'; import 'package:flutter_hbb/utils/multi_window_manager.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:window_manager/window_manager.dart';
/// File Transfer for multi tabs /// File Transfer for multi tabs
class FileManagerTabPage extends StatefulWidget { class FileManagerTabPage extends StatefulWidget {
@ -44,6 +45,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage>
"call ${call.method} with args ${call.arguments} from window ${fromWindowId}"); "call ${call.method} with args ${call.arguments} from window ${fromWindowId}");
// for simplify, just replace connectionId // for simplify, just replace connectionId
if (call.method == "new_file_transfer") { if (call.method == "new_file_transfer") {
window_on_top();
final args = jsonDecode(call.arguments); final args = jsonDecode(call.arguments);
final id = args['id']; final id = args['id'];
final indexOf = connectionIds.indexOf(id); final indexOf = connectionIds.indexOf(id);
@ -111,5 +113,8 @@ class _FileManagerTabPageState extends State<FileManagerTabPage>
initialIndex = max(0, initialIndex - 1); initialIndex = max(0, initialIndex - 1);
tabController.value = TabController( tabController.value = TabController(
length: connectionIds.length, initialIndex: initialIndex, vsync: this); length: connectionIds.length, initialIndex: initialIndex, vsync: this);
if (connectionIds.length == 0) {
windowManager.close();
}
} }
} }

View File

@ -3,6 +3,7 @@ import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hbb/common.dart'; import 'package:flutter_hbb/common.dart';
import 'package:flutter_hbb/consts.dart'; import 'package:flutter_hbb/consts.dart';
import 'package:flutter_hbb/utils/multi_window_manager.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
const Color _bgColor = Color.fromARGB(255, 231, 234, 237); const Color _bgColor = Color.fromARGB(255, 231, 234, 237);
@ -184,7 +185,8 @@ class _AddButton extends StatelessWidget {
return _Hoverable( return _Hoverable(
onHover: (hover) => _hover.value = hover, onHover: (hover) => _hover.value = hover,
onPressed: (pressed) => _pressed.value = pressed, onPressed: (pressed) => _pressed.value = pressed,
onTapUp: () => debugPrint('+'), // TODO onTapUp: () =>
rustDeskWinManager.call(WindowType.Main, "main_window_on_top", ""),
child: Obx((() => Container( child: Obx((() => Container(
height: _kTabBarHeight, height: _kTabBarHeight,
decoration: ShapeDecoration( decoration: ShapeDecoration(

View File

@ -1,5 +1,4 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:ui';
import 'package:desktop_multi_window/desktop_multi_window.dart'; import 'package:desktop_multi_window/desktop_multi_window.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
@ -97,7 +96,7 @@ class RustDeskMultiWindowManager {
int? findWindowByType(WindowType type) { int? findWindowByType(WindowType type) {
switch (type) { switch (type) {
case WindowType.Main: case WindowType.Main:
break; return 0;
case WindowType.RemoteDesktop: case WindowType.RemoteDesktop:
return _remoteDesktopWindowId; return _remoteDesktopWindowId;
case WindowType.FileTransfer: case WindowType.FileTransfer: