Skip to content

Commit a3d6dff

Browse files
authored
feat(core): window API (#1225)
1 parent 4db2196 commit a3d6dff

File tree

17 files changed

+1266
-96
lines changed

17 files changed

+1266
-96
lines changed

.changes/window-api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"api": minor
3+
"tauri": minor
4+
---
5+
6+
Added window management APIs.

api/src/window.ts

Lines changed: 311 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
import { invoke } from './tauri'
22

3+
/**
4+
* Updates the window resizable flag.
5+
*/
6+
function setResizable(resizable: boolean): void {
7+
invoke({
8+
module: 'Window',
9+
message: {
10+
cmd: 'setResizable',
11+
resizable
12+
}
13+
})
14+
}
15+
316
/**
417
* sets the window title
518
*
@@ -15,4 +28,301 @@ function setTitle(title: string): void {
1528
})
1629
}
1730

18-
export { setTitle }
31+
/**
32+
* Maximizes the window.
33+
*/
34+
function maximize(): void {
35+
invoke({
36+
module: 'Window',
37+
message: {
38+
cmd: 'maximize'
39+
}
40+
})
41+
}
42+
43+
/**
44+
* Unmaximizes the window.
45+
*/
46+
function unmaximize(): void {
47+
invoke({
48+
module: 'Window',
49+
message: {
50+
cmd: 'unmaximize'
51+
}
52+
})
53+
}
54+
55+
/**
56+
* Minimizes the window.
57+
*/
58+
function minimize(): void {
59+
invoke({
60+
module: 'Window',
61+
message: {
62+
cmd: 'minimize'
63+
}
64+
})
65+
}
66+
67+
/**
68+
* Unminimizes the window.
69+
*/
70+
function unminimize(): void {
71+
invoke({
72+
module: 'Window',
73+
message: {
74+
cmd: 'unminimize'
75+
}
76+
})
77+
}
78+
79+
/**
80+
* Sets the window visibility to true.
81+
*/
82+
function show(): void {
83+
invoke({
84+
module: 'Window',
85+
message: {
86+
cmd: 'show'
87+
}
88+
})
89+
}
90+
91+
/**
92+
* Sets the window visibility to false.
93+
*/
94+
function hide(): void {
95+
invoke({
96+
module: 'Window',
97+
message: {
98+
cmd: 'hide'
99+
}
100+
})
101+
}
102+
103+
/**
104+
* Sets the window transparent flag.
105+
*
106+
* @param {boolean} transparent whether the the window should be transparent or not
107+
*/
108+
function setTransparent(transparent: boolean): void {
109+
invoke({
110+
module: 'Window',
111+
message: {
112+
cmd: 'setTransparent',
113+
transparent
114+
}
115+
})
116+
}
117+
118+
/**
119+
* Whether the window should have borders and bars.
120+
*
121+
* @param {boolean} decorations whether the window should have borders and bars
122+
*/
123+
function setDecorations(decorations: boolean): void {
124+
invoke({
125+
module: 'Window',
126+
message: {
127+
cmd: 'setDecorations',
128+
decorations
129+
}
130+
})
131+
}
132+
133+
/**
134+
* Whether the window should always be on top of other windows.
135+
*
136+
* @param {boolean} alwaysOnTop whether the window should always be on top of other windows or not
137+
*/
138+
function setAlwaysOnTop(alwaysOnTop: boolean): void {
139+
invoke({
140+
module: 'Window',
141+
message: {
142+
cmd: 'setAlwaysOnTop',
143+
alwaysOnTop
144+
}
145+
})
146+
}
147+
148+
/**
149+
* Sets the window width.
150+
*
151+
* @param {number} width the new window width
152+
*/
153+
function setWidth(width: number): void {
154+
invoke({
155+
module: 'Window',
156+
message: {
157+
cmd: 'setWidth',
158+
width
159+
}
160+
})
161+
}
162+
163+
/**
164+
* Sets the window height.
165+
*
166+
* @param {number} height the new window height
167+
*/
168+
function setHeight(height: number): void {
169+
invoke({
170+
module: 'Window',
171+
message: {
172+
cmd: 'setHeight',
173+
height
174+
}
175+
})
176+
}
177+
178+
/**
179+
* Resizes the window.
180+
*
181+
* @param {number} width the new window width
182+
* @param {number} height the new window height
183+
*/
184+
function resize(width: number, height: number): void {
185+
invoke({
186+
module: 'Window',
187+
message: {
188+
cmd: 'resize',
189+
width,
190+
height,
191+
}
192+
})
193+
}
194+
195+
/**
196+
* Sets the window min size.
197+
*
198+
* @param {number} minWidth the new window min width
199+
* @param {number} minHeight the new window min height
200+
*/
201+
function setMinSize(minWidth: number, minHeight: number): void {
202+
invoke({
203+
module: 'Window',
204+
message: {
205+
cmd: 'setMinSize',
206+
minWidth,
207+
minHeight
208+
}
209+
})
210+
}
211+
212+
/**
213+
* Sets the window max size.
214+
*
215+
* @param {number} maxWidth the new window max width
216+
* @param {number} maxHeight the new window max height
217+
*/
218+
function setMaxSize(maxWidth: number, maxHeight: number): void {
219+
invoke({
220+
module: 'Window',
221+
message: {
222+
cmd: 'setMaxSize',
223+
maxWidth,
224+
maxHeight
225+
}
226+
})
227+
}
228+
229+
/**
230+
* Sets the window x position.
231+
*
232+
* @param {number} x the new window x position
233+
*/
234+
function setX(x: number): void {
235+
invoke({
236+
module: 'Window',
237+
message: {
238+
cmd: 'setX',
239+
x
240+
}
241+
})
242+
}
243+
244+
/**
245+
* Sets the window y position.
246+
*
247+
* @param {number} y the new window y position
248+
*/
249+
function setY(y: number): void {
250+
invoke({
251+
module: 'Window',
252+
message: {
253+
cmd: 'setY',
254+
y
255+
}
256+
})
257+
}
258+
259+
/**
260+
* Sets the window position.
261+
*
262+
* @param {number} x the new window x position
263+
* @param {number} y the new window y position
264+
*/
265+
function setPosition(x: number, y: number): void {
266+
invoke({
267+
module: 'Window',
268+
message: {
269+
cmd: 'setPosition',
270+
x,
271+
y
272+
}
273+
})
274+
}
275+
276+
/**
277+
* Sets the window fullscreen state.
278+
*
279+
* @param {boolean} fullscreen whether the window should go to fullscreen or not
280+
*/
281+
function setFullscreen(fullscreen: boolean): void {
282+
invoke({
283+
module: 'Window',
284+
message: {
285+
cmd: 'setFullscreen',
286+
fullscreen
287+
}
288+
})
289+
}
290+
291+
/**
292+
* Sets the window icon
293+
*
294+
* @param {string | number[]} icon icon bytes or path to the icon file
295+
*/
296+
function setIcon(icon: 'string' | number[]): void {
297+
invoke({
298+
module: 'Window',
299+
message: {
300+
cmd: 'setIcon',
301+
icon
302+
}
303+
})
304+
}
305+
306+
export {
307+
setResizable,
308+
setTitle,
309+
maximize,
310+
unmaximize,
311+
minimize,
312+
unminimize,
313+
show,
314+
hide,
315+
setTransparent,
316+
setDecorations,
317+
setAlwaysOnTop,
318+
setWidth,
319+
setHeight,
320+
resize,
321+
setMinSize,
322+
setMaxSize,
323+
setX,
324+
setY,
325+
setPosition,
326+
setFullscreen,
327+
setIcon
328+
}

tauri/Cargo.toml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ thiserror = "1.0.23"
3232
once_cell = "1.5.2"
3333
tauri-api = { version = "0.7.5", path = "../tauri-api" }
3434
tauri-macros = { version = "0.1", path = "../tauri-macros" }
35-
wry = { git = "https://github.com/tauri-apps/wry", rev = "f4edf89de5dc40b77a94f6b94fcaf76fdac6bbf4" }
35+
wry = { git = "https://github.com/tauri-apps/wry", rev = "b36b3e2d07edddf2ef49dcc901ae2c5888873ad2" }
3636

3737
[target."cfg(target_os = \"windows\")".dependencies]
3838
runas = "0.2"
@@ -50,6 +50,9 @@ serde = { version = "1.0", features = [ "derive" ] }
5050
cli = [ "tauri-api/cli" ]
5151
embedded-server = [ "tiny_http" ]
5252
all-api = [ "tauri-api/notification" ]
53+
updater = [ ]
54+
55+
# FS
5356
read-text-file = [ ]
5457
read-binary-file = [ ]
5558
write-file = [ ]
@@ -61,14 +64,23 @@ remove-dir = [ ]
6164
remove-file = [ ]
6265
rename-file = [ ]
6366
path-api = [ ]
64-
set-title = [ ]
67+
event = [ ]
68+
69+
# window
70+
window = [ ]
71+
72+
#shell
6573
execute = [ ]
6674
open = [ ]
67-
event = [ ]
68-
updater = [ ]
75+
76+
# dialog
6977
open-dialog = [ ]
7078
save-dialog = [ ]
79+
80+
# HTTP
7181
http-request = [ ]
82+
83+
# notification
7284
notification = [ "tauri-api/notification" ]
7385

7486
[[example]]

tauri/build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ fn main() {
2323
path_api: { any(all_api, feature = "path-api") },
2424

2525
// window
26-
set_title: { any(all_api, feature = "set-title") },
27-
open: { any(all_api, feature = "open") },
26+
window: { any(all_api, feature = "window") },
2827

29-
// process
28+
// shell
29+
open: { any(all_api, feature = "open") },
3030
execute: { any(all_api, feature = "execute") },
3131

3232
// event

tauri/examples/api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"svelte": "3.32.2"
1818
},
1919
"dependencies": {
20-
"sirv-cli": "1.0.11",
21-
"@tauri-apps/api": "link:../../../api"
20+
"@tauri-apps/api": "link:../../../api",
21+
"sirv-cli": "1.0.11"
2222
}
2323
}

0 commit comments

Comments
 (0)