Compare commits

..

2 Commits

Author SHA1 Message Date
cast1e dc5d53a953 file select 2024-10-13 19:05:55 +08:00
cast1e ac40bee45e add func complete 2024-10-13 16:56:11 +08:00
10 changed files with 122 additions and 57 deletions

View File

@ -5,3 +5,4 @@
# Generated by Tauri
# will have schema files for capabilities auto-completion
/gen/schemas
resource/

View File

@ -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",

View File

@ -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"

View File

@ -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

View File

@ -1,11 +0,0 @@
{
"name": "test2",
"info": {
"type": "",
"description": "test wallpaper 2",
"created": 0
},
"option": {
"mute": true
}
}

View File

@ -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");
}
@ -38,3 +40,68 @@ async fn get_file(path:String) -> Response{
}
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_all(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")
}

View File

@ -18,37 +18,39 @@
</header>
<main class="item-add-main">
<table class="item-add-form">
<tr>
<td class="item-add-form-title">标题</td>
<td><input type="text" v-model="addInfo.name" /></td>
</tr>
<tr>
<td class="item-add-form-title">文件</td>
<td>
<template v-if="image_src">
<img :src="image_src" class="item-add-image">
</template>
<template v-else>
<div class="item-add-preview" @click="selectPreview">
<div class="item-add-preview-text">
<SvgIcon name="add" size="20px"></SvgIcon>点击添加封面
<tbody>
<tr>
<td class="item-add-form-title">标题</td>
<td><input type="text" v-model="addInfo.name" /></td>
</tr>
<tr>
<td class="item-add-form-title">文件</td>
<td>
<template v-if="image_src">
<img :src="image_src" class="item-add-image" @click="selectPreview">
</template>
<template v-else>
<div class="item-add-preview" @click="selectPreview">
<div class="item-add-preview-text">
<SvgIcon name="add" size="20px"></SvgIcon>点击添加封面
</div>
</div>
</template>
<div class="colbox">
<button class="apply-button" @click="selectMedia"></button>
<div>{{ addInfo.media }}</div>
</div>
</template>
<div class="colbox">
<button class="apply-button" @click="selectMedia"></button>
<div>{{ addInfo.media }}</div>
</div>
</td>
</tr>
<tr>
<td class="item-add-form-title">描述</td>
<td><textarea class="item-add-description" v-model="addInfo.description"></textarea></td>
</tr>
<tr>
<td></td>
<td><button class="apply-button" @click="handleFileOpen"></button></td>
</tr>
</td>
</tr>
<tr>
<td class="item-add-form-title">描述</td>
<td><textarea class="item-add-description" v-model="addInfo.description"></textarea></td>
</tr>
<tr>
<td></td>
<td><button class="apply-button" @click="handleAdd"></button></td>
</tr>
</tbody>
</table>
</main>
</div>
@ -113,6 +115,14 @@ function selectPreview() {
}
})
}
function handleAdd() {
invoke("new_wallpaper", {
info: addInfo.value
}).then((res) => {
console.log(res);
})
}
</script>
<style>
@ -208,6 +218,11 @@ function selectPreview() {
width: 400px;
margin-bottom: 10px;
box-shadow: var(--shadow-edge-glow);
cursor: pointer;
}
.item-add-image:active {
transform: scale(0.95);
}
.item-add-form {

View File

@ -12,7 +12,7 @@
类型
</div>
<div class="apply-bar-info-main">
{{ cell.config.info.type }}
{{ cell.config.info.media_type }}
</div>
</div>
<div class="apply-bar-info rowbox">
@ -28,7 +28,7 @@
创建时间
</div>
<div class="apply-bar-info-main">
{{ (new Date(cell.config.info.created)).toLocaleString() }}
{{ (new Date(cell.config.info.created * 1000)).toLocaleString() }}
</div>
</div>
<div class="apply-bar-info rowbox">
@ -81,7 +81,7 @@ const cell = ref<Cell>({
}
}
})
const info_items = ref<(keyof Info)[]>(["type", "description", "created"]);
const info_items = ref<(keyof Info)[]>(["media_type", "description", "created"]);
const bg = ref<HTMLDivElement | null>(null);
defineExpose({ open })
watch(() => visible.value, (val, _) => {

View File

@ -5,7 +5,7 @@ export interface wpConfig {
}
type WallpaperType = 'Video'
export interface Info {
type: WallpaperType
media_type: WallpaperType
description: string
created: number
}