add func complete
This commit is contained in:
@@ -5,3 +5,4 @@
|
||||
# Generated by Tauri
|
||||
# will have schema files for capabilities auto-completion
|
||||
/gen/schemas
|
||||
resource/
|
||||
Generated
+3
@@ -483,8 +483,10 @@ checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
|
||||
dependencies = [
|
||||
"android-tzdata",
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"wasm-bindgen",
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
@@ -4035,6 +4037,7 @@ dependencies = [
|
||||
name = "wallitor-gui"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tauri",
|
||||
|
||||
@@ -22,4 +22,5 @@ serde_json = "1"
|
||||
window-vibrancy = "0.5.2"
|
||||
tauri-plugin-fs = "2.0.0-rc"
|
||||
tauri-plugin-dialog = "2.0.0-rc"
|
||||
chrono = "0.4.38"
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"name": "test1",
|
||||
"info": {
|
||||
"type": "",
|
||||
"description": "test wallpaper 1",
|
||||
"created": 0
|
||||
},
|
||||
"option": {
|
||||
"mute": true
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 386 KiB |
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"name": "test2",
|
||||
"info": {
|
||||
"type": "",
|
||||
"description": "test wallpaper 2",
|
||||
"created": 0
|
||||
},
|
||||
"option": {
|
||||
"mute": true
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,11 @@ mod setup;
|
||||
mod reader;
|
||||
|
||||
use std::{fs, path};
|
||||
use serde_json;
|
||||
use serde_json::{self,json};
|
||||
use std::path::Path;
|
||||
use tauri::ipc::Response;
|
||||
use serde::{Deserialize,Serialize};
|
||||
use chrono::Local;
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
@@ -12,7 +14,7 @@ pub fn run() {
|
||||
.setup(setup::init)
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.invoke_handler(tauri::generate_handler![read_resource_dir,get_file])
|
||||
.invoke_handler(tauri::generate_handler![read_resource_dir,get_file,new_wallpaper])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
@@ -37,4 +39,69 @@ async fn get_file(path:String) -> Response{
|
||||
return tauri::ipc::Response::new(data);
|
||||
}
|
||||
tauri::ipc::Response::new(String::from(""))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct AddInfo {
|
||||
name: String,
|
||||
preview: String,
|
||||
media: String,
|
||||
description: String
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct Info{
|
||||
media_type:String,
|
||||
description:String,
|
||||
created:i64
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct Opt{
|
||||
mute:bool
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct Config{
|
||||
name:String,
|
||||
info:Info,
|
||||
option:Opt
|
||||
}
|
||||
|
||||
|
||||
#[tauri::command]
|
||||
async fn new_wallpaper(info:AddInfo) -> String{
|
||||
let base_url = String::from("./resource");
|
||||
let current_time:i64 = Local::now().timestamp();
|
||||
let folder = format!("{}/{}",base_url,current_time);
|
||||
if fs::create_dir(Path::new(&folder)).is_err(){
|
||||
return String::from("Error creating folder.");
|
||||
}
|
||||
if let Ok(false) = fs::exists(Path::new(&info.preview)){
|
||||
return String::from("Source Image doesn't exist.");
|
||||
}
|
||||
if fs::copy(Path::new(&info.preview), Path::new(&format!("{}/preview.jpg",folder))).is_err(){
|
||||
return String::from("Error copy image.");
|
||||
}
|
||||
let config =json!( Config{
|
||||
name:info.name,
|
||||
info:Info { media_type: String::from("video"), description: info.description, created: current_time},
|
||||
option:Opt{mute:true}
|
||||
});
|
||||
if fs::write(Path::new(&format!("{}/config.json",folder)), config.to_string()).is_err(){
|
||||
return String::from("Error write config.");
|
||||
}
|
||||
if fs::create_dir(Path::new(&format!("{}/res",folder))).is_err(){
|
||||
return String::from("Error creating res folder.");
|
||||
}
|
||||
let media = Path::new(&info.media);
|
||||
if let Some(filename) = media.file_name().and_then(|f| f.to_str()){
|
||||
if fs::copy(Path::new(&info.media), Path::new(&format!("{}/res/{}",folder,filename))).is_err(){
|
||||
return String::from("Error copy media.");
|
||||
}
|
||||
}
|
||||
else{
|
||||
return String::from("Invalid media path.");
|
||||
}
|
||||
String::from("Success")
|
||||
}
|
||||
Reference in New Issue
Block a user