Skip to content

Commit

Permalink
Add: specta
Browse files Browse the repository at this point in the history
  • Loading branch information
shm11C3 committed Nov 18, 2024
1 parent f0ca688 commit 25920c5
Show file tree
Hide file tree
Showing 16 changed files with 605 additions and 63 deletions.
10 changes: 9 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@
"editor.formatOnSave": true,
"editor.inlayHints.enabled": "off"
},
"cSpell.words": ["consts", "directx", "fullscreen", "nvapi", "tauri"],
"cSpell.words": [
"consts",
"directx",
"fullscreen",
"nvapi",
"rspc",
"specta",
"tauri"
],
"tailwindCSS.experimental.classRegex": [
"tv\\(([^)(]*(?:\\([^)(]*(?:\\([^)(]*(?:\\([^)(]*\\)[^)(]*)*\\)[^)(]*)*\\)[^)(]*)*)\\)"
]
Expand Down
3 changes: 3 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
"formatter": {
"indentStyle": "space",
"indentWidth": 2
},
"files": {
"ignore": ["src/rspc/**"]
}
}
82 changes: 82 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ winapi = { version = "0.3", features = ["dxgi"] }
regex = "1.11.1"
tempfile = "3.14.0"
sys-locale = "0.3.2"
tauri-specta = { version = "=2.0.0-rc.20", features = ["derive", "typescript"] }
specta-typescript = "0.0.7"
specta="=2.0.0-rc.20"

