Skip to content

Commit 665857c

Browse files
committed
feat: implement ts rs
1 parent 1978e69 commit 665857c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+669
-306
lines changed

Cargo.lock

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"format": "prettier --write .",
1515
"format:check": "prettier --check .",
1616
"check": "npm run typecheck && npm run lint && npm run format:check",
17-
"prepare": "husky"
17+
"prepare": "husky",
18+
"generate:types": "cd src-tauri && cargo test export_bindings --no-fail-fast"
1819
},
1920
"lint-staged": {
2021
"*.{ts,tsx}": [

src-tauri/.cargo/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[env]
2+
TS_RS_EXPORT_DIR = { value = "../src/lib/bindings/", relative = true }

src-tauri/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ libloading = "0.9.0"
3535
serde = { version = "1", features = ["derive"] }
3636
serde_json = "1"
3737

38+
ts-rs = { version = "12", features = ["chrono-impl", "serde-json-impl"] }
39+
3840
thiserror = "2"
3941
anyhow = "1"
4042

src-tauri/src/commands/app.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use crate::error::IpcResult;
22
use serde::Serialize;
3+
use ts_rs::TS;
34

4-
#[derive(Debug, Serialize)]
5+
#[derive(Debug, Serialize, TS)]
6+
#[ts(export)]
57
#[serde(rename_all = "camelCase")]
68
pub struct AppInfo {
79
pub name: String,

src-tauri/src/commands/patcher.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,29 @@ use std::sync::atomic::Ordering;
1313
use std::sync::Arc;
1414
use std::thread;
1515
use tauri::{AppHandle, Emitter, Manager, State};
16+
use ts_rs::TS;
1617

1718
/// Configuration for starting the patcher.
18-
#[derive(Debug, Clone, Deserialize)]
19+
#[derive(Debug, Clone, Deserialize, TS)]
20+
#[ts(export)]
1921
#[serde(rename_all = "camelCase")]
2022
pub struct PatcherConfig {
2123
/// Optional log file path.
24+
#[ts(optional)]
2225
pub log_file: Option<String>,
2326
/// Timeout in milliseconds for hook initialization. Defaults to 5 minutes.
27+
#[ts(optional)]
2428
pub timeout_ms: Option<u32>,
2529
/// Optional legacy patcher flags (matches `cslol_set_flags`).
2630
///
2731
/// If not provided, defaults to 0 (equivalent to `--opts:none` in cslol-tools).
32+
#[ts(optional, type = "number")]
2833
pub flags: Option<u64>,
2934
}
3035

3136
/// Current status of the patcher.
32-
#[derive(Debug, Clone, Serialize)]
37+
#[derive(Debug, Clone, Serialize, TS)]
38+
#[ts(export)]
3339
#[serde(rename_all = "camelCase")]
3440
pub struct PatcherStatus {
3541
/// Whether the patcher is currently running.

src-tauri/src/error.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use serde::{Deserialize, Serialize};
22
use thiserror::Error;
3+
use ts_rs::TS;
34

45
/// Error codes that can be communicated across the IPC boundary.
56
/// These are serialized as SCREAMING_SNAKE_CASE for TypeScript consumption.
6-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
8+
#[ts(export)]
79
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
810
pub enum ErrorCode {
911
/// File system I/O error
@@ -46,7 +48,8 @@ pub enum ErrorCode {
4648

4749
/// Structured error response sent over IPC.
4850
/// This provides rich error information to the frontend.
49-
#[derive(Debug, Clone, Serialize, Deserialize)]
51+
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
52+
#[ts(export, rename = "AppError")]
5053
#[serde(rename_all = "camelCase")]
5154
pub struct AppErrorResponse {
5255
/// Machine-readable error code for pattern matching
@@ -55,6 +58,7 @@ pub struct AppErrorResponse {
5558
pub message: String,
5659
/// Optional contextual data (e.g., the invalid path, missing mod ID)
5760
#[serde(skip_serializing_if = "Option::is_none")]
61+
#[ts(optional, type = "unknown")]
5862
pub context: Option<serde_json::Value>,
5963
}
6064

src-tauri/src/mods/inspect.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ use ltk_modpkg::Modpkg;
33
use serde::Serialize;
44
use std::collections::BTreeMap;
55
use std::path::Path;
6+
use ts_rs::TS;
67

78
/// Information returned by `inspect_modpkg`.
8-
#[derive(Debug, Clone, Serialize)]
9+
#[derive(Debug, Clone, Serialize, TS)]
10+
#[ts(export)]
911
#[serde(rename_all = "camelCase")]
1012
pub struct ModpkgInfo {
1113
pub name: String,
@@ -18,7 +20,8 @@ pub struct ModpkgInfo {
1820
pub total_size: u64,
1921
}
2022

21-
#[derive(Debug, Clone, Serialize)]
23+
#[derive(Debug, Clone, Serialize, TS)]
24+
#[ts(export)]
2225
#[serde(rename_all = "camelCase")]
2326
pub struct LayerInfo {
2427
pub name: String,

src-tauri/src/mods/migration.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ use std::fs;
55
use std::io::{Read, Write};
66
use std::path::Path;
77
use tauri::{AppHandle, Emitter};
8+
use ts_rs::TS;
89

910
use super::{BulkInstallResult, MigrationPhase, MigrationProgress, ModLibrary};
1011

1112
/// Metadata for a discovered cslol-manager mod, shown in the UI selection step.
12-
#[derive(Debug, Clone, Serialize, Deserialize)]
13+
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
14+
#[ts(export)]
1315
#[serde(rename_all = "camelCase")]
1416
pub struct CslolModInfo {
1517
pub folder_name: String,

src-tauri/src/mods/mod.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use serde::{Deserialize, Serialize};
1414
use std::fs;
1515
use std::path::{Path, PathBuf};
1616
use tauri::AppHandle;
17+
use ts_rs::TS;
1718
use uuid::Uuid;
1819

1920
/// Managed struct that encapsulates mod library operations.
@@ -94,7 +95,8 @@ impl ModLibrary {
9495
}
9596

9697
/// Slugified profile name used as the filesystem directory name.
97-
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
98+
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, TS)]
99+
#[ts(export)]
98100
#[serde(transparent)]
99101
pub struct ProfileSlug(pub String);
100102

@@ -135,7 +137,8 @@ impl From<String> for ProfileSlug {
135137
}
136138

137139
/// A mod profile for organizing different mod configurations.
138-
#[derive(Debug, Clone, Serialize, Deserialize)]
140+
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
141+
#[ts(export)]
139142
#[serde(rename_all = "camelCase")]
140143
pub struct Profile {
141144
/// Unique identifier (UUID)
@@ -156,7 +159,8 @@ pub struct Profile {
156159
}
157160

158161
/// A mod layer shown in the UI.
159-
#[derive(Debug, Clone, Serialize, Deserialize)]
162+
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
163+
#[ts(export)]
160164
#[serde(rename_all = "camelCase")]
161165
pub struct ModLayer {
162166
pub name: String,
@@ -165,7 +169,8 @@ pub struct ModLayer {
165169
}
166170

167171
/// A mod entry shown in the UI Library.
168-
#[derive(Debug, Clone, Serialize, Deserialize)]
172+
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
173+
#[ts(export)]
169174
#[serde(rename_all = "camelCase")]
170175
pub struct InstalledMod {
171176
pub id: String,
@@ -185,15 +190,17 @@ pub struct InstalledMod {
185190
}
186191

187192
/// Result of a bulk mod install operation.
188-
#[derive(Debug, Clone, Serialize, Deserialize)]
193+
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
194+
#[ts(export)]
189195
#[serde(rename_all = "camelCase")]
190196
pub struct BulkInstallResult {
191197
pub installed: Vec<InstalledMod>,
192198
pub failed: Vec<BulkInstallError>,
193199
}
194200

195201
/// Error info for a single file that failed during bulk install.
196-
#[derive(Debug, Clone, Serialize, Deserialize)]
202+
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
203+
#[ts(export)]
197204
#[serde(rename_all = "camelCase")]
198205
pub struct BulkInstallError {
199206
pub file_path: String,
@@ -202,7 +209,8 @@ pub struct BulkInstallError {
202209
}
203210

204211
/// Progress event emitted per-file during bulk mod install.
205-
#[derive(Debug, Clone, Serialize, Deserialize)]
212+
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
213+
#[ts(export)]
206214
#[serde(rename_all = "camelCase")]
207215
pub struct InstallProgress {
208216
pub current: usize,
@@ -211,7 +219,8 @@ pub struct InstallProgress {
211219
}
212220

213221
/// Progress event emitted during cslol migration (both packaging and installing phases).
214-
#[derive(Debug, Clone, Serialize, Deserialize)]
222+
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
223+
#[ts(export)]
215224
#[serde(rename_all = "camelCase")]
216225
pub struct MigrationProgress {
217226
pub phase: MigrationPhase,
@@ -220,7 +229,8 @@ pub struct MigrationProgress {
220229
pub current_file: String,
221230
}
222231

223-
#[derive(Debug, Clone, Serialize, Deserialize)]
232+
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
233+
#[ts(export)]
224234
#[serde(rename_all = "camelCase")]
225235
pub enum MigrationPhase {
226236
Packaging,

0 commit comments

Comments
 (0)