feat(core): set .rc values from tauri.conf.json, closes #1849 (#1951)

This commit is contained in:
Lucas Fernandes Nogueira 2021-06-05 01:16:54 -03:00 committed by GitHub
parent 9bf82f0d92
commit dc6b0d8522
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 82 additions and 55 deletions

View File

@ -249,7 +249,8 @@
"path": "./core/tauri-build",
"manager": "rust",
"dependencies": [
"tauri-codegen"
"tauri-codegen",
"tauri-utils"
],
"postversion": "node ../../.scripts/sync-cli-metadata.js ${ pkg.pkg } ${ release.type }"
},

View File

@ -0,0 +1,5 @@
---
"tauri-build": patch
---
Pull Windows resource information (`FileVersion`, `ProductVersion`, `ProductName` and `FileDescription`) from `tauri.conf.json > package` configuration.

View File

@ -23,6 +23,8 @@ tauri-codegen = { version = "1.0.0-beta.0", path = "../tauri-codegen", optional
[target."cfg(windows)".dependencies]
winres = "0.1"
serde_json = "1.0"
tauri-utils = { version = "1.0.0-beta.0", path = "../tauri-utils", features = [ "build" ] }
[features]
codegen = [ "tauri-codegen" ]

View File

@ -93,8 +93,15 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
#[cfg(windows)]
{
use anyhow::{anyhow, Context};
use std::fs::read_to_string;
use tauri_utils::config::Config;
use winres::WindowsResource;
let config: Config = serde_json::from_str(
&read_to_string("tauri.conf.json").expect("failed to read tauri.conf.json"),
)
.expect("failed to parse tauri.conf.json");
let icon_path_string = attributes
.windows_attributes
.window_icon_path
@ -103,6 +110,14 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
if attributes.windows_attributes.window_icon_path.exists() {
let mut res = WindowsResource::new();
if let Some(version) = &config.package.version {
res.set("FileVersion", version);
res.set("ProductVersion", version);
}
if let Some(product_name) = &config.package.product_name {
res.set("ProductName", product_name);
res.set("FileDescription", product_name);
}
res.set_icon_with_id(&icon_path_string, "32512");
res.compile().with_context(|| {
format!(

View File

@ -147,7 +147,7 @@ impl<'a, I: MenuId> From<&'a CustomMenuItem<I>> for MenuItemAttributesWrapper<'a
.with_selected(item.selected)
.with_id(WryMenuId(item.id_value()));
if let Some(accelerator) = item.keyboard_accelerator.as_ref() {
attributes = attributes.with_accelerators(&accelerator);
attributes = attributes.with_accelerators(accelerator);
}
Self(attributes)
}

View File

@ -162,13 +162,13 @@ fn get_app<'a>(name: &str, about: Option<&'a String>, config: &'a CliConfig) ->
if let Some(args) = config.args() {
for arg in args {
let arg_name = arg.name.as_ref();
app = app.arg(get_arg(arg_name, &arg));
app = app.arg(get_arg(arg_name, arg));
}
}
if let Some(subcommands) = config.subcommands() {
for (subcommand_name, subcommand) in subcommands {
let clap_subcommand = get_app(&subcommand_name, subcommand.description(), subcommand);
let clap_subcommand = get_app(subcommand_name, subcommand.description(), subcommand);
app = app.subcommand(clap_subcommand);
}
}

View File

@ -84,7 +84,7 @@ impl<'a> Extract<'a> {
let source = fs::File::open(self.source)?;
let archive = self
.archive_format
.unwrap_or_else(|| detect_archive_type(&self.source));
.unwrap_or_else(|| detect_archive_type(self.source));
match archive {
ArchiveFormat::Plain(compression) | ArchiveFormat::Tar(compression) => {
@ -140,7 +140,7 @@ impl<'a> Extract<'a> {
let source = fs::File::open(self.source)?;
let archive = self
.archive_format
.unwrap_or_else(|| detect_archive_type(&self.source));
.unwrap_or_else(|| detect_archive_type(self.source));
match archive {
ArchiveFormat::Plain(compression) | ArchiveFormat::Tar(compression) => {

View File

@ -731,7 +731,7 @@ where
let app_handle = app_handle.clone();
let event = match event {
RuntimeSystemTrayEvent::MenuItemClick(id) => tray::SystemTrayEvent::MenuItemClick {
id: ids.get(&id).unwrap().clone(),
id: ids.get(id).unwrap().clone(),
},
RuntimeSystemTrayEvent::LeftClick { position, size } => {
tray::SystemTrayEvent::LeftClick {

View File

@ -9,6 +9,7 @@ use serde::Deserialize;
/// The API descriptor.
#[derive(Deserialize)]
#[serde(tag = "cmd", rename_all = "camelCase")]
#[allow(clippy::enum_variant_names)]
pub enum Cmd {
/// Get Application Version
GetAppVersion,

View File

@ -21,7 +21,7 @@ impl Cmd {
#[allow(unused_variables)]
Self::CliMatches => {
#[cfg(cli)]
return crate::api::cli::get_matches(&cli_config)
return crate::api::cli::get_matches(cli_config)
.map_err(Into::into)
.map(Into::into);
#[cfg(not(cli))]

View File

@ -52,6 +52,7 @@ pub struct SaveDialogOptions {
/// The API descriptor.
#[derive(Deserialize)]
#[serde(tag = "cmd", rename_all = "camelCase")]
#[allow(clippy::enum_variant_names)]
pub enum Cmd {
/// The open dialog API.
OpenDialog {

View File

@ -594,7 +594,7 @@ impl<P: Params> WindowManager<P> {
.plugins
.lock()
.expect("poisoned plugin store")
.initialize(&app, &self.inner.config.plugins)
.initialize(app, &self.inner.config.plugins)
}
pub fn prepare_window(

View File

@ -72,7 +72,7 @@ impl<P: Params> PluginStore<P> {
self.store.values_mut().try_for_each(|plugin| {
plugin
.initialize(
&app,
app,
config.0.get(plugin.name()).cloned().unwrap_or_default(),
)
.map_err(|e| crate::Error::PluginInitialization(plugin.name().to_string(), e.to_string()))

View File

@ -268,7 +268,7 @@ impl<'a> UpdateBuilder<'a> {
// The main objective is if the update URL is defined via the Cargo.toml
// the URL will be generated dynamicly
let fixed_link = str::replace(
&str::replace(url, "{{current_version}}", &current_version),
&str::replace(url, "{{current_version}}", current_version),
"{{target}}",
&target,
);
@ -328,7 +328,7 @@ impl<'a> UpdateBuilder<'a> {
// did the announced version is greated than our current one?
let should_update =
version::is_greater(&current_version, &final_release.version).unwrap_or(false);
version::is_greater(current_version, &final_release.version).unwrap_or(false);
// create our new updater
Ok(Update {
@ -457,7 +457,7 @@ impl Update {
}
}
// extract using tauri api inside a tmp path
Extract::from_source(&tmp_archive_path).extract_into(&tmp_dir.path())?;
Extract::from_source(&tmp_archive_path).extract_into(tmp_dir.path())?;
// Remove archive (not needed anymore)
remove_file(&tmp_archive_path)?;
// we copy the files depending of the operating system
@ -674,7 +674,7 @@ fn default_archive_name_by_os() -> String {
// Convert base64 to string and prevent failing
fn base64_to_string(base64_string: &str) -> Result<String> {
let decoded_string = &decode(base64_string.to_owned())?;
let result = from_utf8(&decoded_string)?.to_string();
let result = from_utf8(decoded_string)?.to_string();
Ok(result)
}

View File

@ -33,7 +33,7 @@ impl fmt::Display for Event {
f.write_str(match self {
Self::Foo => "foo",
Self::Bar => "bar",
Self::Unknown(s) => &s,
Self::Unknown(s) => s,
})
}
}

View File

@ -84,7 +84,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
// create the shell script file in the target/ folder.
let sh_file = output_path.join("build_appimage.sh");
common::print_bundling(&appimage_path.file_name().unwrap().to_str().unwrap())?;
common::print_bundling(appimage_path.file_name().unwrap().to_str().unwrap())?;
write(&sh_file, temp)?;
// chmod script for execution
@ -101,7 +101,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
let mut cmd = Command::new(&sh_file);
cmd.current_dir(output_path);
common::execute_with_verbosity(&mut cmd, &settings).map_err(|_| {
common::execute_with_verbosity(&mut cmd, settings).map_err(|_| {
crate::Error::ShellScriptError(format!(
"error running appimage.sh{}",
if settings.is_verbose() {

View File

@ -491,7 +491,7 @@ fn tar_and_gzip_dir<P: AsRef<Path>>(src_dir: P) -> crate::Result<PathBuf> {
/// Creates an `ar` archive from the given source files and writes it to the
/// given destination path.
fn create_archive(srcs: Vec<PathBuf>, dest: &Path) -> crate::Result<()> {
let mut builder = ar::Builder::new(common::create_file(&dest)?);
let mut builder = ar::Builder::new(common::create_file(dest)?);
for path in &srcs {
builder.append_path(path)?;
}

View File

@ -589,7 +589,7 @@ impl Settings {
/// Returns the package's homepage URL, defaulting to "" if not defined.
pub fn homepage_url(&self) -> &str {
&self.package.homepage.as_deref().unwrap_or("")
self.package.homepage.as_deref().unwrap_or("")
}
/// Returns the app's category.

View File

@ -109,7 +109,7 @@ fn bundle_update(settings: &Settings, bundles: &[Bundle]) -> crate::Result<Vec<P
let appimage_archived_path = PathBuf::from(&appimage_archived);
// Create our gzip file
create_tar(&source_path, &appimage_archived_path)
create_tar(source_path, &appimage_archived_path)
.with_context(|| "Failed to tar.gz update directory")?;
common::print_bundling(format!("{:?}", &appimage_archived_path).as_str())?;
@ -148,7 +148,7 @@ fn bundle_update(settings: &Settings, bundles: &[Bundle]) -> crate::Result<Vec<P
let msi_archived_path = PathBuf::from(&msi_archived);
// Create our gzip file
create_zip(&source_path, &msi_archived_path).with_context(|| "Failed to zip update MSI")?;
create_zip(source_path, &msi_archived_path).with_context(|| "Failed to zip update MSI")?;
common::print_bundling(format!("{:?}", &msi_archived_path).as_str())?;
Ok(vec![msi_archived_path])
@ -181,7 +181,7 @@ pub fn create_zip(src_file: &Path, dst_file: &Path) -> crate::Result<PathBuf> {
#[cfg(not(target_os = "windows"))]
fn create_tar(src_dir: &Path, dest_path: &Path) -> crate::Result<PathBuf> {
let dest_file = common::create_file(&dest_path)?;
let dest_file = common::create_file(dest_path)?;
let gzip_encoder = libflate::gzip::Encoder::new(dest_file)?;
let gzip_encoder = create_tar_from_src(src_dir, gzip_encoder)?;

View File

@ -17,7 +17,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
wix::get_and_extract_wix(&wix_path)?;
}
let msi_path = wix::build_wix_app_installer(&settings, &wix_path)?;
let msi_path = wix::build_wix_app_installer(settings, &wix_path)?;
Ok(vec![msi_path])
}

View File

@ -297,7 +297,7 @@ fn run_candle(
cmd.args(&args).stdout(Stdio::piped()).current_dir(cwd);
common::print_info("running candle.exe")?;
common::execute_with_verbosity(&mut cmd, &settings).map_err(|_| {
common::execute_with_verbosity(&mut cmd, settings).map_err(|_| {
crate::Error::ShellScriptError(format!(
"error running candle.exe{}",
if settings.is_verbose() {
@ -337,7 +337,7 @@ fn run_light(
.current_dir(build_path);
common::print_info(format!("running light to produce {}", output_path.display()).as_str())?;
common::execute_with_verbosity(&mut cmd, &settings)
common::execute_with_verbosity(&mut cmd, settings)
.map(|_| output_path.to_path_buf())
.map_err(|_| {
crate::Error::ShellScriptError(format!(
@ -393,10 +393,11 @@ pub fn build_wix_app_installer(
.map(|algorithm| algorithm.to_string())
.unwrap_or_else(|| "sha256".to_string()),
certificate_thumbprint: certificate_thumbprint.to_string(),
timestamp_url: match &settings.windows().timestamp_url {
Some(url) => Some(url.to_string()),
None => None,
},
timestamp_url: settings
.windows()
.timestamp_url
.as_ref()
.map(|url| url.to_string()),
},
)?;
}
@ -426,12 +427,12 @@ pub fn build_wix_app_installer(
let app_exe_name = settings.main_binary_name().to_string();
data.insert("app_exe_name", to_json(&app_exe_name));
let binaries = generate_binaries_data(&settings)?;
let binaries = generate_binaries_data(settings)?;
let binaries_json = to_json(&binaries);
data.insert("binaries", binaries_json);
let resources = generate_resource_data(&settings)?;
let resources = generate_resource_data(settings)?;
let mut resources_wix_string = String::from("");
let mut files_ids = Vec::new();
for (_, dir) in resources {
@ -445,13 +446,13 @@ pub fn build_wix_app_installer(
data.insert("resources", to_json(resources_wix_string));
data.insert("resource_file_ids", to_json(files_ids));
let merge_modules = get_merge_modules(&settings)?;
let merge_modules = get_merge_modules(settings)?;
data.insert("merge_modules", to_json(merge_modules));
data.insert("app_exe_source", to_json(&app_exe_source));
// copy icon from $CWD/icons/icon.ico folder to resource folder near msi
let icon_path = copy_icon(&settings)?;
let icon_path = copy_icon(settings)?;
data.insert("icon_path", to_json(icon_path));
@ -473,7 +474,7 @@ pub fn build_wix_app_installer(
let template = std::fs::read_to_string(temp_path)?;
handlebars
.register_template_string("main.wxs", &template)
.or_else(|e| Err(e.to_string()))
.map_err(|e| e.to_string())
.expect("Failed to setup custom handlebar template");
has_custom_template = true;
}
@ -507,16 +508,16 @@ pub fn build_wix_app_installer(
}
for wxs in &candle_inputs {
run_candle(settings, &wix_toolset_path, &output_path, &wxs)?;
run_candle(settings, wix_toolset_path, &output_path, wxs)?;
}
let wixobjs = vec!["*.wixobj"];
let target = run_light(
&wix_toolset_path,
wix_toolset_path,
&output_path,
&wixobjs,
&app_installer_dir(&settings)?,
&settings,
&app_installer_dir(settings)?,
settings,
)?;
Ok(target)
@ -651,7 +652,7 @@ fn generate_resource_data(settings: &Settings) -> crate::Result<ResourceMap> {
let first_directory = directories
.first()
.map(|d| d.as_os_str().to_string_lossy().into_owned())
.unwrap_or_else(|| String::new());
.unwrap_or_else(String::new);
let last_index = directories.len() - 1;
let mut path = String::new();
for (i, directory) in directories.into_iter().enumerate() {

View File

@ -125,7 +125,7 @@ impl Build {
crate::interface::rust::build_project(runner, &self.target, cargo_features, self.debug)
.with_context(|| "failed to build app")?;
let app_settings = crate::interface::rust::AppSettings::new(&config_)?;
let app_settings = crate::interface::rust::AppSettings::new(config_)?;
let out_dir = app_settings
.get_out_dir(self.debug)
@ -208,7 +208,7 @@ impl Build {
let settings = crate::interface::get_bundler_settings(
app_settings,
&manifest,
&config_,
config_,
&out_dir,
self.verbose,
package_types,

View File

@ -87,7 +87,7 @@ impl<'a> TermFeatures<'a> {
pub fn is_msys_tty(&self) -> bool {
#[cfg(windows)]
{
msys_tty_on(&self.0)
msys_tty_on(self.0)
}
#[cfg(not(windows))]
{

View File

@ -100,14 +100,14 @@ impl Dev {
let (settings, out_dir) = {
let config_guard = config.lock().unwrap();
let config_ = config_guard.as_ref().unwrap();
let app_settings = crate::interface::rust::AppSettings::new(&config_)?;
let app_settings = crate::interface::rust::AppSettings::new(config_)?;
let out_dir = app_settings
.get_out_dir(true)
.with_context(|| "failed to get project out directory")?;
let settings = crate::interface::get_bundler_settings(
app_settings,
&Default::default(),
&config_,
config_,
&out_dir,
false,
None,

View File

@ -93,7 +93,7 @@ impl<'a> Password<'a> {
let password = Zeroizing::new(self.prompt_password(&mut render, &self.prompt)?);
if let Some((ref prompt, ref err)) = self.confirmation_prompt {
let pw2 = Zeroizing::new(self.prompt_password(&mut render, &prompt)?);
let pw2 = Zeroizing::new(self.prompt_password(&mut render, prompt)?);
if *password == *pw2 {
render.clear()?;

View File

@ -77,7 +77,7 @@ fn get_internal(merge_config: Option<&str>, reload: bool) -> crate::Result<Confi
if let Some(merge_config) = merge_config {
let merge_config: JsonValue =
serde_json::from_str(&merge_config).with_context(|| "failed to parse config to merge")?;
serde_json::from_str(merge_config).with_context(|| "failed to parse config to merge")?;
merge(&mut config, &merge_config);
}

View File

@ -82,11 +82,11 @@ where
std::fs::remove_file(&pk_path)?;
}
let mut sk_writer = create_file(&sk_path)?;
let mut sk_writer = create_file(sk_path)?;
write!(sk_writer, "{:}", key)?;
sk_writer.flush()?;
let mut pk_writer = create_file(&pk_path)?;
let mut pk_writer = create_file(pk_path)?;
write!(pk_writer, "{:}", pubkey)?;
pk_writer.flush()?;
@ -119,7 +119,7 @@ where
let signature_path_string = format!("{}.sig", bin_path.as_ref().display());
let signature_path = Path::new(&signature_path_string);
let mut signature_box_writer = create_file(&signature_path)?;
let mut signature_box_writer = create_file(signature_path)?;
let trusted_comment = format!(
"timestamp:{}\tfile:{}",
@ -139,7 +139,7 @@ where
)?;
let encoded_signature = encode(&signature_box.to_string());
signature_box_writer.write_all(&encoded_signature.as_bytes())?;
signature_box_writer.write_all(encoded_signature.as_bytes())?;
signature_box_writer.flush()?;
Ok((fs::canonicalize(&signature_path)?, encoded_signature))
}

View File

@ -20,7 +20,7 @@ pub fn get_bundler_settings(
let mut settings_builder = SettingsBuilder::new()
.package_settings(app_settings.get_package_settings())
.bundle_settings(app_settings.get_bundle_settings(config, manifest)?)
.binaries(app_settings.get_binaries(&config)?)
.binaries(app_settings.get_binaries(config)?)
.project_out_directory(out_dir);
if verbose {

View File

@ -350,6 +350,7 @@ pub fn get_workspace_dir(current_dir: &Path) -> PathBuf {
current_dir.to_path_buf()
}
#[allow(unused_variables)]
fn tauri_config_to_bundle_settings(
manifest: &Manifest,
config: crate::helpers::config::BundleConfig,

View File

@ -268,15 +268,15 @@ fn main() -> Result<()> {
let matches = app_matches.subcommand_matches("tauri").unwrap();
if let Some(matches) = matches.subcommand_matches("init") {
init_command(&matches)?;
init_command(matches)?;
} else if let Some(matches) = matches.subcommand_matches("dev") {
dev_command(&matches)?;
dev_command(matches)?;
} else if let Some(matches) = matches.subcommand_matches("build") {
build_command(&matches)?;
build_command(matches)?;
} else if matches.subcommand_matches("info").is_some() {
info_command()?;
} else if let Some(matches) = matches.subcommand_matches("sign") {
sign_command(&matches)?;
sign_command(matches)?;
}
Ok(())