Skip to content

Commit

Permalink
add multiwebview example
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Nov 21, 2023
1 parent b9f1668 commit 2296c63
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ path = "../../examples/commands/main.rs"
name = "helloworld"
path = "../../examples/helloworld/main.rs"

[[example]]
name = "multiwebview"
path = "../../examples/multiwebview/main.rs"

[[example]]
name = "multiwindow"
path = "../../examples/multiwindow/main.rs"
Expand Down
3 changes: 3 additions & 0 deletions examples/multiwebview/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Hello World Example

To execute run the following on the root directory of the repository: `cargo run --example helloworld`.
11 changes: 11 additions & 0 deletions examples/multiwebview/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Welcome to Tauri!</title>
</head>
<body>
<h1>Welcome to Tauri!</h1>
</body>
</html>
54 changes: 54 additions & 0 deletions examples/multiwebview/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use tauri::{LogicalPosition, LogicalSize, WebviewUrl};

fn main() {
tauri::Builder::default()
.setup(|app| {
let width = 800.;
let height = 600.;
let window = tauri::WindowBuilder::new(app, "main")
.inner_size(width, height)
.build()?;

let _webview1 = window.add_child(
tauri::WebviewBuilder::new("main1", WebviewUrl::App(Default::default())),
LogicalPosition::new(0., 0.),
LogicalSize::new(width / 2., height / 2.),
)?;
let _webview2 = window.add_child(
tauri::WebviewBuilder::new(
"main2",
WebviewUrl::External("https://github.com/tauri-apps/tauri".parse().unwrap()),
),
LogicalPosition::new(width / 2., 0.),
LogicalSize::new(width / 2., height / 2.),
)?;
let _webview3 = window.add_child(
tauri::WebviewBuilder::new(
"main3",
WebviewUrl::External("https://tauri.app".parse().unwrap()),
),
LogicalPosition::new(0., height / 2.),
LogicalSize::new(width / 2., height / 2.),
)?;
let _webview4 = window.add_child(
tauri::WebviewBuilder::new(
"main4",
WebviewUrl::External("https://twitter.com/TauriApps".parse().unwrap()),
),
LogicalPosition::new(width / 2., height / 2.),
LogicalSize::new(width / 2., height / 2.),
)?;

Ok(())
})
.run(tauri::generate_context!(
"../../examples/multiwebview/tauri.conf.json"
))
.expect("error while running tauri application");
}
43 changes: 43 additions & 0 deletions examples/multiwebview/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"$schema": "../../core/tauri-config-schema/schema.json",
"build": {
"distDir": ["index.html"],
"devPath": ["index.html"],
"beforeDevCommand": "",
"beforeBuildCommand": ""
},
"package": {
"productName": "MultiWebview",
"version": "0.1.0"
},
"tauri": {
"bundle": {
"active": true,
"targets": "all",
"identifier": "com.tauri.dev",
"icon": [
"../.icons/32x32.png",
"../.icons/128x128.png",
"../.icons/[email protected]",
"../.icons/icon.icns",
"../.icons/icon.ico"
],
"resources": [],
"externalBin": [],
"copyright": "",
"category": "DeveloperTool",
"shortDescription": "",
"longDescription": "",
"deb": {
"depends": []
},
"macOS": {
"frameworks": [],
"exceptionDomain": ""
}
},
"security": {
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost"
}
}
}

0 comments on commit 2296c63

Please sign in to comment.