Skip to content

Commit dc6b0d8

Browse files
authored
feat(core): set .rc values from tauri.conf.json, closes #1849 (#1951)
1 parent 9bf82f0 commit dc6b0d8

30 files changed

Lines changed: 82 additions & 55 deletions

File tree

.changes/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@
249249
"path": "./core/tauri-build",
250250
"manager": "rust",
251251
"dependencies": [
252-
"tauri-codegen"
252+
"tauri-codegen",
253+
"tauri-utils"
253254
],
254255
"postversion": "node ../../.scripts/sync-cli-metadata.js ${ pkg.pkg } ${ release.type }"
255256
},
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-build": patch
3+
---
4+
5+
Pull Windows resource information (`FileVersion`, `ProductVersion`, `ProductName` and `FileDescription`) from `tauri.conf.json > package` configuration.

core/tauri-build/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ tauri-codegen = { version = "1.0.0-beta.0", path = "../tauri-codegen", optional
2323

2424
[target."cfg(windows)".dependencies]
2525
winres = "0.1"
26+
serde_json = "1.0"
27+
tauri-utils = { version = "1.0.0-beta.0", path = "../tauri-utils", features = [ "build" ] }
2628

2729
[features]
2830
codegen = [ "tauri-codegen" ]

core/tauri-build/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,15 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
9393
#[cfg(windows)]
9494
{
9595
use anyhow::{anyhow, Context};
96+
use std::fs::read_to_string;
97+
use tauri_utils::config::Config;
9698
use winres::WindowsResource;
9799

100+
let config: Config = serde_json::from_str(
101+
&read_to_string("tauri.conf.json").expect("failed to read tauri.conf.json"),
102+
)
103+
.expect("failed to parse tauri.conf.json");
104+
98105
let icon_path_string = attributes
99106
.windows_attributes
100107
.window_icon_path
@@ -103,6 +110,14 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
103110

104111
if attributes.windows_attributes.window_icon_path.exists() {
105112
let mut res = WindowsResource::new();
113+
if let Some(version) = &config.package.version {
114+
res.set("FileVersion", version);
115+
res.set("ProductVersion", version);
116+
}
117+
if let Some(product_name) = &config.package.product_name {
118+
res.set("ProductName", product_name);
119+
res.set("FileDescription", product_name);
120+
}
106121
res.set_icon_with_id(&icon_path_string, "32512");
107122
res.compile().with_context(|| {
108123
format!(

core/tauri-runtime-wry/src/menu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'a, I: MenuId> From<&'a CustomMenuItem<I>> for MenuItemAttributesWrapper<'a
147147
.with_selected(item.selected)
148148
.with_id(WryMenuId(item.id_value()));
149149
if let Some(accelerator) = item.keyboard_accelerator.as_ref() {
150-
attributes = attributes.with_accelerators(&accelerator);
150+
attributes = attributes.with_accelerators(accelerator);
151151
}
152152
Self(attributes)
153153
}

core/tauri/src/api/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ fn get_app<'a>(name: &str, about: Option<&'a String>, config: &'a CliConfig) ->
162162
if let Some(args) = config.args() {
163163
for arg in args {
164164
let arg_name = arg.name.as_ref();
165-
app = app.arg(get_arg(arg_name, &arg));
165+
app = app.arg(get_arg(arg_name, arg));
166166
}
167167
}
168168

169169
if let Some(subcommands) = config.subcommands() {
170170
for (subcommand_name, subcommand) in subcommands {
171-
let clap_subcommand = get_app(&subcommand_name, subcommand.description(), subcommand);
171+
let clap_subcommand = get_app(subcommand_name, subcommand.description(), subcommand);
172172
app = app.subcommand(clap_subcommand);
173173
}
174174
}

core/tauri/src/api/file/extract.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'a> Extract<'a> {
8484
let source = fs::File::open(self.source)?;
8585
let archive = self
8686
.archive_format
87-
.unwrap_or_else(|| detect_archive_type(&self.source));
87+
.unwrap_or_else(|| detect_archive_type(self.source));
8888

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

145145
match archive {
146146
ArchiveFormat::Plain(compression) | ArchiveFormat::Tar(compression) => {

core/tauri/src/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ where
731731
let app_handle = app_handle.clone();
732732
let event = match event {
733733
RuntimeSystemTrayEvent::MenuItemClick(id) => tray::SystemTrayEvent::MenuItemClick {
734-
id: ids.get(&id).unwrap().clone(),
734+
id: ids.get(id).unwrap().clone(),
735735
},
736736
RuntimeSystemTrayEvent::LeftClick { position, size } => {
737737
tray::SystemTrayEvent::LeftClick {

core/tauri/src/endpoints/app.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use serde::Deserialize;
99
/// The API descriptor.
1010
#[derive(Deserialize)]
1111
#[serde(tag = "cmd", rename_all = "camelCase")]
12+
#[allow(clippy::enum_variant_names)]
1213
pub enum Cmd {
1314
/// Get Application Version
1415
GetAppVersion,

core/tauri/src/endpoints/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl Cmd {
2121
#[allow(unused_variables)]
2222
Self::CliMatches => {
2323
#[cfg(cli)]
24-
return crate::api::cli::get_matches(&cli_config)
24+
return crate::api::cli::get_matches(cli_config)
2525
.map_err(Into::into)
2626
.map(Into::into);
2727
#[cfg(not(cli))]

0 commit comments

Comments
 (0)