Skip to content

Commit

Permalink
feat(core): add skip_taskbar API to the WindowBuilder/WindowOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed May 30, 2021
1 parent 36506c9 commit 5525b03
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .changes/api-skip-taskbar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"api": patch
---

Adds `skipTaskbar?: boolean` to the WindowOptions interface.
7 changes: 7 additions & 0 deletions .changes/skip-taskbar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri": patch
"tauri-runtime": patch
"tauri-runtime-wry": patch
---

Adds `skip_taskbar` API to the WindowBuilder.
11 changes: 10 additions & 1 deletion core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ impl WindowBuilder for WindowBuilderWrapper {
.maximized(config.maximized)
.fullscreen(config.fullscreen)
.transparent(config.transparent)
.always_on_top(config.always_on_top);
.always_on_top(config.always_on_top)
.skip_taskbar(config.skip_taskbar);

if let (Some(min_width), Some(min_height)) = (config.min_width, config.min_height) {
window = window.min_inner_size(min_width, min_height);
Expand All @@ -260,6 +261,10 @@ impl WindowBuilder for WindowBuilderWrapper {
window = window.position(x, y);
}

if config.focus {
window = window.focus();
}

window
}

Expand Down Expand Up @@ -355,6 +360,10 @@ impl WindowBuilder for WindowBuilderWrapper {
))
}

fn skip_taskbar(self, skip: bool) -> Self {
Self(self.0.with_skip_taskbar(skip))
}

fn has_icon(&self) -> bool {
self.0.window.window_icon.is_some()
}
Expand Down
3 changes: 3 additions & 0 deletions core/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ pub trait WindowBuilder: WindowBuilderBase {
/// Sets the window icon.
fn icon(self, icon: Icon) -> crate::Result<Self>;

/// Sets whether or not the window icon should be added to the taskbar.
fn skip_taskbar(self, skip: bool) -> Self;

/// Sets a parent to the window to be created.
///
/// A child window has the WS_CHILD style and is confined to the client area of its parent window.
Expand Down
9 changes: 8 additions & 1 deletion core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ pub struct WindowConfig {
/// Whether the window should always be on top of other windows.
#[serde(default)]
pub always_on_top: bool,
/// Whether or not the window icon should be added to the taskbar.
#[serde(default)]
pub skip_taskbar: bool,
}

fn default_window_label() -> String {
Expand Down Expand Up @@ -139,6 +142,7 @@ impl Default for WindowConfig {
visible: default_visible(),
decorations: default_decorations(),
always_on_top: false,
skip_taskbar: false,
}
}
}
Expand Down Expand Up @@ -640,6 +644,7 @@ mod build {
let visible = self.visible;
let decorations = self.decorations;
let always_on_top = self.always_on_top;
let skip_taskbar = self.skip_taskbar;

literal_struct!(
tokens,
Expand All @@ -662,7 +667,8 @@ mod build {
maximized,
visible,
decorations,
always_on_top
always_on_top,
skip_taskbar
);
}
}
Expand Down Expand Up @@ -911,6 +917,7 @@ mod test {
visible: true,
decorations: true,
always_on_top: false,
skip_taskbar: false,
}],
bundle: BundleConfig {
identifier: String::from(""),
Expand Down
34 changes: 15 additions & 19 deletions examples/api/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,23 @@ fn main() {
SystemTrayMenuItem::Custom(CustomMenuItem::new("toggle".into(), "Toggle")),
SystemTrayMenuItem::Custom(CustomMenuItem::new("new".into(), "New window")),
])
.on_system_tray_event(|app, event| {
match event.menu_item_id().as_str() {
"toggle" => {
let window = app.get_window("main").unwrap();
if window.is_visible().unwrap() {
window.hide().unwrap();
} else {
window.show().unwrap();
}
.on_system_tray_event(|app, event| match event.menu_item_id().as_str() {
"toggle" => {
let window = app.get_window("main").unwrap();
if window.is_visible().unwrap() {
window.hide().unwrap();
} else {
window.show().unwrap();
}
"new" => app
.create_window(
"new".into(),
WindowUrl::App("index.html".into()),
|window_builder, webview_attributes| {
(window_builder.title("Tauri"), webview_attributes)
},
)
.unwrap(),
_ => {}
}
"new" => app
.create_window(
"new".into(),
WindowUrl::App("index.html".into()),
|window_builder, webview_attributes| (window_builder.title("Tauri"), webview_attributes),
)
.unwrap(),
_ => {}
})
.invoke_handler(tauri::generate_handler![
cmd::log_operation,
Expand Down
2 changes: 2 additions & 0 deletions tooling/api/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,8 @@ interface WindowOptions {
decorations?: boolean
/** Whether the window should always be on top of other windows or not. */
alwaysOnTop?: boolean
/** Whether or not the window icon should be added to the taskbar. */
skipTaskbar?: boolean
}

/**
Expand Down
22 changes: 4 additions & 18 deletions tooling/cli.rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5525b03

Please sign in to comment.