Skip to content

Commit 641374b

Browse files
authored
feat(core): window creation at runtime (#1249)
1 parent 0f3009b commit 641374b

File tree

25 files changed

+841
-320
lines changed

25 files changed

+841
-320
lines changed

.changes/window-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"tauri": minor
44
---
55

6-
Added window management APIs.
6+
Added window management and window creation APIs.

api/src/window.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,4 +371,38 @@ class WindowManager {
371371

372372
const manager = new WindowManager()
373373

374-
export { TauriWindow, getTauriWindow, getCurrentWindow, getWindows, manager }
374+
export interface WindowOptions {
375+
url?: 'app' | string
376+
x?: number
377+
y?: number
378+
width?: number
379+
height?: number
380+
minWidth?: number
381+
minHeight?: number
382+
maxWidth?: number
383+
maxHeight?: number
384+
resizable?: boolean
385+
title?: string
386+
fullscreen?: boolean
387+
transparent?: boolean
388+
maximized?: boolean
389+
visible?: boolean
390+
decorations?: boolean
391+
alwaysOnTop?: boolean
392+
}
393+
394+
async function createWindow(label: string, options: WindowOptions = {}): Promise<TauriWindow> {
395+
await invoke({
396+
__tauriModule: 'Window',
397+
message: {
398+
cmd: 'createWebview',
399+
options: {
400+
label,
401+
...options
402+
}
403+
}
404+
})
405+
return new TauriWindow(label)
406+
}
407+
408+
export { TauriWindow, getTauriWindow, getCurrentWindow, getWindows, manager, createWindow }

cli/core/src/templates/tauri.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,20 @@ if (!String.prototype.startsWith) {
194194
);
195195
}
196196

197+
window.__TAURI__.invoke({
198+
__tauriModule: 'Event',
199+
message: {
200+
cmd: 'listen',
201+
event: 'tauri://window-created',
202+
handler: window.__TAURI__.transformCallback(function (event) {
203+
if (event.payload) {
204+
var windowLabel = event.payload.label
205+
window.__TAURI__.__windows.push({ label: windowLabel })
206+
}
207+
})
208+
}
209+
})
210+
197211
let permissionSettable = false;
198212
let permissionValue = "default";
199213

cli/tauri.js/src/types/config.schema.json

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,23 +427,61 @@
427427
"additionalProperties": false,
428428
"defaultProperties": [],
429429
"properties": {
430+
"alwaysOnTop": {
431+
"type": "boolean"
432+
},
433+
"decorations": {
434+
"type": "boolean"
435+
},
430436
"fullscreen": {
431437
"type": "boolean"
432438
},
433439
"height": {
434440
"type": "number"
435441
},
442+
"label": {
443+
"type": "string"
444+
},
445+
"maxHeight": {
446+
"type": "number"
447+
},
448+
"maxWidth": {
449+
"type": "number"
450+
},
451+
"maximized": {
452+
"type": "boolean"
453+
},
454+
"minHeight": {
455+
"type": "number"
456+
},
457+
"minWidth": {
458+
"type": "number"
459+
},
436460
"resizable": {
437461
"type": "boolean"
438462
},
439463
"title": {
440464
"type": "string"
441465
},
466+
"transparent": {
467+
"type": "boolean"
468+
},
469+
"url": {
470+
"type": "string"
471+
},
472+
"visible": {
473+
"type": "boolean"
474+
},
442475
"width": {
443476
"type": "number"
477+
},
478+
"x": {
479+
"type": "number"
480+
},
481+
"y": {
482+
"type": "number"
444483
}
445484
},
446-
"required": ["title"],
447485
"type": "object"
448486
}
449487
]
@@ -453,23 +491,61 @@
453491
"additionalProperties": false,
454492
"defaultProperties": [],
455493
"properties": {
494+
"alwaysOnTop": {
495+
"type": "boolean"
496+
},
497+
"decorations": {
498+
"type": "boolean"
499+
},
456500
"fullscreen": {
457501
"type": "boolean"
458502
},
459503
"height": {
460504
"type": "number"
461505
},
506+
"label": {
507+
"type": "string"
508+
},
509+
"maxHeight": {
510+
"type": "number"
511+
},
512+
"maxWidth": {
513+
"type": "number"
514+
},
515+
"maximized": {
516+
"type": "boolean"
517+
},
518+
"minHeight": {
519+
"type": "number"
520+
},
521+
"minWidth": {
522+
"type": "number"
523+
},
462524
"resizable": {
463525
"type": "boolean"
464526
},
465527
"title": {
466528
"type": "string"
467529
},
530+
"transparent": {
531+
"type": "boolean"
532+
},
533+
"url": {
534+
"type": "string"
535+
},
536+
"visible": {
537+
"type": "boolean"
538+
},
468539
"width": {
469540
"type": "number"
541+
},
542+
"x": {
543+
"type": "number"
544+
},
545+
"y": {
546+
"type": "number"
470547
}
471548
},
472-
"required": ["title"],
473549
"type": "object"
474550
}
475551
],

