autostart & icon change & bug fixes

This commit is contained in:
cast1e
2024-10-17 14:10:51 +08:00
parent 56ccc04f2a
commit c7ad45ebbb
36 changed files with 547 additions and 122 deletions
+44 -13
View File
@@ -1,7 +1,8 @@
use crate::reader;
use std::path::Path;
use std::fs;
use crate::{reader, VERSION};
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::fs;
use std::path::Path;
use tauri::ipc::Response;
#[tauri::command]
@@ -42,15 +43,45 @@ pub async fn del_folder(path: String) -> bool {
false
}
#[derive(Serialize,Deserialize)]
struct settings{
title_bar:String,
auto_start:bool,
auto_pause:bool
}
#[derive(Serialize, Deserialize)]
pub struct Settings {
title_bar: String,
auto_start: bool,
auto_pause: bool,
version: String,
}
impl Settings {
fn new() -> Settings {
Settings {
title_bar: String::from("win"),
auto_start: false,
auto_pause: true,
version: String::from(VERSION),
}
}
}
static SETTING_PATH: &str = "./settings.json";
#[tauri::command]
pub async fn get_config() -> String{
if let Ok()
}
pub async fn get_settings() -> String {
let setting_path = Path::new(SETTING_PATH);
if let Ok(file) = fs::read(setting_path) {
let mut settings: Settings = serde_json::from_slice(&file).unwrap();
settings.version = String::from(VERSION);
return json!(settings).to_string();
} else {
set_settings(Settings::new()).await;
return json!(Settings::new()).to_string();
}
}
#[tauri::command]
pub async fn set_settings(settings: Settings) -> bool {
let setting_path = Path::new(SETTING_PATH);
if fs::write(setting_path, json!(settings).to_string()).is_ok() {
return true;
}
false
}
+12 -3
View File
@@ -1,7 +1,10 @@
mod setup;
mod handler;
mod reader;
extern crate lazy_static;
mod setup;
extern crate lazy_static;
use tauri_plugin_autostart::MacosLauncher;
static VERSION: &str = "1.0.0";
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
@@ -9,6 +12,10 @@ pub fn run() {
.setup(setup::init)
.plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_autostart::init(
MacosLauncher::LaunchAgent,
Some(vec!["--flag1", "--flag2"]),
))
.invoke_handler(tauri::generate_handler![
handler::file::get_file,
handler::file::read_resource_dir,
@@ -16,7 +23,9 @@ pub fn run() {
handler::wallpaper::new_wallpaper,
handler::apply::set_wallpaper,
handler::wallpaper::edit_wallpaper,
handler::apply::any_zoomed
handler::apply::any_zoomed,
handler::file::get_settings,
handler::file::set_settings,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");