diff --git a/.gitignore b/.gitignore index 409a8a26..887927ae 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ yarn-error.log* pnpm-debug.log* lerna-debug.log* +.yarn/* + node_modules dist dist-ssr diff --git a/src-tauri/src/helpers.rs b/src-tauri/src/helpers.rs index d6808fc7..f698e322 100644 --- a/src-tauri/src/helpers.rs +++ b/src-tauri/src/helpers.rs @@ -34,25 +34,4 @@ fn open_folder(path: PathBuf) { #[cfg(target_os = "linux")] fn open_folder(path: PathBuf) { Command::new("xdg-open").arg(path).spawn().unwrap(); -} - -#[cfg(target_os = "windows")] -pub fn resource_folder() -> PathBuf { - let mut path = std::env::current_exe().unwrap(); - path.pop(); - - path -} - -#[cfg(target_os = "linux")] -pub fn resource_folder() -> PathBuf { - PathBuf::from("/usr/lib/dorion/") -} - -#[cfg(target_os = "macos")] -pub fn resource_folder() -> PathBuf { - let mut path = std::env::current_exe().unwrap(); - path.pop(); - - path -} +} \ No newline at end of file diff --git a/src-tauri/src/injection.rs b/src-tauri/src/injection.rs index baacb5ed..9c5b216f 100644 --- a/src-tauri/src/injection.rs +++ b/src-tauri/src/injection.rs @@ -1,12 +1,17 @@ use std::{collections::HashMap, env, fs, path::PathBuf, thread, time::Duration}; use tauri::{regex::Regex, Manager}; -use crate::{helpers::resource_folder, js_preprocess::eval_js_imports, plugin}; +use crate::{js_preprocess::eval_js_imports, plugin}; #[tauri::command] -pub async fn get_injection_js(theme_js: &str) -> Result { +pub async fn get_injection_js(win: tauri::Window, theme_js: &str) -> Result { let theme_rxg = Regex::new(r"/\* __THEMES__ \*/").unwrap(); - let injection_js = match fs::read_to_string(resource_folder().join("injection/injection_min.js")) + let js_path = win + .app_handle() + .path_resolver() + .resolve_resource(PathBuf::from("injection/injection_min.js")) + .unwrap(); + let injection_js = match fs::read_to_string(js_path) { Ok(f) => f, Err(e) => { @@ -33,14 +38,19 @@ pub fn do_injection(win: tauri::Window) { // Gotta make sure the window location is where it needs to be std::thread::spawn(move || { - std::thread::sleep(std::time::Duration::from_secs(2)); + std::thread::sleep(std::time::Duration::from_secs(1)); preinject(&win); }); } pub fn preinject(window: &tauri::Window) { - let injection_js = match fs::read_to_string(resource_folder().join("injection/preinject_min.js")) + let js_path = window + .app_handle() + .path_resolver() + .resolve_resource(PathBuf::from("injection/preinject_min.js")) + .unwrap(); + let injection_js = match fs::read_to_string(js_path) { Ok(f) => f, Err(e) => { diff --git a/src-tauri/src/local_html.rs b/src-tauri/src/local_html.rs index a386c178..cb916920 100644 --- a/src-tauri/src/local_html.rs +++ b/src-tauri/src/local_html.rs @@ -1,12 +1,16 @@ -use std::fs; +use std::{fs, path::PathBuf}; -use crate::helpers::resource_folder; +use tauri::Manager; -pub fn get_html(dir: &str) -> String { - match fs::read_to_string(resource_folder().join(dir)) { +pub fn get_html(app: tauri::AppHandle, dir: &str) -> String { + let dir = app + .path_resolver() + .resolve_resource(PathBuf::from(dir)) + .unwrap(); + match fs::read_to_string(&dir) { Ok(f) => f, Err(e) => { - println!("Failed to read {} in local dir: {}", dir, e); + println!("Failed to read {:?} in local dir: {}", dir, e); String::new() } @@ -14,16 +18,16 @@ pub fn get_html(dir: &str) -> String { } #[tauri::command] -pub fn get_index() -> String { - get_html("html/index.html") +pub fn get_index(win: tauri::Window) -> String { + get_html(win.app_handle(), "html/index.html") } #[tauri::command] -pub fn get_top_bar() -> String { - get_html("html/top.html") +pub fn get_top_bar(win: tauri::Window) -> String { + get_html(win.app_handle(), "html/top.html") } #[tauri::command] -pub fn get_notif() -> String { - get_html("html/notification.html") +pub fn get_notif(win: tauri::Window) -> String { + get_html(win.app_handle(), "html/notification.html") } diff --git a/src-tauri/src/notifications.rs b/src-tauri/src/notifications.rs index d4beca93..b5a9e55e 100644 --- a/src-tauri/src/notifications.rs +++ b/src-tauri/src/notifications.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use tauri::Icon; +use tauri::{Icon, Manager}; pub fn set_notif_icon(window: tauri::Window, amount: u16) { let icon_num = if amount > 9 { 9 } else { amount }; @@ -10,7 +10,9 @@ pub fn set_notif_icon(window: tauri::Window, amount: u16) { let mut icon_path = PathBuf::from("icons/icon"); icon_path.set_extension("ico"); - window.set_icon(Icon::File(icon_path)).unwrap_or(()); + window.set_icon(Icon::File( + window.app_handle().path_resolver().resolve_resource(icon_path).unwrap(), + )).unwrap_or(()); return; } @@ -18,7 +20,9 @@ pub fn set_notif_icon(window: tauri::Window, amount: u16) { let mut icon_path = PathBuf::from("icons/").join(icon_name); icon_path.set_extension("ico"); - window.set_icon(Icon::File(icon_path)).unwrap_or(()); + window.set_icon(Icon::File( + window.app_handle().path_resolver().resolve_resource(icon_path).unwrap(), + )).unwrap_or(()); } #[tauri::command]