[Update] update tauri v1-> v2 (development)
This commit is contained in:
64
src-tauri/src/lib.rs
Normal file
64
src-tauri/src/lib.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
use tauri::Manager;
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.setup(|app| {
|
||||
let main_window = app.get_webview_window("main").unwrap(); // `main_window` is declared here for all builds
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
{ main_window.open_devtools(); }
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.plugin(tauri_plugin_http::init())
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.invoke_handler(tauri::generate_handler![get_font_list, download_zip_asset])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
|
||||
use font_kit::{source::SystemSource};
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[tauri::command]
|
||||
async fn get_font_list() -> Vec<String> {
|
||||
let source = SystemSource::new();
|
||||
let mut font_families = HashSet::new();
|
||||
|
||||
if let Ok(fonts) = source.all_fonts() {
|
||||
for font in fonts {
|
||||
if let Ok(info) = font.load() {
|
||||
font_families.insert(info.family_name().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
font_families.into_iter().collect()
|
||||
}
|
||||
|
||||
|
||||
use base64::engine::general_purpose::STANDARD as BASE64;
|
||||
use base64::Engine;
|
||||
|
||||
#[tauri::command]
|
||||
async fn download_zip_asset(url: String) -> Result<String, String> {
|
||||
use reqwest;
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
let resp = client.get(&url)
|
||||
.header("Accept", "application/octet-stream")
|
||||
.send()
|
||||
.await.map_err(|e| format!("Request error: {}", e))?;
|
||||
if !resp.status().is_success() {
|
||||
return Err(format!("HTTP error: {}", resp.status()));
|
||||
}
|
||||
|
||||
let bytes = resp.bytes().await.map_err(|e| format!("Reading bytes error: {}", e))?;
|
||||
|
||||
Ok(BASE64.encode(&bytes))
|
||||
}
|
||||
@@ -1,67 +1,6 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use tauri::Manager;
|
||||
use window_shadows::set_shadow;
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.setup(|app| {
|
||||
let main_window = app.get_window("main").unwrap(); // `main_window` is declared here for all builds
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
{ main_window.open_devtools(); }
|
||||
|
||||
#[cfg(any(windows, target_os = "macos"))]
|
||||
set_shadow(main_window, true).unwrap();
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.on_window_event(|event| { // This is for fix the bug that the window scaling issue when dragging between monitors.
|
||||
if let tauri::WindowEvent::ScaleFactorChanged { new_inner_size, .. } = event.event() {
|
||||
event.window().set_size(tauri::Size::Physical(*new_inner_size)).unwrap();
|
||||
}
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![get_font_list, download_zip_asset])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
vrct_lib::run()
|
||||
}
|
||||
|
||||
|
||||
use font_kit::{source::SystemSource};
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[tauri::command]
|
||||
async fn get_font_list() -> Vec<String> {
|
||||
let source = SystemSource::new();
|
||||
let mut font_families = HashSet::new();
|
||||
|
||||
if let Ok(fonts) = source.all_fonts() {
|
||||
for font in fonts {
|
||||
if let Ok(info) = font.load() {
|
||||
font_families.insert(info.family_name().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
font_families.into_iter().collect()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn download_zip_asset(url: String) -> Result<String, String> {
|
||||
use reqwest;
|
||||
// reqwest のクライアントを作成
|
||||
let client = reqwest::Client::new();
|
||||
// GET リクエストを送信(リダイレクトも自動追従します)
|
||||
let resp = client.get(&url)
|
||||
.header("Accept", "application/octet-stream")
|
||||
.send()
|
||||
.await.map_err(|e| format!("Request error: {}", e))?;
|
||||
if !resp.status().is_success() {
|
||||
return Err(format!("HTTP error: {}", resp.status()));
|
||||
}
|
||||
// レスポンスのバイナリデータを取得
|
||||
let bytes = resp.bytes().await.map_err(|e| format!("Reading bytes error: {}", e))?;
|
||||
// バイナリデータを base64 エンコードして返す
|
||||
Ok(base64::encode(&bytes))
|
||||
}
|
||||
Reference in New Issue
Block a user