Skip to content

Commit

Permalink
Merge branch 'rustdesk:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangbo8418 authored Mar 6, 2024
2 parents 9ef4ca5 + dd44bb2 commit 150ccd2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
14 changes: 11 additions & 3 deletions flutter/windows/runner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> parameters_white_list = {"--install", "--cm"};

Expand All @@ -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<std::string> command_line_arguments =
GetCommandLineArguments();
// Remove possible trailing whitespace from command line arguments
Expand All @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down
11 changes: 11 additions & 0 deletions src/flutter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<StreamSink<EventToUI>>,
Expand Down
3 changes: 2 additions & 1 deletion src/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,7 @@ pub fn get_double_click_time() -> u32 {
unsafe { GetDoubleClickTime() }
}

fn wide_string(s: &str) -> Vec<u16> {
pub fn wide_string(s: &str) -> Vec<u16> {
use std::os::windows::prelude::OsStrExt;
std::ffi::OsStr::new(s)
.encode_wide()
Expand Down

0 comments on commit 150ccd2

Please sign in to comment.