mirror of
https://github.com/OSMA-D/osma-app.git
synced 2025-03-04 01:01:25 +03:00
feat: i18n
This commit is contained in:
parent
37c3c3f069
commit
0a1f979891
15 changed files with 314 additions and 16 deletions
|
@ -1,4 +1,6 @@
|
|||
use crate::AppData;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use crate::{AppData, Language};
|
||||
use reqwest::blocking::*;
|
||||
use tauri::{App, State};
|
||||
|
||||
|
@ -26,3 +28,17 @@ pub fn check_auth(state: State<AppData>) -> bool {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn change_lng(state: State<Mutex<Language>>, lng: String) {
|
||||
let mut state = state.lock().unwrap();
|
||||
*state = Language { lng };
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_lng(state: State<Mutex<Language>>) -> String {
|
||||
match state.lock() {
|
||||
Ok(val) => val.lng.clone(),
|
||||
Err(_) => "ru".to_string(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,21 +3,30 @@
|
|||
windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
use std::fs;
|
||||
use std::{fs, sync::Mutex};
|
||||
|
||||
mod types;
|
||||
use types::*;
|
||||
|
||||
mod commands;
|
||||
fn main() {
|
||||
let options = fs::read_to_string("options.json").unwrap_or("{\"jwt\":null}".to_string());
|
||||
let options = {
|
||||
let op = fs::read_to_string("options.json").unwrap_or("{\"jwt\":null}".to_string());
|
||||
serde_json::from_str::<AppData>(&op).unwrap_or(AppData {
|
||||
jwt: "null".to_string(),
|
||||
lng: "en".to_string(),
|
||||
})
|
||||
};
|
||||
tauri::Builder::default()
|
||||
.manage(
|
||||
serde_json::from_str::<AppData>(&options).unwrap_or(AppData {
|
||||
jwt: "null".to_string(),
|
||||
}),
|
||||
)
|
||||
.invoke_handler(tauri::generate_handler![commands::check_auth])
|
||||
.manage(Mutex::new(Language {
|
||||
lng: options.lng.clone(),
|
||||
}))
|
||||
.manage(options)
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
commands::check_auth,
|
||||
commands::change_lng,
|
||||
commands::get_lng
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running osma app");
|
||||
}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, Clone)]
|
||||
pub struct AppData {
|
||||
pub jwt: String,
|
||||
pub lng: String,
|
||||
}
|
||||
|
||||
pub struct Language {
|
||||
pub lng: String,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue