Skip to content

Commit

Permalink
feat(core): window creation at runtime (#1249)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Feb 17, 2021
1 parent 0f3009b commit 641374b
Show file tree
Hide file tree
Showing 25 changed files with 841 additions and 320 deletions.
2 changes: 1 addition & 1 deletion .changes/window-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"tauri": minor
---

Added window management APIs.
Added window management and window creation APIs.
36 changes: 35 additions & 1 deletion api/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,38 @@ class WindowManager {

const manager = new WindowManager()

export { TauriWindow, getTauriWindow, getCurrentWindow, getWindows, manager }
export interface WindowOptions {
url?: 'app' | string
x?: number
y?: number
width?: number
height?: number
minWidth?: number
minHeight?: number
maxWidth?: number
maxHeight?: number
resizable?: boolean
title?: string
fullscreen?: boolean
transparent?: boolean
maximized?: boolean
visible?: boolean
decorations?: boolean
alwaysOnTop?: boolean
}

async function createWindow(label: string, options: WindowOptions = {}): Promise<TauriWindow> {
await invoke({
__tauriModule: 'Window',
message: {
cmd: 'createWebview',
options: {
label,
...options
}
}
})
return new TauriWindow(label)
}

export { TauriWindow, getTauriWindow, getCurrentWindow, getWindows, manager, createWindow }
14 changes: 14 additions & 0 deletions cli/core/src/templates/tauri.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,20 @@ if (!String.prototype.startsWith) {
);
}

window.__TAURI__.invoke({
__tauriModule: 'Event',
message: {
cmd: 'listen',
event: 'tauri://window-created',
handler: window.__TAURI__.transformCallback(function (event) {
if (event.payload) {
var windowLabel = event.payload.label
window.__TAURI__.__windows.push({ label: windowLabel })
}
})
}
})

let permissionSettable = false;
let permissionValue = "default";

Expand Down
80 changes: 78 additions & 2 deletions cli/tauri.js/src/types/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,23 +427,61 @@
"additionalProperties": false,
"defaultProperties": [],
"properties": {
"alwaysOnTop": {
"type": "boolean"
},
"decorations": {
"type": "boolean"
},
"fullscreen": {
"type": "boolean"
},
"height": {
"type": "number"
},
"label": {
"type": "string"
},
"maxHeight": {
"type": "number"
},
"maxWidth": {
"type": "number"
},
"maximized": {
"type": "boolean"
},
"minHeight": {
"type": "number"
},
"minWidth": {
"type": "number"
},
"resizable": {
"type": "boolean"
},
"title": {
"type": "string"
},
"transparent": {
"type": "boolean"
},
"url": {
"type": "string"
},
"visible": {
"type": "boolean"
},
"width": {
"type": "number"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"required": ["title"],
"type": "object"
}
]
Expand All @@ -453,23 +491,61 @@
"additionalProperties": false,
"defaultProperties": [],
"properties": {
"alwaysOnTop": {
"type": "boolean"
},
"decorations": {
"type": "boolean"
},
"fullscreen": {
"type": "boolean"
},
"height": {
"type": "number"
},
"label": {
"type": "string"
},
"maxHeight": {
"type": "number"
},
"maxWidth": {
"type": "number"
},
"maximized": {
"type": "boolean"
},
"minHeight": {
"type": "number"
},
"minWidth": {
"type": "number"
},
"resizable": {
"type": "boolean"
},
"title": {
"type": "string"
},
"transparent": {
"type": "boolean"
},
"url": {
"type": "string"
},
"visible": {
"type": "boolean"
},
"width": {
"type": "number"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"required": ["title"],
"type": "object"
}
],
Expand Down
15 changes: 14 additions & 1 deletion cli/tauri.js/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,24 @@ export interface TauriConfig {
}
windows: [
{
title: string
label?: string
url?: 'app' | string
x?: number
y?: number
width?: number
height?: number
minWidth?: number
minHeight?: number
maxWidth?: number
maxHeight?: number
resizable?: boolean
title?: string
fullscreen?: boolean
transparent?: boolean
maximized?: boolean
visible?: boolean
decorations?: boolean
alwaysOnTop?: boolean
}
]
security: {
Expand Down
80 changes: 78 additions & 2 deletions cli/tauri.js/src/types/config.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,23 +479,61 @@ export const TauriConfigSchema = {
additionalProperties: false,
defaultProperties: [],
properties: {
alwaysOnTop: {
type: 'boolean'
},
decorations: {
type: 'boolean'
},
fullscreen: {
type: 'boolean'
},
height: {
type: 'number'
},
label: {
type: 'string'
},
maxHeight: {
type: 'number'
},
maxWidth: {
type: 'number'
},
maximized: {
type: 'boolean'
},
minHeight: {
type: 'number'
},
minWidth: {
type: 'number'
},
resizable: {
type: 'boolean'
},
title: {
type: 'string'
},
transparent: {
type: 'boolean'
},
url: {
type: 'string'
},
visible: {
type: 'boolean'
},
width: {
type: 'number'
},
x: {
type: 'number'
},
y: {
type: 'number'
}
},
required: ['title'],
type: 'object'
}
]
Expand All @@ -505,23 +543,61 @@ export const TauriConfigSchema = {
additionalProperties: false,
defaultProperties: [],
properties: {
alwaysOnTop: {
type: 'boolean'
},
decorations: {
type: 'boolean'
},
fullscreen: {
type: 'boolean'
},
height: {
type: 'number'
},
label: {
type: 'string'
},
maxHeight: {
type: 'number'
},
maxWidth: {
type: 'number'
},
maximized: {
type: 'boolean'
},
minHeight: {
type: 'number'
},
minWidth: {
type: 'number'
},
resizable: {
type: 'boolean'
},
title: {
type: 'string'
},
transparent: {
type: 'boolean'
},
url: {
type: 'string'
},
visible: {
type: 'boolean'
},
width: {
type: 'number'
},
x: {
type: 'number'
},
y: {
type: 'number'
}
},
required: ['title'],
type: 'object'
}
],
Expand Down
3 changes: 2 additions & 1 deletion tauri/Cargo.toml
Original file line number Diff line number Diff line change
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 = "af07c28503e41a0a164cb7256fa0ec938d5daee4" }
wry = { git = "https://github.com/tauri-apps/wry", rev = "e6cc7f0825220a0117827b6f0a366f60ce7420ea" }
rand = "0.8"

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

# window
window = [ ]
create-window = [ ]

#shell
execute = [ ]
Expand Down
4 changes: 1 addition & 3 deletions tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ fn main() {

// window
window: { any(all_api, feature = "window") },
create_window: { any(all_api, feature = "create-window") },

// shell
open: { any(all_api, feature = "open") },
execute: { any(all_api, feature = "execute") },

// event
event: { any(all_api, feature = "event") },

// dialog
open_dialog: { any(all_api, feature = "open-dialog") },
save_dialog: { any(all_api, feature = "save-dialog") },
Expand Down
16 changes: 15 additions & 1 deletion tauri/examples/communication/dist/__tauri.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tauri/examples/communication/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion tauri/examples/multiwindow/dist/__tauri.js

Large diffs are not rendered by default.

Loading

0 comments on commit 641374b

Please sign in to comment.