Skip to content

Commit

Permalink
feat(core): window API (#1225)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Feb 14, 2021
1 parent 4db2196 commit a3d6dff
Show file tree
Hide file tree
Showing 17 changed files with 1,266 additions and 96 deletions.
6 changes: 6 additions & 0 deletions .changes/window-api.md
@@ -0,0 +1,6 @@
---
"api": minor
"tauri": minor
---

Added window management APIs.
312 changes: 311 additions & 1 deletion api/src/window.ts
@@ -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
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
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
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"
}
}

0 comments on commit a3d6dff

Please sign in to comment.