add option to hide stop-service when service is running (#14563)

* add option to hide stop-service when service is running

Signed-off-by: 21pages <sunboeasy@gmail.com>

* update hbb_common to upstream

Signed-off-by: 21pages <sunboeasy@gmail.com>

---------

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages
2026-03-19 20:04:10 +08:00
committed by GitHub
parent c0da4a6645
commit c457b0e7d3
9 changed files with 87 additions and 36 deletions

View File

@@ -3049,6 +3049,22 @@ pub mod server_side {
return env.new_string(res).unwrap_or_default().into_raw();
}
#[no_mangle]
pub unsafe extern "system" fn Java_ffi_FFI_getBuildinOption(
env: JNIEnv,
_class: JClass,
key: JString,
) -> jstring {
let mut env = env;
let res = if let Ok(key) = env.get_string(&key) {
let key: String = key.into();
super::get_builtin_option(&key)
} else {
"".into()
};
return env.new_string(res).unwrap_or_default().into_raw();
}
#[no_mangle]
pub unsafe extern "system" fn Java_ffi_FFI_isServiceClipboardEnabled(
env: JNIEnv,

View File

@@ -54,9 +54,22 @@ fn make_tray() -> hbb_common::ResultType<()> {
let mut event_loop = EventLoopBuilder::new().build();
let tray_menu = Menu::new();
let quit_i = MenuItem::new(translate("Stop service".to_owned()), true, None);
let hide_stop_service = crate::ui_interface::get_builtin_option(
hbb_common::config::keys::OPTION_HIDE_STOP_SERVICE,
) == "Y";
// The tray icon is only shown when the service is running, so we don't need to check
// the `stop-service` option here.
let quit_i = if !hide_stop_service {
Some(MenuItem::new(translate("Stop service".to_owned()), true, None))
} else {
None
};
let open_i = MenuItem::new(translate("Open".to_owned()), true, None);
tray_menu.append_items(&[&open_i, &quit_i]).ok();
if let Some(quit_i) = &quit_i {
tray_menu.append_items(&[&open_i, quit_i]).ok();
} else {
tray_menu.append_items(&[&open_i]).ok();
}
let tooltip = |count: usize| {
if count == 0 {
format!(
@@ -155,15 +168,19 @@ fn make_tray() -> hbb_common::ResultType<()> {
}
if let Ok(event) = menu_channel.try_recv() {
if event.id == quit_i.id() {
/* failed in windows, seems no permission to check system process
if !crate::check_process("--server", false) {
*control_flow = ControlFlow::Exit;
return;
}
*/
if !crate::platform::uninstall_service(false, false) {
*control_flow = ControlFlow::Exit;
if let Some(quit_i) = &quit_i {
if event.id == quit_i.id() {
/* failed in windows, seems no permission to check system process
if !crate::check_process("--server", false) {
*control_flow = ControlFlow::Exit;
return;
}
*/
if !crate::platform::uninstall_service(false, false) {
*control_flow = ControlFlow::Exit;
}
} else if event.id == open_i.id() {
open_func();
}
} else if event.id == open_i.id() {
open_func();

View File

@@ -16,6 +16,7 @@ const disable_ab = handler.is_disable_ab();
const hide_server_settings = handler.get_builtin_option("hide-server-settings") == "Y";
const hide_proxy_settings = handler.get_builtin_option("hide-proxy-settings") == "Y";
const hide_websocket_settings = handler.get_builtin_option("hide-websocket-settings") == "Y";
const hide_stop_service = handler.get_builtin_option("hide-stop-service") == "Y";
const disable_change_permanent_password = handler.get_builtin_option("disable-change-permanent-password") == "Y";
const disable_change_id = handler.get_builtin_option("disable-change-id") == "Y";
@@ -532,7 +533,7 @@ class MyIdMenu: Reactor.Component {
{!disable_settings && !using_public_server && !outgoing_only && <li #disable-udp class={disable_udp ? "selected" : "line-through"}><span>{svg_checkmark}</span>{translate('Disable UDP')}</li>}
{!disable_settings && !using_public_server && <li #allow-insecure-tls-fallback><span>{svg_checkmark}</span>{translate('Allow insecure TLS fallback')}</li>}
<div .separator />
<li #stop-service class={service_stopped ? "line-through" : "selected"}><span>{svg_checkmark}</span>{translate("Enable service")}</li>
{(!hide_stop_service || service_stopped) && <li #stop-service class={service_stopped ? "line-through" : "selected"}><span>{svg_checkmark}</span>{translate("Enable service")}</li>}
{!disable_settings && is_win && handler.is_installed() ? <ShareRdp /> : ""}
{!disable_settings && <DirectServer />}
{!disable_settings && false && handler.using_public_server() && <li #allow-always-relay><span>{svg_checkmark}</span>{translate('Always connect via relay')}</li>}