From 313ba1170fe3f72bcb308ea4002113ea1fca5143 Mon Sep 17 00:00:00 2001 From: tho Date: Sun, 15 Nov 2020 00:22:04 -0800 Subject: [PATCH] only allow one instance --- Cargo.lock | 44 +++++++++++++++++++++++++++++++++++++++++--- Cargo.toml | 7 +------ src/main.rs | 5 +++++ 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bece4b5..0a5e88f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -157,6 +157,18 @@ dependencies = [ "serde", ] +[[package]] +name = "single-instance" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5cf81b17aaa439345566aff22f4e0c11a50c265f6d5589ab693e40913326385" +dependencies = [ + "failure", + "libc", + "widestring", + "winapi", +] + [[package]] name = "swayipc" version = "2.7.0" @@ -173,9 +185,7 @@ dependencies = [ name = "swkb" version = "0.2.4" dependencies = [ - "failure", - "serde", - "serde_json", + "single-instance", "swayipc", ] @@ -207,3 +217,31 @@ name = "unicode-xid" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "widestring" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7157704c2e12e3d2189c507b7482c52820a16dfa4465ba91add92f266667cadb" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index ed67faf..332af53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,13 +7,8 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -failure = "0.1" swayipc = {version = "2.7.0", features = [ "event_stream"]} - -#[dependencies.swayipc] -#features = ["async", "event_stream"] +single-instance = "0.1.2" [packaging] depends = ["sway"] diff --git a/src/main.rs b/src/main.rs index 7b24dbb..0cd4836 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,11 @@ fn get_input_id(c: &mut Connection) -> Vec { } fn main() -> Fallible<()> { + let instance_a = single_instance::SingleInstance::new("whatever").unwrap(); + if !instance_a.is_single() { + println!("only one instance of swkb at a time is allowed"); + std::process::exit(1); + } let mut connection = Connection::new()?; let inputs = get_input_id(&mut connection); let mut layouts: HashMap = HashMap::new();