Skip to content

Commit

Permalink
fix: stabilize extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Sep 20, 2024
1 parent 897a5e2 commit d27e79e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
16 changes: 7 additions & 9 deletions src-tauri/src/functionality/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub fn add_extension(win: &WebviewWindow, path: PathBuf) {
.unwrap_or_default();
}

#[cfg(target_os = "windows")]
pub fn load_extensions(win: &WebviewWindow) {
log!("Loading extensions...");

Expand All @@ -75,21 +76,18 @@ pub fn load_extensions(win: &WebviewWindow) {
// Read all files in the extensions dir
if let Ok(files) = fs::read_dir(extensions_dir) {
for file in files.flatten() {
let path = file.path();

// Path can be file or folder, doesn't matter
let path = path.to_str().unwrap_or_default();
let path = PathBuf::from(path);

add_extension(win, path);
add_extension(win, file.path());
}
}
}

// Refresh the page to ensure extensions are loaded
win.eval("window.location.reload();").unwrap_or_default();
#[cfg(not(target_os = "windows"))]
pub fn load_extensions(_win: &WebviewWindow) {
log!("Extensions are unsupported on non-Windows platforms!");
}

#[cfg(not(target_os = "windows"))]
pub fn add_extension(_win: &WebviewWindow, _path: PathBuf) {
log!("Extension is unsupported on non-Windows platforms!");
log!("Extensions are unsupported on non-Windows platforms!");
}
7 changes: 7 additions & 0 deletions src-tauri/src/functionality/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,15 @@ pub fn after_build(window: &tauri::WebviewWindow) {
}
}

// This should be the last extension loaded, the others are loaded early on
add_extension(window, get_main_extension_path());

#[cfg(target_os = "windows")]
{
// Refresh the page to ensure extensions are loaded
window.eval("window.location.reload();").unwrap_or_default();
}

window_zoom_level(window.clone(), None);
}

Expand Down
11 changes: 10 additions & 1 deletion src-tauri/src/processors/css_preprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub async fn clear_css_cache() {
}
}

#[cfg(not(target_os = "windows"))]
#[tauri::command]
pub fn localize_imports(win: tauri::WebviewWindow, css: String, name: String) -> String {
let reg = Regex::new(r#"(?m)^@import url\((?:"|'|)(?:|.+?)\/\/(.+?)(?:"|'|)\);"#).unwrap();
Expand Down Expand Up @@ -162,6 +163,14 @@ pub fn localize_imports(win: tauri::WebviewWindow, css: String, name: String) ->
new_css
}

#[cfg(target_os = "windows")]
#[tauri::command]
pub fn localize_imports(_win: tauri::WebviewWindow, css: String, _name: String) -> String {
log!("Windows no longer requires CSS imports to be localized");
return css
}

#[cfg(not(target_os = "windows"))]
pub fn localize_images(win: tauri::WebviewWindow, css: String) -> String {
let img_reg = Regex::new(r#"url\((?:'|"|)(http.+?)(?:'|"|)\)"#).unwrap();
let mut new_css = css.clone();
Expand Down Expand Up @@ -285,4 +294,4 @@ pub fn localize_images(win: tauri::WebviewWindow, css: String) -> String {
}

new_css
}
}

0 comments on commit d27e79e

Please sign in to comment.