cli/tauri.js/src/types/config.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,24 @@ export interface TauriConfig {
279279
}
280280
windows: [
281281
{
282-
title: string
282+
label?: string
283+
url?: 'app' | string
284+
x?: number
285+
y?: number
283286
width?: number
284287
height?: number
288+
minWidth?: number
289+
minHeight?: number
290+
maxWidth?: number
291+
maxHeight?: number
285292
resizable?: boolean
293+
title?: string
286294
fullscreen?: boolean
295+
transparent?: boolean
296+
maximized?: boolean
297+
visible?: boolean
298+
decorations?: boolean
299+
alwaysOnTop?: boolean
287300
}
288301
]
289302
security: {

cli/tauri.js/src/types/config.validator.ts

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,23 +479,61 @@ export const TauriConfigSchema = {
479479
additionalProperties: false,
480480
defaultProperties: [],
481481
properties: {
482+
alwaysOnTop: {
483+
type: 'boolean'
484+
},
485+
decorations: {
486+
type: 'boolean'
487+
},
482488
fullscreen: {
483489
type: 'boolean'
484490
},
485491
height: {
486492
type: 'number'
487493
},
494+
label: {
495+
type: 'string'
496+
},
497+
maxHeight: {
498+
type: 'number'
499+
},
500+
maxWidth: {
501+
type: 'number'
502+
},
503+
maximized: {
504+
type: 'boolean'
505+
},
506+
minHeight: {
507+
type: 'number'
508+
},
509+
minWidth: {
510+
type: 'number'
511+
},
488512
resizable: {
489513
type: 'boolean'
490514
},
491515
title: {
492516
type: 'string'
493517
},
518+
transparent: {
519+
type: 'boolean'
520+
},
521+
url: {
522+
type: 'string'
523+
},
524+
visible: {
525+
type: 'boolean'
526+
},
494527
width: {
495528
type: 'number'
529+
},
530+
x: {
531+
type: 'number'
532+
},
533+
y: {
534+
type: 'number'
496535
}
497536
},
498-
required: ['title'],
499537
type: 'object'
500538
}
501539
]
@@ -505,23 +543,61 @@ export const TauriConfigSchema = {
505543
additionalProperties: false,
506544
defaultProperties: [],
507545
properties: {
546+
alwaysOnTop: {
547+
type: 'boolean'
548+
},
549+
decorations: {
550+
type: 'boolean'
551+
},
508552
fullscreen: {
509553
type: 'boolean'
510554
},
511555
height: {
512556
type: 'number'
513557
},
558+
label: {
559+
type: 'string'
560+
},
561+
maxHeight: {
562+
type: 'number'
563+
},
564+
maxWidth: {
565+
type: 'number'
566+
},
567+
maximized: {
568+
type: 'boolean'
569+
},
570+
minHeight: {
571+
type: 'number'
572+
},
573+
minWidth: {
574+
type: 'number'
575+
},
514576
resizable: {
515577
type: 'boolean'
516578
},
517579
title: {
518580
type: 'string'
519581
},
582+
transparent: {
583+
type: 'boolean'
584+
},
585+
url: {
586+
type: 'string'
587+
},
588+
visible: {
589+
type: 'boolean'
590+
},
520591
width: {
521592
type: 'number'
593+
},
594+
x: {
595+
type: 'number'
596+
},
597+
y: {
598+
type: 'number'
522599
}
523600
},
524-
required: ['title'],
525601
type: 'object'
526602
}
527603
],

tauri/Cargo.toml

Lines changed: 2 additions & 1 deletion
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 = "af07c28503e41a0a164cb7256fa0ec938d5daee4" }
35+
wry = { git = "https://github.com/tauri-apps/wry", rev = "e6cc7f0825220a0117827b6f0a366f60ce7420ea" }
3636
rand = "0.8"
3737

3838
[target."cfg(target_os = \"windows\")".dependencies]
@@ -69,6 +69,7 @@ event = [ ]
6969

7070
# window
7171
window = [ ]
72+
create-window = [ ]
7273

7374
#shell
7475
execute = [ ]

tauri/build.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ fn main() {
2424

2525
// window
2626
window: { any(all_api, feature = "window") },
27+
create_window: { any(all_api, feature = "create-window") },
2728

2829
// shell
2930
open: { any(all_api, feature = "open") },
3031
execute: { any(all_api, feature = "execute") },
3132

32-
// event
33-
event: { any(all_api, feature = "event") },
34-
3533
// dialog
3634
open_dialog: { any(all_api, feature = "open-dialog") },
3735
save_dialog: { any(all_api, feature = "save-dialog") },

tauri/examples/communication/dist/__tauri.js

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tauri/examples/communication/src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)