From 5d7c23124c6b5fd794d4d8f84ae613f7f98e6d93 Mon Sep 17 00:00:00 2001 From: Gabriel Vogel Date: Sun, 9 Apr 2023 16:32:54 +0200 Subject: [PATCH 1/2] Reenable send_reply This reverts commit 36fb89b9561e8c3425fea9c455a0f64e9b8cb88a and 76e8c0d8f2216ede6a5b6625e399c75bda8ff506. --- src/browser.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/browser.rs b/src/browser.rs index 7e60ecc..fbfc56c 100644 --- a/src/browser.rs +++ b/src/browser.rs @@ -1,7 +1,7 @@ use serde::Deserialize; use std::io; use std::io::BufReader; -use std::io::Read; +use std::io::{Read, Write}; use crate::error::FF2MpvError; @@ -10,6 +10,10 @@ pub struct FF2MpvMessage { pub url: String, } +pub fn send_reply() -> Result<(), io::Error> { + send_message("ok") +} + pub fn get_mpv_message() -> Result { let message = read_message()?; let ff2mpv_message = serde_json::from_str(&message)?; @@ -28,3 +32,13 @@ fn read_message() -> Result { reader.read_to_string(&mut string)?; Ok(string) } + +fn send_message(message: &str) -> Result<(), io::Error> { + let length = (message.len() as u32).to_ne_bytes(); + let message = message.as_bytes(); + + let mut stdout = io::stdout(); + stdout.write_all(&length)?; + stdout.write_all(message)?; + Ok(()) +} From 3c9db73c544cedc2d01bea905d44a5cf78b12e86 Mon Sep 17 00:00:00 2001 From: Gabriel Vogel Date: Sun, 9 Apr 2023 16:50:42 +0200 Subject: [PATCH 2/2] Send correct reply and suppress mpv output This prevents errors in the browser log --- src/browser.rs | 3 ++- src/command.rs | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/browser.rs b/src/browser.rs index fbfc56c..c69dfc6 100644 --- a/src/browser.rs +++ b/src/browser.rs @@ -11,7 +11,8 @@ pub struct FF2MpvMessage { } pub fn send_reply() -> Result<(), io::Error> { - send_message("ok") + // "ok" formatted as a JSON string + send_message("\"ok\"") } pub fn get_mpv_message() -> Result { diff --git a/src/command.rs b/src/command.rs index c255711..042e9ae 100644 --- a/src/command.rs +++ b/src/command.rs @@ -64,12 +64,15 @@ impl Command { let config = Config::build(); let ff2mpv_message = browser::get_mpv_message()?; Command::launch_mpv(config.player_command, config.player_args, &ff2mpv_message.url)?; + browser::send_reply()?; Ok(()) } fn launch_mpv(command: String, args: Vec, url: &str) -> Result<(), io::Error> { process::Command::new(command) + .stdout(process::Stdio::null()) + .stderr(process::Stdio::null()) .args(args) .arg(url) .spawn()?;