Commit 430c601ff2
Unregistered key
Layout: unified · split
src/config.rs +4
| @@ -237,6 +237,7 @@ pub struct TunableValues { | |||
| 237 | pub typing_notice_display: bool, | 237 | pub typing_notice_display: bool, |
| 238 | pub users: UserOverrides, | 238 | pub users: UserOverrides, |
| 239 | pub default_room: Option<String>, | 239 | pub default_room: Option<String>, |
| 240 | pub open_command: Option<Vec<String>>, | ||
| 240 | } | 241 | } |
| 241 | 242 | ||
| 242 | #[derive(Clone, Default, Deserialize)] | 243 | #[derive(Clone, Default, Deserialize)] |
| @@ -251,6 +252,7 @@ pub struct Tunables { | |||
| 251 | pub typing_notice_display: Option<bool>, | 252 | pub typing_notice_display: Option<bool>, |
| 252 | pub users: Option<UserOverrides>, | 253 | pub users: Option<UserOverrides>, |
| 253 | pub default_room: Option<String>, | 254 | pub default_room: Option<String>, |
| 255 | pub open_command: Option<Vec<String>>, | ||
| 254 | } | 256 | } |
| 255 | 257 | ||
| 256 | impl Tunables { | 258 | impl Tunables { |
| @@ -268,6 +270,7 @@ impl Tunables { | |||
| 268 | typing_notice_display: self.typing_notice_display.or(other.typing_notice_display), | 270 | typing_notice_display: self.typing_notice_display.or(other.typing_notice_display), |
| 269 | users: merge_users(self.users, other.users), | 271 | users: merge_users(self.users, other.users), |
| 270 | default_room: self.default_room.or(other.default_room), | 272 | default_room: self.default_room.or(other.default_room), |
| 273 | open_command: self.open_command.or(other.open_command), | ||
| 271 | } | 274 | } |
| 272 | } | 275 | } |
| 273 | 276 | ||
| @@ -283,6 +286,7 @@ impl Tunables { | |||
| 283 | typing_notice_display: self.typing_notice_display.unwrap_or(true), | 286 | typing_notice_display: self.typing_notice_display.unwrap_or(true), |
| 284 | users: self.users.unwrap_or_default(), | 287 | users: self.users.unwrap_or_default(), |
| 285 | default_room: self.default_room, | 288 | default_room: self.default_room, |
| 289 | open_command: self.open_command, | ||
| 286 | } | 290 | } |
| 287 | } | 291 | } |
| 288 | } | 292 | } |
src/tests.rs +1
| @@ -188,6 +188,7 @@ pub fn mock_tunables() -> TunableValues { | |||
| 188 | })] | 188 | })] |
| 189 | .into_iter() | 189 | .into_iter() |
| 190 | .collect::<HashMap<_, _>>(), | 190 | .collect::<HashMap<_, _>>(), |
| 191 | open_command: None, | ||
| 191 | } | 192 | } |
| 192 | } | 193 | } |
| 193 | 194 | ||
src/windows/room/chat.rs +39 −8
| @@ -1,10 +1,11 @@ | |||
| 1 | use std::borrow::Cow; | 1 | use std::borrow::Cow; |
| 2 | use std::ffi::OsStr; | 2 | use std::ffi::{OsStr, OsString}; |
| 3 | use std::fs; | 3 | use std::fs; |
| 4 | use std::ops::Deref; | 4 | use std::ops::Deref; |
| 5 | use std::path::{Path, PathBuf}; | 5 | use std::path::{Path, PathBuf}; |
| 6 | 6 | ||
| 7 | use modalkit::editing::store::RegisterError; | 7 | use modalkit::editing::store::RegisterError; |
| 8 | use std::process::Command; | ||
| 8 | use tokio; | 9 | use tokio; |
| 9 | 10 | ||
| 10 | use matrix_sdk::{ | 11 | use matrix_sdk::{ |
| @@ -246,14 +247,21 @@ impl ChatState { | |||
| 246 | } | 247 | } |
| 247 | 248 | ||
| 248 | let info = if flags.contains(DownloadFlags::OPEN) { | 249 | let info = if flags.contains(DownloadFlags::OPEN) { |
| 249 | // open::that may not return until the spawned program closes. | ||
| 250 | let target = filename.clone().into_os_string(); | 250 | let target = filename.clone().into_os_string(); |
| 251 | tokio::task::spawn_blocking(move || open::that(target)); | 251 | match open_command( |
| 252 | 252 | store.application.settings.tunables.open_command.as_ref(), | |
| 253 | InfoMessage::from(format!( | 253 | target, |
| 254 | "Attachment downloaded to {} and opened", | 254 | ) { |
| 255 | filename.display() | 255 | Ok(_) => { |
| 256 | )) | 256 | InfoMessage::from(format!( |
| 257 | "Attachment downloaded to {} and opened", | ||
| 258 | filename.display() | ||
| 259 | )) | ||
| 260 | }, | ||
| 261 | Err(err) => { | ||
| 262 | return Err(err); | ||
| 263 | }, | ||
| 264 | } | ||
| 257 | } else { | 265 | } else { |
| 258 | InfoMessage::from(format!( | 266 | InfoMessage::from(format!( |
| 259 | "Attachment downloaded to {}", | 267 | "Attachment downloaded to {}", |
| @@ -844,3 +852,26 @@ impl<'a> StatefulWidget for Chat<'a> { | |||
| 844 | scrollback.render(scrollarea, buf, &mut state.scrollback); | 852 | scrollback.render(scrollarea, buf, &mut state.scrollback); |
| 845 | } | 853 | } |
| 846 | } | 854 | } |
| 855 | |||
| 856 | fn open_command(open_command: Option<&Vec<String>>, target: OsString) -> IambResult<()> { | ||
| 857 | if let Some(mut cmd) = open_command.and_then(cmd) { | ||
| 858 | cmd.arg(target); | ||
| 859 | cmd.spawn()?; | ||
| 860 | return Ok(()); | ||
| 861 | } else { | ||
| 862 | // open::that may not return until the spawned program closes. | ||
| 863 | tokio::task::spawn_blocking(move || { | ||
| 864 | return open::that(target); | ||
| 865 | }); | ||
| 866 | return Ok(()); | ||
| 867 | } | ||
| 868 | } | ||
| 869 | |||
| 870 | fn cmd(open_command: &Vec<String>) -> Option<Command> { | ||
| 871 | if let [program, args @ ..] = open_command.as_slice() { | ||
| 872 | let mut cmd = Command::new(program); | ||
| 873 | cmd.args(args); | ||
| 874 | return Some(cmd); | ||
| 875 | } | ||
| 876 | None | ||
| 877 | } | ||