save lock file in XDG_CONFIG_DIR

This commit is contained in:
tho
2020-11-15 05:34:34 -08:00
parent 73c12cdcba
commit c901d00e36
3 changed files with 11 additions and 1 deletions

7
Cargo.lock generated
View File

@ -187,6 +187,7 @@ version = "0.2.4"
dependencies = [
"single-instance",
"swayipc",
"xdg",
]
[[package]]
@ -245,3 +246,9 @@ name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "xdg"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57"

View File

@ -9,6 +9,7 @@ edition = "2018"
[dependencies]
swayipc = {version = "2.7.0", features = [ "event_stream"]}
single-instance = "0.1.2"
xdg = "*"
[packaging]
depends = ["sway"]

View File

@ -16,7 +16,9 @@ fn get_input_id(c: &mut Connection) -> Vec<String> {
}
fn main() -> Fallible<()> {
let instance_a = single_instance::SingleInstance::new("swkb").unwrap();
let xdg_dirs = xdg::BaseDirectories::new().unwrap();
let file = xdg_dirs.place_config_file("swkb.lock").unwrap();
let instance_a = single_instance::SingleInstance::new(file.to_str().unwrap()).unwrap();
if !instance_a.is_single() {
println!("only one instance of swkb at a time is allowed");
std::process::exit(1);