From f2745452e9c3b4fcc08238ec1899b4e912b02f5a Mon Sep 17 00:00:00 2001 From: Nazar Antoniuk Date: Tue, 4 Feb 2025 09:07:29 +0200 Subject: [PATCH] add support for browser extensions --- src-tauri/.gitignore | 5 +++++ src-tauri/Cargo.toml | 1 + src-tauri/extensions/README.md | 8 ++++++++ src-tauri/src/lib.rs | 26 +++++++++++++++++++++++++- src-tauri/tauri.conf.json | 11 +---------- 5 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 src-tauri/extensions/README.md diff --git a/src-tauri/.gitignore b/src-tauri/.gitignore index c37e5aa..8d92853 100644 --- a/src-tauri/.gitignore +++ b/src-tauri/.gitignore @@ -1,2 +1,7 @@ +# Tauri build output gen/schemas/ target/ + +# Browser extenions +extensions/* +!extensions/README.md diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index dd7a8fb..d340876 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [features] test = [] +debug = [] [profile.release] opt-level = "s" diff --git a/src-tauri/extensions/README.md b/src-tauri/extensions/README.md new file mode 100644 index 0000000..cc38ed3 --- /dev/null +++ b/src-tauri/extensions/README.md @@ -0,0 +1,8 @@ +# Browser Extensions (Windows-only) + +Place here builds of those browser extensions that you want to use during development. + +It is recommended to add [Vue.js DevTools](https://devtools.vuejs.org) and [Pixi.js DevTools](https://pixijs.io/devtools) extensions. +You can place their builds in the `extensions/vuejs-devtools` and `extensions/pixijs-devtools` directories, respectively. + +You can then run the application with `cargo tauri dev --features debug` to enable these extensions. diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 35f4183..e18612f 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::sync::RwLock; use state::HistoryStateInner; -use tauri::Manager; +use tauri::{Manager, WebviewUrl, WebviewWindowBuilder}; pub mod commands; pub mod state; @@ -17,6 +17,29 @@ mod utils; pub fn setup_app(builder: tauri::Builder) -> tauri::App { builder .setup(|app| { + #[allow(unused_mut)] + let mut webview_window_builder = WebviewWindowBuilder::new(app, "main", WebviewUrl::default()) + .title(app.package_info().name.clone()) + .min_inner_size(640.0, 480.0) + .maximized(true) + .decorations(false) + .additional_browser_args("--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection,ElasticOverscroll"); + + // We are using a custom `debug` feature to enable browser extensions only for development and not in debug builds. + #[cfg(all(target_os = "windows", feature = "debug"))] + { + // Enable and setup browser extensions for development. + webview_window_builder = webview_window_builder + .browser_extensions_enabled(true) + // Load the browser extensions from the `src-tauri/extensions/` directory. + .extensions_path(std::env::current_dir()?.join("extensions")); + } + + let webview_window = webview_window_builder.build()?; + + #[cfg(debug_assertions)] + webview_window.open_devtools(); + let app_document_dir = utils::path::app_document_dir(app.handle())?; if !cfg!(test) && !app_document_dir.exists() { // Create the Embroidery Studio directory in the user's document directory @@ -30,6 +53,7 @@ pub fn setup_app(builder: tauri::Builder) -> tauri::App std::fs::copy(pattern.clone(), app_document_dir.join(pattern.file_name().unwrap()))?; } } + Ok(()) }) .manage(RwLock::new( diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 1cefac9..566e99b 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -40,15 +40,6 @@ "style-src": "'unsafe-inline' 'self'", "script-src": "'unsafe-eval' 'self'" } - }, - "windows": [ - { - "title": "Embroidery Studio", - "minWidth": 1024, - "minHeight": 768, - "maximized": true, - "decorations": false - } - ] + } } }