Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): window API #1225

Merged
merged 3 commits into from
Feb 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/window-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"api": minor
"tauri": minor
---

Added window management APIs.
312 changes: 311 additions & 1 deletion api/src/window.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import { invoke } from './tauri'

/**
* Updates the window resizable flag.
*/
function setResizable(resizable: boolean): void {
invoke({
module: 'Window',
message: {
cmd: 'setResizable',
resizable
}
})
}

/**
* sets the window title
*
Expand All @@ -15,4 +28,301 @@ function setTitle(title: string): void {
})
}

export { setTitle }
/**
* Maximizes the window.
*/
function maximize(): void {
invoke({
module: 'Window',
message: {
cmd: 'maximize'
}
})
}

/**
* Unmaximizes the window.
*/
function unmaximize(): void {
invoke({
module: 'Window',
message: {
cmd: 'unmaximize'
}
})
}

/**
* Minimizes the window.
*/
function minimize(): void {
invoke({
module: 'Window',
message: {
cmd: 'minimize'
}
})
}

/**
* Unminimizes the window.
*/
function unminimize(): void {
invoke({
module: 'Window',
message: {
cmd: 'unminimize'
}
})
}

/**
* Sets the window visibility to true.
*/
function show(): void {
invoke({
module: 'Window',
message: {
cmd: 'show'
}
})
}

/**
* Sets the window visibility to false.
*/
function hide(): void {
invoke({
module: 'Window',
message: {
cmd: 'hide'
}
})
}

/**
* Sets the window transparent flag.
*
* @param {boolean} transparent whether the the window should be transparent or not
*/
function setTransparent(transparent: boolean): void {
invoke({
module: 'Window',
message: {
cmd: 'setTransparent',
transparent
}
})
}

/**
* Whether the window should have borders and bars.
*
* @param {boolean} decorations whether the window should have borders and bars
*/
function setDecorations(decorations: boolean): void {
invoke({
module: 'Window',
message: {
cmd: 'setDecorations',
decorations
}
})
}

/**
* Whether the window should always be on top of other windows.
*
* @param {boolean} alwaysOnTop whether the window should always be on top of other windows or not
*/
function setAlwaysOnTop(alwaysOnTop: boolean): void {
invoke({
module: 'Window',
message: {
cmd: 'setAlwaysOnTop',
alwaysOnTop
}
})
}

/**
* Sets the window width.
*
* @param {number} width the new window width
*/
function setWidth(width: number): void {
invoke({
module: 'Window',
message: {
cmd: 'setWidth',
width
}
})
}

/**
* Sets the window height.
*
* @param {number} height the new window height
*/
function setHeight(height: number): void {
invoke({
module: 'Window',
message: {
cmd: 'setHeight',
height
}
})
}

/**
* Resizes the window.
*
* @param {number} width the new window width
* @param {number} height the new window height
*/
function resize(width: number, height: number): void {
invoke({
module: 'Window',
message: {
cmd: 'resize',
width,
height,
}
})
}

/**
* Sets the window min size.
*
* @param {number} minWidth the new window min width
* @param {number} minHeight the new window min height
*/
function setMinSize(minWidth: number, minHeight: number): void {
invoke({
module: 'Window',
message: {
cmd: 'setMinSize',
minWidth,
minHeight
}
})
}

/**
* Sets the window max size.
*
* @param {number} maxWidth the new window max width
* @param {number} maxHeight the new window max height
*/
function setMaxSize(maxWidth: number, maxHeight: number): void {
invoke({
module: 'Window',
message: {
cmd: 'setMaxSize',
maxWidth,
maxHeight
}
})
}

/**
* Sets the window x position.
*
* @param {number} x the new window x position
*/
function setX(x: number): void {
invoke({
module: 'Window',
message: {
cmd: 'setX',
x
}
})
}

/**
* Sets the window y position.
*
* @param {number} y the new window y position
*/
function setY(y: number): void {
invoke({
module: 'Window',
message: {
cmd: 'setY',
y
}
})
}

/**
* Sets the window position.
*
* @param {number} x the new window x position
* @param {number} y the new window y position
*/
function setPosition(x: number, y: number): void {
invoke({
module: 'Window',
message: {
cmd: 'setPosition',
x,
y
}
})
}

/**
* Sets the window fullscreen state.
*
* @param {boolean} fullscreen whether the window should go to fullscreen or not
*/
function setFullscreen(fullscreen: boolean): void {
invoke({
module: 'Window',
message: {
cmd: 'setFullscreen',
fullscreen
}
})
}

/**
* Sets the window icon
*
* @param {string | number[]} icon icon bytes or path to the icon file
*/
function setIcon(icon: 'string' | number[]): void {
invoke({
module: 'Window',
message: {
cmd: 'setIcon',
icon
}
})
}

export {
setResizable,
setTitle,
maximize,
unmaximize,
minimize,
unminimize,
show,
hide,
setTransparent,
setDecorations,
setAlwaysOnTop,
setWidth,
setHeight,
resize,
setMinSize,
setMaxSize,
setX,
setY,
setPosition,
setFullscreen,
setIcon
}
20 changes: 16 additions & 4 deletions tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ thiserror = "1.0.23"
once_cell = "1.5.2"
tauri-api = { version = "0.7.5", path = "../tauri-api" }
tauri-macros = { version = "0.1", path = "../tauri-macros" }
wry = { git = "https://github.com/tauri-apps/wry", rev = "f4edf89de5dc40b77a94f6b94fcaf76fdac6bbf4" }
wry = { git = "https://github.com/tauri-apps/wry", rev = "b36b3e2d07edddf2ef49dcc901ae2c5888873ad2" }

[target."cfg(target_os = \"windows\")".dependencies]
runas = "0.2"
Expand All @@ -50,6 +50,9 @@ serde = { version = "1.0", features = [ "derive" ] }
cli = [ "tauri-api/cli" ]
embedded-server = [ "tiny_http" ]
all-api = [ "tauri-api/notification" ]
updater = [ ]

# FS
read-text-file = [ ]
read-binary-file = [ ]
write-file = [ ]
Expand All @@ -61,14 +64,23 @@ remove-dir = [ ]
remove-file = [ ]
rename-file = [ ]
path-api = [ ]
set-title = [ ]
event = [ ]

# window
window = [ ]

#shell
execute = [ ]
open = [ ]
event = [ ]
updater = [ ]

# dialog
open-dialog = [ ]
save-dialog = [ ]

# HTTP
http-request = [ ]

# notification
notification = [ "tauri-api/notification" ]

[[example]]
Expand Down
6 changes: 3 additions & 3 deletions tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ fn main() {
path_api: { any(all_api, feature = "path-api") },

// window
set_title: { any(all_api, feature = "set-title") },
open: { any(all_api, feature = "open") },
window: { any(all_api, feature = "window") },

// process
// shell
open: { any(all_api, feature = "open") },
execute: { any(all_api, feature = "execute") },

// event
Expand Down
4 changes: 2 additions & 2 deletions tauri/examples/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"svelte": "3.32.2"
},
"dependencies": {
"sirv-cli": "1.0.11",
"@tauri-apps/api": "link:../../../api"
"@tauri-apps/api": "link:../../../api",
"sirv-cli": "1.0.11"
}
}