Skip to content

Commit

Permalink
fix(cli): open resp sock before sending query
Browse files Browse the repository at this point in the history
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
  • Loading branch information
LGUG2Z committed Sep 18, 2022
1 parent 0903be7 commit 33520a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 5 additions & 5 deletions komorebi/src/process_command.rs
Expand Up @@ -49,9 +49,9 @@ use crate::BORDER_ENABLED;
use crate::BORDER_HWND;
use crate::BORDER_OVERFLOW_IDENTIFIERS;
use crate::CUSTOM_FFM;
use crate::DATA_DIR;
use crate::FLOAT_IDENTIFIERS;
use crate::HIDING_BEHAVIOUR;
use crate::HOME_DIR;
use crate::INITIAL_CONFIGURATION_LOADED;
use crate::LAYERED_WHITELIST;
use crate::MANAGE_IDENTIFIERS;
Expand Down Expand Up @@ -416,7 +416,7 @@ impl WindowManager {
Err(error) => error.to_string(),
};

let mut socket = HOME_DIR.clone();
let mut socket = DATA_DIR.clone();
socket.push("komorebic.sock");
let socket = socket.as_path();

Expand All @@ -439,7 +439,7 @@ impl WindowManager {
}
.to_string();

let mut socket = HOME_DIR.clone();
let mut socket = DATA_DIR.clone();
socket.push("komorebic.sock");
let socket = socket.as_path();

Expand Down Expand Up @@ -831,7 +831,7 @@ impl WindowManager {
SocketMessage::NotificationSchema => {
let notification = schema_for!(Notification);
let schema = serde_json::to_string_pretty(&notification)?;
let mut socket = HOME_DIR.clone();
let mut socket = DATA_DIR.clone();
socket.push("komorebic.sock");
let socket = socket.as_path();

Expand All @@ -841,7 +841,7 @@ impl WindowManager {
SocketMessage::SocketSchema => {
let socket_message = schema_for!(SocketMessage);
let schema = serde_json::to_string_pretty(&socket_message)?;
let mut socket = HOME_DIR.clone();
let mut socket = DATA_DIR.clone();
socket.push("komorebic.sock");
let socket = socket.as_path();

Expand Down
14 changes: 8 additions & 6 deletions komorebic/src/main.rs
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 33520a4

Please sign in to comment.