aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/packages/docs/content/en/development/guide.mdx
blob: 8ff2906b53cfa59230dc91703fb7435206395119 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
---
title: Development Guide
description: Build, test, and contribute to DropOut
---

# Development Guide

This guide will help you set up a development environment, build DropOut from source, and contribute to the project.

## Prerequisites

### Required Software

1. **Rust** (latest stable)
   ```bash
   # Install via rustup
   curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
   ```

2. **Node.js** (v22+) and **pnpm** (v9+)
   ```bash
   # Install Node.js from https://nodejs.org/
   # Install pnpm
   npm install -g pnpm@9
   ```

3. **System Dependencies**

   Follow the [Tauri Prerequisites](https://v2.tauri.app/start/prerequisites/) for your platform:

   **Linux (Debian/Ubuntu):**
   ```bash
   sudo apt update
   sudo apt install libwebkit2gtk-4.1-dev \
     build-essential \
     curl \
     wget \
     file \
     libssl-dev \
     libayatana-appindicator3-dev \
     librsvg2-dev
   ```

   **macOS:**
   ```bash
   xcode-select --install
   ```

   **Windows:**
   - Install [Microsoft Visual C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)
   - Install [WebView2](https://developer.microsoft.com/microsoft-edge/webview2/)

## Getting Started

### Clone the Repository

```bash
git clone https://github.com/HydroRoll-Team/DropOut.git
cd DropOut
```

### Install Dependencies

**Frontend dependencies:**
```bash
cd packages/ui
pnpm install
cd ../..
```

**Documentation dependencies:**
```bash
cd packages/docs
pnpm install
cd ../..
```

### Development Mode

Run DropOut in development mode with hot reload:

```bash
cargo tauri dev
```

This will:
1. Start the frontend dev server (Vite on port 5173)
2. Compile the Rust backend
3. Open the Tauri window
4. Enable hot reload for frontend changes
5. Recompile on Rust file changes

**Terminal output:**
- Frontend logs from Vite
- Rust stdout/stderr
- Compilation status

### Building for Production

Build release binaries:

```bash
cargo tauri build
```

**Output locations:**
- **Linux**: `src-tauri/target/release/bundle/`
  - `.deb` package
  - `.AppImage` bundle
- **macOS**: `src-tauri/target/release/bundle/`
  - `.dmg` installer
  - `.app` bundle
- **Windows**: `src-tauri/target/release/bundle/`
  - `.msi` installer
  - `.exe` executable

## Project Structure

```
DropOut/
├── src-tauri/              # Rust backend
│   ├── src/
│   │   ├── main.rs         # Tauri commands & entry point
│   │   ├── core/           # Core modules
│   │   │   ├── auth.rs     # Authentication
│   │   │   ├── downloader.rs # Download manager
│   │   │   ├── fabric.rs   # Fabric support
│   │   │   ├── forge.rs    # Forge support
│   │   │   ├── java.rs     # Java management
│   │   │   ├── instance.rs # Instance system
│   │   │   └── ...
│   │   └── utils/          # Utilities
│   └── Cargo.toml
├── packages/
│   ├── ui/                 # Svelte 5 frontend
│   │   ├── src/
│   │   │   ├── App.svelte
│   │   │   ├── components/
│   │   │   ├── stores/     # State management
│   │   │   └── lib/
│   │   └── package.json
│   └── docs/               # Documentation site
│       ├── content/docs/
│       └── package.json
├── .github/
│   └── workflows/          # CI/CD pipelines
└── scripts/                # Build scripts
```

## Development Workflows

### Frontend Development

**Start dev server:**
```bash
cd packages/ui
pnpm dev
```

**Type checking:**
```bash
pnpm check
```

**Linting:**
```bash
pnpm lint
```

**Formatting:**
```bash
pnpm format
```

### Backend Development

**Run Rust tests:**
```bash
cargo test
```

**Check code:**
```bash
cargo check
```

**Format code:**
```bash
cargo fmt
```

**Lint code:**
```bash
cargo clippy
```

### Documentation Development

**Start docs dev server:**
```bash
cd packages/docs
pnpm dev
```

**Build docs:**
```bash
pnpm build
```

**Type check:**
```bash
pnpm types:check
```

## Code Style

### Rust

Follow standard Rust conventions:
- Use `cargo fmt` for formatting
- Use `cargo clippy` for linting
- Write documentation comments (`///`)
- Handle errors properly
- Use async/await for I/O

**Example:**
```rust
/// Starts the Microsoft authentication device flow
#[tauri::command]
async fn start_microsoft_login(
    window: Window,
) -> Result<DeviceCodeResponse, String> {
    emit_log!(window, "Starting Microsoft login...");
    
    start_device_flow()
        .await
        .map_err(|e| e.to_string())
}
```

### TypeScript/Svelte

Follow the project's conventions:
- Use Svelte 5 runes (`$state`, `$effect`)
- Prefer TypeScript over JavaScript
- Use Biome for formatting and linting
- Follow component structure

**Example:**
```typescript
// stores/auth.svelte.ts
export class AuthState {
  currentAccount = $state<Account | null>(null);
  isLoginModalOpen = $state(false);
  
  async login(username: string) {
    const account = await invoke('offline_login', { username });
    this.currentAccount = account;
  }
}
```

## Testing

### Unit Tests

**Rust:**
```rust
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_generate_offline_uuid() {
        let uuid = generate_offline_uuid("Player");
        assert!(uuid.len() > 0);
    }
}
```

**Run:**
```bash
cargo test
```

### Integration Tests

Test the full application:
1. Build in dev mode: `cargo tauri dev`
2. Manually test features
3. Check console for errors
4. Verify UI behavior

### CI Tests

GitHub Actions runs tests on:
- Ubuntu (latest)
- Arch Linux (Wayland)
- Windows (latest)
- macOS (ARM64)

View workflow: `.github/workflows/test.yml`

## Debugging

### Frontend Debugging

1. Open DevTools in Tauri window: `Ctrl+Shift+I` (Windows/Linux) or `Cmd+Option+I` (macOS)
2. Check Console for errors
3. Use React DevTools or Svelte DevTools
4. Monitor Network tab for API calls

### Backend Debugging

**Print debugging:**
```rust
emit_log!(window, format!("Debug: {}", value));
println!("Debug: {}", value);
```

**Rust debugger:**
```bash
# Install rust-lldb or rust-gdb
cargo install rust-gdb

# Debug
rust-gdb target/debug/dropout
```

### Logging

**Frontend:**
```typescript
console.log("Info message");
console.error("Error message");
```

**Backend:**
```rust
emit_log!(window, "Status update");
eprintln!("Error: {}", error);
```

## Contributing

### Contribution Workflow

1. **Fork** the repository
2. **Create** a feature branch:
   ```bash
   git checkout -b feature/my-feature
   ```
3. **Make** your changes
4. **Test** thoroughly
5. **Commit** with conventional commits:
   ```bash
   git commit -m "feat: add new feature"
   ```
6. **Push** to your fork:
   ```bash
   git push origin feature/my-feature
   ```
7. **Create** a pull request

### Commit Messages

Follow [Conventional Commits](https://www.conventionalcommits.org/):

**Format:**
```
<type>[scope]: <description>

[optional body]

[optional footer]
```

**Types:**
- `feat`: New feature
- `fix`: Bug fix
- `docs`: Documentation
- `style`: Formatting
- `refactor`: Code restructuring
- `perf`: Performance improvement
- `test`: Adding tests
- `chore`: Maintenance

**Examples:**
```bash
feat(auth): add offline authentication support
fix(java): resolve detection on Windows
docs: update installation guide
refactor(download): simplify progress tracking
```

### Pull Request Guidelines

**Before submitting:**
- [ ] Code follows style guidelines
- [ ] Tests pass locally
- [ ] Documentation updated if needed
- [ ] No unnecessary files committed
- [ ] Commit messages are clear

**PR Description:**
- Explain what and why
- Link related issues
- List breaking changes
- Add screenshots for UI changes

### Code Review

Maintainers will review your PR for:
- Code quality and style
- Test coverage
- Documentation
- Performance impact
- Security implications

Be responsive to feedback and make requested changes.

## Common Tasks

### Adding a Tauri Command

1. **Define command in `main.rs`:**
   ```rust
   #[tauri::command]
   async fn my_command(param: String) -> Result<String, String> {
       Ok(format!("Received: {}", param))
   }
   ```

2. **Register in builder:**
   ```rust
   .invoke_handler(tauri::generate_handler![
       my_command,
       // ... other commands
   ])
   ```

3. **Call from frontend:**
   ```typescript
   const result = await invoke('my_command', { param: 'value' });
   ```

### Adding a UI Component

1. **Create component file:**
   ```svelte
   <!-- packages/ui/src/components/MyComponent.svelte -->
   <script lang="ts">
     let count = $state(0);
   </script>

   <button onclick={() => count++}>
     Count: {count}
   </button>
   ```

2. **Import and use:**
   ```svelte
   <script>
     import MyComponent from './components/MyComponent.svelte';
   </script>

   <MyComponent />
   ```

### Adding a Store

1. **Create store file:**
   ```typescript
   // packages/ui/src/stores/mystore.svelte.ts
   export class MyState {
     value = $state(0);
     
     increment() {
       this.value++;
     }
   }
   
   export const myState = new MyState();
   ```

2. **Use in components:**
   ```svelte
   <script>
     import { myState } from '../stores/mystore.svelte';
   </script>

   <button onclick={() => myState.increment()}>
     {myState.value}
   </button>
   ```

## Troubleshooting Development Issues

### Build Failures

**"cannot find -lwebkit2gtk"**
```bash
# Install WebKit dependencies
sudo apt install libwebkit2gtk-4.1-dev
```

**"pnpm not found"**
```bash
# Install pnpm
npm install -g pnpm@9
```

**"Rust version too old"**
```bash
# Update Rust
rustup update
```

### Runtime Issues

**"Failed to load dynamic library"**
- Rebuild: `cargo clean && cargo tauri dev`
- Check library paths
- Verify dependencies installed

**"CORS error"**
- Normal in dev mode
- Tauri handles CORS automatically

**"Hot reload not working"**
- Check Vite config
- Restart dev server
- Clear browser cache

## Resources

- [Tauri Documentation](https://v2.tauri.app/)
- [Svelte 5 Documentation](https://svelte.dev/docs)
- [Rust Book](https://doc.rust-lang.org/book/)
- [DropOut Repository](https://github.com/HydroRoll-Team/DropOut)

## Getting Help

- **Issues**: [GitHub Issues](https://github.com/HydroRoll-Team/DropOut/issues)
- **Discussions**: [GitHub Discussions](https://github.com/HydroRoll-Team/DropOut/discussions)
- **Documentation**: This site