mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-02-06 13:57:16 +00:00
refactor(core): make zstd optional enabled by default (#3133)
This commit is contained in:
parent
543e6bdb91
commit
efbf236f35
@ -21,6 +21,10 @@ serde_json = "1"
|
||||
tauri-utils = { version = "1.0.0-beta.3", path = "../tauri-utils", features = [ "build" ] }
|
||||
thiserror = "1"
|
||||
walkdir = "2"
|
||||
zstd = "0.9"
|
||||
zstd = { version = "0.9", optional = true }
|
||||
kuchiki = "0.8"
|
||||
regex = "1"
|
||||
|
||||
[features]
|
||||
default = [ "compression" ]
|
||||
compression = [ "zstd", "tauri-utils/compression" ]
|
||||
|
||||
@ -155,6 +155,7 @@ impl EmbeddedAssets {
|
||||
}
|
||||
|
||||
/// Use highest compression level for release, the fastest one for everything else
|
||||
#[cfg(feature = "compression")]
|
||||
fn compression_level() -> i32 {
|
||||
let levels = zstd::compression_level_range();
|
||||
if cfg!(debug_assertions) {
|
||||
@ -259,11 +260,25 @@ impl EmbeddedAssets {
|
||||
|
||||
// only compress and write to the file if it doesn't already exist.
|
||||
if !out_path.exists() {
|
||||
let out_file = File::create(&out_path).map_err(|error| EmbeddedAssetsError::AssetWrite {
|
||||
path: out_path.clone(),
|
||||
error,
|
||||
})?;
|
||||
#[allow(unused_mut)]
|
||||
let mut out_file =
|
||||
File::create(&out_path).map_err(|error| EmbeddedAssetsError::AssetWrite {
|
||||
path: out_path.clone(),
|
||||
error,
|
||||
})?;
|
||||
|
||||
#[cfg(not(feature = "compression"))]
|
||||
{
|
||||
use std::io::Write;
|
||||
out_file
|
||||
.write_all(&input)
|
||||
.map_err(|error| EmbeddedAssetsError::AssetWrite {
|
||||
path: path.to_owned(),
|
||||
error,
|
||||
})?;
|
||||
}
|
||||
|
||||
#[cfg(feature = "compression")]
|
||||
// entirely write input to the output file path with compression
|
||||
zstd::stream::copy_encode(&*input, out_file, Self::compression_level()).map_err(|error| {
|
||||
EmbeddedAssetsError::AssetWrite {
|
||||
|
||||
@ -19,7 +19,8 @@ proc-macro = true
|
||||
proc-macro2 = "1"
|
||||
quote = "1"
|
||||
syn = { version = "1", features = [ "full" ] }
|
||||
tauri-codegen = { version = "1.0.0-beta.4", path = "../tauri-codegen" }
|
||||
tauri-codegen = { version = "1.0.0-beta.4", default-features = false, path = "../tauri-codegen" }
|
||||
|
||||
[features]
|
||||
custom-protocol = [ ]
|
||||
compression = [ "tauri-codegen/compression" ]
|
||||
|
||||
@ -28,10 +28,7 @@ use tauri_runtime::{SystemTray, SystemTrayEvent};
|
||||
#[cfg(windows)]
|
||||
use webview2_com::FocusChangedEventHandler;
|
||||
#[cfg(windows)]
|
||||
use windows::Win32::{
|
||||
Foundation::HWND,
|
||||
System::WinRT::EventRegistrationToken,
|
||||
};
|
||||
use windows::Win32::{Foundation::HWND, System::WinRT::EventRegistrationToken};
|
||||
#[cfg(all(feature = "system-tray", target_os = "macos"))]
|
||||
use wry::application::platform::macos::{SystemTrayBuilderExtMacOS, SystemTrayExtMacOS};
|
||||
#[cfg(target_os = "linux")]
|
||||
|
||||
@ -16,7 +16,7 @@ serde = { version = "1.0", features = [ "derive" ] }
|
||||
serde_json = "1.0"
|
||||
thiserror = "1.0.30"
|
||||
phf = { version = "0.10", features = [ "macros" ] }
|
||||
zstd = "0.9"
|
||||
zstd = { version = "0.9", optional = true }
|
||||
url = { version = "2.2", features = [ "serde" ] }
|
||||
kuchiki = "0.8"
|
||||
html5ever = "0.25"
|
||||
@ -28,3 +28,4 @@ heck = "0.4"
|
||||
|
||||
[features]
|
||||
build = [ "proc-macro2", "quote" ]
|
||||
compression = [ "zstd" ]
|
||||
|
||||
@ -94,6 +94,7 @@ impl EmbeddedAssets {
|
||||
}
|
||||
|
||||
impl Assets for EmbeddedAssets {
|
||||
#[cfg(feature = "compression")]
|
||||
fn get(&self, key: &AssetKey) -> Option<Cow<'_, [u8]>> {
|
||||
self
|
||||
.0
|
||||
@ -103,4 +104,13 @@ impl Assets for EmbeddedAssets {
|
||||
.and_then(Result::ok)
|
||||
.map(Cow::Owned)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "compression"))]
|
||||
fn get(&self, key: &AssetKey) -> Option<Cow<'_, [u8]>> {
|
||||
self
|
||||
.0
|
||||
.get(key.as_ref())
|
||||
.copied()
|
||||
.map(|a| Cow::Owned(a.to_vec()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,8 @@ exclude = [
|
||||
readme = "README.md"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
default-features = false
|
||||
features = ["wry", "custom-protocol", "api-all", "cli", "updater", "system-tray", "dox"]
|
||||
rustdoc-args = [ "--cfg", "doc_cfg" ]
|
||||
default-target = "x86_64-unknown-linux-gnu"
|
||||
targets = [
|
||||
@ -95,7 +96,8 @@ tokio = { version = "1.15", features = [ "full" ] }
|
||||
mockito = "0.30"
|
||||
|
||||
[features]
|
||||
default = [ "wry" ]
|
||||
default = [ "wry", "compression" ]
|
||||
compression = [ "tauri-macros/compression", "tauri-utils/compression" ]
|
||||
dox = [ "tauri-runtime-wry/dox" ]
|
||||
wry = [ "tauri-runtime-wry" ]
|
||||
cli = [ "clap" ]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user