Skip to content

Commit 07208df

Browse files
authored
feat(core): add mult-window support (#1217)
1 parent 763d027 commit 07208df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1333
-508
lines changed

.changes/event.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": minor
3+
---
4+
5+
The `tauri::event` module has been moved to a Webview manager API.

.changes/multiwindow.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": minor
3+
---
4+
5+
Added support to multiple windows.

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ If you are interested in making a tauri-app, please visit the [documentation web
104104
| Multithreading | Yes | No |
105105
| Bytecode Delivery | Yes | No |
106106
| Can Render PDF | Yes | No |
107-
| Multiple Windows | Soon | Yes |
107+
| Multiple Windows | Yes | Yes |
108108
| Auto Updater | Soon | Yes (2) |
109109
| Cross Platform | Yes | Yes |
110110
| Custom App Icon | Yes | Yes |
@@ -116,7 +116,6 @@ If you are interested in making a tauri-app, please visit the [documentation web
116116
| Localhost Server | Yes | Yes |
117117
| No localhost option | Yes | No |
118118
| Desktop Tray | Soon | Yes |
119-
| Splashscreen | Yes | Yes |
120119
| Sidecar Binaries | Yes | No |
121120

122121
#### Notes

cli/core/src/helpers/config.rs

-51
Original file line numberDiff line numberDiff line change
@@ -21,53 +21,6 @@ fn config_handle() -> &'static ConfigHandle {
2121
&CONFING_HANDLE
2222
}
2323

24-
/// The window configuration object.
25-
#[derive(PartialEq, Clone, Deserialize, Serialize, Debug)]
26-
#[serde(tag = "window", rename_all = "camelCase")]
27-
pub struct WindowConfig {
28-
/// The window width.
29-
#[serde(default = "default_width")]
30-
pub width: i32,
31-
/// The window height.
32-
#[serde(default = "default_height")]
33-
pub height: i32,
34-
/// Whether the window is resizable or not.
35-
#[serde(default = "default_resizable")]
36-
pub resizable: bool,
37-
/// The window title.
38-
#[serde(default = "default_title")]
39-
pub title: String,
40-
/// Whether the window starts as fullscreen or not.
41-
#[serde(default)]
42-
pub fullscreen: bool,
43-
}
44-
45-
fn default_width() -> i32 {
46-
800
47-
}
48-
49-
fn default_height() -> i32 {
50-
600
51-
}
52-
53-
fn default_resizable() -> bool {
54-
true
55-
}
56-
57-
fn default_title() -> String {
58-
"Tauri App".to_string()
59-
}
60-
61-
fn default_window() -> WindowConfig {
62-
WindowConfig {
63-
width: default_width(),
64-
height: default_height(),
65-
resizable: default_resizable(),
66-
title: default_title(),
67-
fullscreen: false,
68-
}
69-
}
70-
7124
/// The embedded server port.
7225
#[derive(PartialEq, Clone, Debug, Deserialize, Serialize)]
7326
pub enum Port {
@@ -312,9 +265,6 @@ fn default_bundle() -> BundleConfig {
312265
#[derive(PartialEq, Clone, Deserialize, Serialize, Debug)]
313266
#[serde(tag = "tauri", rename_all = "camelCase")]
314267
pub struct TauriConfig {
315-
/// The window configuration.
316-
#[serde(default = "default_window")]
317-
pub window: WindowConfig,
318268
/// The embeddedServer configuration.
319269
#[serde(default = "default_embedded_server")]
320270
pub embedded_server: EmbeddedServerConfig,
@@ -370,7 +320,6 @@ pub struct Config {
370320

371321
fn default_tauri() -> TauriConfig {
372322
TauriConfig {
373-
window: default_window(),
374323
embedded_server: default_embedded_server(),
375324
cli: None,
376325
bundle: default_bundle(),

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

+55-27
Original file line numberDiff line numberDiff line change
@@ -420,36 +420,64 @@
420420
},
421421
"type": "object"
422422
},
423-
"window": {
424-
"additionalProperties": false,
425-
"defaultProperties": [],
426-
"properties": {
427-
"fullscreen": {
428-
"type": "boolean"
429-
},
430-
"height": {
431-
"type": "number"
432-
},
433-
"resizable": {
434-
"type": "boolean"
435-
},
436-
"title": {
437-
"type": "string"
438-
},
439-
"width": {
440-
"type": "number"
441-
}
423+
"windows": {
424+
"additionalItems": {
425+
"anyOf": [
426+
{
427+
"additionalProperties": false,
428+
"defaultProperties": [],
429+
"properties": {
430+
"fullscreen": {
431+
"type": "boolean"
432+
},
433+
"height": {
434+
"type": "number"
435+
},
436+
"resizable": {
437+
"type": "boolean"
438+
},
439+
"title": {
440+
"type": "string"
441+
},
442+
"width": {
443+
"type": "number"
444+
}
445+
},
446+
"required": ["title"],
447+
"type": "object"
448+
}
449+
]
442450
},
443-
"required": ["title"],
444-
"type": "object"
451+
"items": [
452+
{
453+
"additionalProperties": false,
454+
"defaultProperties": [],
455+
"properties": {
456+
"fullscreen": {
457+
"type": "boolean"
458+
},
459+
"height": {
460+
"type": "number"
461+
},
462+
"resizable": {
463+
"type": "boolean"
464+
},
465+
"title": {
466+
"type": "string"
467+
},
468+
"width": {
469+
"type": "number"
470+
}
471+
},
472+
"required": ["title"],
473+
"type": "object"
474+
}
475+
],
476+
"minItems": 1,
477+
"type": "array"
445478
}
446479
},
447-
"required": [
448-
"allowlist",
449-
"bundle",
450-
"security",
451-
"window"
452-
],
480+
"required": ["allowlist", "bundle", "security", "windows"],
453481
"type": "object"
454482
},
455483
"verbose": {

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

+9-7
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,15 @@ export interface TauriConfig {
277277
all: boolean
278278
[index: string]: boolean
279279
}
280-
window: {
281-
title: string
282-
width?: number
283-
height?: number
284-
resizable?: boolean
285-
fullscreen?: boolean
286-
}
280+
windows: [
281+
{
282+
title: string
283+
width?: number
284+
height?: number
285+
resizable?: boolean
286+
fullscreen?: boolean
287+
}
288+
]
287289
security: {
288290
csp?: string
289291
}

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

+55-22
Original file line numberDiff line numberDiff line change
@@ -472,31 +472,64 @@ export const TauriConfigSchema = {
472472
},
473473
type: 'object'
474474
},
475-
window: {
476-
additionalProperties: false,
477-
defaultProperties: [],
478-
properties: {
479-
fullscreen: {
480-
type: 'boolean'
481-
},
482-
height: {
483-
type: 'number'
484-
},
485-
resizable: {
486-
type: 'boolean'
487-
},
488-
title: {
489-
type: 'string'
490-
},
491-
width: {
492-
type: 'number'
493-
}
475+
windows: {
476+
additionalItems: {
477+
anyOf: [
478+
{
479+
additionalProperties: false,
480+
defaultProperties: [],
481+
properties: {
482+
fullscreen: {
483+
type: 'boolean'
484+
},
485+
height: {
486+
type: 'number'
487+
},
488+
resizable: {
489+
type: 'boolean'
490+
},
491+
title: {
492+
type: 'string'
493+
},
494+
width: {
495+
type: 'number'
496+
}
497+
},
498+
required: ['title'],
499+
type: 'object'
500+
}
501+
]
494502
},
495-
required: ['title'],
496-
type: 'object'
503+
items: [
504+
{
505+
additionalProperties: false,
506+
defaultProperties: [],
507+
properties: {
508+
fullscreen: {
509+
type: 'boolean'
510+
},
511+
height: {
512+
type: 'number'
513+
},
514+
resizable: {
515+
type: 'boolean'
516+
},
517+
title: {
518+
type: 'string'
519+
},
520+
width: {
521+
type: 'number'
522+
}
523+
},
524+
required: ['title'],
525+
type: 'object'
526+
}
527+
],
528+
minItems: 1,
529+
type: 'array'
497530
}
498531
},
499-
required: ['allowlist', 'bundle', 'security', 'window'],
532+
required: ['allowlist', 'bundle', 'security', 'windows'],
500533
type: 'object'
501534
},
502535
verbose: {

cli/tauri.js/test/jest/fixtures/app/src-tauri/src/main.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ struct Context;
77

88
fn main() {
99
tauri::AppBuilder::<tauri::flavors::Wry, Context>::new()
10-
.setup(|dispatcher, _| async move {
11-
let mut dispatcher_ = dispatcher.clone();
10+
.setup(|webview_manager| async move {
11+
let mut webview_manager_ = webview_manager.clone();
1212
tauri::event::listen(String::from("hello"), move |_| {
1313
tauri::event::emit(
14-
&mut dispatcher_,
14+
&webview_manager_,
1515
String::from("reply"),
1616
Some("{ msg: 'TEST' }".to_string()),
1717
)
1818
.unwrap();
1919
});
20-
dispatcher.eval("window.onTauriInit && window.onTauriInit()");
20+
webview_manager
21+
.current_webview()
22+
.eval("window.onTauriInit && window.onTauriInit()");
2123
})
22-
.invoke_handler(|dispatcher, arg| async move {
24+
.invoke_handler(|webview_manager, arg| async move {
2325
use cmd::Cmd::*;
2426
match serde_json::from_str(&arg) {
2527
Err(e) => Err(e.to_string()),

cli/tauri.js/test/jest/fixtures/app/src-tauri/tauri.conf.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
],
1818
"identifier": "fixture.app"
1919
},
20-
"window": {
21-
"title": "Fixture"
22-
}
20+
"windows": [
21+
{
22+
"title": "Fixture"
23+
}
24+
]
2325
}
2426
}

0 commit comments

Comments
 (0)