fmt and mpv conf
This commit is contained in:
parent
473b98b0f3
commit
b3eb220359
|
@ -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<dyn std::error::Error + Send + Sync>> {
|
|||
let args: Vec<String> = 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<dyn AsyncRead + Unpin> = 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<dyn AsyncRead + Unpin> = 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(())
|
||||
}
|
||||
|
|
|
@ -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<String>,
|
||||
session: Option<Session>
|
||||
session: Option<Session>,
|
||||
}
|
||||
|
||||
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<dyn std::error::Error + Send + Sync>> {
|
|||
.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<dyn std::error::Error + Send + Sync>> {
|
|||
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<dyn std::error::Error + Send + Sync>> {
|
|||
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(())
|
||||
|
|
Loading…
Reference in a new issue