[dependencies.uuid]
version = "1.11.0"
Expand Down
7 changes: 6 additions & 1 deletion src-tauri/src/commands/background_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use base64::Engine;
use image::load_from_memory;
use image::ImageFormat;
use serde::{Deserialize, Serialize};
use specta::Type;
use tauri::command;
use tokio::fs;
use tokio::io::AsyncWriteExt;
Expand All @@ -19,6 +20,7 @@ const BG_IMG_DIR_NAME: &str = "BgImages";
/// - `file_id`: 画像ファイルID
///
#[command]
#[specta::specta]
pub async fn get_background_image(file_id: String) -> Result<String, String> {
let dir_path = get_app_data_dir(BG_IMG_DIR_NAME);

Expand All @@ -43,7 +45,7 @@ pub async fn get_background_image(file_id: String) -> Result<String, String> {
/// - `file_id` : 画像ファイルID
/// - `image_data` : 画像データのBase64文字列
///
#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone, Type)]
#[serde(rename_all = "camelCase")]
pub struct BackgroundImage {
pub file_id: String,
Expand All @@ -54,6 +56,7 @@ pub struct BackgroundImage {
/// BG_IMG_DIR_NAME ディレクトリ内の背景画像一覧を取得
///
#[command]
#[specta::specta]
pub async fn get_background_images() -> Result<Vec<BackgroundImage>, String> {
let dir_path = get_app_data_dir(BG_IMG_DIR_NAME);

Expand Down Expand Up @@ -100,6 +103,7 @@ pub async fn get_background_images() -> Result<Vec<BackgroundImage>, String> {
/// - returns: `file_id`
///
#[command]
#[specta::specta]
pub async fn save_background_image(image_data: String) -> Result<String, String> {
let dir_path = get_app_data_dir(BG_IMG_DIR_NAME);

Expand Down Expand Up @@ -159,6 +163,7 @@ pub async fn save_background_image(image_data: String) -> Result<String, String>
/// - `file_id`: 画像ファイルID
///
#[tauri::command]
#[specta::specta]
pub async fn delete_background_image(file_id: String) -> Result<(), String> {
let dir_path = get_app_data_dir(BG_IMG_DIR_NAME);
let file_name = FILE_NAME_FORMAT.replace("{}", &file_id);
Expand Down
23 changes: 20 additions & 3 deletions src-tauri/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ use crate::utils::color;
use crate::utils::file::get_app_data_dir;
use crate::{log_debug, log_error, log_info, log_internal, log_warn, utils};
use serde::{Deserialize, Serialize};
use specta::Type;
use specta_typescript::Typescript;
use std::fs;
use std::io::Write;
use std::sync::Mutex;
use tauri_specta::{collect_commands, Builder};
use tempfile::NamedTempFile;

const SETTINGS_FILENAME: &str = "settings.json";
Expand All @@ -16,7 +19,7 @@ trait Config {
fn read_file(&mut self) -> Result<(), String>;
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone, Type)]
#[serde(rename_all = "camelCase")]
pub struct StateSettings {
pub display: String,
Expand Down Expand Up @@ -55,15 +58,15 @@ pub struct Settings {
///
/// クライアントに送信する設定の構造体
///
#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone, Type)]
#[serde(rename_all = "camelCase")]
pub struct LineGraphColorStringSettings {
pub cpu: String,
pub memory: String,
pub gpu: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone, Type)]
#[serde(rename_all = "camelCase")]
pub struct ClientSettings {
language: String,
Expand Down Expand Up @@ -412,6 +415,7 @@ pub mod commands {
}

#[tauri::command]
#[specta::specta]
pub async fn get_settings(
state: tauri::State<'_, AppState>,
) -> Result<ClientSettings, String> {
Expand Down Expand Up @@ -462,6 +466,7 @@ pub mod commands {
}

#[tauri::command]
#[specta::specta]
pub async fn set_language(
window: Window,
state: tauri::State<'_, AppState>,
Expand All @@ -478,6 +483,7 @@ pub mod commands {
}

#[tauri::command]
#[specta::specta]
pub async fn set_theme(
window: Window,
state: tauri::State<'_, AppState>,
Expand All @@ -494,6 +500,7 @@ pub mod commands {
}

#[tauri::command]
#[specta::specta]
pub async fn set_display_targets(
window: Window,
state: tauri::State<'_, AppState>,
Expand All @@ -509,6 +516,7 @@ pub mod commands {
}

#[tauri::command]
#[specta::specta]
pub async fn set_graph_size(
window: Window,
state: tauri::State<'_, AppState>,
Expand All @@ -524,6 +532,7 @@ pub mod commands {
}

#[tauri::command]
#[specta::specta]
pub async fn set_line_graph_border(
window: Window,
state: tauri::State<'_, AppState>,
Expand All @@ -539,6 +548,7 @@ pub mod commands {
}

#[tauri::command]
#[specta::specta]
pub async fn set_line_graph_fill(
window: Window,
state: tauri::State<'_, AppState>,
Expand All @@ -554,6 +564,7 @@ pub mod commands {
}

#[tauri::command]
#[specta::specta]
pub async fn set_line_graph_color(
window: Window,
state: tauri::State<'_, AppState>,
Expand All @@ -572,6 +583,7 @@ pub mod commands {
}

#[tauri::command]
#[specta::specta]
pub async fn set_line_graph_mix(
window: Window,
state: tauri::State<'_, AppState>,
Expand All @@ -587,6 +599,7 @@ pub mod commands {
}

#[tauri::command]
#[specta::specta]
pub async fn set_line_graph_show_legend(
window: Window,
state: tauri::State<'_, AppState>,
Expand All @@ -602,6 +615,7 @@ pub mod commands {
}

#[tauri::command]
#[specta::specta]
pub async fn set_line_graph_show_scale(
window: Window,
state: tauri::State<'_, AppState>,
Expand All @@ -617,6 +631,7 @@ pub mod commands {
}

#[tauri::command]
#[specta::specta]
pub async fn set_background_img_opacity(
window: Window,
state: tauri::State<'_, AppState>,
Expand All @@ -632,6 +647,7 @@ pub mod commands {
}

#[tauri::command]
#[specta::specta]
pub async fn set_selected_background_img(
window: Window,
state: tauri::State<'_, AppState>,
Expand All @@ -647,6 +663,7 @@ pub mod commands {
}

#[tauri::command]
#[specta::specta]
pub async fn set_state(
window: Window,
state: tauri::State<'_, AppState>,
Expand Down
Loading

0 comments on commit 25920c5

Please sign in to comment.