add: multi window focus

This commit is contained in:
kingtous 2022-08-09 19:32:19 +08:00
parent 8a113caf2e
commit ec3f7a8e91
4 changed files with 13 additions and 7 deletions

@ -1,6 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:io'; import 'dart:io';
import 'package:desktop_multi_window/desktop_multi_window.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
@ -110,10 +111,15 @@ backToHome() {
Navigator.popUntil(globalKey.currentContext!, ModalRoute.withName("/")); Navigator.popUntil(globalKey.currentContext!, ModalRoute.withName("/"));
} }
void window_on_top() { void window_on_top(int? id) {
windowManager.restore(); if (id == null) {
windowManager.show(); // main window
windowManager.focus(); windowManager.restore();
windowManager.show();
windowManager.focus();
} else {
WindowController.fromWindowId(id)..focus()..show();
}
} }
typedef DialogBuilder = CustomAlertDialog Function( typedef DialogBuilder = CustomAlertDialog Function(

@ -49,9 +49,9 @@ 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'];
window_on_top(windowId());
final indexOf = connectionIds.indexOf(id); final indexOf = connectionIds.indexOf(id);
if (indexOf >= 0) { if (indexOf >= 0) {
initialIndex = indexOf; initialIndex = indexOf;

@ -472,7 +472,7 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener, Wi
print( print(
"call ${call.method} with args ${call.arguments} from window ${fromWindowId}"); "call ${call.method} with args ${call.arguments} from window ${fromWindowId}");
if (call.method == "main_window_on_top") { if (call.method == "main_window_on_top") {
window_on_top(); window_on_top(null);
} }
}); });
} }

@ -46,9 +46,9 @@ 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'];
window_on_top(windowId());
final indexOf = connectionIds.indexOf(id); final indexOf = connectionIds.indexOf(id);
if (indexOf >= 0) { if (indexOf >= 0) {
initialIndex = indexOf; initialIndex = indexOf;