diff --git a/flutter/windows/runner/main.cpp b/flutter/windows/runner/main.cpp index 34ffb817ee6f..2e6a9c0ce33d 100644 --- a/flutter/windows/runner/main.cpp +++ b/flutter/windows/runner/main.cpp @@ -12,7 +12,7 @@ typedef char** (*FUNC_RUSTDESK_CORE_MAIN)(int*); typedef void (*FUNC_RUSTDESK_FREE_ARGS)( char**, int); -const char* uniLinksPrefix = "rustdesk://"; +typedef int (*FUNC_RUSTDESK_GET_APP_NAME)(wchar_t*, int); /// Note: `--server`, `--service` are already handled in [core_main.rs]. const std::vector parameters_white_list = {"--install", "--cm"}; @@ -39,6 +39,14 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, std::cout << "Failed to get free_c_args." << std::endl; return EXIT_FAILURE; } + std::wstring app_name = L"RustDesk"; + FUNC_RUSTDESK_GET_APP_NAME get_rustdesk_app_name = (FUNC_RUSTDESK_GET_APP_NAME)GetProcAddress(hInstance, "get_rustdesk_app_name"); + if (get_rustdesk_app_name) { + wchar_t app_name_buffer[512] = {0}; + if (get_rustdesk_app_name(app_name_buffer, 512) == 0) { + app_name = std::wstring(app_name_buffer); + } + } std::vector command_line_arguments = GetCommandLineArguments(); // Remove possible trailing whitespace from command line arguments @@ -61,7 +69,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, free_c_args(c_args, args_len); // Uri links dispatch - HWND hwnd = ::FindWindow(_T("FLUTTER_RUNNER_WIN32_WINDOW"), _T("RustDesk")); + HWND hwnd = ::FindWindow(_T("FLUTTER_RUNNER_WIN32_WINDOW"), app_name.c_str()); if (hwnd != NULL) { // Allow multiple flutter instances when being executed by parameters // contained in whitelists. @@ -112,7 +120,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, Win32Window::Point origin(10, 10); Win32Window::Size size(800, 600); if (!window.CreateAndShow( - is_cm_page ? L"RustDesk - Connection Manager" : L"RustDesk", origin, + is_cm_page ? app_name + L" - Connection Manager" : app_name, origin, size, !is_cm_page)) { return EXIT_FAILURE; } diff --git a/src/flutter.rs b/src/flutter.rs index 39016842cc9f..7420635d9029 100644 --- a/src/flutter.rs +++ b/src/flutter.rs @@ -154,6 +154,17 @@ pub unsafe extern "C" fn free_c_args(ptr: *mut *mut c_char, len: c_int) { // Afterwards the vector will be dropped and thus freed. } +#[cfg(windows)] +#[no_mangle] +pub unsafe extern "C" fn get_rustdesk_app_name(buffer: *mut u16, length: i32) -> i32 { + let name = crate::platform::wide_string(&crate::get_app_name()); + if length > name.len() as i32 { + std::ptr::copy_nonoverlapping(name.as_ptr(), buffer, name.len()); + return 0; + } + -1 +} + #[derive(Default)] struct SessionHandler { event_stream: Option>, diff --git a/src/lang.rs b/src/lang.rs index 74bd62ff6289..27f2b6939577 100644 --- a/src/lang.rs +++ b/src/lang.rs @@ -83,11 +83,12 @@ pub const LANGS: &[(&str, &str)] = &[ #[cfg(not(any(target_os = "android", target_os = "ios")))] pub fn translate(name: String) -> String { - let locale = sys_locale::get_locale().unwrap_or_default().to_lowercase(); + let locale = sys_locale::get_locale().unwrap_or_default(); translate_locale(name, &locale) } pub fn translate_locale(name: String, locale: &str) -> String { + let locale = locale.to_lowercase(); let mut lang = hbb_common::config::LocalConfig::get_option("lang").to_lowercase(); if lang.is_empty() { // zh_CN on Linux, zh-Hans-CN on mac, zh_CN_#Hans on Android diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 7fefd89fb148..c33976c9fc61 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -1748,7 +1748,7 @@ pub fn get_double_click_time() -> u32 { unsafe { GetDoubleClickTime() } } -fn wide_string(s: &str) -> Vec { +pub fn wide_string(s: &str) -> Vec { use std::os::windows::prelude::OsStrExt; std::ffi::OsStr::new(s) .encode_wide()