Skip to content

Commit

Permalink
feat(core): add mult-window support (#1217)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Feb 12, 2021
1 parent 763d027 commit 07208df
Show file tree
Hide file tree
Showing 63 changed files with 1,333 additions and 508 deletions.
5 changes: 5 additions & 0 deletions .changes/event.md
@@ -0,0 +1,5 @@
---
"tauri": minor
---

The `tauri::event` module has been moved to a Webview manager API.
5 changes: 5 additions & 0 deletions .changes/multiwindow.md
@@ -0,0 +1,5 @@
---
"tauri": minor
---

Added support to multiple windows.
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -104,7 +104,7 @@ If you are interested in making a tauri-app, please visit the [documentation web
| Multithreading | Yes | No |
| Bytecode Delivery | Yes | No |
| Can Render PDF | Yes | No |
| Multiple Windows | Soon | Yes |
| Multiple Windows | Yes | Yes |
| Auto Updater | Soon | Yes (2) |
| Cross Platform | Yes | Yes |
| Custom App Icon | Yes | Yes |
Expand All @@ -116,7 +116,6 @@ If you are interested in making a tauri-app, please visit the [documentation web
| Localhost Server | Yes | Yes |
| No localhost option | Yes | No |
| Desktop Tray | Soon | Yes |
| Splashscreen | Yes | Yes |
| Sidecar Binaries | Yes | No |

#### Notes
Expand Down
51 changes: 0 additions & 51 deletions cli/core/src/helpers/config.rs
Expand Up @@ -21,53 +21,6 @@ fn config_handle() -> &'static ConfigHandle {
&CONFING_HANDLE
}

/// The window configuration object.
#[derive(PartialEq, Clone, Deserialize, Serialize, Debug)]
#[serde(tag = "window", rename_all = "camelCase")]
pub struct WindowConfig {
/// The window width.
#[serde(default = "default_width")]
pub width: i32,
/// The window height.
#[serde(default = "default_height")]
pub height: i32,
/// Whether the window is resizable or not.
#[serde(default = "default_resizable")]
pub resizable: bool,
/// The window title.
#[serde(default = "default_title")]
pub title: String,
/// Whether the window starts as fullscreen or not.
#[serde(default)]
pub fullscreen: bool,
}

fn default_width() -> i32 {
800
}

fn default_height() -> i32 {
600
}

fn default_resizable() -> bool {
true
}

fn default_title() -> String {
"Tauri App".to_string()
}

fn default_window() -> WindowConfig {
WindowConfig {
width: default_width(),
height: default_height(),
resizable: default_resizable(),
title: default_title(),
fullscreen: false,
}
}

/// The embedded server port.
#[derive(PartialEq, Clone, Debug, Deserialize, Serialize)]
pub enum Port {
Expand Down Expand Up @@ -312,9 +265,6 @@ fn default_bundle() -> BundleConfig {
#[derive(PartialEq, Clone, Deserialize, Serialize, Debug)]
#[serde(tag = "tauri", rename_all = "camelCase")]
pub struct TauriConfig {
/// The window configuration.
#[serde(default = "default_window")]
pub window: WindowConfig,
/// The embeddedServer configuration.
#[serde(default = "default_embedded_server")]
pub embedded_server: EmbeddedServerConfig,
Expand Down Expand Up @@ -370,7 +320,6 @@ pub struct Config {

fn default_tauri() -> TauriConfig {
TauriConfig {
window: default_window(),
embedded_server: default_embedded_server(),
cli: None,
bundle: default_bundle(),
Expand Down
82 changes: 55 additions & 27 deletions cli/tauri.js/src/types/config.schema.json
Expand Up @@ -420,36 +420,64 @@
},
"type": "object"
},
"window": {
"additionalProperties": false,
"defaultProperties": [],
"properties": {
"fullscreen": {
"type": "boolean"
},
"height": {
"type": "number"
},
"resizable": {
"type": "boolean"
},
"title": {
"type": "string"
},
"width": {
"type": "number"
}
"windows": {
"additionalItems": {
"anyOf": [
{
"additionalProperties": false,
"defaultProperties": [],
"properties": {
"fullscreen": {
"type": "boolean"
},
"height": {
"type": "number"
},
"resizable": {
"type": "boolean"
},
"title": {
"type": "string"
},
"width": {
"type": "number"
}
},
"required": ["title"],
"type": "object"
}
]
},
"required": ["title"],
"type": "object"
"items": [
{
"additionalProperties": false,
"defaultProperties": [],
"properties": {
"fullscreen": {
"type": "boolean"
},
"height": {
"type": "number"
},
"resizable": {
"type": "boolean"
},
"title": {
"type": "string"
},
"width": {
"type": "number"
}
},
"required": ["title"],
"type": "object"
}
],
"minItems": 1,
"type": "array"
}
},
"required": [
"allowlist",
"bundle",
"security",
"window"
],
"required": ["allowlist", "bundle", "security", "windows"],
"type": "object"
},
"verbose": {
Expand Down
16 changes: 9 additions & 7 deletions cli/tauri.js/src/types/config.ts
Expand Up @@ -277,13 +277,15 @@ export interface TauriConfig {
all: boolean
[index: string]: boolean
}
window: {
title: string
width?: number
height?: number
resizable?: boolean
fullscreen?: boolean
}
windows: [
{
title: string
width?: number
height?: number
resizable?: boolean
fullscreen?: boolean
}
]
security: {
csp?: string
}
Expand Down
77 changes: 55 additions & 22 deletions cli/tauri.js/src/types/config.validator.ts
Expand Up @@ -472,31 +472,64 @@ export const TauriConfigSchema = {
},
type: 'object'
},
window: {
additionalProperties: false,
defaultProperties: [],
properties: {
fullscreen: {
type: 'boolean'
},
height: {
type: 'number'
},
resizable: {
type: 'boolean'
},
title: {
type: 'string'
},
width: {
type: 'number'
}
windows: {
additionalItems: {
anyOf: [
{
additionalProperties: false,
defaultProperties: [],
properties: {
fullscreen: {
type: 'boolean'
},
height: {
type: 'number'
},
resizable: {
type: 'boolean'
},
title: {
type: 'string'
},
width: {
type: 'number'
}
},
required: ['title'],
type: 'object'
}
]
},
required: ['title'],
type: 'object'
items: [
{
additionalProperties: false,
defaultProperties: [],
properties: {
fullscreen: {
type: 'boolean'
},
height: {
type: 'number'
},
resizable: {
type: 'boolean'
},
title: {
type: 'string'
},
width: {
type: 'number'
}
},
required: ['title'],
type: 'object'
}
],
minItems: 1,
type: 'array'
}
},
required: ['allowlist', 'bundle', 'security', 'window'],
required: ['allowlist', 'bundle', 'security', 'windows'],
type: 'object'
},
verbose: {
Expand Down
12 changes: 7 additions & 5 deletions cli/tauri.js/test/jest/fixtures/app/src-tauri/src/main.rs
Expand Up @@ -7,19 +7,21 @@ struct Context;

fn main() {
tauri::AppBuilder::<tauri::flavors::Wry, Context>::new()
.setup(|dispatcher, _| async move {
let mut dispatcher_ = dispatcher.clone();
.setup(|webview_manager| async move {
let mut webview_manager_ = webview_manager.clone();
tauri::event::listen(String::from("hello"), move |_| {
tauri::event::emit(
&mut dispatcher_,
&webview_manager_,
String::from("reply"),
Some("{ msg: 'TEST' }".to_string()),
)
.unwrap();
});
dispatcher.eval("window.onTauriInit && window.onTauriInit()");
webview_manager
.current_webview()
.eval("window.onTauriInit && window.onTauriInit()");
})
.invoke_handler(|dispatcher, arg| async move {
.invoke_handler(|webview_manager, arg| async move {
use cmd::Cmd::*;
match serde_json::from_str(&arg) {
Err(e) => Err(e.to_string()),
Expand Down
8 changes: 5 additions & 3 deletions cli/tauri.js/test/jest/fixtures/app/src-tauri/tauri.conf.json
Expand Up @@ -17,8 +17,10 @@
],
"identifier": "fixture.app"
},
"window": {
"title": "Fixture"
}
"windows": [
{
"title": "Fixture"
}
]
}
}

0 comments on commit 07208df

Please sign in to comment.