Skip to content

Commit 2a75c64

Browse files
amrbashirgeraudlouplucasfernog
authored
feat(core): add window_class name API on Windows (#11469)
* On Windows, set name of Window Class, closes #7498 allow to customize it instead of current value hard coded "Window Class" * feat(windows): add window_classname, closes #7498 allow to customize the window class name instead of current value hard coded "Window Class" * feat: add window_classname, closes #7498 * add changes file * Update core/tauri-config-schema/schema.json * Update tooling/cli/schema.json * missing pieces after merge * clippy --------- Co-authored-by: Géraud-Loup <47665233+geraudloup@users.noreply.github.com> Co-authored-by: Lucas Nogueira <lucas@tauri.app>
1 parent 1b6b2cf commit 2a75c64

File tree

11 files changed

+78
-0
lines changed

11 files changed

+78
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tauri-apps/api": 'minor:feat'
3+
---
4+
5+
Added `windowClassname` option, when constructing a `Webview` or `WebviewWindow`, to specify the name of the window class on Windows.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": 'minor:feat'
3+
"tauri-utils": 'minor:feat'
4+
---
5+
6+
Added `app > windows > windowClassname` config option to specify the name of the window class on Windows.

.changes/window-class-name.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri": 'minor:feat'
3+
"tauri-runtime-wry": 'minor:feat'
4+
"tauri-runtime": 'minor:feat'
5+
---
6+
7+
Added `WindowBuilder/WebviewWindowBuilder::window_classname` method to specify the name of the window class on Windows.

crates/tauri-cli/config.schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,13 @@
397397
"default": false,
398398
"type": "boolean"
399399
},
400+
"windowClassname": {
401+
"description": "The name of the window class created on Windows to create the window. **Windows only**.",
402+
"type": [
403+
"string",
404+
"null"
405+
]
406+
},
400407
"theme": {
401408
"description": "The initial window theme. Defaults to the system theme. Only implemented on Windows and macOS 10.14+.",
402409
"anyOf": [

crates/tauri-runtime-wry/src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,11 @@ impl WindowBuilder for WindowBuilderWrapper {
763763

764764
builder = builder.title("Tauri App");
765765

766+
#[cfg(windows)]
767+
{
768+
builder = builder.window_classname("Tauri Window");
769+
}
770+
766771
builder
767772
}
768773

@@ -846,6 +851,10 @@ impl WindowBuilder for WindowBuilderWrapper {
846851
if config.center {
847852
window = window.center();
848853
}
854+
855+
if let Some(window_classname) = &config.window_classname {
856+
window = window.window_classname(window_classname);
857+
}
849858
}
850859

851860
window
@@ -1106,6 +1115,16 @@ impl WindowBuilder for WindowBuilderWrapper {
11061115
_ => Theme::Light,
11071116
})
11081117
}
1118+
1119+
#[cfg(windows)]
1120+
fn window_classname<S: Into<String>>(mut self, window_classname: S) -> Self {
1121+
self.inner = self.inner.with_window_classname(window_classname);
1122+
self
1123+
}
1124+
#[cfg(not(windows))]
1125+
fn window_classname<S: Into<String>>(self, _window_classname: S) -> Self {
1126+
self
1127+
}
11091128
}
11101129

11111130
#[cfg(any(

crates/tauri-runtime/src/window.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,10 @@ pub trait WindowBuilder: WindowBuilderBase {
438438
fn has_icon(&self) -> bool;
439439

440440
fn get_theme(&self) -> Option<Theme>;
441+
442+
/// Sets custom name for Windows' window class. **Windows only**.
443+
#[must_use]
444+
fn window_classname<S: Into<String>>(self, window_classname: S) -> Self;
441445
}
442446

443447
/// A window that has yet to be built.

crates/tauri-schema-generator/schemas/config.schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,13 @@
397397
"default": false,
398398
"type": "boolean"
399399
},
400+
"windowClassname": {
401+
"description": "The name of the window class created on Windows to create the window. **Windows only**.",
402+
"type": [
403+
"string",
404+
"null"
405+
]
406+
},
400407
"theme": {
401408
"description": "The initial window theme. Defaults to the system theme. Only implemented on Windows and macOS 10.14+.",
402409
"anyOf": [

crates/tauri-utils/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,8 @@ pub struct WindowConfig {
14291429
/// If `true`, hides the window icon from the taskbar on Windows and Linux.
14301430
#[serde(default, alias = "skip-taskbar")]
14311431
pub skip_taskbar: bool,
1432+
/// The name of the window class created on Windows to create the window. **Windows only**.
1433+
pub window_classname: Option<String>,
14321434
/// The initial window theme. Defaults to the system theme. Only implemented on Windows and macOS 10.14+.
14331435
pub theme: Option<crate::Theme>,
14341436
/// The style of the macOS title bar.
@@ -1566,6 +1568,7 @@ impl Default for WindowConfig {
15661568
visible_on_all_workspaces: false,
15671569
content_protected: false,
15681570
skip_taskbar: false,
1571+
window_classname: None,
15691572
theme: None,
15701573
title_bar_style: Default::default(),
15711574
hidden_title: false,
@@ -2539,6 +2542,7 @@ mod build {
25392542
let visible_on_all_workspaces = self.visible_on_all_workspaces;
25402543
let content_protected = self.content_protected;
25412544
let skip_taskbar = self.skip_taskbar;
2545+
let window_classname = opt_str_lit(self.window_classname.as_ref());
25422546
let theme = opt_lit(self.theme.as_ref());
25432547
let title_bar_style = &self.title_bar_style;
25442548
let hidden_title = self.hidden_title;
@@ -2587,6 +2591,7 @@ mod build {
25872591
visible_on_all_workspaces,
25882592
content_protected,
25892593
skip_taskbar,
2594+
window_classname,
25902595
theme,
25912596
title_bar_style,
25922597
hidden_title,

crates/tauri/src/test/mock_runtime.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,10 @@ impl WindowBuilder for MockWindowBuilder {
421421
self
422422
}
423423

424+
fn window_classname<S: Into<String>>(self, classname: S) -> Self {
425+
self
426+
}
427+
424428
fn shadow(self, enable: bool) -> Self {
425429
self
426430
}

crates/tauri/src/webview/webview_window.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,13 @@ impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M> {
571571
self
572572
}
573573

574+
/// Sets custom name for Windows' window class. **Windows only**.
575+
#[must_use]
576+
pub fn window_classname<S: Into<String>>(mut self, classname: S) -> Self {
577+
self.window_builder = self.window_builder.window_classname(classname);
578+
self
579+
}
580+
574581
/// Sets whether or not the window has shadow.
575582
///
576583
/// ## Platform-specific

0 commit comments

Comments
 (0)