Respect options passed by ff2mpv extension (#12)

* Respect options passed by ff2mpv extension

The upstream ff2mpv extension started passing `options`. Respect
those by passing them after our `config.player_args`.

* Restore the order of imports

---------

Co-authored-by: Ryze <50497128+ryze312@users.noreply.github.com>
This commit is contained in:
eNV25 2024-02-16 08:33:12 +00:00 committed by GitHub
parent a971c7c35b
commit ce98b95008
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View file

@ -8,6 +8,7 @@ use crate::error::FF2MpvError;
#[derive(Deserialize)]
pub struct FF2MpvMessage {
pub url: String,
pub options: Vec<String>,
}
pub fn send_reply() -> Result<(), io::Error> {

View file

@ -12,10 +12,9 @@ pub enum Command {
ShowManifest,
ShowManifestChromium,
ValidateConfig,
FF2Mpv
FF2Mpv,
}
impl Command {
pub fn execute(&self) -> Result<(), FF2MpvError> {
match self {
@ -23,7 +22,7 @@ impl Command {
Command::ShowManifest => Self::show_manifest(false),
Command::ShowManifestChromium => Self::show_manifest(true),
Command::ValidateConfig => Self::validate_config(),
Command::FF2Mpv => Self::ff2mpv()
Command::FF2Mpv => Self::ff2mpv(),
}
}
@ -43,7 +42,10 @@ impl Command {
fn show_manifest(chromium: bool) -> Result<(), FF2MpvError> {
let executable_path = env::current_exe()?;
let allowed_keyvalue = if chromium {
("allowed_origins", "chrome-extension://ephjcajbkgplkjmelpglennepbpmdpjg")
(
"allowed_origins",
"chrome-extension://ephjcajbkgplkjmelpglennepbpmdpjg",
)
} else {
("allowed_extensions", "ff2mpv@yossarian.net")
};
@ -72,7 +74,8 @@ impl Command {
fn ff2mpv() -> Result<(), FF2MpvError> {
let config = Config::build();
let ff2mpv_message = browser::get_mpv_message()?;
Command::launch_mpv(config.player_command, config.player_args, &ff2mpv_message.url)?;
let args = [config.player_args, ff2mpv_message.options].concat();
Command::launch_mpv(config.player_command, args, &ff2mpv_message.url)?;
browser::send_reply()?;
Ok(())