Skip to content

Commit

Permalink
feat: improvements to support hyphens in crate name (#5989)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
  • Loading branch information
amrbashir and lucasfernog committed Jan 6, 2023
1 parent 2c4a0bb commit 50f6dd8
Show file tree
Hide file tree
Showing 25 changed files with 651 additions and 753 deletions.
6 changes: 6 additions & 0 deletions .changes/mobile-lib-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"cli.rs": patch
"cli.js": patch
---

Add support to custom and kebab case library names for mobile apps.
2 changes: 1 addition & 1 deletion core/tauri-macros/src/mobile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn entry_point(_attributes: TokenStream, item: TokenStream) -> TokenStream {
let domain = get_env_var("TAURI_ANDROID_PACKAGE_PREFIX", |r| r, &mut error, &function);
let app_name = get_env_var(
"CARGO_PKG_NAME",
|r| r.replace('_', "_1"),
|r| r.replace('-', "_"),
&mut error,
&function,
);
Expand Down
2 changes: 1 addition & 1 deletion core/tauri-runtime-wry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exclude = [ "CHANGELOG.md", "/target" ]
readme = "README.md"

[dependencies]
wry = { version = "0.23.4", default-features = false, features = [ "file-drop", "protocol" ] }
wry = { git = "https://github.com/tauri-apps/wry", branch = "dev", default-features = false, features = [ "file-drop", "protocol" ] }
tauri-runtime = { version = "0.13.0-alpha.0", path = "../tauri-runtime" }
tauri-utils = { version = "2.0.0-alpha.0", path = "../tauri-utils" }
uuid = { version = "1", features = [ "v4" ] }
Expand Down
3 changes: 2 additions & 1 deletion core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub use wry::application::platform::macos::{
};

use std::{
borrow::Cow,
cell::RefCell,
collections::{
hash_map::Entry::{Occupied, Vacant},
Expand Down Expand Up @@ -284,7 +285,7 @@ impl From<&WryRequest<Vec<u8>>> for HttpRequestWrapper {
}

// response
struct HttpResponseWrapper(WryResponse<Vec<u8>>);
struct HttpResponseWrapper(WryResponse<Cow<'static, [u8]>>);
impl From<HttpResponse> for HttpResponseWrapper {
fn from(response: HttpResponse) -> Self {
let (parts, body) = response.into_parts();
Expand Down
21 changes: 12 additions & 9 deletions core/tauri-runtime/src/http/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::{
status::StatusCode,
version::Version,
};
use std::fmt;
use std::{borrow::Cow, fmt};

type Result<T> = core::result::Result<T, Box<dyn std::error::Error>>;

Expand All @@ -33,7 +33,7 @@ type Result<T> = core::result::Result<T, Box<dyn std::error::Error>>;
///
pub struct Response {
head: ResponseParts,
body: Vec<u8>,
body: Cow<'static, [u8]>,
}

/// Component parts of an HTTP `Response`
Expand Down Expand Up @@ -67,7 +67,7 @@ pub struct Builder {
impl Response {
/// Creates a new blank `Response` with the body
#[inline]
pub fn new(body: Vec<u8>) -> Response {
pub fn new(body: Cow<'static, [u8]>) -> Response {
Response {
head: ResponseParts::new(),
body,
Expand All @@ -81,7 +81,7 @@ impl Response {
/// This API is used internally. It may have breaking changes in the future.
#[inline]
#[doc(hidden)]
pub fn into_parts(self) -> (ResponseParts, Vec<u8>) {
pub fn into_parts(self) -> (ResponseParts, Cow<'static, [u8]>) {
(self.head, self.body)
}

Expand Down Expand Up @@ -129,21 +129,21 @@ impl Response {

/// Returns a mutable reference to the associated HTTP body.
#[inline]
pub fn body_mut(&mut self) -> &mut Vec<u8> {
pub fn body_mut(&mut self) -> &mut Cow<'static, [u8]> {
&mut self.body
}

/// Returns a reference to the associated HTTP body.
#[inline]
pub fn body(&self) -> &Vec<u8> {
pub fn body(&self) -> &Cow<'static, [u8]> {
&self.body
}
}

impl Default for Response {
#[inline]
fn default() -> Response {
Response::new(Vec::new())
Response::new(Default::default())
}
}

Expand Down Expand Up @@ -280,8 +280,11 @@ impl Builder {
/// .body(Vec::new())
/// .unwrap();
/// ```
pub fn body(self, body: Vec<u8>) -> Result<Response> {
self.inner.map(move |head| Response { head, body })
pub fn body(self, body: impl Into<Cow<'static, [u8]>>) -> Result<Response> {
self.inner.map(move |head| Response {
head,
body: body.into(),
})
}

// private
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ state = "0.5"
tar = "0.4.38"
tempfile = "3"
zip = { version = "0.6", default-features = false, optional = true }
ignore = "0.4"
ignore = "=0.4.18"
flate2 = "1.0"
http = "0.2"
dirs-next = "2.0"
Expand Down
6 changes: 3 additions & 3 deletions core/tauri/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ impl<R: Runtime> WindowManager<R> {
struct CachedResponse {
status: http::StatusCode,
headers: http::HeaderMap,
body: Vec<u8>,
body: Cow<'static, [u8]>,
}

#[cfg(dev)]
Expand Down Expand Up @@ -951,7 +951,7 @@ impl<R: Runtime> WindowManager<R> {
let response = CachedResponse {
status,
headers,
body,
body: body.into(),
};
response_cache_.insert(url.clone(), response);
response_cache_.get(&url).unwrap()
Expand Down Expand Up @@ -988,7 +988,7 @@ impl<R: Runtime> WindowManager<R> {
let response_csp = String::from_utf8_lossy(response_csp.as_bytes());
let html = String::from_utf8_lossy(response.body());
let body = html.replacen(tauri_utils::html::CSP_TOKEN, &response_csp, 1);
*response.body_mut() = body.as_bytes().to_vec();
*response.body_mut() = body.as_bytes().to_vec().into();
}
Ok(response)
})
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/updater/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ fn copy_files_and_run<R: Read + Seek>(archive_buffer: R, extract_path: &Path) ->
})?;

let _ = std::process::Command::new("touch")
.arg(&extract_path)
.arg(extract_path)
.status();

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion core/tests/app-updater/tests/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn bundle_path(root_dir: &Path, version: &str) -> PathBuf {

#[cfg(target_os = "macos")]
fn bundle_path(root_dir: &Path, _version: &str) -> PathBuf {
root_dir.join(format!("target/debug/bundle/macos/app-updater.app"))
root_dir.join("target/debug/bundle/macos/app-updater.app")
}

#[cfg(target_os = "ios")]
Expand Down

0 comments on commit 50f6dd8

Please sign in to comment.