Merge pull request #2892 from Kingtous/master

fix: --install cannot be invoke caused by singleton optimization
This commit is contained in:
RustDesk 2023-01-21 13:56:18 +08:00 committed by GitHub
commit 8b2f0e508a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,20 +1,21 @@
#include <flutter/dart_project.h> #include <flutter/dart_project.h>
#include <flutter/flutter_view_controller.h> #include <flutter/flutter_view_controller.h>
#include <windows.h>
#include <tchar.h> #include <tchar.h>
#include <uni_links_desktop/uni_links_desktop_plugin.h>
#include <windows.h>
#include <algorithm>
#include <iostream> #include <iostream>
#include "flutter_window.h" #include "flutter_window.h"
#include "utils.h" #include "utils.h"
// #include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
#include <uni_links_desktop/uni_links_desktop_plugin.h>
typedef char** (*FUNC_RUSTDESK_CORE_MAIN)(int*); typedef char** (*FUNC_RUSTDESK_CORE_MAIN)(int*);
typedef void (*FUNC_RUSTDESK_FREE_ARGS)( char**, int); typedef void (*FUNC_RUSTDESK_FREE_ARGS)( char**, int);
const char* uniLinksPrefix = "rustdesk://"; const char* uniLinksPrefix = "rustdesk://";
/// Note: `--server`, `--service` are already handled in [core_main.rs].
const std::vector<std::string> parameters_white_list = {"--install", "--cm"};
// auto bdw = bitsdojo_window_configure(BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP);
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command) _In_ wchar_t *command_line, _In_ int show_command)
{ {
@ -40,6 +41,10 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
} }
std::vector<std::string> command_line_arguments = std::vector<std::string> command_line_arguments =
GetCommandLineArguments(); GetCommandLineArguments();
// Remove possible trailing whitespace from command line arguments
for (auto& argument : command_line_arguments) {
argument.erase(argument.find_last_not_of(" \n\r\t"));
}
int args_len = 0; int args_len = 0;
char** c_args = rustdesk_core_main(&args_len); char** c_args = rustdesk_core_main(&args_len);
@ -51,9 +56,20 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
std::vector<std::string> rust_args(c_args, c_args + args_len); std::vector<std::string> rust_args(c_args, c_args + args_len);
free_c_args(c_args, args_len); free_c_args(c_args, args_len);
// uni links dispatch // Uri links dispatch
HWND hwnd = ::FindWindow(_T("FLUTTER_RUNNER_WIN32_WINDOW"), _T("RustDesk")); HWND hwnd = ::FindWindow(_T("FLUTTER_RUNNER_WIN32_WINDOW"), _T("RustDesk"));
if (hwnd != NULL) { if (hwnd != NULL) {
// Allow multiple flutter instances when being executed by parameters
// contained in whitelists.
bool allow_multiple_instances = false;
for (auto& whitelist_param : parameters_white_list) {
allow_multiple_instances =
allow_multiple_instances ||
std::find(command_line_arguments.begin(),
command_line_arguments.end(),
whitelist_param) != command_line_arguments.end();
}
if (!allow_multiple_instances) {
if (!command_line_arguments.empty()) { if (!command_line_arguments.empty()) {
// Dispatch command line arguments // Dispatch command line arguments
DispatchToUniLinksDesktop(hwnd); DispatchToUniLinksDesktop(hwnd);
@ -65,6 +81,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
} }
return EXIT_FAILURE; return EXIT_FAILURE;
} }
}
// Attach to console when present (e.g., 'flutter run') or create a // Attach to console when present (e.g., 'flutter run') or create a
// new console when running with a debugger. // new console when running with a debugger.