diff --git a/.changes/txt-mime-type.md b/.changes/txt-mime-type.md new file mode 100644 index 000000000..b8d02acac --- /dev/null +++ b/.changes/txt-mime-type.md @@ -0,0 +1,5 @@ +--- +"tauri-utils": patch +--- + +Correctly determine MIME type of `.txt` files. diff --git a/.github/workflows/test-core.yml b/.github/workflows/test-core.yml index 9097ad445..e7dab46ef 100644 --- a/.github/workflows/test-core.yml +++ b/.github/workflows/test-core.yml @@ -93,6 +93,7 @@ jobs: cargo update -p time --precise 0.3.15 cargo update -p ignore --precise 0.4.18 cargo update -p raw-window-handle --precise 0.5.0 + cargo update -p cargo_toml:0.15.3 --precise 0.15.2 - name: test run: cargo test --target ${{ matrix.platform.target }} ${{ matrix.features.args }} diff --git a/core/tauri-codegen/src/context.rs b/core/tauri-codegen/src/context.rs index c2929320c..778a7fc29 100644 --- a/core/tauri-codegen/src/context.rs +++ b/core/tauri-codegen/src/context.rs @@ -176,10 +176,10 @@ pub fn context_codegen(data: ContextData) -> Result Token pub fn command_test(attributes: HandlerTestAttributes, function: ItemFn) -> TokenStream2 { let allowlist = attributes.allowlist; let error_message = attributes.error_message.as_str(); - let signature = function.sig.clone(); + let signature = &function.sig; let enum_variant_name = function.sig.ident.to_string().to_lower_camel_case(); let response = match attributes.allowlist_check_kind { AllowlistCheckKind::Runtime => { - let test_name = function.sig.ident.clone(); + let test_name = &signature.ident; quote!(super::Cmd::#test_name(crate::test::mock_invoke_context())) } AllowlistCheckKind::Serde => quote! { diff --git a/core/tauri-utils/src/mime_type.rs b/core/tauri-utils/src/mime_type.rs index ba8a2571b..6b51335e6 100644 --- a/core/tauri-utils/src/mime_type.rs +++ b/core/tauri-utils/src/mime_type.rs @@ -18,10 +18,11 @@ pub enum MimeType { Js, Json, Jsonld, + Mp4, OctetStream, Rtf, Svg, - Mp4, + Txt, } impl std::fmt::Display for MimeType { @@ -34,10 +35,11 @@ impl std::fmt::Display for MimeType { MimeType::Js => "text/javascript", MimeType::Json => "application/json", MimeType::Jsonld => "application/ld+json", + MimeType::Mp4 => "video/mp4", MimeType::OctetStream => "application/octet-stream", MimeType::Rtf => "application/rtf", MimeType::Svg => "image/svg+xml", - MimeType::Mp4 => "video/mp4", + MimeType::Txt => MIMETYPE_PLAIN, }; write!(f, "{mime}") } @@ -62,9 +64,10 @@ impl MimeType { Some("json") => Self::Json, Some("jsonld") => Self::Jsonld, Some("mjs") => Self::Js, + Some("mp4") => Self::Mp4, Some("rtf") => Self::Rtf, Some("svg") => Self::Svg, - Some("mp4") => Self::Mp4, + Some("txt") => Self::Txt, // Assume HTML when a TLD is found for eg. `wry:://tauri.app` | `wry://hello.com` Some(_) => fallback, // using octet stream according to this: @@ -133,14 +136,17 @@ mod tests { let mjs: String = MimeType::parse_from_uri("https://example.com/bundled.mjs").to_string(); assert_eq!(mjs, String::from("text/javascript")); + let mp4: String = MimeType::parse_from_uri("https://example.com/video.mp4").to_string(); + assert_eq!(mp4, String::from("video/mp4")); + let rtf: String = MimeType::parse_from_uri("https://example.com/document.rtf").to_string(); assert_eq!(rtf, String::from("application/rtf")); let svg: String = MimeType::parse_from_uri("https://example.com/picture.svg").to_string(); assert_eq!(svg, String::from("image/svg+xml")); - let mp4: String = MimeType::parse_from_uri("https://example.com/video.mp4").to_string(); - assert_eq!(mp4, String::from("video/mp4")); + let txt: String = MimeType::parse_from_uri("https://example.com/file.txt").to_string(); + assert_eq!(txt, String::from("text/plain")); let custom_scheme = MimeType::parse_from_uri("wry://tauri.app").to_string(); assert_eq!(custom_scheme, String::from("text/html")); diff --git a/core/tauri/src/event.rs b/core/tauri/src/event.rs index 7fb2110e7..c47e1ee13 100644 --- a/core/tauri/src/event.rs +++ b/core/tauri/src/event.rs @@ -282,14 +282,13 @@ mod test { // check to see if on_event properly grabs the stored function from listen. #[test] - fn check_on_event(e in "[a-z]+", d in "[a-z]+") { + fn check_on_event(key in "[a-z]+", d in "[a-z]+") { let listeners: Listeners = Default::default(); - // clone e as the key - let key = e.clone(); + // call listen with e and the event_fn dummy func - listeners.listen(e.clone(), None, event_fn); + listeners.listen(key.clone(), None, event_fn); // call on event with e and d. - listeners.trigger(&e, None, Some(d)); + listeners.trigger(&key, None, Some(d)); // lock the mutex let l = listeners.inner.handlers.lock().unwrap();