Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/core_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,28 @@ pub fn core_main() -> Option<Vec<String>> {
crate::virtual_display_manager::amyuni_idd::uninstall_driver()
);
return None;
} else if args[0] == "--install-remote-printer" {
#[cfg(windows)]
if crate::platform::is_win_10_or_greater() {
match remote_printer::install_update_printer(&crate::get_app_name()) {
Ok(_) => {
log::info!("Remote printer installed/updated successfully");
}
Err(e) => {
log::error!("Failed to install/update the remote printer: {}", e);
}
}
} else {
log::error!("Win10 or greater required!");
}
return None;
} else if args[0] == "--uninstall-remote-printer" {
#[cfg(windows)]
if crate::platform::is_win_10_or_greater() {
remote_printer::uninstall_printer(&crate::get_app_name());
log::info!("Remote printer uninstalled");
}
return None;
}
}
#[cfg(target_os = "macos")]
Expand Down
38 changes: 15 additions & 23 deletions src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,16 @@ copy /Y \"{tmp_path}\\{app_name} Tray.lnk\" \"%PROGRAMDATA%\\Microsoft\\Windows\
")
};

let install_remote_printer = if install_printer {
// No need to use `|| true` here.
// The script will not exit even if `--install-remote-printer` panics.
format!("\"{}\" --install-remote-printer", &src_exe)
} else if crate::platform::is_win_10_or_greater() {
format!("\"{}\" --uninstall-remote-printer", &src_exe)
} else {
"".to_owned()
};

// Remember to check if `update_me` need to be changed if changing the `cmds`.
// No need to merge the existing dup code, because the code in these two functions are too critical.
// New code should be written in a common function.
Expand Down Expand Up @@ -1418,6 +1428,7 @@ cscript \"{uninstall_shortcut}\"
{tray_shortcuts}
{shortcuts}
copy /Y \"{tmp_path}\\Uninstall {app_name}.lnk\" \"{path}\\\"
{install_remote_printer}
{dels}
{import_config}
{after_install}
Expand All @@ -1437,11 +1448,6 @@ copy /Y \"{tmp_path}\\Uninstall {app_name}.lnk\" \"{path}\\\"
import_config = get_import_config(&exe),
);
run_cmds(cmds, debug, "install")?;
if install_printer {
allow_err!(remote_printer::install_update_printer(
&crate::get_app_name()
));
}
run_after_run_cmds(silent);
Ok(())
}
Expand Down Expand Up @@ -1658,27 +1664,13 @@ 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<()> {
// Don't update registry if not installed or not server process.
if !is_installed() || !crate::is_server() {
return Ok(());
}
let app_name = crate::get_app_name();
let ext = app_name.to_lowercase();
let cmds =
Expand Down
2 changes: 1 addition & 1 deletion src/rendezvous_mediator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl RendezvousMediator {
}
crate::hbbs_http::sync::start();
#[cfg(target_os = "windows")]
if crate::platform::is_installed() && !crate::is_custom_client() {
if crate::platform::is_installed() && crate::is_server() && !crate::is_custom_client() {
crate::updater::start_auto_update();
}
check_zombie();
Expand Down
2 changes: 0 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,6 @@ pub async fn start_server(is_server: bool, no_server: bool) {
crate::platform::try_kill_broker();
#[cfg(feature = "hwcodec")]
scrap::hwcodec::start_check_process();
#[cfg(target_os = "windows")]
crate::platform::check_update_printer_option();
crate::RendezvousMediator::start_all().await;
} else {
match crate::ipc::connect(1000, "").await {
Expand Down
Loading