diff --git a/draft/webxdc-user-guide.md b/draft/webxdc-user-guide.md index 4e71197fd..9cd79d524 100644 --- a/draft/webxdc-user-guide.md +++ b/draft/webxdc-user-guide.md @@ -96,16 +96,19 @@ the `manifest.toml` has the following format ```toml name = "My App Name" -icon = "icon.png" ``` - **name** - The name of the app. If no name is set or if there is no manifest, the filename is used as the app name. -- **icon** - The icon to use for the app. - The icon must be a `.png` or `.jpg` file and is read from the ZIP-file root directory. - The icon should be a square at reasonable width/height - and the implementations will add round corners etc. as needed. - If no icon is set or if there is no manifest, a default icon will be used. + + +## App Icon + +If the ZIP-root contains an `icon.png` or `icon.jpg`, +these files are used as the icon for the app. +The icon should be a square at reasonable width/height; +round corners etc. will be added by the implementations as needed. +If no icon is set, a default icon will be used. ## Webxdc Example diff --git a/src/webxdc.rs b/src/webxdc.rs index 7d6b9aeec..8060a7a46 100644 --- a/src/webxdc.rs +++ b/src/webxdc.rs @@ -25,7 +25,6 @@ const WEBXDC_DEFAULT_ICON: &str = "__webxdc__/default-icon.png"; #[non_exhaustive] struct WebxdcManifest { name: Option, - icon: Option, } /// Parsed information from WebxdcManifest and fallbacks. @@ -299,16 +298,10 @@ impl Message { if let Ok(manifest) = parse_webxdc_manifest(&bytes).await { manifest } else { - WebxdcManifest { - name: None, - icon: None, - } + WebxdcManifest { name: None } } } else { - WebxdcManifest { - name: None, - icon: None, - } + WebxdcManifest { name: None } }; if let Some(ref name) = manifest.name { @@ -319,24 +312,16 @@ impl Message { } } - if let Some(ref icon) = manifest.icon { - if !icon.ends_with(".png") && !icon.ends_with(".jpg") { - warn!(context, "bad icon format \"{}\"; use .png or .jpg", icon); - manifest.icon = None; - } else if archive.by_name(icon).is_err() { - warn!(context, "cannot find icon \"{}\"", icon); - manifest.icon = None; - } - } - Ok(WebxdcInfo { name: if let Some(name) = manifest.name { name } else { self.get_filename().unwrap_or_default() }, - icon: if let Some(icon) = manifest.icon { - icon + icon: if archive.by_name("icon.png").is_ok() { + "icon.png".to_string() + } else if archive.by_name("icon.jpg").is_ok() { + "icon.jpg".to_string() } else { WEBXDC_DEFAULT_ICON.to_string() }, @@ -851,11 +836,9 @@ mod tests { let manifest = parse_webxdc_manifest(r#"no_name = "no name, no icon""#.as_bytes()).await?; assert_eq!(manifest.name, None); - assert_eq!(manifest.icon, None); let manifest = parse_webxdc_manifest(r#"name = "name, no icon""#.as_bytes()).await?; assert_eq!(manifest.name, Some("name, no icon".to_string())); - assert_eq!(manifest.icon, None); let manifest = parse_webxdc_manifest( r#"name = "foo" @@ -864,7 +847,6 @@ icon = "bar""# ) .await?; assert_eq!(manifest.name, Some("foo".to_string())); - assert_eq!(manifest.icon, Some("bar".to_string())); let manifest = parse_webxdc_manifest( r#"name = "foz" @@ -877,7 +859,6 @@ sth_for_the = "future""# ) .await?; assert_eq!(manifest.name, Some("foz".to_string())); - assert_eq!(manifest.icon, Some("baz".to_string())); Ok(()) } @@ -912,7 +893,7 @@ sth_for_the = "future""# chat_id.set_draft(&t, Some(&mut instance)).await?; let info = instance.get_webxdc_info(&t).await?; assert_eq!(info.name, "with-manifest-no-name.xdc"); - assert_eq!(info.icon, "some.png".to_string()); + assert_eq!(info.icon, WEBXDC_DEFAULT_ICON.to_string()); let mut instance = create_webxdc_instance( &t, @@ -927,36 +908,36 @@ sth_for_the = "future""# let mut instance = create_webxdc_instance( &t, - "with-manifest-icon-not-existent.xdc", - include_bytes!("../test-data/webxdc/with-manifest-icon-not-existent.xdc"), - ) - .await?; - chat_id.set_draft(&t, Some(&mut instance)).await?; - let info = instance.get_webxdc_info(&t).await?; - assert_eq!(info.name, "with bad icon"); - assert_eq!(info.icon, WEBXDC_DEFAULT_ICON.to_string()); - - let mut instance = create_webxdc_instance( - &t, - "with-manifest-and-icon.xdc", - include_bytes!("../test-data/webxdc/with-manifest-and-icon.xdc"), + "with-manifest-and-png-icon.xdc", + include_bytes!("../test-data/webxdc/with-manifest-and-png-icon.xdc"), ) .await?; chat_id.set_draft(&t, Some(&mut instance)).await?; let info = instance.get_webxdc_info(&t).await?; assert_eq!(info.name, "with some icon"); - assert_eq!(info.icon, "some.png"); + assert_eq!(info.icon, "icon.png"); let mut instance = create_webxdc_instance( &t, - "with-manifest-and-unsupported-icon-format.xdc", - include_bytes!("../test-data/webxdc/with-manifest-and-unsupported-icon-format.xdc"), + "with-png-icon.xdc", + include_bytes!("../test-data/webxdc/with-png-icon.xdc"), ) .await?; chat_id.set_draft(&t, Some(&mut instance)).await?; let info = instance.get_webxdc_info(&t).await?; - assert_eq!(info.name, "with tiff icon"); - assert_eq!(info.icon, WEBXDC_DEFAULT_ICON); + assert_eq!(info.name, "with-png-icon.xdc"); + assert_eq!(info.icon, "icon.png"); + + let mut instance = create_webxdc_instance( + &t, + "with-jpg-icon.xdc", + include_bytes!("../test-data/webxdc/with-jpg-icon.xdc"), + ) + .await?; + chat_id.set_draft(&t, Some(&mut instance)).await?; + let info = instance.get_webxdc_info(&t).await?; + assert_eq!(info.name, "with-jpg-icon.xdc"); + assert_eq!(info.icon, "icon.jpg"); let msg_id = send_text_msg(&t, chat_id, "foo".to_string()).await?; let msg = Message::load_from_db(&t, msg_id).await?; diff --git a/test-data/webxdc/with-jpg-icon.xdc b/test-data/webxdc/with-jpg-icon.xdc new file mode 100644 index 000000000..09f5cee67 Binary files /dev/null and b/test-data/webxdc/with-jpg-icon.xdc differ diff --git a/test-data/webxdc/with-manifest-and-icon.xdc b/test-data/webxdc/with-manifest-and-icon.xdc deleted file mode 100644 index 96291b470..000000000 Binary files a/test-data/webxdc/with-manifest-and-icon.xdc and /dev/null differ diff --git a/test-data/webxdc/with-manifest-and-png-icon.xdc b/test-data/webxdc/with-manifest-and-png-icon.xdc new file mode 100644 index 000000000..0524860f5 Binary files /dev/null and b/test-data/webxdc/with-manifest-and-png-icon.xdc differ diff --git a/test-data/webxdc/with-manifest-and-unsupported-icon-format.xdc b/test-data/webxdc/with-manifest-and-unsupported-icon-format.xdc deleted file mode 100644 index 26785b345..000000000 Binary files a/test-data/webxdc/with-manifest-and-unsupported-icon-format.xdc and /dev/null differ diff --git a/test-data/webxdc/with-manifest-icon-not-existent.xdc b/test-data/webxdc/with-manifest-icon-not-existent.xdc deleted file mode 100644 index 1697cbcd6..000000000 Binary files a/test-data/webxdc/with-manifest-icon-not-existent.xdc and /dev/null differ diff --git a/test-data/webxdc/with-manifest-no-name.xdc b/test-data/webxdc/with-manifest-no-name.xdc index d25767ada..d4d11b580 100644 Binary files a/test-data/webxdc/with-manifest-no-name.xdc and b/test-data/webxdc/with-manifest-no-name.xdc differ diff --git a/test-data/webxdc/with-png-icon.xdc b/test-data/webxdc/with-png-icon.xdc new file mode 100644 index 000000000..7c909fdce Binary files /dev/null and b/test-data/webxdc/with-png-icon.xdc differ