fufesou
2022-12-29 14:28:15 +08:00
parent 1651cef4f3
commit 01ade73304
5 changed files with 20 additions and 11 deletions

View File

@@ -1,3 +1,4 @@
#[cfg(any(target_os = "linux", target_os = "windows"))]
use super::ui_interface::get_option_opt;
#[cfg(target_os = "linux")]
use hbb_common::log::{debug, error, info};
@@ -44,7 +45,7 @@ pub fn start_tray() {
} else {
*control_flow = ControlFlow::Wait;
}
let stopped = is_service_stoped();
let stopped = is_service_stopped();
let state = if stopped { 2 } else { 1 };
let old = *old_state.lock().unwrap();
if state != old {
@@ -101,7 +102,7 @@ pub fn start_tray() {
}
if let Some(mut appindicator) = get_default_app_indicator() {
let mut menu = gtk::Menu::new();
let stoped = is_service_stoped();
let stoped = is_service_stopped();
// start/stop service
let label = if stoped {
crate::client::translate("Start Service".to_owned())
@@ -137,7 +138,7 @@ pub fn start_tray() {
#[cfg(target_os = "linux")]
fn change_service_state() {
if is_service_stoped() {
if is_service_stopped() {
debug!("Now try to start service");
crate::ipc::set_option("stop-service", "");
} else {
@@ -151,7 +152,7 @@ fn change_service_state() {
fn update_tray_service_item(item: &gtk::MenuItem) {
use gtk::traits::GtkMenuItemExt;
if is_service_stoped() {
if is_service_stopped() {
item.set_label(&crate::client::translate("Start Service".to_owned()));
} else {
item.set_label(&crate::client::translate("Stop service".to_owned()));
@@ -194,7 +195,8 @@ fn get_default_app_indicator() -> Option<AppIndicator> {
/// Check if service is stoped.
/// Return [`true`] if service is stoped, [`false`] otherwise.
#[inline]
fn is_service_stoped() -> bool {
#[cfg(any(target_os = "linux", target_os = "windows"))]
fn is_service_stopped() -> bool {
if let Some(v) = get_option_opt("stop-service") {
v == "Y"
} else {