Files
tauri/examples/resources/src-tauri/src/main.rs
Lucas Fernandes Nogueira c77b40324e refactor(core): add support to multiple webviews on a Tauri window (#8280)
* feat: update to latest wry

* wry dev branch [skip ci]

* fix linux [skip ci]

* refactor(runtime): split webview and window types

* split dispatch

* implement create_webview

* move webview message

* wip webview mod

* create webview manager, finish webview struct and builder

* fix tests and docs

* rename WindowUrl to WebviewUrl

* update examples

* event refactor

* update JS API

* fix events

* update example

* add WebviewWindow class on JS

* fix macos build

* allow creating window+webview on the same runtime call

* rename tauri://window-created to tauri://webview-created

* Window::add_child

* use inner_size from webview on macOS

* add multiwebview example

* automatically resize webviews on window resize

* fix tests

* set_position, set_size

* position, size getters

* set_focus

* add close fn

* update mock runtime

* lint [skip ci]

* fix inner_size getter [skip ci]

* import hwnd [skip ci]

* update webview bound ratios on set_size/set_position

* add auto_resize option

* fix android

* fix build on windows

* typo

* with_webview isnt desktop only

* add WebviewWindow rust struct (and builder)

* fix build on android

* license header

* fix macos/windows

* fix macos build

* resolve todo

* handle window not found

* hide unstable features

* document unstable feature [skip ci]

* webview plugin permissions

* hide more stuff

* fix doctests

* typos

* add change files

* fix examples

* rename hook
2024-01-24 11:05:18 -03:00

52 lines
1.3 KiB
Rust

// 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 std::{
io::{BufRead, BufReader},
process::{Command, Stdio},
};
use tauri::Manager;
fn main() {
tauri::Builder::default()
.setup(move |app| {
let window = app.get_webview_window("main").unwrap();
let script_path = app
.path()
.resolve("assets/index.js", tauri::path::BaseDirectory::Resource)
.unwrap()
.to_string_lossy()
.to_string();
std::thread::spawn(move || {
let mut child = Command::new("node")
.args(&[script_path])
.stdout(Stdio::piped())
.spawn()
.expect("Failed to spawn node");
let stdout = child.stdout.take().unwrap();
let mut stdout = BufReader::new(stdout);
let mut line = String::new();
loop {
let n = stdout.read_line(&mut line).unwrap();
if n == 0 {
break;
}
window
.emit("message", Some(format!("'{}'", line)))
.expect("failed to emit event");
line.clear();
}
});
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}