Skip to content

Commit

Permalink
feat(core): set .rc values from tauri.conf.json, closes #1849 (#1951)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Jun 5, 2021
1 parent 9bf82f0 commit dc6b0d8
Show file tree
Hide file tree
Showing 30 changed files with 82 additions and 55 deletions.
3 changes: 2 additions & 1 deletion .changes/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 }"
},
Expand Down
5 changes: 5 additions & 0 deletions .changes/windows-resources-set-values.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-build": patch
---

Pull Windows resource information (`FileVersion`, `ProductVersion`, `ProductName` and `FileDescription`) from `tauri.conf.json > package` configuration.
2 changes: 2 additions & 0 deletions core/tauri-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
15 changes: 15 additions & 0 deletions core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion core/tauri-runtime-wry/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions core/tauri/src/api/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/tauri/src/api/file/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions core/tauri/src/endpoints/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/endpoints/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
1 change: 1 addition & 0 deletions core/tauri/src/endpoints/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
8 changes: 4 additions & 4 deletions core/tauri/src/updater/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion examples/params/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions tooling/bundler/src/bundle/linux/appimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tooling/bundler/src/bundle/linux/debian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down
2 changes: 1 addition & 1 deletion tooling/bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions tooling/bundler/src/bundle/updater_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?;
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion tooling/bundler/src/bundle/windows/msi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
33 changes: 17 additions & 16 deletions tooling/bundler/src/bundle/windows/msi/wix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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()),
},
)?;
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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));

Expand All @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions tooling/cli.rs/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -208,7 +208,7 @@ impl Build {
let settings = crate::interface::get_bundler_settings(
app_settings,
&manifest,
&config_,
config_,
&out_dir,
self.verbose,
package_types,
Expand Down
2 changes: 1 addition & 1 deletion tooling/cli.rs/src/console/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
{
Expand Down

0 comments on commit dc6b0d8

Please sign in to comment.