opt: hide main window when using shortcut
This commit is contained in:
parent
03c1395565
commit
f343478016
@ -6,6 +6,7 @@ import 'dart:typed_data';
|
|||||||
|
|
||||||
import 'package:back_button_interceptor/back_button_interceptor.dart';
|
import 'package:back_button_interceptor/back_button_interceptor.dart';
|
||||||
import 'package:desktop_multi_window/desktop_multi_window.dart';
|
import 'package:desktop_multi_window/desktop_multi_window.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
@ -321,7 +322,7 @@ void window_on_top(int? id) {
|
|||||||
windowManager.restore();
|
windowManager.restore();
|
||||||
windowManager.show();
|
windowManager.show();
|
||||||
windowManager.focus();
|
windowManager.focus();
|
||||||
rustDeskWinManager.registerActiveWindow(0);
|
rustDeskWinManager.registerActiveWindow(kWindowMainId);
|
||||||
} else {
|
} else {
|
||||||
WindowController.fromWindowId(id)
|
WindowController.fromWindowId(id)
|
||||||
..focus()
|
..focus()
|
||||||
@ -1227,41 +1228,50 @@ StreamSubscription? listenUniLinks() {
|
|||||||
return sub;
|
return sub;
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkArguments() {
|
/// Returns true if we successfully handle the startup arguments.
|
||||||
|
bool checkArguments() {
|
||||||
// check connect args
|
// check connect args
|
||||||
final connectIndex = bootArgs.indexOf("--connect");
|
final connectIndex = bootArgs.indexOf("--connect");
|
||||||
if (connectIndex == -1) {
|
if (connectIndex == -1) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
String? arg =
|
String? arg =
|
||||||
bootArgs.length < connectIndex + 1 ? null : bootArgs[connectIndex + 1];
|
bootArgs.length < connectIndex + 1 ? null : bootArgs[connectIndex + 1];
|
||||||
if (arg != null) {
|
if (arg != null) {
|
||||||
if (arg.startsWith(kUniLinksPrefix)) {
|
if (arg.startsWith(kUniLinksPrefix)) {
|
||||||
parseRustdeskUri(arg);
|
return parseRustdeskUri(arg);
|
||||||
} else {
|
} else {
|
||||||
|
// remove "--connect xxx" in the `bootArgs` array
|
||||||
|
bootArgs.removeAt(connectIndex);
|
||||||
|
bootArgs.removeAt(connectIndex);
|
||||||
// fallback to peer id
|
// fallback to peer id
|
||||||
rustDeskWinManager.newRemoteDesktop(arg);
|
Future.delayed(Duration.zero, () {
|
||||||
bootArgs.removeAt(connectIndex);
|
rustDeskWinManager.newRemoteDesktop(arg);
|
||||||
bootArgs.removeAt(connectIndex);
|
});
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse `rustdesk://` unilinks
|
/// Parse `rustdesk://` unilinks
|
||||||
///
|
///
|
||||||
|
/// Returns true if we successfully handle the uri provided.
|
||||||
/// [Functions]
|
/// [Functions]
|
||||||
/// 1. New Connection: rustdesk://connection/new/your_peer_id
|
/// 1. New Connection: rustdesk://connection/new/your_peer_id
|
||||||
void parseRustdeskUri(String uriPath) {
|
bool parseRustdeskUri(String uriPath) {
|
||||||
final uri = Uri.tryParse(uriPath);
|
final uri = Uri.tryParse(uriPath);
|
||||||
if (uri == null) {
|
if (uri == null) {
|
||||||
print("uri is not valid: $uriPath");
|
print("uri is not valid: $uriPath");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
callUniLinksUriHandler(uri);
|
return callUniLinksUriHandler(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// uri handler
|
/// uri handler
|
||||||
void callUniLinksUriHandler(Uri uri) {
|
///
|
||||||
|
/// Returns true if we successfully handle the uri provided.
|
||||||
|
bool callUniLinksUriHandler(Uri uri) {
|
||||||
debugPrint("uni links called: $uri");
|
debugPrint("uni links called: $uri");
|
||||||
// new connection
|
// new connection
|
||||||
if (uri.authority == "connection" && uri.path.startsWith("/new/")) {
|
if (uri.authority == "connection" && uri.path.startsWith("/new/")) {
|
||||||
@ -1269,7 +1279,9 @@ void callUniLinksUriHandler(Uri uri) {
|
|||||||
Future.delayed(Duration.zero, () {
|
Future.delayed(Duration.zero, () {
|
||||||
rustDeskWinManager.newRemoteDesktop(peerId);
|
rustDeskWinManager.newRemoteDesktop(peerId);
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Connect to a peer with [id].
|
/// Connect to a peer with [id].
|
||||||
|
@ -20,6 +20,7 @@ const String kTabLabelHomePage = "Home";
|
|||||||
const String kTabLabelSettingPage = "Settings";
|
const String kTabLabelSettingPage = "Settings";
|
||||||
|
|
||||||
const String kWindowPrefix = "wm_";
|
const String kWindowPrefix = "wm_";
|
||||||
|
const int kWindowMainId = 0;
|
||||||
|
|
||||||
// the executable name of the portable version
|
// the executable name of the portable version
|
||||||
const String kEnvPortableExecutable = "RUSTDESK_APPNAME";
|
const String kEnvPortableExecutable = "RUSTDESK_APPNAME";
|
||||||
|
@ -420,7 +420,17 @@ class _DesktopHomePageState extends State<DesktopHomePage>
|
|||||||
// initTray();
|
// initTray();
|
||||||
trayManager.addListener(this);
|
trayManager.addListener(this);
|
||||||
rustDeskWinManager.registerActiveWindowListener(onActiveWindowChanged);
|
rustDeskWinManager.registerActiveWindowListener(onActiveWindowChanged);
|
||||||
rustDeskWinManager.registerActiveWindow(0);
|
// main window may be hidden because of the initial uni link or arguments.
|
||||||
|
// note that we must wrap this active window registration in future because
|
||||||
|
// we must ensure the execution is after `windowManager.hide/show()`.
|
||||||
|
Future.delayed(Duration.zero, () {
|
||||||
|
windowManager.isVisible().then((visibility) {
|
||||||
|
if (visibility) {
|
||||||
|
rustDeskWinManager.registerActiveWindow(kWindowMainId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
rustDeskWinManager.setMethodHandler((call, fromWindowId) async {
|
rustDeskWinManager.setMethodHandler((call, fromWindowId) async {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
"[Main] call ${call.method} with args ${call.arguments} from window $fromWindowId");
|
"[Main] call ${call.method} with args ${call.arguments} from window $fromWindowId");
|
||||||
@ -455,9 +465,6 @@ class _DesktopHomePageState extends State<DesktopHomePage>
|
|||||||
rustDeskWinManager.unregisterActiveWindow(call.arguments["id"]);
|
rustDeskWinManager.unregisterActiveWindow(call.arguments["id"]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Future.delayed(Duration.zero, () {
|
|
||||||
checkArguments();
|
|
||||||
});
|
|
||||||
_uniLinksSubscription = listenUniLinks();
|
_uniLinksSubscription = listenUniLinks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,13 +118,18 @@ void runMainApp(bool startService) async {
|
|||||||
gFFI.serverModel.startService();
|
gFFI.serverModel.startService();
|
||||||
}
|
}
|
||||||
runApp(App());
|
runApp(App());
|
||||||
|
// check the startup argument, if we successfully handle the argument, we keep the main window hidden.
|
||||||
|
if (checkArguments()) {
|
||||||
|
windowManager.hide();
|
||||||
|
} else {
|
||||||
|
windowManager.show();
|
||||||
|
windowManager.focus();
|
||||||
|
}
|
||||||
// set window option
|
// set window option
|
||||||
WindowOptions windowOptions = getHiddenTitleBarWindowOptions();
|
WindowOptions windowOptions = getHiddenTitleBarWindowOptions();
|
||||||
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||||
restoreWindowPosition(WindowType.Main);
|
restoreWindowPosition(WindowType.Main);
|
||||||
await windowManager.show();
|
windowManager.setOpacity(1);
|
||||||
await windowManager.focus();
|
|
||||||
await windowManager.setOpacity(1);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ packages:
|
|||||||
name: archive
|
name: archive
|
||||||
url: "https://pub.flutter-io.cn"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.3.4"
|
version: "3.3.5"
|
||||||
args:
|
args:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -257,8 +257,8 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: "8ee8eb59cabf6ac83a13fe002de7d4a231263a58"
|
ref: cb086219bd4760a95a483cb14c1791d2a39ca5a0
|
||||||
resolved-ref: "8ee8eb59cabf6ac83a13fe002de7d4a231263a58"
|
resolved-ref: cb086219bd4760a95a483cb14c1791d2a39ca5a0
|
||||||
url: "https://github.com/Kingtous/rustdesk_desktop_multi_window"
|
url: "https://github.com/Kingtous/rustdesk_desktop_multi_window"
|
||||||
source: git
|
source: git
|
||||||
version: "0.1.0"
|
version: "0.1.0"
|
||||||
@ -462,7 +462,7 @@ packages:
|
|||||||
name: frontend_server_client
|
name: frontend_server_client
|
||||||
url: "https://pub.flutter-io.cn"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.1.0"
|
version: "3.2.0"
|
||||||
get:
|
get:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -735,7 +735,7 @@ packages:
|
|||||||
name: path_provider_android
|
name: path_provider_android
|
||||||
url: "https://pub.flutter-io.cn"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.21"
|
version: "2.0.22"
|
||||||
path_provider_ios:
|
path_provider_ios:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1054,14 +1054,14 @@ packages:
|
|||||||
name: url_launcher
|
name: url_launcher
|
||||||
url: "https://pub.flutter-io.cn"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "6.1.6"
|
version: "6.1.7"
|
||||||
url_launcher_android:
|
url_launcher_android:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: url_launcher_android
|
name: url_launcher_android
|
||||||
url: "https://pub.flutter-io.cn"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "6.0.21"
|
version: "6.0.22"
|
||||||
url_launcher_ios:
|
url_launcher_ios:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1124,7 +1124,7 @@ packages:
|
|||||||
name: video_player
|
name: video_player
|
||||||
url: "https://pub.flutter-io.cn"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.4.7"
|
version: "2.4.8"
|
||||||
video_player_android:
|
video_player_android:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1215,7 +1215,7 @@ packages:
|
|||||||
name: win32
|
name: win32
|
||||||
url: "https://pub.flutter-io.cn"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.1.1"
|
version: "3.1.2"
|
||||||
win32_registry:
|
win32_registry:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user