Skip to content

Commit 3f82c45

Browse files
Klemen2jkelleyrtp
andauthored
feat: windows app icon (#3753)
* default icon * cli * fix typos, fmt + icon fix I don't think it's a good idea to do [default.extend-words] fo = "fo" as it's a very common mispelling for 'for' * fix clippy * return error on non implemented platforms instead of default dx icon * fix * fix fix the amazing merge renamed winres to windows moved windows winres build request to windows * fix typos * fix schema * Update schema.json * fix schema again * use default icon if no fallback * wire up the rest of windows * fmt --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
1 parent 6d1f190 commit 3f82c45

17 files changed

Lines changed: 1124 additions & 24 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_typos.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ unparented = "unparented"
1414
flate2="flate2"
1515

1616
[files]
17-
extend-exclude = ["notes/translations/*", "CHANGELOG.md", "*.js"]
17+
extend-exclude = ["notes/translations/*", "CHANGELOG.md", "*.js", "packages/cli/src/build/windows.rs"]

packages/cli/assets/icon.ico

110 KB
Binary file not shown.

packages/cli/schema.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,13 @@
541541
"null"
542542
]
543543
},
544+
"name": {
545+
"description": "Display name of the application",
546+
"type": [
547+
"string",
548+
"null"
549+
]
550+
},
544551
"out_dir": {
545552
"type": [
546553
"string",
@@ -649,6 +656,12 @@
649656
"type": "string"
650657
}
651658
},
659+
"file_version": {
660+
"type": [
661+
"string",
662+
"null"
663+
]
664+
},
652665
"icon": {
653666
"type": [
654667
"array",
@@ -680,6 +693,12 @@
680693
}
681694
]
682695
},
696+
"original_file_name": {
697+
"type": [
698+
"string",
699+
"null"
700+
]
701+
},
683702
"publisher": {
684703
"type": [
685704
"string",
@@ -701,6 +720,18 @@
701720
"null"
702721
]
703722
},
723+
"trademark": {
724+
"type": [
725+
"string",
726+
"null"
727+
]
728+
},
729+
"version": {
730+
"type": [
731+
"string",
732+
"null"
733+
]
734+
},
704735
"windows": {
705736
"anyOf": [
706737
{
@@ -2864,6 +2895,13 @@
28642895
"WindowsSettings": {
28652896
"type": "object",
28662897
"properties": {
2898+
"add_toolkit_include": {
2899+
"description": "Pass the host Windows SDK's `um/` and `shared/` headers to `rc.exe` via `/I` flags. Only relevant when cross-compiling to MSVC from a non-Windows host where the SDK headers aren't on the default include path. Has no effect for the GNU (`windres`) toolchain.",
2900+
"type": [
2901+
"boolean",
2902+
"null"
2903+
]
2904+
},
28672905
"allow_downgrades": {
28682906
"type": "boolean"
28692907
},
@@ -2873,18 +2911,48 @@
28732911
"null"
28742912
]
28752913
},
2914+
"comments": {
2915+
"description": "Free-form developer comments embedded in the executable's VERSIONINFO, surfaced in Windows Explorer → Properties → Details → Comments.",
2916+
"type": [
2917+
"string",
2918+
"null"
2919+
]
2920+
},
28762921
"digest_algorithm": {
28772922
"type": [
28782923
"string",
28792924
"null"
28802925
]
28812926
},
2927+
"extra_rc": {
2928+
"description": "Raw `.rc` snippet appended verbatim to the generated resource file. Use this to add custom resources not covered by other settings — application manifests, custom string tables, accelerators, etc. Contents are not escaped.",
2929+
"type": [
2930+
"string",
2931+
"null"
2932+
]
2933+
},
28822934
"icon_path": {
28832935
"type": [
28842936
"string",
28852937
"null"
28862938
]
28872939
},
2940+
"internal_name": {
2941+
"description": "Internal name embedded in the executable's VERSIONINFO. Most apps leave this equal to the product name; override only if the binary is known internally by a different identifier (e.g. an original codename).",
2942+
"type": [
2943+
"string",
2944+
"null"
2945+
]
2946+
},
2947+
"language": {
2948+
"description": "VERSIONINFO LANGID for the resource block. Hex form like `0x0409` (en-US) or `0x0407` (de-DE). Defaults to `0x0000` (neutral). See <https://learn.microsoft.com/en-us/windows/win32/menurc/versioninfo-resource#langID> for the full table.",
2949+
"type": [
2950+
"integer",
2951+
"null"
2952+
],
2953+
"format": "uint16",
2954+
"minimum": 0.0
2955+
},
28882956
"nsis": {
28892957
"anyOf": [
28902958
{

packages/cli/src/build/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
mod android;
1313
mod apple;
1414
mod web;
15+
mod windows;
1516

1617
mod assets;
1718
mod builder;

packages/cli/src/build/request.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,15 @@ impl BuildRequest {
943943
AndroidTools::unpack_prebuilt_openssl()?;
944944
}
945945

946+
// Compile the Windows resource (.res) so it's ready to be linked in later
947+
if matches!(self.triple.operating_system, OperatingSystem::Windows) {
948+
if let Err(err) = self.write_winres() {
949+
if self.using_dioxus_explicitly {
950+
tracing::warn!("Application may not have an icon: {err}");
951+
}
952+
}
953+
}
954+
946955
Ok(())
947956
}
948957

@@ -1767,6 +1776,11 @@ impl BuildRequest {
17671776
cargo_args.push("-Clink-arg=-Wl,-rpath,$ORIGIN/../lib".to_string());
17681777
cargo_args.push("-Clink-arg=-Wl,-rpath,$ORIGIN".to_string());
17691778
}
1779+
OperatingSystem::Windows => {
1780+
if let Some((search_path, link_spec)) = self.winres_linker_args() {
1781+
cargo_args.extend(["-L".to_string(), search_path, "-l".to_string(), link_spec]);
1782+
}
1783+
}
17701784
_ => {}
17711785
}
17721786

@@ -2505,7 +2519,7 @@ impl BuildRequest {
25052519
/// target/dx/build/app/web/
25062520
/// target/dx/build/app/web/public/
25072521
/// target/dx/build/app/web/server.exe
2508-
fn platform_dir(&self) -> PathBuf {
2522+
pub(crate) fn platform_dir(&self) -> PathBuf {
25092523
self.internal_out_dir()
25102524
.join(&self.main_target)
25112525
.join(if self.release { "release" } else { "debug" })

0 commit comments

Comments
 (0)