applybar complete

This commit is contained in:
cast1e
2024-10-13 10:23:08 +08:00
parent 989aaf73a8
commit cd10769d5d
40 changed files with 7060 additions and 448 deletions
+39
View File
@@ -0,0 +1,39 @@
mod setup;
mod reader;
use std::{fs, path};
use serde_json;
use std::path::Path;
use tauri::ipc::Response;
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.setup(setup::init)
.plugin(tauri_plugin_fs::init())
.invoke_handler(tauri::generate_handler![read_resource_dir,get_file])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
#[tauri::command]
async fn read_resource_dir() -> String {
let mut file_map = reader::FileMap::new();
let path = Path::new("./resource");
if let Ok(false) = fs::exists(path){
fs::create_dir(path).expect("Can't create dir");
}
file_map.read_resourse_directory(path).expect("Can't read dir");
serde_json::to_string(&file_map).unwrap()
}
// remember to call `.manage(MyState::default())`
#[tauri::command]
async fn get_file(path:String) -> Response{
let p = path::Path::new(&path);
if let Ok(true) = fs::exists(p){
let data: Vec<u8> = fs::read(p).unwrap();
return tauri::ipc::Response::new(data);
}
tauri::ipc::Response::new(String::from(""))
}
+1 -29
View File
@@ -1,34 +1,6 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
mod setup;
mod reader;
use std::fs;
use serde_json;
use std::path::Path;
fn main() {
tauri::Builder::default()
.setup(setup::init)
.invoke_handler(tauri::generate_handler![test_command])
.invoke_handler(tauri::generate_handler![read_resource_dir])
.run(tauri::generate_context!())
.expect("error while running tauri application");
wallitor_gui_lib::run()
}
#[tauri::command]
async fn test_command() -> String {
return String::from("Hello World");
}
#[tauri::command]
async fn read_resource_dir() -> String {
let file_map = reader::FileMap::new();
let path = Path::new("./resource");
if let Ok(false) = fs::exists(path){
fs::create_dir(path).expect("Can't create dir");
}
serde_json::to_string(&file_map).unwrap()
}
+1 -2
View File
@@ -1,7 +1,6 @@
use std::fs;
use std::path::Path;
use serde::{ Serialize,Serializer};
use serde_json;
use std::collections::HashMap;
enum FileType {
@@ -45,7 +44,7 @@ impl FileMap {
Ok(files)
}
fn read_resourse_directory(&mut self,p:&Path)->std::io::Result<()>{
pub fn read_resourse_directory(&mut self,p:&Path)->std::io::Result<()>{
for entry in fs::read_dir(p)?{
let dir = entry?;
let path = dir.path();
+2 -6
View File
@@ -1,15 +1,11 @@
use tauri::{App, Manager};
use window_vibrancy::{self, NSVisualEffectMaterial};
#[cfg(target_os = "windows")]
use window_vibrancy;
/// setup
pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>> {
let win = app.get_webview_window("main").unwrap();
// 仅在 macOS 下执行
#[cfg(target_os = "macos")]
window_vibrancy::apply_vibrancy(&win, NSVisualEffectMaterial::FullScreenUI)
.expect("Unsupported platform! 'apply_vibrancy' is only supported on macOS");
// 仅在 windows 下执行
#[cfg(target_os = "windows")]
if let Err(_) = window_vibrancy::apply_mica(&win, None){