From a3a101641a90a94a3ba2f00ba611c0420dc5b099 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 6 Jan 2022 01:27:12 +0100 Subject: [PATCH] use well-known icon-filenames instead of manifest --- draft/webxdc-user-guide.md | 15 ++-- src/webxdc.rs | 69 +++++++----------- test-data/webxdc/with-jpg-icon.xdc | Bin 0 -> 467 bytes test-data/webxdc/with-manifest-and-icon.xdc | Bin 623 -> 0 bytes .../webxdc/with-manifest-and-png-icon.xdc | Bin 0 -> 611 bytes ...h-manifest-and-unsupported-icon-format.xdc | Bin 1239 -> 0 bytes .../with-manifest-icon-not-existent.xdc | Bin 390 -> 0 bytes test-data/webxdc/with-manifest-no-name.xdc | Bin 605 -> 367 bytes test-data/webxdc/with-png-icon.xdc | Bin 0 -> 433 bytes 9 files changed, 34 insertions(+), 50 deletions(-) create mode 100644 test-data/webxdc/with-jpg-icon.xdc delete mode 100644 test-data/webxdc/with-manifest-and-icon.xdc create mode 100644 test-data/webxdc/with-manifest-and-png-icon.xdc delete mode 100644 test-data/webxdc/with-manifest-and-unsupported-icon-format.xdc delete mode 100644 test-data/webxdc/with-manifest-icon-not-existent.xdc create mode 100644 test-data/webxdc/with-png-icon.xdc 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 0000000000000000000000000000000000000000..09f5cee67e0f8f6811f8dd244084a3620a1b2540 GIT binary patch literal 467 zcmWIWW@Zs#U}E54*wmpG^8b@`XDb5(gB&9RP(+3yGdVv`FRLIuG=!6ZIY9V&Vlohy zR&X;gvU~+90qSI6_+9__KQkMnzPZ0So14Og#4CvjKk8>6oT+&9s`a7UcB)DSiwv}v z*4$cu^zyD<%l_{FTl0GT|09eG6ni3DTQARA{x^Ql5Br%97@8H>n;DuJj29~~PgYRg ztnm21GLI5Z4^IYzidKVfh{y{~lfbkINsc~8w@XyakZjy$z-@HHIO8ls*Busy0H8Ox zfZkwW;IB~$QEB154ssd@bAh~(my%kcmr;_N1NKO5)Rn{sLKq&gQFQTl4v7qKRRF29 z7b_&V(1HqL8ZLK2Oalfh!;;41Ak&as4Kxqr VY7FyO*+BL(0pUC#Ef3Pn0001EeBJ;6 literal 0 HcmV?d00001 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 96291b4702aca4f899400f9488204688e1b5b78c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 623 zcmWIWW@h1HU}9ik;IB~$QEB15E&^nOFc*UiLuOt|YK2}#Np4PP2qyz`ZPb;-qd;6* z!Og(P@|BT+fd!<}M$yIJIV3W`RRN^Zjw>&-f-3-Mt_aXv4u+4LRYF)Y=ABdls?-8v zUZAL0&r812MaL>ANrpmkK9B&-f-3-Mt_aXv4hG+yDj^)b6RxNMRcZk- zFVNiF#JtS3)Z!Aol6^yadE(MxXXR;~TmmG(hXT&dC6clRnLDYfId%lRzJdvNHg!mtiQ*&rQ`U$xH)#A?3)G#55pA zvuA0DZ-%g=NZoGFY!B|dx}K$-5&_u)7ac^R_pFg(TG$>I9k?RF=~wdFTNi#zZZ_ra zGSB7LlCzm|E!a^&M1)sWJ<#!mqrVep;6je14+<-emZsgCT~hw>`GW&*s_*alzVG|9 zvuBoFzOBH{@~}E(>wcDKD#ci6!3%beGNkwx5%@V8&^h@ zOfBJ`t=E0eXIHoH{6~3ferL`-Un*wnvg_cps!#o!Zmu)o{A)cs@lxow&WI#)4XrH( zFJqYn7MD)-o%?bRgMRdj%|AYGjCG7XwNmr)o1512?|79xK7IDEwrYb}=U-p>I-@^t zYu2{@4(C*t)91WXZF~9n-{s6Z+GLOX+vRobPvIj@ z9fkdCqCe^LEpe@}?6CO%VvX*6xq@e>Z-0_ZVRzX5WU|eihJ%$-3{mWG;hu3(|KPz_s604_q!@?)^GoO=Y70s#XhBj zHw^cb8=as3qcp1DCA(rB<8FD2A5!lp-rKn6e9*H_{oR~DfBY=2QIh1*6x+8r_eHp+ zsNie~G1+zC(w0+s|CaG}G|O%pKukm8*?4^6gz`&ahE>^gR0G z{mAmfAEKKNyi@;uG4)j3Q*-n8QLANNXK#G>PPcB&^hZnL=e;>CZg}5~J$|qBZw>d> zd;aV{r>|HS+inz?eMd(5k$&cR?VN_1(D|AFg^KTH{l9+T@A_Z*SNXE)yUhzdSPmb) zFyC)!!k3b=lovlT4!+!PKU-RQri6WYnm`?6fHxzP95b#QEdk7b3=F`0%dn&o#6r&B ztdRVTmN6ja;mXO#=0yO_L(A7dBSHBZkCB-96=EdFaZ4JH0!c*f1)2uRy%?skvVl}H N1K~#?eSsOo0|0hP?P~x4 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 1697cbcd603015f5d4edb3ebe6bb886aec4dd1ed..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 390 zcmWIWW@h1HU}9ik;IB~$QEB15E&^nOFc*UiLuOt|YK2}#Np4PP2qyz`ZPb-S5H79Y zW?*Fb%E-XL0#a$C=;H4j5*gsC08(kkm6ut;6#z6>1ZXY?gBsA>0`{v>dO($iK+Fp? zH#adaGcC2aM6VNLDtGjbrsfW?pa#2FYEBqrud>Smt3mY4;^r4`%^j4WRn85meZ zfO6j2x|+IPz5d?5EEl=9ad~AfwY2n#nHKYl6%{Gb6y8l?`YV P&|W5n#Xx!+h{FH?rJ*F0 literal 605 zcmWIWW@h1HU}9ik;IB~$QEB15E&^nOFc*UiLuOt|YK2}#Np4PP2qyz`ZPb;-qd;6* z!Og(P@|BT+fd!<}M$yIJIV3W`RRN^Zjw>&-f-3-SZVQ8I$fX<}At9hj5atD%o12)I znU-2yqF0g+H9Gy$mBdUSMl(7yIX_RqRzayaKQ~pcATM1BY_JH>!5j=5HmQUx5kBsb z3^X(yh&g};!_G8`)5{C+He;)t;vu98B)=PCcv!_dB-6;I-&@W|vxXf?n zyXBg*(i>h$*u?&gxn`+q!pIQd&B!Fjj4NCvfR1Hg0EQmJl12~$VDxg#%?yMefpi$icMJgc CK%DRZ diff --git a/test-data/webxdc/with-png-icon.xdc b/test-data/webxdc/with-png-icon.xdc new file mode 100644 index 0000000000000000000000000000000000000000..7c909fdce5e68fee62c26ff266ebbd59fd41e157 GIT binary patch literal 433 zcmWIWW@Zs#U}E54*sw_@WQp)`k7Nc0hIAn2V31+ROwP~KE67U^4dG;9j@fl3@%8y@ ziKP|X42&#a85tOWIvE&V^L!|N{&do#q=bYAU%wP^GF@U)ICFwWB{a8qYJ*60gMUYM zef@tRIG=OxBfo~y