From: Greg Burri Date: Tue, 19 Sep 2023 14:47:24 +0000 (+0200) Subject: Cargo fmt X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=52520a2f096921aa4e26818c669dc5fdf01c0528;p=temp2RGB.git Cargo fmt --- diff --git a/src/main.rs b/src/main.rs index 5f6e55a..29a9343 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use std::{ }; use anyhow::Result; -use log::{error, info, trace, warn, debug}; +use log::{debug, error, info, trace, warn}; use windows::Win32::Foundation::{ERROR_SERVICE_DOES_NOT_EXIST, WIN32_ERROR}; use windows_service::{ service::{ @@ -65,7 +65,11 @@ fn main() -> Result<()> { .basename(consts::SERVICE_NAME), ) .duplicate_to_stdout(flexi_logger::Duplicate::All) - .format(if is_debug { flexi_logger::default_format } else { flexi_logger::detailed_format }) + .format(if is_debug { + flexi_logger::default_format + } else { + flexi_logger::detailed_format + }) .rotate( flexi_logger::Criterion::Size(1024 * 1024), flexi_logger::Naming::Timestamps, @@ -168,7 +172,7 @@ fn uninstall_service() -> windows_service::Result<()> { fn service_main(arguments: Vec) { if let Err(error) = run_service(arguments) { - println!("Error: {error}"); + error!("{error}"); } } @@ -176,6 +180,9 @@ fn run_service(_arguments: Vec) -> Result<(), windows_service::Error> let completed: Arc = Arc::new(AtomicBool::new(false)); let completed_event_handler = Arc::clone(&completed); + + info!("Setuping the event handler..."); + let event_handler = move |control_event| -> ServiceControlHandlerResult { match control_event { ServiceControl::Stop => { @@ -204,29 +211,15 @@ fn run_service(_arguments: Vec) -> Result<(), windows_service::Error> // Register system service event handler let status_handle = service_control_handler::register(consts::SERVICE_NAME, event_handler)?; - let running_status = ServiceStatus { - // Should match the one from system service registry + status_handle.set_service_status(ServiceStatus { service_type: ServiceType::OWN_PROCESS, - - // The new state current_state: ServiceState::Running, - - // Accept stop events when running controls_accepted: ServiceControlAccept::STOP | ServiceControlAccept::SHUTDOWN, - - // Used to report an error when starting or stopping only, otherwise must be zero exit_code: ServiceExitCode::Win32(0), - - // Only used for pending states, otherwise must be zero checkpoint: 0, - - // Only used for pending states, otherwise must be zero wait_hint: Duration::default(), - - process_id: None, - }; - - status_handle.set_service_status(running_status)?; + process_id: None, //Some(std::process::id()), + })?; main_loop::main_loop(completed.clone()); @@ -237,7 +230,7 @@ fn run_service(_arguments: Vec) -> Result<(), windows_service::Error> exit_code: ServiceExitCode::Win32(0), checkpoint: 0, wait_hint: Duration::default(), - process_id: None, + process_id: None, //Some(std::process::id()), })?; info!("Main loop stopped: Temperature to RGB will now shut down");