✨ 整理下下载功能
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
use std::fs;
|
||||||
use tauri::{api, command, AppHandle, Manager};
|
use tauri::{api, command, AppHandle, Manager};
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
@@ -19,3 +20,9 @@ pub fn fullscreen(app: AppHandle) {
|
|||||||
pub fn open_browser(app: AppHandle, url: String) {
|
pub fn open_browser(app: AppHandle, url: String) {
|
||||||
api::shell::open(&app.shell_scope(), url, None).unwrap();
|
api::shell::open(&app.shell_scope(), url, None).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
pub fn download(_app: AppHandle, name: String, blob: Vec<u8>) {
|
||||||
|
let path = api::path::download_dir().unwrap().join(name);
|
||||||
|
fs::write(&path, blob).unwrap();
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ mod app;
|
|||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
use app::{invoke, menu, window};
|
use app::{invoke, menu, window};
|
||||||
use invoke::{drag_window, fullscreen, open_browser};
|
use invoke::{download, drag_window, fullscreen, open_browser};
|
||||||
use menu::{get_menu, menu_event_handle};
|
use menu::{get_menu, menu_event_handle};
|
||||||
use util::{get_data_dir, get_pake_config};
|
use util::{get_data_dir, get_pake_config};
|
||||||
use window::get_window;
|
use window::get_window;
|
||||||
@@ -43,7 +43,8 @@ pub fn run_app() {
|
|||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
drag_window,
|
drag_window,
|
||||||
fullscreen,
|
fullscreen,
|
||||||
open_browser
|
open_browser,
|
||||||
|
download
|
||||||
])
|
])
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
let _window = get_window(app, pake_config, data_dir);
|
let _window = get_window(app, pake_config, data_dir);
|
||||||
|
|||||||
Reference in New Issue
Block a user