Repository navigation
feat: create vendored flag to embed verso into tauri app #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 11 commits
f3b6069
9e1a24c
221033b
4d0827a
9cfbab6
4d072d7
ad90b7e
d4d39f6
7b8716c
3383aff
bbc2f1e
ba6c69d
fc8d88a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| gen | ||
| versoview/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| [package] | ||
| name = "vendored" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
|
|
||
| [build-dependencies] | ||
| tauri-runtime-verso-build = { path = "../../tauri-runtime-verso-build" } | ||
| tauri-build = { version = "2", features = [] } | ||
|
|
||
| [dependencies] | ||
| tauri = { version = "2", default-features = false, features = [ | ||
| # Default features | ||
| # "wry", | ||
| # "compression", | ||
| "common-controls-v6", | ||
| # "x11", | ||
| # "dynamic-acl", | ||
| # Additional features | ||
| # "tray-icon", | ||
| ] } | ||
| tauri-runtime-verso = { path = "../../", features = ["vendored"] } | ||
| # serde = "1" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| To get started with this example, run `cargo run --package helloworld` (You'll need the [prerequisites](https://tauri.app/start/prerequisites/) of Tauri) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| fn main() { | ||
| tauri_runtime_verso_build::get_verso_as_external_bin().unwrap(); | ||
| tauri_build::build(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "$schema": "../gen/schemas/desktop-schema.json", | ||
| "identifier": "main", | ||
| "windows": [ | ||
| "main" | ||
| ], | ||
| "permissions": [ | ||
| "core:default" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| <!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> | ||
| <style> | ||
| :root { | ||
| background-color: #f0f0f2; | ||
| font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, | ||
| Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; | ||
|
|
||
| --color-on-primary: white; | ||
| --color-primary: hsl(205, 85%, 40%); | ||
| --color-primary-hightlight: hsl(205, 85%, 35%); | ||
| } | ||
|
|
||
| button, | ||
| input, | ||
| textarea, | ||
| select { | ||
| font: inherit; | ||
| } | ||
|
|
||
| body { | ||
| display: flex; | ||
| flex-direction: column; | ||
| margin: 0; | ||
| height: 100vh; | ||
| } | ||
|
|
||
| .title { | ||
| margin-top: 3em; | ||
| margin-bottom: 2em; | ||
| text-align: center; | ||
| } | ||
|
|
||
| .form-and-message { | ||
| background-color: aliceblue; | ||
| padding: 1em; | ||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: center; | ||
| gap: 1em; | ||
| } | ||
|
|
||
| .form-and-message > #form { | ||
| display: flex; | ||
| justify-content: center; | ||
| gap: 1em; | ||
| } | ||
|
|
||
| .form-and-message > #message { | ||
| display: flex; | ||
| justify-content: center; | ||
| } | ||
|
|
||
| .form-and-message > #form input { | ||
| padding: 0.5em 0.8em; | ||
| border: 1px solid hsl(0, 0%, 60%); | ||
| outline: none; | ||
| min-width: 0; | ||
| } | ||
| .form-and-message > #form input:focus { | ||
| border-color: var(--color-primary); | ||
| } | ||
|
|
||
| .form-and-message > #form button { | ||
| appearance: none; | ||
| border: none; | ||
| cursor: pointer; | ||
| outline: none; | ||
| padding: 0.4em 1em; | ||
| color: var(--color-on-primary); | ||
| background-color: var(--color-primary); | ||
| display: inline-flex; | ||
| align-items: center; | ||
| } | ||
| .form-and-message > #form button:hover, | ||
| .form-and-message > #form button:focus { | ||
| background-color: var(--color-primary-hightlight); | ||
| } | ||
| </style> | ||
| <script type="module"> | ||
| const { invoke } = window.__TAURI__.core | ||
|
|
||
| const form = document.querySelector('#form') | ||
| const nameEl = document.querySelector('#name') | ||
| const messageEl = document.querySelector('#message') | ||
|
|
||
| form.addEventListener('submit', async (e) => { | ||
| e.preventDefault() | ||
|
|
||
| const name = nameEl.value | ||
| const newMessage = await invoke('greet', { name }) | ||
| messageEl.textContent = newMessage | ||
| }) | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <h1 class="title">Welcome to Tauri!</h1> | ||
|
|
||
| <div class="form-and-message"> | ||
| <form id="form"> | ||
| <input id="name" placeholder="Enter a name..." /> | ||
| <button>Greet</button> | ||
| </form> | ||
| <div id="message"></div> | ||
| </div> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] | ||
|
|
||
| use tauri::Manager; | ||
|
|
||
| #[tauri::command] | ||
| fn greet(name: &str) -> String { | ||
| format!("Hello {name}, You have been greeted from Rust!") | ||
| } | ||
|
|
||
| fn main() { | ||
| // You can also set the `versoview` executable path yourself | ||
| // tauri_runtime_verso::set_verso_path("../verso/target/debug/versoview"); | ||
|
|
||
| // To use the devtools, set it like to let verso open a devtools server, | ||
| // and you can connect to it through Firefox's devtools in the `about:debugging` page | ||
| tauri_runtime_verso::set_verso_devtools_port(1234); | ||
|
|
||
| tauri_runtime_verso::builder() | ||
| .invoke_handler(tauri::generate_handler![greet]) | ||
| .setup(|app| { | ||
| dbg!(app.get_webview_window("main").unwrap().inner_size()).unwrap(); | ||
| // embed verso webview into app | ||
| tauri_runtime_verso::vendored::create_embedded_versoview().unwrap(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I get this, isn't this just running the versoview? Don't we need to connect our app with it? And 2 different event loops can't work together, versoview will still need to be on another process for now |
||
|
|
||
| Ok(()) | ||
| }) | ||
| .run(tauri::generate_context!()) | ||
| .expect("error while running tauri application") | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| { | ||
| "$schema": "https://schema.tauri.app/config/2", | ||
| "productName": "Hello World", | ||
| "version": "0.1.0", | ||
| "identifier": "com.tauri.dev", | ||
| "build": { | ||
| "frontendDist": ["index.html"] | ||
| }, | ||
| "app": { | ||
| "withGlobalTauri": true, | ||
| "windows": [ | ||
| { | ||
| "title": "Welcome to Tauri!", | ||
| "width": 700, | ||
| "height": 500 | ||
| } | ||
| ] | ||
| }, | ||
| "bundle": { | ||
| "icon": [ | ||
| "../.icons/icon.ico", | ||
| "../.icons/icon.png" | ||
| ], | ||
| "externalBin": [ | ||
| "versoview/versoview" | ||
| ] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| use versoview::{Result, Verso, verso::EventLoopProxyMessage}; | ||
| use winit::{ | ||
| application::ApplicationHandler, | ||
| event_loop::{self, DeviceEvents, EventLoop, EventLoopProxy}, | ||
| }; | ||
|
|
||
| struct App { | ||
| verso: Option<Verso>, | ||
| proxy: EventLoopProxy<EventLoopProxyMessage>, | ||
| } | ||
|
|
||
| impl ApplicationHandler<EventLoopProxyMessage> for App { | ||
| fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) { | ||
| self.verso = Some(Verso::new(event_loop, self.proxy.clone())); | ||
| } | ||
|
|
||
| fn window_event( | ||
| &mut self, | ||
| event_loop: &winit::event_loop::ActiveEventLoop, | ||
| window_id: winit::window::WindowId, | ||
| event: winit::event::WindowEvent, | ||
| ) { | ||
| if let Some(v) = self.verso.as_mut() { | ||
| v.handle_window_event(event_loop, window_id, event); | ||
| } | ||
| } | ||
|
|
||
| fn user_event( | ||
| &mut self, | ||
| event_loop: &event_loop::ActiveEventLoop, | ||
| event: EventLoopProxyMessage, | ||
| ) { | ||
| if let Some(v) = self.verso.as_mut() { | ||
| match event { | ||
| EventLoopProxyMessage::Wake => { | ||
| v.request_redraw(event_loop); | ||
| } | ||
| EventLoopProxyMessage::IpcMessage(message) => { | ||
| v.handle_incoming_webview_message(event_loop, *message); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub fn create_embedded_versoview() -> Result<()> { | ||
| init_crypto(); | ||
|
|
||
| let event_loop = EventLoop::<EventLoopProxyMessage>::with_user_event().build()?; | ||
| event_loop.listen_device_events(DeviceEvents::Never); | ||
| let proxy = event_loop.create_proxy(); | ||
| let mut app = App { verso: None, proxy }; | ||
| event_loop.run_app(&mut app)?; | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn init_crypto() { | ||
| rustls::crypto::aws_lc_rs::default_provider() | ||
| .install_default() | ||
| .expect("Error initializing crypto provider"); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.