43 lines
1.6 KiB
Rust
43 lines
1.6 KiB
Rust
// file: kb-app-demo-desktop/src/main.rs
|
|
// version: 1
|
|
|
|
//! Binary entry point for the desktop demo application.
|
|
|
|
#![forbid(unsafe_code)]
|
|
#![deny(unreachable_pub)]
|
|
#![warn(missing_docs)]
|
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
|
|
|
use fs2::FileExt; // rust-rules: trait-import
|
|
|
|
/// Starts the single desktop demo application instance.
|
|
#[tokio::main]
|
|
async fn main() -> std::process::ExitCode {
|
|
let mut lock_path = std::env::temp_dir();
|
|
lock_path.push("com_sasedev_kb_app_demo_desktop.lock");
|
|
let lock_file = match std::fs::File::create(&lock_path) {
|
|
std::result::Result::Ok(file) => file,
|
|
std::result::Result::Err(error) => {
|
|
eprintln!("cannot create application lock '{}': {error}", lock_path.display());
|
|
return std::process::ExitCode::FAILURE;
|
|
},
|
|
};
|
|
if let std::result::Result::Err(error) = lock_file.try_lock_exclusive() {
|
|
if error.kind() == std::io::ErrorKind::WouldBlock {
|
|
eprintln!("another kb-app-demo-desktop instance is already running");
|
|
return std::process::ExitCode::FAILURE;
|
|
}
|
|
eprintln!("cannot acquire application lock '{}': {error}", lock_path.display());
|
|
return std::process::ExitCode::FAILURE;
|
|
}
|
|
let _lock_file = lock_file;
|
|
let run_result = kb_app_demo_desktop_lib::run();
|
|
return match run_result {
|
|
std::result::Result::Ok(()) => std::process::ExitCode::SUCCESS,
|
|
std::result::Result::Err(error) => {
|
|
eprintln!("application error: {error}");
|
|
std::process::ExitCode::FAILURE
|
|
},
|
|
};
|
|
}
|