Commit d75abde232
Unregistered key
Layout: unified · split
docs/iamb.5 +11 −1
| @@ -224,9 +224,19 @@ See | ||
| 224 | 224 | .Sx NOTIFICATIONS |
| 225 | 225 | for more details. |
| 226 | 226 | .It Sy open_command |
| 227 | Defines a custom command and its arguments to run when opening downloads instead of the default. | |
| 227 | Defines a custom command and its arguments to run when handling | |
| 228 | .Sy :open | |
| 229 | instead of the default system behaviour. | |
| 228 | 230 | (For example, |
| 229 | 231 | .Sy ["my-open",\ "--file"] . ) |
| 232 | Keep in mind that | |
| 233 | .Sy :open | |
| 234 | can be used for more than just opening downloads: | |
| 235 | this command may also be passed | |
| 236 | .Sy http[s]:// | |
| 237 | and | |
| 238 | .Sy geo: | |
| 239 | URLs for relevant messages. | |
| 230 | 240 | .It Sy proxy |
| 231 | 241 | When this subsection is present, you can configure how requests are proxied to the homeserver. |
| 232 | 242 | See |
src/windows/room/chat.rs +44
| @@ -160,6 +160,25 @@ impl ChatState { | ||
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | if let Some(msgtype) = msg.event.msgtype() { |
| 163 | // A location message has no attachment to download, so `:open` | |
| 164 | // hands its `geo:` URI over to the system handler, which will | |
| 165 | // let the desktop open it with an application of its choosing. | |
| 166 | if let Some(geo_uri) = location_geo_uri(msgtype) { | |
| 167 | if !flags.contains(DownloadFlags::OPEN) { | |
| 168 | return Err(IambError::NoAttachment.into()); | |
| 169 | } | |
| 170 | ||
| 171 | let target = OsString::from(geo_uri.to_owned()); | |
| 172 | ||
| 173 | return match open_command( | |
| 174 | store.application.settings.tunables.open_command.as_ref(), | |
| 175 | target, | |
| 176 | ) { | |
| 177 | Ok(_) => Ok(InfoMessage::from(format!("Opened {geo_uri}")).into()), | |
| 178 | Err(err) => Err(err), | |
| 179 | }; | |
| 180 | } | |
| 181 | ||
| 163 | 182 | let media = client.media(); |
| 164 | 183 | let mut filename = match (filename, &settings.dirs.downloads) { |
| 165 | 184 | (Some(f), _) => PathBuf::from(f), |
| @@ -1175,6 +1194,14 @@ impl StatefulWidget for Chat<'_> { | ||
| 1175 | 1194 | } |
| 1176 | 1195 | } |
| 1177 | 1196 | |
| 1197 | /// Returns the `geo:` URI that a location message refers to. | |
| 1198 | fn location_geo_uri(msgtype: &MessageType) -> Option<&str> { | |
| 1199 | match msgtype { | |
| 1200 | MessageType::Location(content) => Some(content.geo_uri()), | |
| 1201 | _ => None, | |
| 1202 | } | |
| 1203 | } | |
| 1204 | ||
| 1178 | 1205 | fn open_command(open_command: Option<&Vec<String>>, target: OsString) -> IambResult<()> { |
| 1179 | 1206 | if let Some(mut cmd) = open_command.and_then(cmd) { |
| 1180 | 1207 | cmd.arg(target); |
| @@ -1306,6 +1333,23 @@ mod tests { | ||
| 1306 | 1333 | |
| 1307 | 1334 | use crate::tests::{TEST_ROOM1_ID, mock_store}; |
| 1308 | 1335 | |
| 1336 | #[test] | |
| 1337 | fn test_location_geo_uri() { | |
| 1338 | use matrix_sdk::ruma::events::room::message::{ | |
| 1339 | LocationMessageEventContent, | |
| 1340 | TextMessageEventContent, | |
| 1341 | }; | |
| 1342 | ||
| 1343 | let location = MessageType::Location(LocationMessageEventContent::new( | |
| 1344 | "geo test".into(), | |
| 1345 | "geo:51.5072,-0.1276".into(), | |
| 1346 | )); | |
| 1347 | assert_eq!(location_geo_uri(&location), Some("geo:51.5072,-0.1276")); | |
| 1348 | ||
| 1349 | let text = MessageType::Text(TextMessageEventContent::plain("not a location")); | |
| 1350 | assert_eq!(location_geo_uri(&text), None); | |
| 1351 | } | |
| 1352 | ||
| 1309 | 1353 | macro_rules! move_line { |
| 1310 | 1354 | ($dir: expr, $count: expr) => { |
| 1311 | 1355 | EditorAction::Edit( |