fix: uni links cause main window show

This commit is contained in:
Kingtous 2023-02-03 18:52:22 +08:00
parent 66851efaa3
commit c13c89c0d6
2 changed files with 15 additions and 9 deletions

View File

@ -1272,9 +1272,9 @@ Future<bool> restoreWindowPosition(WindowType type, {int? windowId}) async {
/// [Availability] /// [Availability]
/// initUniLinks should only be used on macos/windows. /// initUniLinks should only be used on macos/windows.
/// we use dbus for linux currently. /// we use dbus for linux currently.
Future<void> initUniLinks() async { Future<bool> initUniLinks() async {
if (Platform.isLinux) { if (Platform.isLinux) {
return; return false;
} }
// Register uni links for Windows. The required info of url scheme is already // Register uni links for Windows. The required info of url scheme is already
// declared in `Info.plist` for macOS. // declared in `Info.plist` for macOS.
@ -1285,11 +1285,12 @@ Future<void> initUniLinks() async {
try { try {
final initialLink = await getInitialLink(); final initialLink = await getInitialLink();
if (initialLink == null) { if (initialLink == null) {
return; return false;
} }
parseRustdeskUri(initialLink); return parseRustdeskUri(initialLink);
} catch (err) { } catch (err) {
debugPrintStack(label: "$err"); debugPrintStack(label: "$err");
return false;
} }
} }
@ -1310,11 +1311,13 @@ StreamSubscription? listenUniLinks() {
return sub; return sub;
} }
/// Returns true if we successfully handle the startup arguments. /// Handle command line arguments
///
/// * Returns true if we successfully handle the startup arguments.
bool checkArguments() { bool checkArguments() {
// bootArgs:[--connect, 362587269, --switch_uuid, e3d531cc-5dce-41e0-bd06-5d4a2b1eec05] // bootArgs:[--connect, 362587269, --switch_uuid, e3d531cc-5dce-41e0-bd06-5d4a2b1eec05]
// check connect args // check connect args
final connectIndex = kBootArgs.indexOf("--connect"); var connectIndex = kBootArgs.indexOf("--connect");
if (connectIndex == -1) { if (connectIndex == -1) {
return false; return false;
} }
@ -1368,7 +1371,7 @@ bool callUniLinksUriHandler(Uri uri) {
Future.delayed(Duration.zero, () { Future.delayed(Duration.zero, () {
rustDeskWinManager.newRemoteDesktop(peerId, switch_uuid: switch_uuid); rustDeskWinManager.newRemoteDesktop(peerId, switch_uuid: switch_uuid);
}); });
return false; return true;
} }
return false; return false;
} }

View File

@ -114,7 +114,6 @@ Future<void> initEnv(String appType) async {
void runMainApp(bool startService) async { void runMainApp(bool startService) async {
// register uni links // register uni links
initUniLinks();
await initEnv(kAppTypeMain); await initEnv(kAppTypeMain);
// trigger connection status updater // trigger connection status updater
await bind.mainCheckConnectStatus(); await bind.mainCheckConnectStatus();
@ -130,7 +129,11 @@ void runMainApp(bool startService) async {
// Restore the location of the main window before window hide or show. // Restore the location of the main window before window hide or show.
await restoreWindowPosition(WindowType.Main); await restoreWindowPosition(WindowType.Main);
// Check the startup argument, if we successfully handle the argument, we keep the main window hidden. // Check the startup argument, if we successfully handle the argument, we keep the main window hidden.
if (checkArguments()) { final handledByUniLinks = await initUniLinks();
final handledByCli = checkArguments();
debugPrint(
"handled by uni links: $handledByUniLinks, handled by cli: $handledByCli");
if (handledByUniLinks || handledByCli) {
windowManager.hide(); windowManager.hide();
} else { } else {
windowManager.show(); windowManager.show();