fix(cli): open resp sock before sending query

This commit ensures that a response socket is opened before sending a
query request from komorebic to komorebi. Additionally, I have taken
this opportunity to ensure that all socket files are created in
DATA_DIR.

fix #218
This commit is contained in:
LGUG2Z
2022-09-18 08:30:00 -07:00
parent 0903be7931
commit 33520a46b5
2 changed files with 13 additions and 11 deletions

View File

@@ -1106,7 +1106,7 @@ fn main() -> Result<()> {
)?;
}
SubCommand::State => {
let home = HOME_DIR.clone();
let home = DATA_DIR.clone();
let mut socket = home;
socket.push("komorebic.sock");
let socket = socket.as_path();
@@ -1122,9 +1122,10 @@ fn main() -> Result<()> {
},
};
let listener = UnixListener::bind(&socket)?;
send_message(&SocketMessage::State.as_bytes()?)?;
let listener = UnixListener::bind(&socket)?;
match listener.accept() {
Ok(incoming) => {
let stream = BufReader::new(incoming.0);
@@ -1140,7 +1141,7 @@ fn main() -> Result<()> {
}
}
SubCommand::Query(arg) => {
let home = HOME_DIR.clone();
let home = DATA_DIR.clone();
let mut socket = home;
socket.push("komorebic.sock");
let socket = socket.as_path();
@@ -1156,9 +1157,10 @@ fn main() -> Result<()> {
},
};
let listener = UnixListener::bind(&socket)?;
send_message(&SocketMessage::Query(arg.state_query).as_bytes()?)?;
let listener = UnixListener::bind(&socket)?;
match listener.accept() {
Ok(incoming) => {
let stream = BufReader::new(incoming.0);
@@ -1342,7 +1344,7 @@ fn main() -> Result<()> {
println!("File successfully formatted for PRs to https://github.com/LGUG2Z/komorebi-application-specific-configuration");
}
SubCommand::NotificationSchema => {
let home = HOME_DIR.clone();
let home = DATA_DIR.clone();
let mut socket = home;
socket.push("komorebic.sock");
let socket = socket.as_path();
@@ -1376,7 +1378,7 @@ fn main() -> Result<()> {
}
}
SubCommand::SocketSchema => {
let home = HOME_DIR.clone();
let home = DATA_DIR.clone();
let mut socket = home;
socket.push("komorebic.sock");
let socket = socket.as_path();