fix: remote printer, update install option (#11461)

* fix: remote printer, update install option

Signed-off-by: fufesou <linlong1266@gmail.com>

* Add comments

Signed-off-by: fufesou <linlong1266@gmail.com>

* Add comments

Signed-off-by: fufesou <linlong1266@gmail.com>

* Win, run_cmds, remove extra whitespace and newline

Signed-off-by: fufesou <linlong1266@gmail.com>

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2025-04-24 18:24:22 +08:00
committed by GitHub
parent 5c2538e7af
commit 279fb72a4f
5 changed files with 73 additions and 4 deletions

View File

@@ -76,7 +76,7 @@ pub const SET_FOREGROUND_WINDOW: &'static str = "SET_FOREGROUND_WINDOW";
const REG_NAME_INSTALL_DESKTOPSHORTCUTS: &str = "DESKTOPSHORTCUTS";
const REG_NAME_INSTALL_STARTMENUSHORTCUTS: &str = "STARTMENUSHORTCUTS";
const REG_NAME_INSTALL_PRINTER: &str = "PRINTER";
pub const REG_NAME_INSTALL_PRINTER: &str = "PRINTER";
pub fn get_focused_display(displays: Vec<DisplayInfo>) -> Option<usize> {
unsafe {
@@ -1590,6 +1590,35 @@ pub fn get_license_from_exe_name() -> ResultType<CustomServer> {
get_custom_server_from_string(&exe)
}
pub fn check_update_printer_option() {
if !is_installed() {
return;
}
let app_name = crate::get_app_name();
if let Ok(b) = remote_printer::is_rd_printer_installed(&app_name) {
let v = if b { "1" } else { "0" };
if let Err(e) = update_install_option(REG_NAME_INSTALL_PRINTER, v) {
log::error!(
"Failed to update printer option \"{}\" to \"{}\", error: {}",
REG_NAME_INSTALL_PRINTER,
v,
e
);
}
}
}
// We can't directly use `RegKey::set_value` to update the registry value, because it will fail with `ERROR_ACCESS_DENIED`
// So we have to use `run_cmds` to update the registry value.
pub fn update_install_option(k: &str, v: &str) -> ResultType<()> {
let app_name = crate::get_app_name();
let ext = app_name.to_lowercase();
let cmds =
format!("chcp 65001 && reg add HKEY_CLASSES_ROOT\\.{ext} /f /v {k} /t REG_SZ /d \"{v}\"");
run_cmds(cmds, false, "update_install_option")?;
Ok(())
}
#[inline]
pub fn is_win_server() -> bool {
unsafe { is_windows_server() > 0 }