Skip to content

Commit

Permalink
Added support for only launching a single instance
Browse files Browse the repository at this point in the history
Since it probably defeats the purpose to be running multiple pomodoro
timers, I've added support to only launch one instance of the program.
This resolves Issue #43
  • Loading branch information
Vadoola committed Dec 12, 2023
1 parent e6cce1c commit 073838d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ hex_color = { version = "2.1.0", features = [ "serde" ] }
walkdir = "2.4"
etcetera = "0.8.0"
directories = "5.0.1"
single-instance = "0.3.3"


[target.'cfg(windows)'.dependencies]
Expand Down
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use hex_color::HexColor;
use serde::{Deserialize, Serialize};
use serde_json::json;
use settings::{GlobalShortcuts, JsonSettings};
use single_instance::SingleInstance;
use slint::{Color, ModelRc, Timer, TimerMode, VecModel};
use std::{
fs::File,
Expand Down Expand Up @@ -243,6 +244,12 @@ impl Main {
}

fn main() -> Result<()> {
let instance = SingleInstance::new("org.vadoola.tomotroid").unwrap();
assert!(instance.is_single());
if !instance.is_single() {
return Err(anyhow::anyhow!("Only one instance of Tomotroid is allowed to run"));
}

//TODO: I'm not seeing an obvious way to mimic the Pomotroid behavoir
//where it just minimizes or restores by clicking the tray icon
//because I don't see any way to capture when the tray icon is clicked
Expand Down

0 comments on commit 073838d

Please sign in to comment.