From 5cc480ba4e3790b66efeff8816c8cd2e24e8b508 Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sat, 1 Feb 2025 11:39:08 -0500 Subject: [PATCH] fix: ensure single_instance works https://github.com/WLBF/single-instance#ensuring-the-singleinstance-stays-during-lifetime-of-the-process --- src/ui/single_instance.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/ui/single_instance.rs b/src/ui/single_instance.rs index 31a8b42..640fdb2 100644 --- a/src/ui/single_instance.rs +++ b/src/ui/single_instance.rs @@ -3,16 +3,19 @@ use single_instance::SingleInstance; use std::process; pub fn single_instance() { - let instance = SingleInstance::new("hyprdim").unwrap(); + let instance = Box::new(SingleInstance::new("hyprdim").unwrap()); - // Don't allow more than one hyprdim instance to run - if !instance.is_single() { - println!( - "hyprdim is already running. Use `killall hyprdim` to stop any existing processes." - ); + if instance.is_single() { + Box::leak(instance); - process::exit(1); - }; + log("hyprdim is now running."); - log("hyprdim is now running."); + return; + } + + println!( + "hyprdim is already running. Use `killall hyprdim` to stop any existing processes." + ); + + process::exit(1); }