From b3eb220359df52a0ec8481bb94d74c0b39d409b2 Mon Sep 17 00:00:00 2001 From: lif <> Date: Sun, 12 Nov 2023 02:53:51 -0800 Subject: [PATCH] fmt and mpv conf --- src/bin/main.rs | 31 ++++++++++++++++++++----------- src/bin/matrix.rs | 47 ++++++++++++++++++++++++++++------------------- 2 files changed, 48 insertions(+), 30 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index 6cc2e63..b48140f 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -1,8 +1,8 @@ -use std::process::Stdio; use futures::StreamExt; -use tokio::io::{AsyncRead, AsyncBufReadExt, BufReader}; -use tokio::process::Command; use libmpv::{FileState, Mpv}; +use std::process::Stdio; +use tokio::io::{AsyncBufReadExt, AsyncRead, BufReader}; +use tokio::process::Command; use tokio_stream::wrappers::LinesStream; #[tokio::main] @@ -10,23 +10,32 @@ async fn main() -> Result<(), Box> { let args: Vec = std::env::args().skip(1).collect(); let mut subprocs: Vec<_> = args .iter() - .map(|arg| Command::new(arg) - .stdout(Stdio::piped()) - .spawn() - .unwrap_or_else(|e| panic!("couldn't spawn {arg}: {e:?}"))) + .map(|arg| { + Command::new(arg) + .stdout(Stdio::piped()) + .spawn() + .unwrap_or_else(|e| panic!("couldn't spawn {arg}: {e:?}")) + }) .collect(); let stdin_box: Box = Box::new(tokio::io::stdin()); - let mut combined = futures::stream::select_all(Some(LinesStream::new(BufReader::new(stdin_box).lines()))); + let mut combined = + futures::stream::select_all(Some(LinesStream::new(BufReader::new(stdin_box).lines()))); for subproc in &mut subprocs { let stdout_box: Box = Box::new(subproc.stdout.take().unwrap()); combined.push(LinesStream::new(BufReader::new(stdout_box).lines())); } let mpv = Mpv::new().expect("couldn't create mpv"); - while let Some(Ok(line)) = combined.next().await { - mpv.playlist_load_files(&[(&line, FileState::AppendPlay, None)]).expect("couldn't load path"); - } + #[allow(deprecated)] + let home = std::env::home_dir().unwrap(); + mpv.load_config(home.join(".config/mpv/mpv.conf").to_str().unwrap()) + .unwrap(); + + while let Some(Ok(line)) = combined.next().await { + mpv.playlist_load_files(&[(&line, FileState::AppendPlay, None)]) + .expect("couldn't load path"); + } Ok(()) } diff --git a/src/bin/matrix.rs b/src/bin/matrix.rs index b619438..3a860ca 100644 --- a/src/bin/matrix.rs +++ b/src/bin/matrix.rs @@ -1,20 +1,21 @@ -use std::io::Write; -use std::path::PathBuf; -use serde::{Deserialize, Serialize}; -use matrix_sdk::{Client, config::SyncSettings, ruma::{ - OwnedRoomId, OwnedUserId, - events::room::message::SyncRoomMessageEvent -}, Session}; use matrix_sdk::ruma::api::client::filter::{FilterDefinition, RoomFilter}; use matrix_sdk::ruma::api::client::sync::sync_events::v3::Filter; use matrix_sdk::ruma::api::client::uiaa; +use matrix_sdk::{ + config::SyncSettings, + ruma::{events::room::message::SyncRoomMessageEvent, OwnedRoomId, OwnedUserId}, + Client, Session, +}; +use serde::{Deserialize, Serialize}; +use std::io::Write; +use std::path::PathBuf; #[derive(Serialize, Deserialize)] struct Config { user: OwnedUserId, room: OwnedRoomId, password: Option, - session: Option + session: Option, } impl Config { @@ -25,10 +26,9 @@ impl Config { } fn read() -> Self { let path = Self::path(); - let f = std::fs::File::open(&path) - .unwrap_or_else(|e| panic!("couldn't read {path:?}: {e:?}")); - serde_json::from_reader(f) - .unwrap_or_else(|e| panic!("couldn't load config: {e:?}")) + let f = + std::fs::File::open(&path).unwrap_or_else(|e| panic!("couldn't read {path:?}: {e:?}")); + serde_json::from_reader(f).unwrap_or_else(|e| panic!("couldn't load config: {e:?}")) } fn write(&self) { let json = serde_json::to_string_pretty(self).unwrap(); @@ -73,19 +73,30 @@ async fn main() -> Result<(), Box> { .send() .await?; logged_in = true; - let devices_to_delete: Vec<_> = client.devices() + let devices_to_delete: Vec<_> = client + .devices() .await .unwrap() .devices .into_iter() - .filter(|d| d.display_name.clone().unwrap_or_default().as_str() == "tubest" && d.device_id != client.device_id().unwrap()) + .filter(|d| { + d.display_name.clone().unwrap_or_default().as_str() == "tubest" + && d.device_id != client.device_id().unwrap() + }) .map(|d| d.device_id) .collect(); if let Err(e) = client.delete_devices(&devices_to_delete, None).await { if let Some(info) = e.uiaa_response() { - let mut password = uiaa::Password::new(uiaa::UserIdentifier::UserIdOrLocalpart(cfg.user.localpart()), password); + let mut password = uiaa::Password::new( + uiaa::UserIdentifier::UserIdOrLocalpart(cfg.user.localpart()), + password, + ); password.session = info.session.as_deref(); - client.delete_devices(&devices_to_delete, Some(uiaa::AuthData::Password(password))) + client + .delete_devices( + &devices_to_delete, + Some(uiaa::AuthData::Password(password)), + ) .await?; } } @@ -97,7 +108,6 @@ async fn main() -> Result<(), Box> { cfg.write(); } - client.add_room_event_handler(cfg.room.as_ref(), |ev: SyncRoomMessageEvent| async { match ev { SyncRoomMessageEvent::Original(orig) => { @@ -118,8 +128,7 @@ async fn main() -> Result<(), Box> { room_filter.rooms = Some(&room_list); filter_def.room = room_filter; client - .sync(SyncSettings::default() - .filter(Filter::FilterDefinition(filter_def))) + .sync(SyncSettings::default().filter(Filter::FilterDefinition(filter_def))) .await?; Ok(())