mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-27 23:19:02 +08:00
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:desktop_multi_window/desktop_multi_window.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@ -321,7 +322,7 @@ void window_on_top(int? id) {
|
||||
windowManager.restore();
|
||||
windowManager.show();
|
||||
windowManager.focus();
|
||||
rustDeskWinManager.registerActiveWindow(0);
|
||||
rustDeskWinManager.registerActiveWindow(kWindowMainId);
|
||||
} else {
|
||||
WindowController.fromWindowId(id)
|
||||
..focus()
|
||||
@ -1227,41 +1228,50 @@ StreamSubscription? listenUniLinks() {
|
||||
return sub;
|
||||
}
|
||||
|
||||
void checkArguments() {
|
||||
/// Returns true if we successfully handle the startup arguments.
|
||||
bool checkArguments() {
|
||||
// check connect args
|
||||
final connectIndex = bootArgs.indexOf("--connect");
|
||||
if (connectIndex == -1) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
String? arg =
|
||||
bootArgs.length < connectIndex + 1 ? null : bootArgs[connectIndex + 1];
|
||||
if (arg != null) {
|
||||
if (arg.startsWith(kUniLinksPrefix)) {
|
||||
parseRustdeskUri(arg);
|
||||
return parseRustdeskUri(arg);
|
||||
} else {
|
||||
// remove "--connect xxx" in the `bootArgs` array
|
||||
bootArgs.removeAt(connectIndex);
|
||||
bootArgs.removeAt(connectIndex);
|
||||
// fallback to peer id
|
||||
rustDeskWinManager.newRemoteDesktop(arg);
|
||||
bootArgs.removeAt(connectIndex);
|
||||
bootArgs.removeAt(connectIndex);
|
||||
Future.delayed(Duration.zero, () {
|
||||
rustDeskWinManager.newRemoteDesktop(arg);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Parse `rustdesk://` unilinks
|
||||
///
|
||||
/// Returns true if we successfully handle the uri provided.
|
||||
/// [Functions]
|
||||
/// 1. New Connection: rustdesk://connection/new/your_peer_id
|
||||
void parseRustdeskUri(String uriPath) {
|
||||
bool parseRustdeskUri(String uriPath) {
|
||||
final uri = Uri.tryParse(uriPath);
|
||||
if (uri == null) {
|
||||
print("uri is not valid: $uriPath");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
callUniLinksUriHandler(uri);
|
||||
return callUniLinksUriHandler(uri);
|
||||
}
|
||||
|
||||
/// uri handler
|
||||
void callUniLinksUriHandler(Uri uri) {
|
||||
///
|
||||
/// Returns true if we successfully handle the uri provided.
|
||||
bool callUniLinksUriHandler(Uri uri) {
|
||||
debugPrint("uni links called: $uri");
|
||||
// new connection
|
||||
if (uri.authority == "connection" && uri.path.startsWith("/new/")) {
|
||||
@ -1269,7 +1279,9 @@ void callUniLinksUriHandler(Uri uri) {
|
||||
Future.delayed(Duration.zero, () {
|
||||
rustDeskWinManager.newRemoteDesktop(peerId);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Connect to a peer with [id].
|
||||
|
@ -20,6 +20,7 @@ const String kTabLabelHomePage = "Home";
|
||||
const String kTabLabelSettingPage = "Settings";
|
||||
|
||||
const String kWindowPrefix = "wm_";
|
||||
const int kWindowMainId = 0;
|
||||
|
||||
// the executable name of the portable version
|
||||
const String kEnvPortableExecutable = "RUSTDESK_APPNAME";
|
||||
|
@ -420,7 +420,17 @@ class _DesktopHomePageState extends State<DesktopHomePage>
|
||||
// initTray();
|
||||
trayManager.addListener(this);
|
||||
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 {
|
||||
debugPrint(
|
||||
"[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"]);
|
||||
}
|
||||
});
|
||||
Future.delayed(Duration.zero, () {
|
||||
checkArguments();
|
||||
});
|
||||
_uniLinksSubscription = listenUniLinks();
|
||||
}
|
||||
|
||||
|
@ -118,13 +118,18 @@ void runMainApp(bool startService) async {
|
||||
gFFI.serverModel.startService();
|
||||
}
|
||||
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
|
||||
WindowOptions windowOptions = getHiddenTitleBarWindowOptions();
|
||||
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||
restoreWindowPosition(WindowType.Main);
|
||||
await windowManager.show();
|
||||
await windowManager.focus();
|
||||
await windowManager.setOpacity(1);
|
||||
windowManager.setOpacity(1);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ packages:
|
||||
name: archive
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "3.3.4"
|
||||
version: "3.3.5"
|
||||
args:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -257,8 +257,8 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: "8ee8eb59cabf6ac83a13fe002de7d4a231263a58"
|
||||
resolved-ref: "8ee8eb59cabf6ac83a13fe002de7d4a231263a58"
|
||||
ref: cb086219bd4760a95a483cb14c1791d2a39ca5a0
|
||||
resolved-ref: cb086219bd4760a95a483cb14c1791d2a39ca5a0
|
||||
url: "https://github.com/Kingtous/rustdesk_desktop_multi_window"
|
||||
source: git
|
||||
version: "0.1.0"
|
||||
@ -462,7 +462,7 @@ packages:
|
||||
name: frontend_server_client
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "3.1.0"
|
||||
version: "3.2.0"
|
||||
get:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -735,7 +735,7 @@ packages:
|
||||
name: path_provider_android
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.0.21"
|
||||
version: "2.0.22"
|
||||
path_provider_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -1054,14 +1054,14 @@ packages:
|
||||
name: url_launcher
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "6.1.6"
|
||||
version: "6.1.7"
|
||||
url_launcher_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_android
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "6.0.21"
|
||||
version: "6.0.22"
|
||||
url_launcher_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -1124,7 +1124,7 @@ packages:
|
||||
name: video_player
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.4.7"
|
||||
version: "2.4.8"
|
||||
video_player_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -1215,7 +1215,7 @@ packages:
|
||||
name: win32
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "3.1.1"
|
||||
version: "3.1.2"
|
||||
win32_registry:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
Loading…
Reference in New Issue
Block a user