complete main function
This commit is contained in:
@@ -5,4 +5,5 @@
|
||||
# Generated by Tauri
|
||||
# will have schema files for capabilities auto-completion
|
||||
/gen/schemas
|
||||
resource/
|
||||
resource/
|
||||
wallitor-core.dll
|
||||
Generated
+12
-1
@@ -1795,7 +1795,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e9ec52138abedcc58dc17a7c6c0c00a2bdb4f3427c7f63fa97fd0d859155caf"
|
||||
dependencies = [
|
||||
"gtk-sys",
|
||||
"libloading",
|
||||
"libloading 0.7.4",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
@@ -1815,6 +1815,16 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libredox"
|
||||
version = "0.1.3"
|
||||
@@ -4038,6 +4048,7 @@ name = "wallitor-gui"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"libloading 0.8.5",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tauri",
|
||||
|
||||
@@ -5,6 +5,7 @@ description = "A Tauri App"
|
||||
authors = ["you"]
|
||||
edition = "2021"
|
||||
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
@@ -15,7 +16,7 @@ crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
tauri-build = { version = "2.0.0-rc", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2.0.0-rc", features = [] }
|
||||
tauri = { version = "2.0.0-rc", features = ["unstable"] }
|
||||
tauri-plugin-shell = "2.0.0-rc"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
@@ -23,4 +24,5 @@ window-vibrancy = "0.5.2"
|
||||
tauri-plugin-fs = "2.0.0-rc"
|
||||
tauri-plugin-dialog = "2.0.0-rc"
|
||||
chrono = "0.4.38"
|
||||
libloading = "0.8.5"
|
||||
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
"identifier": "default",
|
||||
"description": "Capability for the main window",
|
||||
"windows": ["main"],
|
||||
"permissions": ["core:default", "shell:allow-open", "dialog:allow-open", "dialog:default"]
|
||||
"permissions": ["core:default", "shell:allow-open", "dialog:allow-open", "dialog:default","core:webview:allow-create-webview-window"]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "video",
|
||||
"description": "Capability for the main window",
|
||||
"windows": ["wallitor_video_playback"],
|
||||
"permissions": ["core:default", "shell:allow-open"]
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
{"default":{"identifier":"default","description":"Capability for the main window","local":true,"windows":["main"],"permissions":["core:default","shell:allow-open","dialog:allow-open","dialog:default"]},"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main"],"permissions":["core:default","core:window:allow-maximize","core:window:allow-unmaximize","core:window:allow-toggle-maximize","core:window:allow-minimize","core:window:allow-unminimize","core:window:allow-show","core:window:allow-hide","core:window:allow-close","core:window:allow-start-dragging"]}}
|
||||
{"default":{"identifier":"default","description":"Capability for the main window","local":true,"windows":["main"],"permissions":["core:default","shell:allow-open","dialog:allow-open","dialog:default","core:webview:allow-create-webview-window"]},"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main"],"permissions":["core:default","core:window:allow-maximize","core:window:allow-unmaximize","core:window:allow-toggle-maximize","core:window:allow-minimize","core:window:allow-unminimize","core:window:allow-show","core:window:allow-hide","core:window:allow-close","core:window:allow-start-dragging"]},"video":{"identifier":"video","description":"Capability for the main window","local":true,"windows":["wallitor_video_playback"],"permissions":["core:default","shell:allow-open"]}}
|
||||
@@ -7,6 +7,8 @@ use std::path::Path;
|
||||
use tauri::ipc::Response;
|
||||
use serde::{Deserialize,Serialize};
|
||||
use chrono::Local;
|
||||
use libloading::{Library,Symbol};
|
||||
use std::ffi::CString;
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
@@ -14,7 +16,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,new_wallpaper])
|
||||
.invoke_handler(tauri::generate_handler![read_resource_dir,get_file,new_wallpaper,set_wallpaper])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
@@ -53,7 +55,8 @@ struct AddInfo {
|
||||
struct Info{
|
||||
media_type:String,
|
||||
description:String,
|
||||
created:i64
|
||||
created:i64,
|
||||
entry_point:String
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -83,14 +86,6 @@ async fn new_wallpaper(info:AddInfo) -> String{
|
||||
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.");
|
||||
}
|
||||
@@ -99,9 +94,34 @@ async fn new_wallpaper(info:AddInfo) -> String{
|
||||
if fs::copy(Path::new(&info.media), Path::new(&format!("{}/res/{}",folder,filename))).is_err(){
|
||||
return String::from("Error copy media.");
|
||||
}
|
||||
let config =json!( Config{
|
||||
name:info.name,
|
||||
info:Info { media_type: String::from("video"), description: info.description, created: current_time,entry_point:String::from(filename)},
|
||||
option:Opt{mute:true}
|
||||
});
|
||||
if fs::write(Path::new(&format!("{}/config.json",folder)), config.to_string()).is_err(){
|
||||
return String::from("Error write config.");
|
||||
}
|
||||
}
|
||||
else{
|
||||
return String::from("Invalid media path.");
|
||||
}
|
||||
String::from("Success")
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn set_wallpaper(title:String)->bool{
|
||||
let lib = unsafe {
|
||||
Library::new("wallitor-core.dll").unwrap()
|
||||
};
|
||||
type SetFn = unsafe extern "C" fn(*const i8)->i8;
|
||||
let set:Symbol<SetFn> = unsafe {
|
||||
lib.get(b"set_wallpaper\0").unwrap()
|
||||
};
|
||||
let title = CString::new(title.to_string()).unwrap();
|
||||
unsafe {
|
||||
let res = set(title.as_ptr());
|
||||
if res == 0 {return false;};
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user