use well-known icon-filenames instead of manifest

This commit is contained in:
B. Petersen
2022-01-06 01:27:12 +01:00
committed by bjoern
parent 8bd93fe495
commit a3a101641a
9 changed files with 34 additions and 50 deletions

View File

@@ -96,16 +96,19 @@ the `manifest.toml` has the following format
```toml ```toml
name = "My App Name" name = "My App Name"
icon = "icon.png"
``` ```
- **name** - The name of the app. - **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. 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 ## App Icon
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. 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 ## Webxdc Example

View File

@@ -25,7 +25,6 @@ const WEBXDC_DEFAULT_ICON: &str = "__webxdc__/default-icon.png";
#[non_exhaustive] #[non_exhaustive]
struct WebxdcManifest { struct WebxdcManifest {
name: Option<String>, name: Option<String>,
icon: Option<String>,
} }
/// Parsed information from WebxdcManifest and fallbacks. /// Parsed information from WebxdcManifest and fallbacks.
@@ -299,16 +298,10 @@ impl Message {
if let Ok(manifest) = parse_webxdc_manifest(&bytes).await { if let Ok(manifest) = parse_webxdc_manifest(&bytes).await {
manifest manifest
} else { } else {
WebxdcManifest { WebxdcManifest { name: None }
name: None,
icon: None,
}
} }
} else { } else {
WebxdcManifest { WebxdcManifest { name: None }
name: None,
icon: None,
}
}; };
if let Some(ref name) = manifest.name { 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 { Ok(WebxdcInfo {
name: if let Some(name) = manifest.name { name: if let Some(name) = manifest.name {
name name
} else { } else {
self.get_filename().unwrap_or_default() self.get_filename().unwrap_or_default()
}, },
icon: if let Some(icon) = manifest.icon { icon: if archive.by_name("icon.png").is_ok() {
icon "icon.png".to_string()
} else if archive.by_name("icon.jpg").is_ok() {
"icon.jpg".to_string()
} else { } else {
WEBXDC_DEFAULT_ICON.to_string() 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?; let manifest = parse_webxdc_manifest(r#"no_name = "no name, no icon""#.as_bytes()).await?;
assert_eq!(manifest.name, None); assert_eq!(manifest.name, None);
assert_eq!(manifest.icon, None);
let manifest = parse_webxdc_manifest(r#"name = "name, no icon""#.as_bytes()).await?; 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.name, Some("name, no icon".to_string()));
assert_eq!(manifest.icon, None);
let manifest = parse_webxdc_manifest( let manifest = parse_webxdc_manifest(
r#"name = "foo" r#"name = "foo"
@@ -864,7 +847,6 @@ icon = "bar""#
) )
.await?; .await?;
assert_eq!(manifest.name, Some("foo".to_string())); assert_eq!(manifest.name, Some("foo".to_string()));
assert_eq!(manifest.icon, Some("bar".to_string()));
let manifest = parse_webxdc_manifest( let manifest = parse_webxdc_manifest(
r#"name = "foz" r#"name = "foz"
@@ -877,7 +859,6 @@ sth_for_the = "future""#
) )
.await?; .await?;
assert_eq!(manifest.name, Some("foz".to_string())); assert_eq!(manifest.name, Some("foz".to_string()));
assert_eq!(manifest.icon, Some("baz".to_string()));
Ok(()) Ok(())
} }
@@ -912,7 +893,7 @@ sth_for_the = "future""#
chat_id.set_draft(&t, Some(&mut instance)).await?; chat_id.set_draft(&t, Some(&mut instance)).await?;
let info = instance.get_webxdc_info(&t).await?; let info = instance.get_webxdc_info(&t).await?;
assert_eq!(info.name, "with-manifest-no-name.xdc"); 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( let mut instance = create_webxdc_instance(
&t, &t,
@@ -927,36 +908,36 @@ sth_for_the = "future""#
let mut instance = create_webxdc_instance( let mut instance = create_webxdc_instance(
&t, &t,
"with-manifest-icon-not-existent.xdc", "with-manifest-and-png-icon.xdc",
include_bytes!("../test-data/webxdc/with-manifest-icon-not-existent.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 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"),
) )
.await?; .await?;
chat_id.set_draft(&t, Some(&mut instance)).await?; chat_id.set_draft(&t, Some(&mut instance)).await?;
let info = instance.get_webxdc_info(&t).await?; let info = instance.get_webxdc_info(&t).await?;
assert_eq!(info.name, "with some icon"); 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( let mut instance = create_webxdc_instance(
&t, &t,
"with-manifest-and-unsupported-icon-format.xdc", "with-png-icon.xdc",
include_bytes!("../test-data/webxdc/with-manifest-and-unsupported-icon-format.xdc"), include_bytes!("../test-data/webxdc/with-png-icon.xdc"),
) )
.await?; .await?;
chat_id.set_draft(&t, Some(&mut instance)).await?; chat_id.set_draft(&t, Some(&mut instance)).await?;
let info = instance.get_webxdc_info(&t).await?; let info = instance.get_webxdc_info(&t).await?;
assert_eq!(info.name, "with tiff icon"); assert_eq!(info.name, "with-png-icon.xdc");
assert_eq!(info.icon, WEBXDC_DEFAULT_ICON); 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_id = send_text_msg(&t, chat_id, "foo".to_string()).await?;
let msg = Message::load_from_db(&t, msg_id).await?; let msg = Message::load_from_db(&t, msg_id).await?;

Binary file not shown.

Binary file not shown.

Binary file not shown.