get language despite admin or not

This commit is contained in:
SpikeHD
2022-06-01 17:40:24 -07:00
parent 174a990c40
commit ecd4bff882
2 changed files with 15 additions and 2 deletions

View File

@@ -1,9 +1,11 @@
use crate::system_helpers::*;
#[tauri::command]
pub async fn get_lang(window: tauri::Window, lang: String) -> String {
let lang = lang.to_lowercase();
// Send contents of language file back
let contents = match std::fs::read_to_string(format!("./lang/{}.json", lang)) {
let contents = match std::fs::read_to_string(format!("{}/lang/{}.json", install_location(), lang)) {
Ok(x) => x,
Err(e) => {
emit_lang_err(window, format!("Failed to read language file: {}", e));
@@ -19,7 +21,7 @@ pub async fn get_languages() -> std::collections::HashMap<String, String> {
// for each lang file, set the key as the filename and the value as the lang_name contained in the file
let mut languages = std::collections::HashMap::new();
let mut lang_files = std::fs::read_dir("./lang").unwrap();
let mut lang_files = std::fs::read_dir(format!("{}/lang", install_location())).unwrap();
while let Some(entry) = lang_files.next() {
let entry = entry.unwrap();

View File

@@ -54,3 +54,14 @@ pub fn open_in_browser(url: String) {
Err(e) => println!("Failed to open URL: {}", e),
};
}
pub fn install_location() -> String {
let mut exe_path = std::env::current_exe().unwrap();
// Get the path to the executable.
exe_path.pop();
println!("{}", exe_path.to_str().unwrap().to_string());
return exe_path.to_str().unwrap().to_string();
}