Skip to content
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

chore: add support for browser extensions #89

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src-tauri/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# Tauri build output
gen/schemas/
target/

# Browser extenions
extensions/*
!extensions/README.md
1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"

[features]
test = []
debug = []

[profile.release]
opt-level = "s"
Expand Down
8 changes: 8 additions & 0 deletions src-tauri/extensions/README.md
Original file line number Diff line number Diff line change
@@ -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.
26 changes: 25 additions & 1 deletion src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +17,29 @@ mod utils;
pub fn setup_app<R: tauri::Runtime>(builder: tauri::Builder<R>) -> tauri::App<R> {
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
Expand All @@ -30,6 +53,7 @@ pub fn setup_app<R: tauri::Runtime>(builder: tauri::Builder<R>) -> tauri::App<R>
std::fs::copy(pattern.clone(), app_document_dir.join(pattern.file_name().unwrap()))?;
}
}

Ok(())
})
.manage(RwLock::new(
Expand Down
11 changes: 1 addition & 10 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
}
}