1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-04-19 19:34:24 +02:00

fix: bars duplicate when starting second instance

This ensures that starting `ironbar` while an instance already running causes the 2nd instance to cleanly exit, and avoids launching the init code a second time.
This commit is contained in:
Jake Stanger 2023-04-30 19:43:58 +01:00
parent 0e3102de8c
commit 14b6c1a69f
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61

View file

@ -24,10 +24,12 @@ use dirs::config_dir;
use gtk::gdk::Display;
use gtk::prelude::*;
use gtk::Application;
use std::cell::Cell;
use std::env;
use std::future::Future;
use std::path::PathBuf;
use std::process::exit;
use std::rc::Rc;
use tokio::runtime::Handle;
use tokio::task::block_in_place;
@ -40,7 +42,7 @@ const GTK_APP_ID: &str = "dev.jstanger.ironbar";
const VERSION: &str = env!("CARGO_PKG_VERSION");
#[tokio::main]
async fn main() -> Result<()> {
async fn main() {
let _guard = logging::install_logging();
info!("Ironbar version {}", VERSION);
@ -50,7 +52,16 @@ async fn main() -> Result<()> {
let app = Application::builder().application_id(GTK_APP_ID).build();
let running = Rc::new(Cell::new(false));
app.connect_activate(move |app| {
if running.get() {
info!("Ironbar already running, returning");
return;
}
running.set(true);
let display = Display::default().map_or_else(
|| {
let report = Report::msg("Failed to get default GTK display");
@ -105,7 +116,8 @@ async fn main() -> Result<()> {
// Some are provided by swaybar_config but not currently supported
app.run_with_args(&Vec::<&str>::new());
Ok(())
info!("Shutting down");
exit(0);
}
/// Creates each of the bars across each of the (configured) outputs.