Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bde7d78c3d | ||
|
|
355a798c34 | ||
|
|
7a4ba815fe | ||
|
|
6839fdbf47 | ||
|
|
78fc2951a8 | ||
|
|
dd91910f98 | ||
|
|
ea21eef396 | ||
|
|
64e058ad2e | ||
|
|
7be5517d18 | ||
|
|
9c221cb101 | ||
|
|
a2800c3664 | ||
|
|
50ab1cd54a | ||
|
|
826e07adf5 | ||
|
|
03b35868a8 | ||
|
|
cb8eeea9cf | ||
|
|
4c3dec9304 |
No files matched your search
@@ -0,0 +1,45 @@
|
|||||||
|
---
|
||||||
|
name: Bug Report
|
||||||
|
about: Bug Report template
|
||||||
|
title: "[Bug]: "
|
||||||
|
labels: bug, enhancement
|
||||||
|
assignees: Alvin-Zilverstand
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Bug Description
|
||||||
|
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
## Steps to Reproduce
|
||||||
|
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '...'
|
||||||
|
3. Scroll down to '...'
|
||||||
|
4. See error
|
||||||
|
|
||||||
|
## Expected Behavior
|
||||||
|
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
## Actual Behavior
|
||||||
|
|
||||||
|
What actually happened (include error messages, screenshots, etc.)
|
||||||
|
|
||||||
|
## Environment
|
||||||
|
|
||||||
|
- **OS**: Windows 10/11 (version)
|
||||||
|
- **ClipForge Version**: (e.g., v0.1.0)
|
||||||
|
- **GPU**: NVIDIA/AMD/Intel (model)
|
||||||
|
- **Game**: (if game-specific)
|
||||||
|
|
||||||
|
## Logs
|
||||||
|
|
||||||
|
Please attach relevant logs:
|
||||||
|
- Application logs (if available)
|
||||||
|
- Windows Event Viewer entries
|
||||||
|
- FFmpeg output (if capture-related)
|
||||||
|
|
||||||
|
## Additional Context
|
||||||
|
|
||||||
|
Add any other context about the problem here.
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
---
|
||||||
|
name: Feature Request
|
||||||
|
about: Feature Request template
|
||||||
|
title: "[Feature]: "
|
||||||
|
labels: enhancement
|
||||||
|
assignees: Alvin-Zilverstand
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Feature Description
|
||||||
|
|
||||||
|
A clear and concise description of the feature you'd like to see.
|
||||||
|
|
||||||
|
## Problem/Use Case
|
||||||
|
|
||||||
|
What problem does this solve? What's the use case?
|
||||||
|
|
||||||
|
## Proposed Solution
|
||||||
|
|
||||||
|
Describe how you'd like this feature to work.
|
||||||
|
|
||||||
|
## Alternatives Considered
|
||||||
|
|
||||||
|
Any alternative solutions or workarounds you've considered.
|
||||||
|
|
||||||
|
## Additional Context
|
||||||
|
|
||||||
|
Add any other context, mockups, or screenshots here.
|
||||||
|
|
||||||
|
## Implementation Ideas
|
||||||
|
|
||||||
|
If you have technical ideas on how to implement this, share them here.
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
---
|
||||||
|
name: Pull Request
|
||||||
|
description: Template for pull requests
|
||||||
|
title: "[PR]: "
|
||||||
|
labels: []
|
||||||
|
---
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
Brief description of changes.
|
||||||
|
|
||||||
|
## Type of Change
|
||||||
|
|
||||||
|
- [ ] Bug fix
|
||||||
|
- [ ] New feature
|
||||||
|
- [ ] Breaking change
|
||||||
|
- [ ] Documentation update
|
||||||
|
- [ ] Refactoring
|
||||||
|
- [ ] Tests
|
||||||
|
- [ ] CI/CD
|
||||||
|
|
||||||
|
## Related Issues
|
||||||
|
|
||||||
|
Fixes #(issue number)
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
- [ ] All existing tests pass (`cargo test`)
|
||||||
|
- [ ] New tests added for changes
|
||||||
|
- [ ] Manual testing performed
|
||||||
|
- [ ] UI builds successfully (`pnpm run build`)
|
||||||
|
|
||||||
|
## Checklist
|
||||||
|
|
||||||
|
- [ ] Code follows project style (`cargo fmt`, `pnpm run lint`)
|
||||||
|
- [ ] Clippy clean (`cargo clippy`)
|
||||||
|
- [ ] No new warnings
|
||||||
|
- [ ] Documentation updated (if applicable)
|
||||||
|
- [ ] CHANGELOG updated (if applicable)
|
||||||
|
|
||||||
|
## Screenshots (if UI changes)
|
||||||
|
|
||||||
|
## Additional Notes
|
||||||
@@ -124,6 +124,7 @@ jobs:
|
|||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ steps.release.outputs.tag }}
|
tag_name: ${{ steps.release.outputs.tag }}
|
||||||
|
generate_release_notes: true
|
||||||
files: |
|
files: |
|
||||||
src-tauri/target/release/bundle/msi/*.msi
|
src-tauri/target/release/bundle/msi/*.msi
|
||||||
src-tauri/target/release/bundle/nsis/*.exe
|
src-tauri/target/release/bundle/nsis/*.exe
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
# Contributor Covenant Code of Conduct
|
||||||
|
|
||||||
|
## Our Pledge
|
||||||
|
|
||||||
|
We as members, contributors, and leaders pledge to make participation in our
|
||||||
|
community a harassment-free experience for everyone, regardless of age, body
|
||||||
|
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||||
|
identity and expression, level of experience, education, socio-economic status,
|
||||||
|
nationality, personal appearance, race, religion, or sexual identity
|
||||||
|
and orientation.
|
||||||
|
|
||||||
|
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||||
|
diverse, inclusive, and healthy community.
|
||||||
|
|
||||||
|
## Our Standards
|
||||||
|
|
||||||
|
Examples of behavior that contributes to a positive environment for our
|
||||||
|
community include:
|
||||||
|
|
||||||
|
* Demonstrating empathy and kindness toward other people
|
||||||
|
* Being respectful of differing opinions, viewpoints, and experiences
|
||||||
|
* Giving and gracefully accepting constructive feedback
|
||||||
|
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||||
|
and learning from the experience
|
||||||
|
* Focusing on what is best not just for us as individuals, but for the
|
||||||
|
overall community
|
||||||
|
|
||||||
|
Examples of unacceptable behavior include:
|
||||||
|
|
||||||
|
* The use of sexualized language or imagery, and sexual attention or
|
||||||
|
advances of any kind
|
||||||
|
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||||
|
* Public or private harassment
|
||||||
|
* Publishing others' private information, such as a physical or email
|
||||||
|
address, without their explicit permission
|
||||||
|
* Other conduct which could reasonably be considered inappropriate in a
|
||||||
|
professional setting
|
||||||
|
|
||||||
|
## Enforcement Responsibilities
|
||||||
|
|
||||||
|
Community leaders are responsible for clarifying and enforcing our standards of
|
||||||
|
acceptable behavior and will take appropriate and fair corrective action in
|
||||||
|
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||||
|
or harmful.
|
||||||
|
|
||||||
|
Community leaders have the right and responsibility to remove, edit, or reject
|
||||||
|
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||||
|
not aligned to this Code of Conduct, and will communicate reasons for
|
||||||
|
moderation decisions when appropriate.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
This Code of Conduct applies within all community spaces, and also applies when
|
||||||
|
an individual is officially representing the community in public spaces.
|
||||||
|
Examples of representing our community include using an official e-mail address,
|
||||||
|
posting via an official social media account, or acting as an appointed
|
||||||
|
representative at an online or offline event.
|
||||||
|
|
||||||
|
## Enforcement
|
||||||
|
|
||||||
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||||
|
reported to the community leaders responsible for enforcement at
|
||||||
|
alvin@alvnx.xyz.
|
||||||
|
|
||||||
|
All complaints will be reviewed and investigated promptly and fairly.
|
||||||
|
|
||||||
|
All community leaders are obligated to respect the privacy and security of the
|
||||||
|
reporter of any incident.
|
||||||
|
|
||||||
|
## Enforcement Guidelines
|
||||||
|
|
||||||
|
Community leaders will follow these Community Impact Guidelines in determining
|
||||||
|
the consequences for any action they deem in violation of this Code of Conduct:
|
||||||
|
|
||||||
|
### 1. Correction
|
||||||
|
|
||||||
|
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||||
|
unprofessional or unwelcome in the community.
|
||||||
|
|
||||||
|
**Consequence**: A private, written warning from community leaders, providing
|
||||||
|
clarity around the nature of the violation and an explanation of why the
|
||||||
|
behavior was inappropriate. A public apology may be requested.
|
||||||
|
|
||||||
|
### 2. Warning
|
||||||
|
|
||||||
|
**Community Impact**: A violation through a single incident or series of
|
||||||
|
actions.
|
||||||
|
|
||||||
|
**Consequence**: A warning with consequences for continued behavior. No
|
||||||
|
interaction with the people involved, including unsolicited interaction with
|
||||||
|
those enforcing the Code of Conduct, for a specified period of time. This
|
||||||
|
includes avoiding interactions in community spaces as well as external channels
|
||||||
|
like social media. Violating these terms may lead to a temporary or permanent
|
||||||
|
ban.
|
||||||
|
|
||||||
|
### 3. Temporary Ban
|
||||||
|
|
||||||
|
**Community Impact**: A serious violation of community standards, including
|
||||||
|
sustained inappropriate behavior.
|
||||||
|
|
||||||
|
**Consequence**: A temporary ban from any sort of interaction or public
|
||||||
|
communication with the community for a specified period of time. No public or
|
||||||
|
private interaction with the people involved, including unsolicited interaction
|
||||||
|
with those enforcing the Code of Conduct, is allowed during this period.
|
||||||
|
Violating these terms may lead to a permanent ban.
|
||||||
|
|
||||||
|
### 4. Permanent Ban
|
||||||
|
|
||||||
|
**Community Impact**: Demonstrating a pattern of violation of community
|
||||||
|
standards, including sustained inappropriate behavior, harassment of an
|
||||||
|
individual, or aggression toward or disparagement of classes of individuals.
|
||||||
|
|
||||||
|
**Consequence**: A permanent ban from any sort of public interaction within
|
||||||
|
the community.
|
||||||
|
|
||||||
|
## Attribution
|
||||||
|
|
||||||
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||||
|
version 2.1, available at
|
||||||
|
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
||||||
|
|
||||||
|
Community Impact Guidelines were inspired by
|
||||||
|
[Mozilla's code of conduct enforcement ladder][mozilla coc].
|
||||||
|
|
||||||
|
[homepage]: https://www.contributor-covenant.org
|
||||||
|
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
||||||
|
[mozilla coc]: https://github.com/mozilla/diversity
|
||||||
+151
@@ -0,0 +1,151 @@
|
|||||||
|
# Contributing to ClipForge
|
||||||
|
|
||||||
|
Thank you for your interest in contributing to ClipForge! This document provides guidelines for contributing to the project.
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
- **Rust** (stable toolchain) - install via [rustup](https://rustup.rs/)
|
||||||
|
- **Node.js** (v22+) and **pnpm** (v11+) - install via [corepack](https://github.com/nodejs/corepack)
|
||||||
|
- **Windows** (Windows 10/11) - ClipForge is Windows-first
|
||||||
|
- **Visual Studio 2022** with C++ workload (for MSVC toolchain)
|
||||||
|
|
||||||
|
### Building from Source
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Clone the repository
|
||||||
|
git clone https://github.com/Alvin-Zilverstand/clipforge-game-clipper.git
|
||||||
|
cd clipforge-game-clipper
|
||||||
|
|
||||||
|
# Install frontend dependencies
|
||||||
|
pnpm install
|
||||||
|
|
||||||
|
# Build the frontend
|
||||||
|
pnpm run build
|
||||||
|
|
||||||
|
# Build the Tauri app (debug)
|
||||||
|
pnpm run tauri dev
|
||||||
|
|
||||||
|
# Build the Tauri app (release installers)
|
||||||
|
pnpm run desktop:build
|
||||||
|
```
|
||||||
|
|
||||||
|
Installers will be created in `src-tauri/target/release/bundle/`.
|
||||||
|
|
||||||
|
### Running Tests
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Run all Rust tests
|
||||||
|
cargo test
|
||||||
|
|
||||||
|
# Run only library tests
|
||||||
|
cargo test --lib
|
||||||
|
|
||||||
|
# Run specific test
|
||||||
|
cargo test test_name
|
||||||
|
```
|
||||||
|
|
||||||
|
## Development Workflow
|
||||||
|
|
||||||
|
### Branching Strategy
|
||||||
|
|
||||||
|
- `master` - Protected branch, only updated via PR merges
|
||||||
|
- Feature branches: `feat/description` or `feature/description`
|
||||||
|
- Bug fix branches: `fix/description` or `bugfix/description`
|
||||||
|
- Documentation: `docs/description`
|
||||||
|
|
||||||
|
### Commit Messages
|
||||||
|
|
||||||
|
Follow [Conventional Commits](https://www.conventionalcommits.org/):
|
||||||
|
|
||||||
|
```
|
||||||
|
type(scope): short description
|
||||||
|
|
||||||
|
Longer description if needed.
|
||||||
|
|
||||||
|
Fixes #123
|
||||||
|
```
|
||||||
|
|
||||||
|
Types:
|
||||||
|
- `feat`: New feature
|
||||||
|
- `fix`: Bug fix
|
||||||
|
- `docs`: Documentation changes
|
||||||
|
- `style`: Code style (formatting, etc.)
|
||||||
|
- `refactor`: Code refactoring
|
||||||
|
- `test`: Adding/updating tests
|
||||||
|
- `chore`: Maintenance tasks
|
||||||
|
|
||||||
|
### Pull Request Process
|
||||||
|
|
||||||
|
1. Fork the repository
|
||||||
|
2. Create a feature branch from `master`
|
||||||
|
3. Make your changes with tests
|
||||||
|
4. Ensure all tests pass (`cargo test`)
|
||||||
|
5. Ensure code is formatted (`cargo fmt`)
|
||||||
|
6. Ensure clippy is clean (`cargo clippy`)
|
||||||
|
7. Open a PR against `master`
|
||||||
|
8. Wait for review and CI checks
|
||||||
|
|
||||||
|
### Code Style
|
||||||
|
|
||||||
|
- Rust: `cargo fmt` (standard rustfmt)
|
||||||
|
- TypeScript: `pnpm run lint` (ESLint + Prettier)
|
||||||
|
- Run `cargo clippy` before committing
|
||||||
|
|
||||||
|
## Architecture Overview
|
||||||
|
|
||||||
|
```
|
||||||
|
clipforge-game-clipper/
|
||||||
|
├── src/ # Rust library (core logic)
|
||||||
|
│ ├── capture.rs # FFmpeg capture backends
|
||||||
|
│ ├── native_wgc.rs # Windows Graphics Capture
|
||||||
|
│ ├── native_audio.rs # WASAPI audio capture
|
||||||
|
│ ├── recorder.rs # Replay buffer, auto-clipping
|
||||||
|
│ ├── integrations.rs # League/Valve GSI events
|
||||||
|
│ ├── library.rs # Clip library (SQLite)
|
||||||
|
│ ├── upload.rs # Upload providers
|
||||||
|
│ ├── settings.rs # Versioned settings
|
||||||
|
│ └── ...
|
||||||
|
├── src-tauri/ # Tauri desktop shell
|
||||||
|
│ └── src/main.rs # Tauri commands, app setup
|
||||||
|
├── ui/ # TypeScript/Vite frontend
|
||||||
|
│ └── src/main.ts # Single-page UI
|
||||||
|
└── scripts/ # Build scripts
|
||||||
|
```
|
||||||
|
|
||||||
|
## Adding Features
|
||||||
|
|
||||||
|
### New Capture Backend
|
||||||
|
|
||||||
|
1. Implement `CaptureBackend` trait in `src/capture.rs`
|
||||||
|
2. Add to `start_best_capture_backend` in `src-tauri/src/main.rs`
|
||||||
|
3. Add tests
|
||||||
|
|
||||||
|
### New Game Integration
|
||||||
|
|
||||||
|
1. Add game profile in `src/game_detection.rs`
|
||||||
|
2. Implement `GameIntegration` trait in `src/integrations.rs`
|
||||||
|
3. Add event normalization
|
||||||
|
4. Update `default_auto_clip_events_for_game` in `src-tauri/src/main.rs`
|
||||||
|
5. Add UI entries in `ui/src/main.ts`
|
||||||
|
|
||||||
|
### New Upload Provider
|
||||||
|
|
||||||
|
1. Implement `Uploader` trait in `src/upload.rs`
|
||||||
|
2. Add to `upload_clip_with_settings` in `src-tauri/src/main.rs`
|
||||||
|
3. Add UI in `ui/src/main.ts` (Uploads view)
|
||||||
|
|
||||||
|
## Reporting Issues
|
||||||
|
|
||||||
|
Use the GitHub issue templates:
|
||||||
|
- [Bug Report](.github/ISSUE_TEMPLATE/bug_report.md)
|
||||||
|
- [Feature Request](.github/ISSUE_TEMPLATE/feature_request.md)
|
||||||
|
|
||||||
|
## Security
|
||||||
|
|
||||||
|
See [SECURITY.md](SECURITY.md) for reporting security vulnerabilities.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
By contributing, you agree that your contributions will be licensed under the [MIT License](LICENSE).
|
||||||
Generated
+150
-16
@@ -87,6 +87,7 @@ dependencies = [
|
|||||||
name = "clipforge"
|
name = "clipforge"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"dirs",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -136,6 +137,27 @@ version = "0.8.23"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
|
checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dirs"
|
||||||
|
version = "5.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
|
||||||
|
dependencies = [
|
||||||
|
"dirs-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dirs-sys"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"option-ext",
|
||||||
|
"redox_users",
|
||||||
|
"windows-sys 0.48.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "displaydoc"
|
name = "displaydoc"
|
||||||
version = "0.2.7"
|
version = "0.2.7"
|
||||||
@@ -505,6 +527,15 @@ version = "0.2.189"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
|
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libredox"
|
||||||
|
version = "0.1.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6480ccc157a1389bb2e4891b24751b0f798ba640d22386f23143fbcc89da195a"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libsqlite3-sys"
|
name = "libsqlite3-sys"
|
||||||
version = "0.30.1"
|
version = "0.30.1"
|
||||||
@@ -609,6 +640,12 @@ version = "1.21.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "option-ext"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking_lot"
|
name = "parking_lot"
|
||||||
version = "0.12.5"
|
version = "0.12.5"
|
||||||
@@ -682,7 +719,7 @@ dependencies = [
|
|||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"rustls",
|
"rustls",
|
||||||
"socket2",
|
"socket2",
|
||||||
"thiserror",
|
"thiserror 2.0.20",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"web-time",
|
"web-time",
|
||||||
@@ -704,7 +741,7 @@ dependencies = [
|
|||||||
"rustls",
|
"rustls",
|
||||||
"rustls-pki-types",
|
"rustls-pki-types",
|
||||||
"slab",
|
"slab",
|
||||||
"thiserror",
|
"thiserror 2.0.20",
|
||||||
"tinyvec",
|
"tinyvec",
|
||||||
"tracing",
|
"tracing",
|
||||||
"web-time",
|
"web-time",
|
||||||
@@ -794,6 +831,17 @@ dependencies = [
|
|||||||
"bitflags",
|
"bitflags",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "redox_users"
|
||||||
|
version = "0.4.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom 0.2.17",
|
||||||
|
"libredox",
|
||||||
|
"thiserror 1.0.69",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "reqwest"
|
name = "reqwest"
|
||||||
version = "0.12.28"
|
version = "0.12.28"
|
||||||
@@ -1073,13 +1121,33 @@ dependencies = [
|
|||||||
"windows 0.57.0",
|
"windows 0.57.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "1.0.69"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl 1.0.69",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "2.0.20"
|
version = "2.0.20"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f"
|
checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"thiserror-impl",
|
"thiserror-impl 2.0.20",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "1.0.69"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.119",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1277,7 +1345,7 @@ checksum = "ee144c215d8d31e94c1a599fbaf540ca82a7017e4f1786816b179f334fac751d"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"num-integer",
|
"num-integer",
|
||||||
"thiserror",
|
"thiserror 2.0.20",
|
||||||
"windows 0.62.2",
|
"windows 0.62.2",
|
||||||
"windows-core 0.62.2",
|
"windows-core 0.62.2",
|
||||||
]
|
]
|
||||||
@@ -1401,7 +1469,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143"
|
checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-core 0.57.0",
|
"windows-core 0.57.0",
|
||||||
"windows-targets",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1424,7 +1492,7 @@ checksum = "09046acbe9b6d039cde50e8c8178d95bb0f9b33ed7feccc4465dadc5404b31b4"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"rayon",
|
"rayon",
|
||||||
"thiserror",
|
"thiserror 2.0.20",
|
||||||
"windows 0.62.2",
|
"windows 0.62.2",
|
||||||
"windows-future",
|
"windows-future",
|
||||||
]
|
]
|
||||||
@@ -1447,7 +1515,7 @@ dependencies = [
|
|||||||
"windows-implement 0.57.0",
|
"windows-implement 0.57.0",
|
||||||
"windows-interface 0.57.0",
|
"windows-interface 0.57.0",
|
||||||
"windows-result 0.1.2",
|
"windows-result 0.1.2",
|
||||||
"windows-targets",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1540,7 +1608,7 @@ version = "0.1.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8"
|
checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-targets",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1561,13 +1629,22 @@ dependencies = [
|
|||||||
"windows-link",
|
"windows-link",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.48.5",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.52.0"
|
version = "0.52.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-targets",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1579,20 +1656,35 @@ dependencies = [
|
|||||||
"windows-link",
|
"windows-link",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-targets"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_gnullvm 0.48.5",
|
||||||
|
"windows_aarch64_msvc 0.48.5",
|
||||||
|
"windows_i686_gnu 0.48.5",
|
||||||
|
"windows_i686_msvc 0.48.5",
|
||||||
|
"windows_x86_64_gnu 0.48.5",
|
||||||
|
"windows_x86_64_gnullvm 0.48.5",
|
||||||
|
"windows_x86_64_msvc 0.48.5",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-targets"
|
name = "windows-targets"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows_aarch64_gnullvm",
|
"windows_aarch64_gnullvm 0.52.6",
|
||||||
"windows_aarch64_msvc",
|
"windows_aarch64_msvc 0.52.6",
|
||||||
"windows_i686_gnu",
|
"windows_i686_gnu 0.52.6",
|
||||||
"windows_i686_gnullvm",
|
"windows_i686_gnullvm",
|
||||||
"windows_i686_msvc",
|
"windows_i686_msvc 0.52.6",
|
||||||
"windows_x86_64_gnu",
|
"windows_x86_64_gnu 0.52.6",
|
||||||
"windows_x86_64_gnullvm",
|
"windows_x86_64_gnullvm 0.52.6",
|
||||||
"windows_x86_64_msvc",
|
"windows_x86_64_msvc 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1604,18 +1696,36 @@ dependencies = [
|
|||||||
"windows-link",
|
"windows-link",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_gnullvm"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_aarch64_gnullvm"
|
name = "windows_aarch64_gnullvm"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_aarch64_msvc"
|
name = "windows_aarch64_msvc"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_gnu"
|
name = "windows_i686_gnu"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
@@ -1628,24 +1738,48 @@ version = "0.52.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_msvc"
|
name = "windows_i686_msvc"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_gnu"
|
name = "windows_x86_64_gnu"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnullvm"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_gnullvm"
|
name = "windows_x86_64_gnullvm"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_msvc"
|
name = "windows_x86_64_msvc"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ reqwest = { version = "0.12", default-features = false, features = ["blocking",
|
|||||||
rusqlite = { version = "0.32", features = ["bundled"] }
|
rusqlite = { version = "0.32", features = ["bundled"] }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
dirs = "5"
|
||||||
sysinfo = "0.31"
|
sysinfo = "0.31"
|
||||||
wasapi = "0.24.0"
|
wasapi = "0.24.0"
|
||||||
windows-capture = "2.0.1"
|
windows-capture = "2.0.1"
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 ClipForge Contributors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
+66
@@ -0,0 +1,66 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
We release security updates for the following versions:
|
||||||
|
|
||||||
|
| Version | Supported |
|
||||||
|
| ------- | ------------------ |
|
||||||
|
| 0.1.x | :white_check_mark: |
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
**Please do not report security vulnerabilities through public GitHub issues.**
|
||||||
|
|
||||||
|
Instead, please report them via email to: **alvin@alvnx.xyz**
|
||||||
|
|
||||||
|
You should receive a response within 48 hours. If for some reason you do not, please follow up via email to ensure we received your original message.
|
||||||
|
|
||||||
|
Please include the following information:
|
||||||
|
- Type of issue (e.g., buffer overflow, injection, information disclosure)
|
||||||
|
- Full paths of source file(s) related to the vulnerability
|
||||||
|
- Steps to reproduce the issue
|
||||||
|
- Proof-of-concept or exploit code (if possible)
|
||||||
|
- Impact of the vulnerability
|
||||||
|
|
||||||
|
## Disclosure Policy
|
||||||
|
|
||||||
|
- We will acknowledge receipt of your vulnerability report within 48 hours
|
||||||
|
- We will provide a timeline for a fix within 5 business days
|
||||||
|
- We will keep you informed of progress
|
||||||
|
- We will credit you in the release notes (unless you prefer anonymity)
|
||||||
|
- We will not take legal action against you for good-faith security research
|
||||||
|
|
||||||
|
## Security Considerations
|
||||||
|
|
||||||
|
ClipForge is a local-first application with the following security characteristics:
|
||||||
|
|
||||||
|
### Data Handling
|
||||||
|
- All clips and metadata stored locally (SQLite + filesystem)
|
||||||
|
- No telemetry or analytics
|
||||||
|
- No account system or cloud sync
|
||||||
|
- Upload is explicitly user-initiated (or via opt-in auto-upload)
|
||||||
|
|
||||||
|
### Network
|
||||||
|
- League Live Client Data: HTTPS to localhost (127.0.0.1:2999) with cert verification disabled (Riot's self-signed cert)
|
||||||
|
- Valve GSI: HTTP receiver on 127.0.0.1:49321 (local only)
|
||||||
|
- Upload providers: HTTPS to Catbox/Litterbox/custom endpoints
|
||||||
|
- No outbound connections except explicit uploads
|
||||||
|
|
||||||
|
### Permissions
|
||||||
|
- Requires Windows screen capture permission (Windows Graphics Capture)
|
||||||
|
- Requires microphone permission (if enabled)
|
||||||
|
- Runs as standard user (not elevated)
|
||||||
|
|
||||||
|
### Known Attack Surface
|
||||||
|
1. **GSI HTTP Receiver** - Local-only, but could be accessed by other local processes
|
||||||
|
2. **FFmpeg subprocess** - User-controlled arguments sanitized, but FFmpeg itself is a large attack surface
|
||||||
|
3. **SQLite database** - Local file, no network exposure
|
||||||
|
4. **Tauri IPC** - Commands validated server-side
|
||||||
|
|
||||||
|
## Security Best Practices for Users
|
||||||
|
|
||||||
|
- Keep ClipForge updated
|
||||||
|
- Only enable auto-upload to trusted providers
|
||||||
|
- Review custom upload endpoints before use
|
||||||
|
- Run on supported Windows versions with latest patches
|
||||||
@@ -36,30 +36,40 @@
|
|||||||
- The UI Upload button uses the selected upload provider and saved provider configuration, including Catbox userhash, Litterbox expiry, custom endpoint, response path, and custom headers.
|
- The UI Upload button uses the selected upload provider and saved provider configuration, including Catbox userhash, Litterbox expiry, custom endpoint, response path, and custom headers.
|
||||||
- Auto-upload is persisted and, when enabled, attempts upload after manual and event clips while preserving local clips on failure.
|
- Auto-upload is persisted and, when enabled, attempts upload after manual and event clips while preserving local clips on failure.
|
||||||
- Upload attempts are recorded in SQLite upload history.
|
- Upload attempts are recorded in SQLite upload history.
|
||||||
|
- The Uploads screen shows recent upload history with retry buttons for failed uploads, refreshed from the backend on load and after uploads.
|
||||||
|
- Screenshot capture is implemented: F9 takes a PNG screenshot via bundled FFmpeg into `~/Pictures/ClipForge`, the recording bar has a Screenshot button, and the Library shows recent screenshots with an Open-in-Explorer action.
|
||||||
|
- Storage guardrails are wired: recording refuses to start below 2 GB free and a backend worker stops an active recording and flags `StorageLow` when available disk drops to critical; the recording bar shows free disk space and a low-disk warning.
|
||||||
|
- Panic reporting writes crash reports with stack traces to the logs folder (`library/logs`), prunes old entries, and the Settings screen can open the logs folder.
|
||||||
|
- Native Windows Graphics Capture now downscales the captured window/monitor to the configured resolution cap (e.g. 720p) with even dimensions while preserving aspect ratio; covered by unit tests.
|
||||||
|
- Capture quality and storage settings are exposed: the Settings screen can change resolution, FPS, bitrate, buffer storage cap, excluded window titles, and the separate-audio-tracks toggle via the `set_capture_settings` command, and current values are shown in DesktopStatus.
|
||||||
|
- Per-game capture quality overrides can be set from the Recording screen per detected game title, saved in settings, and applied automatically by the recorder when that game is active.
|
||||||
|
- The configured storage cap is enforced by a backend worker that prunes the oldest rolling buffer segments once the buffer exceeds `storage_limit_gb`.
|
||||||
|
- SQLite schema uses versioned migrations tracked via `PRAGMA user_version`; legacy databases (missing tables or the `title` column) are repaired and upgraded in place, with migration tests.
|
||||||
|
- Valve GSI event mapping enriches CS2 round, bomb, and match-start events with round number, map scores, and plant-region metadata; Dota 2 game-state transitions map to match-start bookmarks and match-end events carrying final radiant/dire scores. These events are unit tested against realistic JSON payloads.
|
||||||
|
- A GitHub Actions release workflow (`.github/workflows/release.yml`) builds MSI and NSIS installers on tag push or manual dispatch and publishes them to a GitHub Release, ready for the auto-updater to pick up.
|
||||||
|
- Auto-update checks the GitHub repo releases (`Alvin-Zilverstand/clipforge-game-clipper`) for the latest MSI/NSIS installer, compares it against the running version, downloads it to temp, launches the installer, and exits the app to finish; version comparison, asset selection, and parsing are unit tested plus one ignored live test against the GitHub API.
|
||||||
|
- A GitHub Actions release workflow publishes MSI/NSIS assets on tag push; auto-update will pick up newer releases automatically once the repo ships a tag newer than the running app version.
|
||||||
|
- The Settings screen shows the current version, checks for updates, and offers a Download & install button when a newer release exists.
|
||||||
|
- First-run onboarding wizard walks new installs through privacy/audio, capture-source, storage, and hotkey setup before showing the main app; it uses the defaults already saved in `settings.json` so existing users are unaffected.
|
||||||
|
- The default clip library root is `~/Documents/ClipForge` (rather than the process working directory), and a first-run migration moves any legacy `clipforge-library` folder found in the CWD into the new location while rewriting stored clip paths in the SQLite database.
|
||||||
|
- Capture capabilities (bundled FFmpeg discovery, WASAPI/ddagrab support) are detected once at startup and cached, so background workers (`refresh_detected_game` every 2s, UI status poll every 3s) never spawn FFmpeg; all FFmpeg/console subprocesses are launched with a hidden console window on Windows, preventing the app from freezing and flashing a terminal repeatedly.
|
||||||
- Vite TypeScript UI builds and has interactive Library, Recording, Auto Clip, Uploads, and Settings views.
|
- Vite TypeScript UI builds and has interactive Library, Recording, Auto Clip, Uploads, and Settings views.
|
||||||
- Library search, event/upload filters, and grid/list switching are functional in the UI.
|
- Library search, event/upload filters, and grid/list switching are functional in the UI.
|
||||||
- User-visible notices are shown for major actions and failures instead of relying only on console output.
|
- User-visible notices are shown for major actions and failures instead of relying only on console output.
|
||||||
|
|
||||||
## Not Fully Working Yet
|
## Not Fully Working Yet
|
||||||
|
|
||||||
- Native Windows Graphics Capture is wired for rolling replay capture with native audio; resolution downscaling still needs more work.
|
- Native Windows Graphics Capture and FFmpeg capture finalization have not yet been manually QA-tested on real NVIDIA/AMD/Intel gaming systems.
|
||||||
- Native WASAPI audio is mixed into a single AAC track for MVP clips; separate audio tracks and per-process audio capture are still future work.
|
- Native WASAPI audio is mixed into a single AAC track for MVP clips; separate audio tracks are now honored by the FFmpeg recording backend (routing around the single-track native WGC encoder), while per-process audio capture remains future work.
|
||||||
- Capture has not yet been manually QA-tested on real NVIDIA/AMD/Intel gaming systems.
|
- Valve GSI receiver is a lightweight MVP receiver; config templates can be generated from the Auto Clip screen. CS2 round/bomb/match-start and Dota 2 match-start/match-end transitions are mapped, but per-player kill/death/objective event detection for Dota 2 and other Source titles is still needed.
|
||||||
- Upload retry controls and a visible upload-history screen are not complete yet.
|
|
||||||
- Valve GSI receiver is a lightweight MVP receiver; config templates can be generated from the Auto Clip screen, but richer event mapping per game is still needed.
|
|
||||||
- Auto start/stop is conservative but live: when auto-record is enabled, supported detected games can start recording and stop when the game disappears.
|
- Auto start/stop is conservative but live: when auto-record is enabled, supported detected games can start recording and stop when the game disappears.
|
||||||
- Trim still uses timestamp text inputs instead of draggable timeline handles.
|
|
||||||
- Hotkeys are still hardcoded; editable hotkey registration is future work.
|
|
||||||
- Screenshot capture is still not implemented.
|
|
||||||
- Capture source, quality, storage cap, excluded windows, and per-game override UI are still incomplete.
|
|
||||||
- Storage critical-low-disk guardrails are not fully wired into recording start/stop behavior.
|
|
||||||
- Recorder service still runs inside the Tauri process instead of a separate background service process.
|
- Recorder service still runs inside the Tauri process instead of a separate background service process.
|
||||||
- Installer onboarding, auto-update, and crash logging are still not implemented.
|
- Auto-update requires a GitHub release whose tag is newer than the running app version and that ships MSI/NSIS assets (the existing `v0.0.1` release carries 0.1.0 assets, so it correctly reports up to date).
|
||||||
|
|
||||||
## Next Engineering Steps
|
## Next Engineering Steps
|
||||||
|
|
||||||
1. Extend native Windows Graphics Capture with resolution downscaling and richer capture-source selection.
|
1. Add per-process loopback capture so individual application audio can be captured independently of the system mix.
|
||||||
2. Add separate audio tracks and optional per-process loopback capture.
|
2. Add per-player kill/death/objective event detection for Dota 2 and other Source titles beyond the current match-level transitions.
|
||||||
3. Expand CS2/Dota GSI event mapping beyond the current MVP event parser.
|
3. Exercise the GitHub Actions release workflow with a real tag push and verify the published assets appear in a GitHub Release.
|
||||||
4. Add installer/onboarding screens for privacy, capture source, storage, and hotkeys.
|
4. Split the recorder service into a separate background process so capture survives app restarts.
|
||||||
5. Run manual QA on Windows gaming hardware and tune CPU/GPU overhead.
|
5. Run manual QA on Windows gaming hardware and tune CPU/GPU overhead.
|
||||||
Generated
+105
-6
@@ -360,6 +360,7 @@ dependencies = [
|
|||||||
name = "clipforge"
|
name = "clipforge"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"dirs 5.0.1",
|
||||||
"reqwest 0.12.28",
|
"reqwest 0.12.28",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -666,13 +667,34 @@ dependencies = [
|
|||||||
"crypto-common",
|
"crypto-common",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dirs"
|
||||||
|
version = "5.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
|
||||||
|
dependencies = [
|
||||||
|
"dirs-sys 0.4.1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dirs"
|
name = "dirs"
|
||||||
version = "6.0.0"
|
version = "6.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
|
checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dirs-sys",
|
"dirs-sys 0.5.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dirs-sys"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"option-ext",
|
||||||
|
"redox_users 0.4.6",
|
||||||
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -683,7 +705,7 @@ checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"option-ext",
|
"option-ext",
|
||||||
"redox_users",
|
"redox_users 0.5.2",
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -2749,6 +2771,17 @@ dependencies = [
|
|||||||
"bitflags 2.13.1",
|
"bitflags 2.13.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "redox_users"
|
||||||
|
version = "0.4.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom 0.2.17",
|
||||||
|
"libredox",
|
||||||
|
"thiserror 1.0.69",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_users"
|
name = "redox_users"
|
||||||
version = "0.5.2"
|
version = "0.5.2"
|
||||||
@@ -3550,7 +3583,7 @@ dependencies = [
|
|||||||
"anyhow",
|
"anyhow",
|
||||||
"bytes",
|
"bytes",
|
||||||
"cookie",
|
"cookie",
|
||||||
"dirs",
|
"dirs 6.0.0",
|
||||||
"dunce",
|
"dunce",
|
||||||
"embed_plist",
|
"embed_plist",
|
||||||
"getrandom 0.3.4",
|
"getrandom 0.3.4",
|
||||||
@@ -3600,7 +3633,7 @@ checksum = "bc9ce40b16101cb6ea63d3e221567affd1c3a9205f95d7bc574941a10636b632"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cargo_toml",
|
"cargo_toml",
|
||||||
"dirs",
|
"dirs 6.0.0",
|
||||||
"glob",
|
"glob",
|
||||||
"heck 0.5.0",
|
"heck 0.5.0",
|
||||||
"json-patch",
|
"json-patch",
|
||||||
@@ -4117,7 +4150,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "045979e3f037cd18ad1cb2a419dfda133c5c29c9f3453370079f2255d46c257e"
|
checksum = "045979e3f037cd18ad1cb2a419dfda133c5c29c9f3453370079f2255d46c257e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"dirs",
|
"dirs 6.0.0",
|
||||||
"libappindicator",
|
"libappindicator",
|
||||||
"muda",
|
"muda",
|
||||||
"objc2",
|
"objc2",
|
||||||
@@ -4834,6 +4867,15 @@ dependencies = [
|
|||||||
"windows-targets 0.42.2",
|
"windows-targets 0.42.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.48.5",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.52.0"
|
version = "0.52.0"
|
||||||
@@ -4876,6 +4918,21 @@ dependencies = [
|
|||||||
"windows_x86_64_msvc 0.42.2",
|
"windows_x86_64_msvc 0.42.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-targets"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_gnullvm 0.48.5",
|
||||||
|
"windows_aarch64_msvc 0.48.5",
|
||||||
|
"windows_i686_gnu 0.48.5",
|
||||||
|
"windows_i686_msvc 0.48.5",
|
||||||
|
"windows_x86_64_gnu 0.48.5",
|
||||||
|
"windows_x86_64_gnullvm 0.48.5",
|
||||||
|
"windows_x86_64_msvc 0.48.5",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-targets"
|
name = "windows-targets"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
@@ -4925,6 +4982,12 @@ version = "0.42.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
|
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_gnullvm"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_aarch64_gnullvm"
|
name = "windows_aarch64_gnullvm"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
@@ -4937,6 +5000,12 @@ version = "0.42.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
|
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_aarch64_msvc"
|
name = "windows_aarch64_msvc"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
@@ -4949,6 +5018,12 @@ version = "0.42.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
|
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_gnu"
|
name = "windows_i686_gnu"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
@@ -4967,6 +5042,12 @@ version = "0.42.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
|
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_msvc"
|
name = "windows_i686_msvc"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
@@ -4979,6 +5060,12 @@ version = "0.42.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
|
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_gnu"
|
name = "windows_x86_64_gnu"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
@@ -4991,6 +5078,12 @@ version = "0.42.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
|
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnullvm"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_gnullvm"
|
name = "windows_x86_64_gnullvm"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
@@ -5003,6 +5096,12 @@ version = "0.42.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
|
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_msvc"
|
name = "windows_x86_64_msvc"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
@@ -5065,7 +5164,7 @@ dependencies = [
|
|||||||
"block2",
|
"block2",
|
||||||
"cookie",
|
"cookie",
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"dirs",
|
"dirs 6.0.0",
|
||||||
"dom_query",
|
"dom_query",
|
||||||
"dpi",
|
"dpi",
|
||||||
"dunce",
|
"dunce",
|
||||||
|
|||||||
+533
-53
@@ -1,6 +1,9 @@
|
|||||||
|
// Hide console window on Windows (GUI app)
|
||||||
|
#![cfg_attr(target_os = "windows", windows_subsystem = "windows")]
|
||||||
|
|
||||||
use clipforge::audio::{list_ffmpeg_dshow_audio_inputs, AudioDeviceKind};
|
use clipforge::audio::{list_ffmpeg_dshow_audio_inputs, AudioDeviceKind};
|
||||||
use clipforge::capture::{
|
use clipforge::capture::{
|
||||||
ffmpeg_is_available, ffmpeg_supports_filter, ffmpeg_supports_input_device,
|
ffmpeg_supports_filter, ffmpeg_supports_input_device,
|
||||||
find_ffmpeg_executable, CaptureBackend, CaptureConfig, CaptureMethod, CaptureSource,
|
find_ffmpeg_executable, CaptureBackend, CaptureConfig, CaptureMethod, CaptureSource,
|
||||||
EncoderPreference, FfmpegReplayCaptureBackend,
|
EncoderPreference, FfmpegReplayCaptureBackend,
|
||||||
};
|
};
|
||||||
@@ -22,14 +25,15 @@ use clipforge::native_audio::{
|
|||||||
NativeAudioSource,
|
NativeAudioSource,
|
||||||
};
|
};
|
||||||
use clipforge::native_wgc::NativeWgcReplayCaptureBackend;
|
use clipforge::native_wgc::NativeWgcReplayCaptureBackend;
|
||||||
|
use clipforge::proc::hidden_command;
|
||||||
use clipforge::recorder::{RecorderAction, RecorderService};
|
use clipforge::recorder::{RecorderAction, RecorderService};
|
||||||
use clipforge::settings::{load_or_create_settings, save_settings, AppSettings};
|
use clipforge::settings::{load_or_create_settings, save_settings, AppSettings};
|
||||||
use clipforge::storage::{clip_path, is_inside_root, LibraryPaths};
|
use clipforge::storage::{clip_path, is_inside_root, resolve_library_root, LibraryPaths};
|
||||||
|
use clipforge::updater::{self, UpdateCheck};
|
||||||
use clipforge::upload::{
|
use clipforge::upload::{
|
||||||
CatboxUploader, CustomHttpUploader, LitterboxUploader, UploadMetadata, UploadResult, Uploader,
|
CatboxUploader, CustomHttpUploader, LitterboxUploader, UploadMetadata, UploadResult, Uploader,
|
||||||
};
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::env;
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::net::TcpListener;
|
use std::net::TcpListener;
|
||||||
@@ -49,12 +53,37 @@ struct AppRuntime {
|
|||||||
valve_events: Mutex<Vec<RawGameEvent>>,
|
valve_events: Mutex<Vec<RawGameEvent>>,
|
||||||
hotkey_shortcuts: Mutex<Option<HotkeyShortcuts>>,
|
hotkey_shortcuts: Mutex<Option<HotkeyShortcuts>>,
|
||||||
app_handle: Mutex<Option<tauri::AppHandle>>,
|
app_handle: Mutex<Option<tauri::AppHandle>>,
|
||||||
|
capture_capabilities: CaptureCapabilities,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct CaptureCapabilities {
|
||||||
|
ffmpeg_path: Option<PathBuf>,
|
||||||
|
system_audio_available: bool,
|
||||||
|
desktop_duplication_available: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn detect_capture_capabilities() -> CaptureCapabilities {
|
||||||
|
let ffmpeg_path = find_ffmpeg_executable();
|
||||||
|
let (system_audio_available, desktop_duplication_available) = match &ffmpeg_path {
|
||||||
|
Some(path) => (
|
||||||
|
native_system_loopback_available() || ffmpeg_supports_input_device(path, "wasapi"),
|
||||||
|
ffmpeg_supports_filter(path, "ddagrab"),
|
||||||
|
),
|
||||||
|
None => (native_system_loopback_available(), false),
|
||||||
|
};
|
||||||
|
CaptureCapabilities {
|
||||||
|
ffmpeg_path,
|
||||||
|
system_audio_available,
|
||||||
|
desktop_duplication_available,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct HotkeyShortcuts {
|
struct HotkeyShortcuts {
|
||||||
clip_60: tauri_plugin_global_shortcut::Shortcut,
|
clip_60: tauri_plugin_global_shortcut::Shortcut,
|
||||||
clip_30: tauri_plugin_global_shortcut::Shortcut,
|
clip_30: tauri_plugin_global_shortcut::Shortcut,
|
||||||
toggle_recording: tauri_plugin_global_shortcut::Shortcut,
|
toggle_recording: tauri_plugin_global_shortcut::Shortcut,
|
||||||
|
screenshot: tauri_plugin_global_shortcut::Shortcut,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ActiveCapture {
|
struct ActiveCapture {
|
||||||
@@ -117,6 +146,27 @@ struct DesktopStatus {
|
|||||||
hotkey_clip_last_30s: String,
|
hotkey_clip_last_30s: String,
|
||||||
hotkey_toggle_session_recording: String,
|
hotkey_toggle_session_recording: String,
|
||||||
hotkey_screenshot: String,
|
hotkey_screenshot: String,
|
||||||
|
free_disk_gb: f64,
|
||||||
|
capture_fps: u32,
|
||||||
|
capture_bitrate_kbps: u32,
|
||||||
|
capture_resolution: String,
|
||||||
|
storage_limit_gb: u64,
|
||||||
|
excluded_window_titles: Vec<String>,
|
||||||
|
separate_audio_tracks: bool,
|
||||||
|
game_quality_overrides: Vec<GameQualityOverrideDto>,
|
||||||
|
effective_quality_applied: bool,
|
||||||
|
app_version: String,
|
||||||
|
onboarding_complete: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
struct GameQualityOverrideDto {
|
||||||
|
game_id: String,
|
||||||
|
name: String,
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
fps: u32,
|
||||||
|
bitrate_kbps: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
@@ -135,6 +185,17 @@ struct ClipDto {
|
|||||||
color_class: String,
|
color_class: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
struct UploadHistoryDto {
|
||||||
|
id: i64,
|
||||||
|
clip_id: String,
|
||||||
|
provider: String,
|
||||||
|
status: String,
|
||||||
|
url: Option<String>,
|
||||||
|
error: Option<String>,
|
||||||
|
attempted_at: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
struct GsiConfigDto {
|
struct GsiConfigDto {
|
||||||
game_id: String,
|
game_id: String,
|
||||||
@@ -158,7 +219,7 @@ struct AutoClipEventDto {
|
|||||||
fn get_status(runtime: State<'_, AppRuntime>) -> Result<DesktopStatus, String> {
|
fn get_status(runtime: State<'_, AppRuntime>) -> Result<DesktopStatus, String> {
|
||||||
let recorder = runtime.recorder.lock().map_err(|error| error.to_string())?;
|
let recorder = runtime.recorder.lock().map_err(|error| error.to_string())?;
|
||||||
let capture = runtime.capture.lock().map_err(|error| error.to_string())?;
|
let capture = runtime.capture.lock().map_err(|error| error.to_string())?;
|
||||||
Ok(status_from_recorder(&recorder, capture.as_ref()))
|
Ok(status_from_recorder(&recorder, capture.as_ref(), &runtime.capture_capabilities))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -197,7 +258,7 @@ fn refresh_detected_game_inner(runtime: &AppRuntime) -> Result<DesktopStatus, St
|
|||||||
|
|
||||||
if !should_auto_start {
|
if !should_auto_start {
|
||||||
if !should_auto_stop {
|
if !should_auto_stop {
|
||||||
return Ok(status_from_recorder(&recorder, capture.as_ref()));
|
return Ok(status_from_recorder(&recorder, capture.as_ref(), &runtime.capture_capabilities));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -223,7 +284,7 @@ fn set_replay_buffer(seconds: u64, runtime: State<'_, AppRuntime>) -> Result<Des
|
|||||||
recorder.settings.clamp_replay_buffer();
|
recorder.settings.clamp_replay_buffer();
|
||||||
save_settings(&runtime.library_root, &recorder.settings)
|
save_settings(&runtime.library_root, &recorder.settings)
|
||||||
.map_err(|error| format!("Could not save settings: {error}"))?;
|
.map_err(|error| format!("Could not save settings: {error}"))?;
|
||||||
Ok(status_from_recorder(&recorder, capture.as_ref()))
|
Ok(status_from_recorder(&recorder, capture.as_ref(), &runtime.capture_capabilities))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -233,7 +294,7 @@ fn set_mic_enabled(enabled: bool, runtime: State<'_, AppRuntime>) -> Result<Desk
|
|||||||
recorder.settings.privacy.mic_enabled = enabled;
|
recorder.settings.privacy.mic_enabled = enabled;
|
||||||
save_settings(&runtime.library_root, &recorder.settings)
|
save_settings(&runtime.library_root, &recorder.settings)
|
||||||
.map_err(|error| format!("Could not save settings: {error}"))?;
|
.map_err(|error| format!("Could not save settings: {error}"))?;
|
||||||
Ok(status_from_recorder(&recorder, capture.as_ref()))
|
Ok(status_from_recorder(&recorder, capture.as_ref(), &runtime.capture_capabilities))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -246,7 +307,7 @@ fn set_system_audio_enabled(
|
|||||||
recorder.settings.privacy.system_audio_enabled = enabled;
|
recorder.settings.privacy.system_audio_enabled = enabled;
|
||||||
save_settings(&runtime.library_root, &recorder.settings)
|
save_settings(&runtime.library_root, &recorder.settings)
|
||||||
.map_err(|error| format!("Could not save settings: {error}"))?;
|
.map_err(|error| format!("Could not save settings: {error}"))?;
|
||||||
Ok(status_from_recorder(&recorder, capture.as_ref()))
|
Ok(status_from_recorder(&recorder, capture.as_ref(), &runtime.capture_capabilities))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -292,7 +353,7 @@ fn set_mic_device(
|
|||||||
recorder.settings.privacy.mic_device = device.filter(|value| !value.trim().is_empty());
|
recorder.settings.privacy.mic_device = device.filter(|value| !value.trim().is_empty());
|
||||||
save_settings(&runtime.library_root, &recorder.settings)
|
save_settings(&runtime.library_root, &recorder.settings)
|
||||||
.map_err(|error| format!("Could not save settings: {error}"))?;
|
.map_err(|error| format!("Could not save settings: {error}"))?;
|
||||||
Ok(status_from_recorder(&recorder, capture.as_ref()))
|
Ok(status_from_recorder(&recorder, capture.as_ref(), &runtime.capture_capabilities))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -305,7 +366,7 @@ fn set_auto_record_enabled(
|
|||||||
recorder.settings.privacy.desktop_capture_requires_confirmation = !enabled;
|
recorder.settings.privacy.desktop_capture_requires_confirmation = !enabled;
|
||||||
save_settings(&runtime.library_root, &recorder.settings)
|
save_settings(&runtime.library_root, &recorder.settings)
|
||||||
.map_err(|error| format!("Could not save settings: {error}"))?;
|
.map_err(|error| format!("Could not save settings: {error}"))?;
|
||||||
Ok(status_from_recorder(&recorder, capture.as_ref()))
|
Ok(status_from_recorder(&recorder, capture.as_ref(), &runtime.capture_capabilities))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -337,7 +398,7 @@ fn set_upload_settings(
|
|||||||
recorder.settings.upload.custom_headers = parse_header_lines(&custom_headers.join("\n"));
|
recorder.settings.upload.custom_headers = parse_header_lines(&custom_headers.join("\n"));
|
||||||
save_settings(&runtime.library_root, &recorder.settings)
|
save_settings(&runtime.library_root, &recorder.settings)
|
||||||
.map_err(|error| format!("Could not save upload settings: {error}"))?;
|
.map_err(|error| format!("Could not save upload settings: {error}"))?;
|
||||||
Ok(status_from_recorder(&recorder, capture.as_ref()))
|
Ok(status_from_recorder(&recorder, capture.as_ref(), &runtime.capture_capabilities))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -363,7 +424,75 @@ fn set_auto_clip_event_enabled(
|
|||||||
}
|
}
|
||||||
save_settings(&runtime.library_root, &recorder.settings)
|
save_settings(&runtime.library_root, &recorder.settings)
|
||||||
.map_err(|error| format!("Could not save auto-clip setting: {error}"))?;
|
.map_err(|error| format!("Could not save auto-clip setting: {error}"))?;
|
||||||
Ok(status_from_recorder(&recorder, capture.as_ref()))
|
Ok(status_from_recorder(&recorder, capture.as_ref(), &runtime.capture_capabilities))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn set_capture_settings(
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
fps: u32,
|
||||||
|
bitrate_kbps: u32,
|
||||||
|
storage_limit_gb: u64,
|
||||||
|
excluded_window_titles: Vec<String>,
|
||||||
|
separate_audio_tracks: bool,
|
||||||
|
runtime: State<'_, AppRuntime>,
|
||||||
|
) -> Result<DesktopStatus, String> {
|
||||||
|
let mut recorder = runtime.recorder.lock().map_err(|error| error.to_string())?;
|
||||||
|
let capture = runtime.capture.lock().map_err(|error| error.to_string())?;
|
||||||
|
recorder.settings.quality.width = even_between(width, 640, 7680);
|
||||||
|
recorder.settings.quality.height = even_between(height, 360, 4320);
|
||||||
|
recorder.settings.quality.fps = fps.clamp(15, 240);
|
||||||
|
recorder.settings.quality.bitrate_kbps = bitrate_kbps.clamp(500, 50_000);
|
||||||
|
recorder.settings.storage_limit_gb = storage_limit_gb.clamp(5, 5000);
|
||||||
|
recorder.settings.privacy.excluded_window_titles =
|
||||||
|
excluded_window_titles.iter().map(|title| title.trim().to_string()).filter(|title| !title.is_empty()).collect();
|
||||||
|
recorder.settings.privacy.separate_audio_tracks = separate_audio_tracks;
|
||||||
|
save_settings(&runtime.library_root, &recorder.settings)
|
||||||
|
.map_err(|error| format!("Could not save capture settings: {error}"))?;
|
||||||
|
Ok(status_from_recorder(&recorder, capture.as_ref(), &runtime.capture_capabilities))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn finish_onboarding(
|
||||||
|
system_audio_enabled: Option<bool>,
|
||||||
|
mic_enabled: Option<bool>,
|
||||||
|
separate_audio_tracks: Option<bool>,
|
||||||
|
auto_record_enabled: Option<bool>,
|
||||||
|
replay_buffer_seconds: Option<u64>,
|
||||||
|
storage_limit_gb: Option<u64>,
|
||||||
|
runtime: State<'_, AppRuntime>,
|
||||||
|
) -> Result<DesktopStatus, String> {
|
||||||
|
let mut recorder = runtime.recorder.lock().map_err(|error| error.to_string())?;
|
||||||
|
let capture = runtime.capture.lock().map_err(|error| error.to_string())?;
|
||||||
|
if let Some(enabled) = system_audio_enabled {
|
||||||
|
recorder.settings.privacy.system_audio_enabled = enabled;
|
||||||
|
}
|
||||||
|
if let Some(enabled) = mic_enabled {
|
||||||
|
recorder.settings.privacy.mic_enabled = enabled;
|
||||||
|
}
|
||||||
|
if let Some(enabled) = separate_audio_tracks {
|
||||||
|
recorder.settings.privacy.separate_audio_tracks = enabled;
|
||||||
|
}
|
||||||
|
if let Some(enabled) = auto_record_enabled {
|
||||||
|
recorder.settings.privacy.desktop_capture_requires_confirmation = !enabled;
|
||||||
|
}
|
||||||
|
if let Some(seconds) = replay_buffer_seconds {
|
||||||
|
recorder.settings.replay_buffer = Duration::from_secs(seconds);
|
||||||
|
recorder.settings.clamp_replay_buffer();
|
||||||
|
}
|
||||||
|
if let Some(gb) = storage_limit_gb {
|
||||||
|
recorder.settings.storage_limit_gb = gb.clamp(5, 5000);
|
||||||
|
}
|
||||||
|
recorder.settings.onboarding_complete = true;
|
||||||
|
save_settings(&runtime.library_root, &recorder.settings)
|
||||||
|
.map_err(|error| format!("Could not save onboarding settings: {error}"))?;
|
||||||
|
Ok(status_from_recorder(&recorder, capture.as_ref(), &runtime.capture_capabilities))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn even_between(value: u32, min: u32, max: u32) -> u32 {
|
||||||
|
let value = value.clamp(min, max);
|
||||||
|
value - (value % 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -582,7 +711,15 @@ fn start_capture_inner(runtime: &AppRuntime) -> Result<DesktopStatus, String> {
|
|||||||
let mut capture = runtime.capture.lock().map_err(|error| error.to_string())?;
|
let mut capture = runtime.capture.lock().map_err(|error| error.to_string())?;
|
||||||
|
|
||||||
if capture.is_some() {
|
if capture.is_some() {
|
||||||
return Ok(status_from_recorder(&recorder, capture.as_ref()));
|
return Ok(status_from_recorder(&recorder, capture.as_ref(), &runtime.capture_capabilities));
|
||||||
|
}
|
||||||
|
|
||||||
|
let storage = clipforge::storage::check_storage_space(&recorder.paths.buffer_root);
|
||||||
|
if let clipforge::storage::StorageLevel::Critical = storage.level {
|
||||||
|
return Err(format!(
|
||||||
|
"Recording blocked: only {:.1} GB of disk space remains. Free at least 2 GB before recording.",
|
||||||
|
storage.free_gb()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let ffmpeg = find_ffmpeg_executable()
|
let ffmpeg = find_ffmpeg_executable()
|
||||||
@@ -600,6 +737,11 @@ fn start_capture_inner(runtime: &AppRuntime) -> Result<DesktopStatus, String> {
|
|||||||
}
|
}
|
||||||
recorder.toggle_session_recording();
|
recorder.toggle_session_recording();
|
||||||
|
|
||||||
|
let game_id = recorder.state.detected_game_id.clone().unwrap_or_default();
|
||||||
|
let quality = recorder
|
||||||
|
.settings
|
||||||
|
.effective_quality_for(&game_id)
|
||||||
|
.clone();
|
||||||
let session_id = recorder
|
let session_id = recorder
|
||||||
.state
|
.state
|
||||||
.active_session_id
|
.active_session_id
|
||||||
@@ -635,10 +777,10 @@ fn start_capture_inner(runtime: &AppRuntime) -> Result<DesktopStatus, String> {
|
|||||||
let config = CaptureConfig {
|
let config = CaptureConfig {
|
||||||
source,
|
source,
|
||||||
method,
|
method,
|
||||||
width: recorder.settings.quality.width,
|
width: quality.width,
|
||||||
height: recorder.settings.quality.height,
|
height: quality.height,
|
||||||
fps: recorder.settings.quality.fps,
|
fps: quality.fps,
|
||||||
bitrate_kbps: recorder.settings.quality.bitrate_kbps,
|
bitrate_kbps: quality.bitrate_kbps,
|
||||||
encoder: EncoderPreference::HardwareH264,
|
encoder: EncoderPreference::HardwareH264,
|
||||||
system_audio_enabled,
|
system_audio_enabled,
|
||||||
mic_enabled: recorder.settings.privacy.mic_enabled,
|
mic_enabled: recorder.settings.privacy.mic_enabled,
|
||||||
@@ -663,7 +805,7 @@ fn start_capture_inner(runtime: &AppRuntime) -> Result<DesktopStatus, String> {
|
|||||||
backend,
|
backend,
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(status_from_recorder(&recorder, capture.as_ref()))
|
Ok(status_from_recorder(&recorder, capture.as_ref(), &runtime.capture_capabilities))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -706,7 +848,7 @@ fn stop_capture_inner(runtime: &AppRuntime) -> Result<DesktopStatus, String> {
|
|||||||
if matches!(recorder.state.status, RecordingStatus::RecordingSession) {
|
if matches!(recorder.state.status, RecordingStatus::RecordingSession) {
|
||||||
recorder.toggle_session_recording();
|
recorder.toggle_session_recording();
|
||||||
}
|
}
|
||||||
Ok(status_from_recorder(&recorder, capture.as_ref()))
|
Ok(status_from_recorder(&recorder, capture.as_ref(), &runtime.capture_capabilities))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -747,7 +889,7 @@ fn reveal_clip(clip_id: String, runtime: State<'_, AppRuntime>) -> Result<(), St
|
|||||||
return Err(format!("Clip file does not exist: {}", clip.path.display()));
|
return Err(format!("Clip file does not exist: {}", clip.path.display()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::new("explorer")
|
hidden_command("explorer")
|
||||||
.arg(format!("/select,{}", clip.path.display()))
|
.arg(format!("/select,{}", clip.path.display()))
|
||||||
.spawn()
|
.spawn()
|
||||||
.map_err(|error| error.to_string())?;
|
.map_err(|error| error.to_string())?;
|
||||||
@@ -898,6 +1040,29 @@ fn upload_clip(
|
|||||||
Ok(clip_to_dto(&clip))
|
Ok(clip_to_dto(&clip))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn list_upload_history(runtime: State<'_, AppRuntime>) -> Result<Vec<UploadHistoryDto>, String> {
|
||||||
|
let database = runtime.database.lock().map_err(|error| error.to_string())?;
|
||||||
|
Ok(database
|
||||||
|
.load_upload_history()
|
||||||
|
.map_err(|error| error.to_string())?
|
||||||
|
.into_iter()
|
||||||
|
.map(|entry| UploadHistoryDto {
|
||||||
|
id: entry.id,
|
||||||
|
clip_id: entry.clip_id,
|
||||||
|
provider: entry.provider,
|
||||||
|
status: entry.status,
|
||||||
|
url: entry.url,
|
||||||
|
error: entry.error,
|
||||||
|
attempted_at: format_upload_time(entry.attempted_at),
|
||||||
|
})
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn format_upload_time(time: SystemTime) -> String {
|
||||||
|
format_system_time(time)
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn update_clip_metadata(
|
fn update_clip_metadata(
|
||||||
clip_id: String,
|
clip_id: String,
|
||||||
@@ -957,6 +1122,132 @@ fn export_clip_copy(clip_id: String, runtime: State<'_, AppRuntime>) -> Result<S
|
|||||||
Ok(output.display().to_string())
|
Ok(output.display().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn take_screenshot(runtime: State<'_, AppRuntime>) -> Result<DesktopStatus, String> {
|
||||||
|
handle_screenshot()?;
|
||||||
|
let recorder = runtime.recorder.lock().map_err(|error| error.to_string())?;
|
||||||
|
let capture = runtime.capture.lock().map_err(|error| error.to_string())?;
|
||||||
|
Ok(status_from_recorder(&recorder, capture.as_ref(), &runtime.capture_capabilities))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn reveal_screenshot(path: String) -> Result<(), String> {
|
||||||
|
let path = PathBuf::from(&path);
|
||||||
|
if !path.exists() {
|
||||||
|
return Err(format!("Screenshot file does not exist: {}", path.display()));
|
||||||
|
}
|
||||||
|
hidden_command("explorer")
|
||||||
|
.arg(format!("/select,{}", path.display()))
|
||||||
|
.spawn()
|
||||||
|
.map_err(|error| error.to_string())?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn list_screenshots() -> Result<Vec<String>, String> {
|
||||||
|
Ok(clipforge::screenshot::list_screenshots()
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|path| path.to_str().map(|s| s.to_string()))
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn reveal_crash_logs(runtime: State<'_, AppRuntime>) -> Result<(), String> {
|
||||||
|
let logs_dir = runtime.library_root.join("logs");
|
||||||
|
fs::create_dir_all(&logs_dir).map_err(|error| error.to_string())?;
|
||||||
|
hidden_command("explorer")
|
||||||
|
.arg(logs_dir.display().to_string())
|
||||||
|
.spawn()
|
||||||
|
.map_err(|error| error.to_string())?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn list_crash_logs(runtime: State<'_, AppRuntime>) -> Result<Vec<String>, String> {
|
||||||
|
let logs_dir = runtime.library_root.join("logs");
|
||||||
|
let Ok(entries) = fs::read_dir(&logs_dir) else {
|
||||||
|
return Ok(Vec::new());
|
||||||
|
};
|
||||||
|
let mut files = entries
|
||||||
|
.filter_map(|entry| entry.ok())
|
||||||
|
.map(|entry| entry.path())
|
||||||
|
.filter(|path| {
|
||||||
|
path.file_name()
|
||||||
|
.and_then(|name| name.to_str())
|
||||||
|
.map(|name| name.starts_with("crash-"))
|
||||||
|
.unwrap_or(false)
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
files.sort();
|
||||||
|
Ok(files
|
||||||
|
.iter()
|
||||||
|
.rev()
|
||||||
|
.take(10)
|
||||||
|
.filter_map(|path| path.to_str().map(|s| s.to_string()))
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn check_for_updates() -> Result<UpdateCheck, String> {
|
||||||
|
let current_version = env!("CARGO_PKG_VERSION").to_string();
|
||||||
|
let repo = updater::DEFAULT_UPDATE_REPO.to_string();
|
||||||
|
let check = tauri::async_runtime::spawn_blocking(move || {
|
||||||
|
updater::check_for_updates(&repo, ¤t_version)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.map_err(|error| format!("Update check task failed: {error}"))?;
|
||||||
|
check.map_err(|error| error.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn download_and_apply_update(
|
||||||
|
app: tauri::AppHandle,
|
||||||
|
download_url: String,
|
||||||
|
installer_file: String,
|
||||||
|
) -> Result<String, String> {
|
||||||
|
let current_version = env!("CARGO_PKG_VERSION").to_string();
|
||||||
|
let installer_path = tauri::async_runtime::spawn_blocking(move || {
|
||||||
|
let updates_dir = std::env::temp_dir().join("clipforge-updates");
|
||||||
|
updater::download_installer(
|
||||||
|
&download_url,
|
||||||
|
&updates_dir,
|
||||||
|
&installer_file,
|
||||||
|
¤t_version,
|
||||||
|
)
|
||||||
|
.map_err(|error| error.to_string())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.map_err(|error| format!("Update download task failed: {error}"))??;
|
||||||
|
launch_installer(&installer_path)?;
|
||||||
|
let handle = app.clone();
|
||||||
|
thread::spawn(move || {
|
||||||
|
thread::sleep(Duration::from_millis(800));
|
||||||
|
handle.exit(0);
|
||||||
|
});
|
||||||
|
Ok("Installer downloaded and started. ClipForge will close to finish the update.".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn launch_installer(path: &PathBuf) -> Result<(), String> {
|
||||||
|
let extension = path
|
||||||
|
.extension()
|
||||||
|
.and_then(|value| value.to_str())
|
||||||
|
.unwrap_or("")
|
||||||
|
.to_ascii_lowercase();
|
||||||
|
let spawned = if extension == "msi" {
|
||||||
|
Command::new("msiexec")
|
||||||
|
.arg("/i")
|
||||||
|
.arg(path)
|
||||||
|
.arg("/passive")
|
||||||
|
.arg("/norestart")
|
||||||
|
.spawn()
|
||||||
|
} else {
|
||||||
|
Command::new(path).arg("/S").spawn()
|
||||||
|
};
|
||||||
|
spawned
|
||||||
|
.map(|_| ())
|
||||||
|
.map_err(|error| format!("Could not launch installer: {error}"))
|
||||||
|
}
|
||||||
|
|
||||||
fn upload_clip_with_settings(
|
fn upload_clip_with_settings(
|
||||||
clip: &Clip,
|
clip: &Clip,
|
||||||
settings: &AppSettings,
|
settings: &AppSettings,
|
||||||
@@ -1182,6 +1473,7 @@ fn register_hotkeys(
|
|||||||
let _ = app.global_shortcut().unregister(existing.clip_60);
|
let _ = app.global_shortcut().unregister(existing.clip_60);
|
||||||
let _ = app.global_shortcut().unregister(existing.clip_30);
|
let _ = app.global_shortcut().unregister(existing.clip_30);
|
||||||
let _ = app.global_shortcut().unregister(existing.toggle_recording);
|
let _ = app.global_shortcut().unregister(existing.toggle_recording);
|
||||||
|
let _ = app.global_shortcut().unregister(existing.screenshot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1194,9 +1486,14 @@ fn register_hotkeys(
|
|||||||
let clip_30 = Shortcut::new(clip_30_mods, clip_30_code);
|
let clip_30 = Shortcut::new(clip_30_mods, clip_30_code);
|
||||||
let toggle_recording = Shortcut::new(toggle_mods, toggle_code);
|
let toggle_recording = Shortcut::new(toggle_mods, toggle_code);
|
||||||
|
|
||||||
|
let (screenshot_mods, screenshot_code) = parse_accelerator(&settings.screenshot)?;
|
||||||
|
|
||||||
|
let screenshot = Shortcut::new(screenshot_mods, screenshot_code);
|
||||||
|
|
||||||
let handler_clip_60 = clip_60.clone();
|
let handler_clip_60 = clip_60.clone();
|
||||||
let handler_clip_30 = clip_30.clone();
|
let handler_clip_30 = clip_30.clone();
|
||||||
let handler_toggle_recording = toggle_recording.clone();
|
let handler_toggle_recording = toggle_recording.clone();
|
||||||
|
let handler_screenshot = screenshot.clone();
|
||||||
|
|
||||||
app.plugin(
|
app.plugin(
|
||||||
tauri_plugin_global_shortcut::Builder::new()
|
tauri_plugin_global_shortcut::Builder::new()
|
||||||
@@ -1220,6 +1517,8 @@ fn register_hotkeys(
|
|||||||
} else {
|
} else {
|
||||||
let _ = start_capture_inner(runtime.inner());
|
let _ = start_capture_inner(runtime.inner());
|
||||||
}
|
}
|
||||||
|
} else if shortcut == &handler_screenshot {
|
||||||
|
let _ = handle_screenshot();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.build(),
|
.build(),
|
||||||
@@ -1228,12 +1527,14 @@ fn register_hotkeys(
|
|||||||
app.global_shortcut().register(clip_60.clone()).map_err(|e| e.to_string())?;
|
app.global_shortcut().register(clip_60.clone()).map_err(|e| e.to_string())?;
|
||||||
app.global_shortcut().register(clip_30.clone()).map_err(|e| e.to_string())?;
|
app.global_shortcut().register(clip_30.clone()).map_err(|e| e.to_string())?;
|
||||||
app.global_shortcut().register(toggle_recording.clone()).map_err(|e| e.to_string())?;
|
app.global_shortcut().register(toggle_recording.clone()).map_err(|e| e.to_string())?;
|
||||||
|
app.global_shortcut().register(screenshot.clone()).map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
if let Ok(mut shortcuts_guard) = runtime.hotkey_shortcuts.lock() {
|
if let Ok(mut shortcuts_guard) = runtime.hotkey_shortcuts.lock() {
|
||||||
*shortcuts_guard = Some(HotkeyShortcuts {
|
*shortcuts_guard = Some(HotkeyShortcuts {
|
||||||
clip_60,
|
clip_60,
|
||||||
clip_30,
|
clip_30,
|
||||||
toggle_recording,
|
toggle_recording,
|
||||||
|
screenshot,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1278,13 +1579,15 @@ fn set_hotkeys(
|
|||||||
register_hotkeys(&app_handle, runtime.inner())?;
|
register_hotkeys(&app_handle, runtime.inner())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(status_from_recorder(&recorder, capture.as_ref()))
|
Ok(status_from_recorder(&recorder, capture.as_ref(), &runtime.capture_capabilities))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let (library_root, recorder, database) =
|
let (library_root, recorder, database) =
|
||||||
create_runtime().expect("could not initialize ClipForge runtime");
|
create_runtime().expect("could not initialize ClipForge runtime");
|
||||||
|
|
||||||
|
clipforge::crashlog::install_panic_hook(library_root.join("logs"));
|
||||||
|
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.manage(AppRuntime {
|
.manage(AppRuntime {
|
||||||
library_root,
|
library_root,
|
||||||
@@ -1295,6 +1598,7 @@ fn main() {
|
|||||||
valve_events: Mutex::new(Vec::new()),
|
valve_events: Mutex::new(Vec::new()),
|
||||||
hotkey_shortcuts: Mutex::new(None),
|
hotkey_shortcuts: Mutex::new(None),
|
||||||
app_handle: Mutex::new(None),
|
app_handle: Mutex::new(None),
|
||||||
|
capture_capabilities: detect_capture_capabilities(),
|
||||||
})
|
})
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
let handle = app.handle().clone();
|
let handle = app.handle().clone();
|
||||||
@@ -1327,37 +1631,61 @@ fn main() {
|
|||||||
set_mic_enabled,
|
set_mic_enabled,
|
||||||
set_system_audio_enabled,
|
set_system_audio_enabled,
|
||||||
list_audio_devices,
|
list_audio_devices,
|
||||||
set_mic_device,
|
set_mic_device,
|
||||||
set_auto_record_enabled,
|
set_auto_record_enabled,
|
||||||
set_upload_settings,
|
set_upload_settings,
|
||||||
set_auto_clip_event_enabled,
|
set_auto_clip_event_enabled,
|
||||||
write_gsi_configs,
|
set_capture_settings,
|
||||||
poll_auto_clip_events,
|
finish_onboarding,
|
||||||
save_manual_clip,
|
write_gsi_configs,
|
||||||
start_capture,
|
poll_auto_clip_events,
|
||||||
stop_capture,
|
save_manual_clip,
|
||||||
delete_clip,
|
start_capture,
|
||||||
reveal_clip,
|
stop_capture,
|
||||||
trim_clip,
|
delete_clip,
|
||||||
upload_clip,
|
reveal_clip,
|
||||||
update_clip_metadata,
|
trim_clip,
|
||||||
export_clip_copy,
|
upload_clip,
|
||||||
set_hotkeys
|
update_clip_metadata,
|
||||||
|
export_clip_copy,
|
||||||
|
list_upload_history,
|
||||||
|
take_screenshot,
|
||||||
|
list_screenshots,
|
||||||
|
reveal_screenshot,
|
||||||
|
reveal_crash_logs,
|
||||||
|
list_crash_logs,
|
||||||
|
set_game_quality_override,
|
||||||
|
clear_game_quality_override,
|
||||||
|
check_for_updates,
|
||||||
|
download_and_apply_update,
|
||||||
|
set_hotkeys
|
||||||
])
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running ClipForge desktop shell");
|
.expect("error while running ClipForge desktop shell");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_screenshot() -> Result<(), String> {
|
||||||
|
clipforge::screenshot::take_screenshot().map_err(|error| error.to_string())?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn create_runtime() -> Result<(PathBuf, RecorderService, ClipDatabase), String> {
|
fn create_runtime() -> Result<(PathBuf, RecorderService, ClipDatabase), String> {
|
||||||
let root = env::current_dir()
|
let resolution = resolve_library_root()
|
||||||
.unwrap_or_else(|_| PathBuf::from("."))
|
.map_err(|error| format!("Could not resolve library root: {error}"))?;
|
||||||
.join("clipforge-library");
|
let root = resolution.root;
|
||||||
let settings = load_or_create_settings(&root)
|
let settings = load_or_create_settings(&root)
|
||||||
.map_err(|error| format!("Could not load settings: {error}"))?;
|
.map_err(|error| format!("Could not load settings: {error}"))?;
|
||||||
let paths = LibraryPaths::new(&root);
|
let paths = LibraryPaths::new(&root);
|
||||||
paths.ensure().map_err(|error| error.to_string())?;
|
paths.ensure().map_err(|error| error.to_string())?;
|
||||||
let database = ClipDatabase::open(root.join("library.sqlite"))
|
let database = ClipDatabase::open(root.join("library.sqlite"))
|
||||||
.map_err(|error| format!("Could not open clip database: {error}"))?;
|
.map_err(|error| format!("Could not open clip database: {error}"))?;
|
||||||
|
if let Some(legacy) = resolution.migrated_from {
|
||||||
|
let old_prefix = legacy.display().to_string();
|
||||||
|
let new_prefix = root.display().to_string();
|
||||||
|
database
|
||||||
|
.rewrite_path_prefix(&old_prefix, &new_prefix)
|
||||||
|
.map_err(|error| format!("Could not remap migrated clip paths: {error}"))?;
|
||||||
|
}
|
||||||
let mut recorder = RecorderService::new(settings, paths);
|
let mut recorder = RecorderService::new(settings, paths);
|
||||||
for clip in database
|
for clip in database
|
||||||
.load_clips()
|
.load_clips()
|
||||||
@@ -1427,9 +1755,32 @@ fn start_best_capture_backend(
|
|||||||
native_mic_available: bool,
|
native_mic_available: bool,
|
||||||
ffmpeg_system_audio_available: bool,
|
ffmpeg_system_audio_available: bool,
|
||||||
) -> Result<ActiveCaptureBackend, String> {
|
) -> Result<ActiveCaptureBackend, String> {
|
||||||
if (!config.system_audio_enabled || native_system_audio_available)
|
let separate_tracks =
|
||||||
&& (!config.mic_enabled || native_mic_available)
|
config.system_audio_enabled && config.mic_enabled && config.separate_audio_tracks;
|
||||||
{
|
|
||||||
|
// windows-capture exposes a single mixed audio channel, so distinct system/mic tracks
|
||||||
|
// can only be encoded through the FFmpeg backend. Prefer it when the user enabled
|
||||||
|
// separate tracks; fall back to native WGC if FFmpeg cannot start (recording must not
|
||||||
|
// be blocked by a backend choice).
|
||||||
|
if separate_tracks {
|
||||||
|
let mut ffmpeg_backend =
|
||||||
|
FfmpegReplayCaptureBackend::new(ffmpeg, segment_pattern, segment_duration);
|
||||||
|
let mut ffmpeg_config = config.clone();
|
||||||
|
if ffmpeg_config.system_audio_enabled && !ffmpeg_system_audio_available {
|
||||||
|
ffmpeg_config.system_audio_enabled = false;
|
||||||
|
}
|
||||||
|
if ffmpeg_backend.start(ffmpeg_config).is_ok() {
|
||||||
|
return Ok(ActiveCaptureBackend::Ffmpeg(ffmpeg_backend));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if clipforge::capture::native_capture_can_honor_audio(
|
||||||
|
config.system_audio_enabled,
|
||||||
|
config.mic_enabled,
|
||||||
|
config.separate_audio_tracks,
|
||||||
|
native_system_audio_available,
|
||||||
|
native_mic_available,
|
||||||
|
) {
|
||||||
let mut native = NativeWgcReplayCaptureBackend::new(segment_pattern, segment_duration);
|
let mut native = NativeWgcReplayCaptureBackend::new(segment_pattern, segment_duration);
|
||||||
if native.start(config.clone()).is_ok() {
|
if native.start(config.clone()).is_ok() {
|
||||||
return Ok(ActiveCaptureBackend::NativeWgc(native));
|
return Ok(ActiveCaptureBackend::NativeWgc(native));
|
||||||
@@ -1484,12 +1835,68 @@ fn start_backend_workers(app: tauri::AppHandle) {
|
|||||||
let runtime = app.state::<AppRuntime>();
|
let runtime = app.state::<AppRuntime>();
|
||||||
let _ = refresh_detected_game_inner(runtime.inner());
|
let _ = refresh_detected_game_inner(runtime.inner());
|
||||||
let _ = poll_auto_clip_events_inner(runtime.inner());
|
let _ = poll_auto_clip_events_inner(runtime.inner());
|
||||||
|
let _ = stop_capture_on_critical_storage(runtime.inner());
|
||||||
|
let _ = enforce_storage_cap(runtime.inner());
|
||||||
thread::sleep(Duration::from_secs(2));
|
thread::sleep(Duration::from_secs(2));
|
||||||
})
|
})
|
||||||
.expect("could not start ClipForge backend workers");
|
.expect("could not start ClipForge backend workers");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn status_from_recorder(recorder: &RecorderService, capture: Option<&ActiveCapture>) -> DesktopStatus {
|
fn stop_capture_on_critical_storage(runtime: &AppRuntime) -> Result<(), String> {
|
||||||
|
let buffer_root = {
|
||||||
|
let recorder = runtime.recorder.lock().map_err(|error| error.to_string())?;
|
||||||
|
recorder.paths.buffer_root.clone()
|
||||||
|
};
|
||||||
|
if runtime
|
||||||
|
.capture
|
||||||
|
.lock()
|
||||||
|
.map_err(|error| error.to_string())?
|
||||||
|
.is_none()
|
||||||
|
{
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let storage = clipforge::storage::check_storage_space(&buffer_root);
|
||||||
|
if let clipforge::storage::StorageLevel::Critical = storage.level {
|
||||||
|
let _ = stop_capture_inner(runtime);
|
||||||
|
let mut recorder = runtime.recorder.lock().map_err(|error| error.to_string())?;
|
||||||
|
recorder.state.status = RecordingStatus::StorageLow;
|
||||||
|
eprintln!(
|
||||||
|
"ClipForge stopped recording: critical low disk ({:.1} GB free).",
|
||||||
|
storage.free_gb()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn enforce_storage_cap(runtime: &AppRuntime) -> Result<(), String> {
|
||||||
|
let (buffer_root, limit_gb) = {
|
||||||
|
let recorder = runtime.recorder.lock().map_err(|error| error.to_string())?;
|
||||||
|
(recorder.paths.buffer_root.clone(), recorder.settings.storage_limit_gb)
|
||||||
|
};
|
||||||
|
if limit_gb == 0 {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let max_bytes = limit_gb.saturating_mul(1024 * 1024 * 1024);
|
||||||
|
let report =
|
||||||
|
clipforge::storage::cleanup_oldest_files_until_under_limit(&buffer_root, max_bytes)
|
||||||
|
.map_err(|error| format!("Could not enforce storage cap: {error}"))?;
|
||||||
|
if report.deleted_files > 0 {
|
||||||
|
eprintln!(
|
||||||
|
"ClipForge storage cap: removed {} file(s) ({} MB) from the buffer.",
|
||||||
|
report.deleted_files,
|
||||||
|
report.deleted_bytes / (1024 * 1024)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn status_from_recorder(
|
||||||
|
recorder: &RecorderService,
|
||||||
|
capture: Option<&ActiveCapture>,
|
||||||
|
capabilities: &CaptureCapabilities,
|
||||||
|
) -> DesktopStatus {
|
||||||
|
let game_id = recorder.state.detected_game_id.clone().unwrap_or_default();
|
||||||
|
let quality = recorder.settings.effective_quality_for(&game_id).clone();
|
||||||
DesktopStatus {
|
DesktopStatus {
|
||||||
recording_state: recording_status_name(&recorder.state.status).to_string(),
|
recording_state: recording_status_name(&recorder.state.status).to_string(),
|
||||||
detected_game: recorder.state.detected_game_id.clone(),
|
detected_game: recorder.state.detected_game_id.clone(),
|
||||||
@@ -1517,23 +1924,96 @@ fn status_from_recorder(recorder: &RecorderService, capture: Option<&ActiveCaptu
|
|||||||
capture_path: capture.map(|active| active.session_output_path.display().to_string()),
|
capture_path: capture.map(|active| active.session_output_path.display().to_string()),
|
||||||
clip_count: recorder.library.all().len(),
|
clip_count: recorder.library.all().len(),
|
||||||
library_root: recorder.paths.clip_root.display().to_string(),
|
library_root: recorder.paths.clip_root.display().to_string(),
|
||||||
ffmpeg_available: ffmpeg_is_available(),
|
ffmpeg_available: capabilities.ffmpeg_path.is_some(),
|
||||||
ffmpeg_path: find_ffmpeg_executable().map(|path| path.display().to_string()),
|
ffmpeg_path: capabilities
|
||||||
system_audio_available: native_system_loopback_available()
|
.ffmpeg_path
|
||||||
|| find_ffmpeg_executable()
|
.as_ref()
|
||||||
.map(|path| ffmpeg_supports_input_device(&path, "wasapi"))
|
.map(|path| path.display().to_string()),
|
||||||
.unwrap_or(false),
|
system_audio_available: capabilities.system_audio_available,
|
||||||
desktop_duplication_available: find_ffmpeg_executable()
|
desktop_duplication_available: capabilities.desktop_duplication_available,
|
||||||
.map(|path| ffmpeg_supports_filter(&path, "ddagrab"))
|
|
||||||
.unwrap_or(false),
|
|
||||||
auto_clip_enabled_events: auto_clip_event_dtos(&recorder.settings),
|
auto_clip_enabled_events: auto_clip_event_dtos(&recorder.settings),
|
||||||
hotkey_clip_last_60s: recorder.settings.hotkeys.clip_last_60s.clone(),
|
hotkey_clip_last_60s: recorder.settings.hotkeys.clip_last_60s.clone(),
|
||||||
hotkey_clip_last_30s: recorder.settings.hotkeys.clip_last_30s.clone(),
|
hotkey_clip_last_30s: recorder.settings.hotkeys.clip_last_30s.clone(),
|
||||||
hotkey_toggle_session_recording: recorder.settings.hotkeys.toggle_session_recording.clone(),
|
hotkey_toggle_session_recording: recorder.settings.hotkeys.toggle_session_recording.clone(),
|
||||||
hotkey_screenshot: recorder.settings.hotkeys.screenshot.clone(),
|
hotkey_screenshot: recorder.settings.hotkeys.screenshot.clone(),
|
||||||
|
free_disk_gb: clipforge::storage::check_storage_space(&recorder.paths.buffer_root).free_gb(),
|
||||||
|
capture_fps: quality.fps,
|
||||||
|
capture_bitrate_kbps: quality.bitrate_kbps,
|
||||||
|
capture_resolution: format!("{}x{}", quality.width, quality.height),
|
||||||
|
storage_limit_gb: recorder.settings.storage_limit_gb,
|
||||||
|
excluded_window_titles: recorder.settings.privacy.excluded_window_titles.clone(),
|
||||||
|
separate_audio_tracks: recorder.settings.privacy.separate_audio_tracks,
|
||||||
|
game_quality_overrides: quality_override_dtos(&recorder.settings),
|
||||||
|
effective_quality_applied: game_override_is_active(&recorder.settings, &game_id),
|
||||||
|
app_version: env!("CARGO_PKG_VERSION").to_string(),
|
||||||
|
onboarding_complete: recorder.settings.onboarding_complete,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn quality_override_dtos(settings: &AppSettings) -> Vec<GameQualityOverrideDto> {
|
||||||
|
settings
|
||||||
|
.quality_overrides_by_game
|
||||||
|
.iter()
|
||||||
|
.map(|(game_id, preset)| GameQualityOverrideDto {
|
||||||
|
game_id: game_id.clone(),
|
||||||
|
name: preset.name.clone(),
|
||||||
|
width: preset.width,
|
||||||
|
height: preset.height,
|
||||||
|
fps: preset.fps,
|
||||||
|
bitrate_kbps: preset.bitrate_kbps,
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn game_override_is_active(settings: &AppSettings, game_id: &str) -> bool {
|
||||||
|
settings.quality_overrides_by_game.contains_key(game_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn set_game_quality_override(
|
||||||
|
game_id: String,
|
||||||
|
name: String,
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
fps: u32,
|
||||||
|
bitrate_kbps: u32,
|
||||||
|
runtime: State<'_, AppRuntime>,
|
||||||
|
) -> Result<DesktopStatus, String> {
|
||||||
|
let mut recorder = runtime.recorder.lock().map_err(|error| error.to_string())?;
|
||||||
|
let capture = runtime.capture.lock().map_err(|error| error.to_string())?;
|
||||||
|
let preset = clipforge::settings::QualityPreset {
|
||||||
|
name: if name.trim().is_empty() {
|
||||||
|
"Custom".to_string()
|
||||||
|
} else {
|
||||||
|
name.trim().to_string()
|
||||||
|
},
|
||||||
|
width: even_between(width, 640, 7680),
|
||||||
|
height: even_between(height, 360, 4320),
|
||||||
|
fps: fps.clamp(15, 240),
|
||||||
|
bitrate_kbps: bitrate_kbps.clamp(500, 50_000),
|
||||||
|
};
|
||||||
|
recorder
|
||||||
|
.settings
|
||||||
|
.quality_overrides_by_game
|
||||||
|
.insert(game_id, preset);
|
||||||
|
save_settings(&runtime.library_root, &recorder.settings)
|
||||||
|
.map_err(|error| format!("Could not save quality override: {error}"))?;
|
||||||
|
Ok(status_from_recorder(&recorder, capture.as_ref(), &runtime.capture_capabilities))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn clear_game_quality_override(
|
||||||
|
game_id: String,
|
||||||
|
runtime: State<'_, AppRuntime>,
|
||||||
|
) -> Result<DesktopStatus, String> {
|
||||||
|
let mut recorder = runtime.recorder.lock().map_err(|error| error.to_string())?;
|
||||||
|
let capture = runtime.capture.lock().map_err(|error| error.to_string())?;
|
||||||
|
recorder.settings.quality_overrides_by_game.remove(&game_id);
|
||||||
|
save_settings(&runtime.library_root, &recorder.settings)
|
||||||
|
.map_err(|error| format!("Could not save quality override: {error}"))?;
|
||||||
|
Ok(status_from_recorder(&recorder, capture.as_ref(), &runtime.capture_capabilities))
|
||||||
|
}
|
||||||
|
|
||||||
fn clip_to_dto(clip: &Clip) -> ClipDto {
|
fn clip_to_dto(clip: &Clip) -> ClipDto {
|
||||||
ClipDto {
|
ClipDto {
|
||||||
id: clip.id.clone(),
|
id: clip.id.clone(),
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
|
use crate::proc::hidden_command;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum AudioDeviceKind {
|
pub enum AudioDeviceKind {
|
||||||
@@ -14,7 +14,7 @@ pub struct AudioDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_ffmpeg_dshow_audio_inputs(ffmpeg: &Path) -> Vec<AudioDevice> {
|
pub fn list_ffmpeg_dshow_audio_inputs(ffmpeg: &Path) -> Vec<AudioDevice> {
|
||||||
let Ok(output) = Command::new(ffmpeg)
|
let Ok(output) = hidden_command(ffmpeg)
|
||||||
.args([
|
.args([
|
||||||
"-hide_banner",
|
"-hide_banner",
|
||||||
"-list_devices",
|
"-list_devices",
|
||||||
|
|||||||
+104
-8
@@ -1,7 +1,8 @@
|
|||||||
|
use crate::proc::hidden_command;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{Child, Command, Stdio};
|
use std::process::{Child, Stdio};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
@@ -114,7 +115,7 @@ pub fn find_ffmpeg_executable() -> Option<PathBuf> {
|
|||||||
|
|
||||||
let candidates = ["ffmpeg.exe", "ffmpeg"];
|
let candidates = ["ffmpeg.exe", "ffmpeg"];
|
||||||
for candidate in candidates {
|
for candidate in candidates {
|
||||||
if Command::new(candidate).arg("-version").output().is_ok() {
|
if hidden_command(candidate).arg("-version").output().is_ok() {
|
||||||
return Some(PathBuf::from(candidate));
|
return Some(PathBuf::from(candidate));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,7 +128,7 @@ pub fn ffmpeg_is_available() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn ffmpeg_supports_input_device(executable: &std::path::Path, device: &str) -> bool {
|
pub fn ffmpeg_supports_input_device(executable: &std::path::Path, device: &str) -> bool {
|
||||||
let Ok(output) = Command::new(executable)
|
let Ok(output) = hidden_command(executable)
|
||||||
.args(["-hide_banner", "-devices"])
|
.args(["-hide_banner", "-devices"])
|
||||||
.output()
|
.output()
|
||||||
else {
|
else {
|
||||||
@@ -144,7 +145,7 @@ pub fn ffmpeg_supports_input_device(executable: &std::path::Path, device: &str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn ffmpeg_supports_filter(executable: &std::path::Path, filter: &str) -> bool {
|
pub fn ffmpeg_supports_filter(executable: &std::path::Path, filter: &str) -> bool {
|
||||||
let Ok(output) = Command::new(executable)
|
let Ok(output) = hidden_command(executable)
|
||||||
.args(["-hide_banner", "-filters"])
|
.args(["-hide_banner", "-filters"])
|
||||||
.output()
|
.output()
|
||||||
else {
|
else {
|
||||||
@@ -160,6 +161,23 @@ pub fn ffmpeg_supports_filter(executable: &std::path::Path, filter: &str) -> boo
|
|||||||
.any(|line| line.split_whitespace().any(|part| part == filter))
|
.any(|line| line.split_whitespace().any(|part| part == filter))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns true when the single-track native WGC encoder can satisfy the requested audio
|
||||||
|
/// configuration. windows-capture exposes one mixed audio channel, so distinct system/mic
|
||||||
|
/// tracks are only achievable through the FFmpeg backend and route there instead.
|
||||||
|
pub fn native_capture_can_honor_audio(
|
||||||
|
system_audio_enabled: bool,
|
||||||
|
mic_enabled: bool,
|
||||||
|
separate_audio_tracks: bool,
|
||||||
|
native_system_audio_available: bool,
|
||||||
|
native_mic_available: bool,
|
||||||
|
) -> bool {
|
||||||
|
if system_audio_enabled && mic_enabled && separate_audio_tracks {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
(!system_audio_enabled || native_system_audio_available)
|
||||||
|
&& (!mic_enabled || native_mic_available)
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct FfmpegRecordingPlan {
|
pub struct FfmpegRecordingPlan {
|
||||||
pub executable: PathBuf,
|
pub executable: PathBuf,
|
||||||
@@ -298,9 +316,9 @@ fn base_desktop_input_args(config: &CaptureConfig) -> Vec<String> {
|
|||||||
args.extend([
|
args.extend([
|
||||||
"-map".to_string(),
|
"-map".to_string(),
|
||||||
format!("{}:a?", input_idx),
|
format!("{}:a?", input_idx),
|
||||||
"-c:a:{}".to_string(), idx.to_string(),
|
format!("-c:a:{idx}"),
|
||||||
"aac".to_string(),
|
"aac".to_string(),
|
||||||
"-b:a:{}".to_string(), idx.to_string(),
|
format!("-b:a:{idx}"),
|
||||||
"160k".to_string(),
|
"160k".to_string(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -351,7 +369,7 @@ impl CaptureBackend for FfmpegCaptureBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let plan = self.plan(&config);
|
let plan = self.plan(&config);
|
||||||
let child = Command::new(&plan.executable)
|
let child = hidden_command(&plan.executable)
|
||||||
.args(&plan.args)
|
.args(&plan.args)
|
||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.stdout(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
@@ -457,7 +475,7 @@ impl Drop for FfmpegReplayCaptureBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_ffmpeg(plan: &FfmpegRecordingPlan) -> Result<Child, CaptureError> {
|
fn spawn_ffmpeg(plan: &FfmpegRecordingPlan) -> Result<Child, CaptureError> {
|
||||||
Command::new(&plan.executable)
|
hidden_command(&plan.executable)
|
||||||
.args(&plan.args)
|
.args(&plan.args)
|
||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.stdout(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
@@ -572,4 +590,82 @@ mod tests {
|
|||||||
"wasapi"
|
"wasapi"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn separate_tracks_map_distinct_audio_inputs() {
|
||||||
|
let config = CaptureConfig {
|
||||||
|
source: CaptureSource::Desktop,
|
||||||
|
method: CaptureMethod::DesktopDuplication,
|
||||||
|
width: 1280,
|
||||||
|
height: 720,
|
||||||
|
fps: 30,
|
||||||
|
bitrate_kbps: 6000,
|
||||||
|
encoder: EncoderPreference::HardwareH264,
|
||||||
|
system_audio_enabled: true,
|
||||||
|
mic_enabled: true,
|
||||||
|
system_audio_device: None,
|
||||||
|
mic_device: Some("Microphone".to_string()),
|
||||||
|
separate_audio_tracks: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
let plan = FfmpegRecordingPlan::for_windows_desktop_segments(
|
||||||
|
"ffmpeg",
|
||||||
|
"segment-%05d.mp4",
|
||||||
|
&config,
|
||||||
|
Duration::from_secs(5),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(plan.args.iter().any(|arg| arg == "-map"));
|
||||||
|
assert!(plan.args.windows(2).any(|pair| pair == ["-map", "1:a?"]));
|
||||||
|
assert!(plan.args.windows(2).any(|pair| pair == ["-map", "2:a?"]));
|
||||||
|
assert!(plan.args.iter().any(|arg| arg == "-c:a:0"));
|
||||||
|
assert!(plan.args.iter().any(|arg| arg == "-c:a:1"));
|
||||||
|
assert!(plan.args.iter().any(|arg| arg == "wasapi"));
|
||||||
|
assert!(plan.args.iter().any(|arg| arg.contains("Microphone")));
|
||||||
|
assert!(!plan.args.windows(3).any(|triple| triple == ["-c:a", "aac", "-b:a"]));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn legacy_mixed_audio_keeps_single_track_encoding_when_separate_tracks_off() {
|
||||||
|
let config = CaptureConfig {
|
||||||
|
source: CaptureSource::Desktop,
|
||||||
|
method: CaptureMethod::GdiGrab,
|
||||||
|
width: 1280,
|
||||||
|
height: 720,
|
||||||
|
fps: 30,
|
||||||
|
bitrate_kbps: 6000,
|
||||||
|
encoder: EncoderPreference::HardwareH264,
|
||||||
|
system_audio_enabled: true,
|
||||||
|
mic_enabled: true,
|
||||||
|
system_audio_device: None,
|
||||||
|
mic_device: Some("Microphone".to_string()),
|
||||||
|
separate_audio_tracks: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
let plan = FfmpegRecordingPlan::for_windows_desktop("ffmpeg", "out.mp4", &config);
|
||||||
|
|
||||||
|
assert!(plan.args.windows(2).any(|pair| pair == ["-map", "1:a?"]));
|
||||||
|
assert!(plan.args.windows(2).any(|pair| pair == ["-map", "2:a?"]));
|
||||||
|
assert!(plan.args.windows(3).any(|triple| triple == ["-c:a", "aac", "-b:a"]));
|
||||||
|
assert!(!plan.args.iter().any(|arg| arg == "-c:a:0"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn native_capture_cannot_honor_separate_tracks() {
|
||||||
|
assert!(!native_capture_can_honor_audio(true, true, true, true, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn native_capture_honors_single_source_combinations() {
|
||||||
|
assert!(native_capture_can_honor_audio(true, false, true, true, false));
|
||||||
|
assert!(native_capture_can_honor_audio(false, true, true, false, true));
|
||||||
|
assert!(native_capture_can_honor_audio(true, true, false, true, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn native_capture_requires_available_native_sources() {
|
||||||
|
assert!(!native_capture_can_honor_audio(true, false, false, false, true));
|
||||||
|
assert!(!native_capture_can_honor_audio(false, true, false, true, false));
|
||||||
|
assert!(native_capture_can_honor_audio(false, false, true, false, false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+126
@@ -0,0 +1,126 @@
|
|||||||
|
use std::fs;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
|
const MAX_CRASH_FILES: u64 = 5;
|
||||||
|
|
||||||
|
pub fn install_panic_hook(log_dir: impl Into<PathBuf>) {
|
||||||
|
let log_dir = log_dir.into();
|
||||||
|
let _ = fs::create_dir_all(&log_dir);
|
||||||
|
let guard_path = log_dir.join("latest-crash.txt");
|
||||||
|
|
||||||
|
std::panic::set_hook(Box::new(move |panic_info| {
|
||||||
|
let now = SystemTime::now();
|
||||||
|
let timestamp = now
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.unwrap_or_default()
|
||||||
|
.as_secs();
|
||||||
|
let payload = panic_info
|
||||||
|
.payload()
|
||||||
|
.downcast_ref::<&str>()
|
||||||
|
.map(|value| value.to_string())
|
||||||
|
.or_else(|| {
|
||||||
|
panic_info
|
||||||
|
.payload()
|
||||||
|
.downcast_ref::<String>()
|
||||||
|
.map(Clone::clone)
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|| "unknown panic payload".to_string());
|
||||||
|
let location = panic_info
|
||||||
|
.location()
|
||||||
|
.map(|location| format!("{}:{}", location.file(), location.line()))
|
||||||
|
.unwrap_or_else(|| "unknown location".to_string());
|
||||||
|
|
||||||
|
let mut body = String::new();
|
||||||
|
body.push_str("ClipForge crash report\n");
|
||||||
|
body.push_str(&format!("time: {timestamp}\n"));
|
||||||
|
body.push_str(&format!("thread: {}\n", thread_name()));
|
||||||
|
body.push_str(&format!("location: {location}\n"));
|
||||||
|
body.push_str(&format!("message: {payload}\n"));
|
||||||
|
body.push_str("\nBacktrace:\n");
|
||||||
|
body.push_str(&backtrace());
|
||||||
|
|
||||||
|
let _ = fs::write(&guard_path, &body);
|
||||||
|
let file = log_dir.join(format!("crash-{timestamp}.log"));
|
||||||
|
let _ = fs::write(&file, &body);
|
||||||
|
prune_crash_files(&log_dir);
|
||||||
|
|
||||||
|
eprint!("{body}");
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn thread_name() -> String {
|
||||||
|
std::thread::current()
|
||||||
|
.name()
|
||||||
|
.map(ToString::to_string)
|
||||||
|
.unwrap_or_else(|| "<unnamed>".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn backtrace() -> String {
|
||||||
|
let backtrace = std::backtrace::Backtrace::force_capture();
|
||||||
|
format!("{backtrace}")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn prune_crash_files(log_dir: &Path) {
|
||||||
|
let Ok(entries) = fs::read_dir(log_dir) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let mut files = entries
|
||||||
|
.filter_map(|entry| entry.ok())
|
||||||
|
.map(|entry| entry.path())
|
||||||
|
.filter(|path| {
|
||||||
|
path.file_name()
|
||||||
|
.and_then(|name| name.to_str())
|
||||||
|
.map(|name| name.starts_with("crash-") && name.ends_with(".log"))
|
||||||
|
.unwrap_or(false)
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
files.sort();
|
||||||
|
while files.len() as u64 > MAX_CRASH_FILES {
|
||||||
|
let oldest = files.remove(0);
|
||||||
|
let _ = fs::remove_file(oldest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn panic_hook_writes_crash_file() {
|
||||||
|
let log_dir = std::env::temp_dir().join(format!(
|
||||||
|
"clipforge-crashlog-{}",
|
||||||
|
SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.unwrap_or_default()
|
||||||
|
.as_nanos()
|
||||||
|
));
|
||||||
|
fs::create_dir_all(&log_dir).expect("log dir");
|
||||||
|
install_panic_hook(&log_dir);
|
||||||
|
|
||||||
|
let result = std::panic::catch_unwind(|| {
|
||||||
|
let before = fs::read_dir(&log_dir).expect("read").count();
|
||||||
|
assert_eq!(before, 0);
|
||||||
|
panic!("intentional-test-panic");
|
||||||
|
});
|
||||||
|
assert!(result.is_err());
|
||||||
|
drop(std::panic::take_hook());
|
||||||
|
|
||||||
|
let crash_files = fs::read_dir(&log_dir)
|
||||||
|
.expect("read")
|
||||||
|
.filter_map(|entry| entry.ok())
|
||||||
|
.map(|entry| entry.path())
|
||||||
|
.filter(|path| {
|
||||||
|
path.file_name()
|
||||||
|
.and_then(|name| name.to_str())
|
||||||
|
.map(|name| name.starts_with("crash-"))
|
||||||
|
.unwrap_or(false)
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
assert!(!crash_files.is_empty(), "expected a crash log file");
|
||||||
|
let body = fs::read_to_string(&crash_files[0]).expect("crash body");
|
||||||
|
assert!(body.contains("intentional-test-panic"));
|
||||||
|
|
||||||
|
let _ = fs::remove_dir_all(log_dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
+221
-37
@@ -1,8 +1,46 @@
|
|||||||
use crate::models::{Clip, ClipSource, GameEventType, UploadProvider};
|
use crate::models::{Clip, ClipSource, GameEventType, UploadHistoryEntry, UploadProvider};
|
||||||
use rusqlite::{params, Connection};
|
use rusqlite::{params, Connection};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
|
const CURRENT_SCHEMA_VERSION: u32 = MIGRATIONS.len() as u32;
|
||||||
|
|
||||||
|
const MIGRATIONS: &[&str] = &[
|
||||||
|
// v1: initial clips table (also used to repair databases predating versioned migrations).
|
||||||
|
"
|
||||||
|
CREATE TABLE IF NOT EXISTS clips (
|
||||||
|
id TEXT PRIMARY KEY NOT NULL,
|
||||||
|
title TEXT,
|
||||||
|
session_id TEXT NOT NULL,
|
||||||
|
game_id TEXT NOT NULL,
|
||||||
|
path TEXT NOT NULL,
|
||||||
|
thumbnail_path TEXT,
|
||||||
|
created_at_ms INTEGER NOT NULL,
|
||||||
|
duration_ms INTEGER NOT NULL,
|
||||||
|
source TEXT NOT NULL,
|
||||||
|
event_type TEXT,
|
||||||
|
tags_json TEXT NOT NULL,
|
||||||
|
upload_url TEXT,
|
||||||
|
upload_provider TEXT
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS clips_created_at_idx ON clips(created_at_ms DESC);
|
||||||
|
CREATE INDEX IF NOT EXISTS clips_game_id_idx ON clips(game_id);
|
||||||
|
",
|
||||||
|
// v2: upload history bookkeeping.
|
||||||
|
"
|
||||||
|
CREATE TABLE IF NOT EXISTS upload_history (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
clip_id TEXT NOT NULL,
|
||||||
|
provider TEXT NOT NULL,
|
||||||
|
status TEXT NOT NULL,
|
||||||
|
url TEXT,
|
||||||
|
error TEXT,
|
||||||
|
attempted_at_ms INTEGER NOT NULL
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS upload_history_clip_id_idx ON upload_history(clip_id);
|
||||||
|
",
|
||||||
|
];
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ClipDatabase {
|
pub struct ClipDatabase {
|
||||||
connection: Connection,
|
connection: Connection,
|
||||||
@@ -22,42 +60,32 @@ impl ClipDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(&self) -> rusqlite::Result<()> {
|
pub fn init(&self) -> rusqlite::Result<()> {
|
||||||
self.connection.execute_batch(
|
self.migrate()?;
|
||||||
"
|
|
||||||
CREATE TABLE IF NOT EXISTS clips (
|
|
||||||
id TEXT PRIMARY KEY NOT NULL,
|
|
||||||
title TEXT,
|
|
||||||
session_id TEXT NOT NULL,
|
|
||||||
game_id TEXT NOT NULL,
|
|
||||||
path TEXT NOT NULL,
|
|
||||||
thumbnail_path TEXT,
|
|
||||||
created_at_ms INTEGER NOT NULL,
|
|
||||||
duration_ms INTEGER NOT NULL,
|
|
||||||
source TEXT NOT NULL,
|
|
||||||
event_type TEXT,
|
|
||||||
tags_json TEXT NOT NULL,
|
|
||||||
upload_url TEXT,
|
|
||||||
upload_provider TEXT
|
|
||||||
);
|
|
||||||
CREATE INDEX IF NOT EXISTS clips_created_at_idx ON clips(created_at_ms DESC);
|
|
||||||
CREATE INDEX IF NOT EXISTS clips_game_id_idx ON clips(game_id);
|
|
||||||
CREATE TABLE IF NOT EXISTS upload_history (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
clip_id TEXT NOT NULL,
|
|
||||||
provider TEXT NOT NULL,
|
|
||||||
status TEXT NOT NULL,
|
|
||||||
url TEXT,
|
|
||||||
error TEXT,
|
|
||||||
attempted_at_ms INTEGER NOT NULL
|
|
||||||
);
|
|
||||||
CREATE INDEX IF NOT EXISTS upload_history_clip_id_idx ON upload_history(clip_id);
|
|
||||||
",
|
|
||||||
)?;
|
|
||||||
if !self.column_exists("clips", "title")? {
|
if !self.column_exists("clips", "title")? {
|
||||||
self.connection
|
self.connection
|
||||||
.execute("ALTER TABLE clips ADD COLUMN title TEXT", [])?;
|
.execute("ALTER TABLE clips ADD COLUMN title TEXT", [])?;
|
||||||
}
|
}
|
||||||
self.connection.pragma_update(None, "user_version", 2)
|
if self.user_version()? != CURRENT_SCHEMA_VERSION {
|
||||||
|
self.connection
|
||||||
|
.pragma_update(None, "user_version", CURRENT_SCHEMA_VERSION)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn migrate(&self) -> rusqlite::Result<()> {
|
||||||
|
let mut version = self.user_version()?;
|
||||||
|
while (version as usize) < MIGRATIONS.len() {
|
||||||
|
self.connection.execute_batch(MIGRATIONS[version as usize])?;
|
||||||
|
version += 1;
|
||||||
|
self.connection
|
||||||
|
.pragma_update(None, "user_version", version)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn user_version(&self) -> rusqlite::Result<u32> {
|
||||||
|
self.connection
|
||||||
|
.query_row("PRAGMA user_version", [], |row| row.get(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_clips(&self) -> rusqlite::Result<Vec<Clip>> {
|
pub fn load_clips(&self) -> rusqlite::Result<Vec<Clip>> {
|
||||||
@@ -144,6 +172,16 @@ impl ClipDatabase {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn rewrite_path_prefix(&self, old_prefix: &str, new_prefix: &str) -> rusqlite::Result<usize> {
|
||||||
|
self.connection.execute(
|
||||||
|
"UPDATE clips SET
|
||||||
|
path = REPLACE(path, ?1, ?2),
|
||||||
|
thumbnail_path = REPLACE(thumbnail_path, ?1, ?2)
|
||||||
|
WHERE path LIKE ?1 || '%' OR thumbnail_path LIKE ?1 || '%'",
|
||||||
|
params![old_prefix, new_prefix],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn insert_upload_history(
|
pub fn insert_upload_history(
|
||||||
&self,
|
&self,
|
||||||
clip_id: &str,
|
clip_id: &str,
|
||||||
@@ -176,6 +214,31 @@ impl ClipDatabase {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn load_upload_history(&self) -> rusqlite::Result<Vec<UploadHistoryEntry>> {
|
||||||
|
let mut statement = self.connection.prepare(
|
||||||
|
"
|
||||||
|
SELECT id, clip_id, provider, status, url, error, attempted_at_ms
|
||||||
|
FROM upload_history
|
||||||
|
ORDER BY attempted_at_ms DESC
|
||||||
|
LIMIT 200
|
||||||
|
",
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let rows = statement.query_map([], |row| {
|
||||||
|
Ok(UploadHistoryEntry {
|
||||||
|
id: row.get(0)?,
|
||||||
|
clip_id: row.get(1)?,
|
||||||
|
provider: row.get(2)?,
|
||||||
|
status: row.get(3)?,
|
||||||
|
url: row.get(4)?,
|
||||||
|
error: row.get(5)?,
|
||||||
|
attempted_at: millis_to_system_time(row.get(6)?),
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
rows.collect()
|
||||||
|
}
|
||||||
|
|
||||||
fn column_exists(&self, table: &str, column: &str) -> rusqlite::Result<bool> {
|
fn column_exists(&self, table: &str, column: &str) -> rusqlite::Result<bool> {
|
||||||
let mut statement = self
|
let mut statement = self
|
||||||
.connection
|
.connection
|
||||||
@@ -256,12 +319,89 @@ fn millis_to_system_time(millis: i64) -> SystemTime {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
fn temp_database_path(name: &str) -> PathBuf {
|
||||||
fn round_trips_clip_records() {
|
let path = std::env::temp_dir().join(format!(
|
||||||
let db_path = std::env::temp_dir().join(format!(
|
"clipforge-db-{name}-{}.sqlite",
|
||||||
"clipforge-db-{}.sqlite",
|
|
||||||
system_time_to_millis(SystemTime::now())
|
system_time_to_millis(SystemTime::now())
|
||||||
));
|
));
|
||||||
|
let _ = std::fs::remove_file(&path);
|
||||||
|
path
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn fresh_database_walks_to_current_version() {
|
||||||
|
let db_path = temp_database_path("fresh");
|
||||||
|
let database = ClipDatabase::open(&db_path).expect("database");
|
||||||
|
assert_eq!(database.user_version().expect("version"), CURRENT_SCHEMA_VERSION);
|
||||||
|
database.connection.execute("SELECT 1 FROM upload_history", []).expect("v2 table exists");
|
||||||
|
let _ = std::fs::remove_file(db_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn opening_is_idempotent_and_does_not_downgrade() {
|
||||||
|
let db_path = temp_database_path("idempotent");
|
||||||
|
let first = ClipDatabase::open(&db_path).expect("database");
|
||||||
|
let second = ClipDatabase::open(&db_path).expect("database re-open");
|
||||||
|
assert_eq!(
|
||||||
|
first.user_version().expect("version"),
|
||||||
|
CURRENT_SCHEMA_VERSION
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
second.user_version().expect("version"),
|
||||||
|
CURRENT_SCHEMA_VERSION
|
||||||
|
);
|
||||||
|
let _ = std::fs::remove_file(db_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn legacy_database_is_repaired_and_upgraded() {
|
||||||
|
let db_path = temp_database_path("legacy");
|
||||||
|
{
|
||||||
|
let connection = Connection::open(&db_path).expect("raw connection");
|
||||||
|
connection
|
||||||
|
.execute_batch(
|
||||||
|
"
|
||||||
|
CREATE TABLE clips (
|
||||||
|
id TEXT PRIMARY KEY NOT NULL,
|
||||||
|
session_id TEXT NOT NULL,
|
||||||
|
game_id TEXT NOT NULL,
|
||||||
|
path TEXT NOT NULL,
|
||||||
|
thumbnail_path TEXT,
|
||||||
|
created_at_ms INTEGER NOT NULL,
|
||||||
|
duration_ms INTEGER NOT NULL,
|
||||||
|
source TEXT NOT NULL,
|
||||||
|
event_type TEXT,
|
||||||
|
tags_json TEXT NOT NULL,
|
||||||
|
upload_url TEXT,
|
||||||
|
upload_provider TEXT
|
||||||
|
);
|
||||||
|
",
|
||||||
|
)
|
||||||
|
.expect("legacy clips table");
|
||||||
|
connection
|
||||||
|
.pragma_update(None, "user_version", 0)
|
||||||
|
.expect("version 0");
|
||||||
|
}
|
||||||
|
let database = ClipDatabase::open(&db_path).expect("open with repair");
|
||||||
|
assert_eq!(database.user_version().expect("version"), CURRENT_SCHEMA_VERSION);
|
||||||
|
assert!(database.column_exists("clips", "title").expect("column lookup"));
|
||||||
|
assert!(database.column_exists("clips", "id").expect("column lookup"));
|
||||||
|
database
|
||||||
|
.insert_upload_history(
|
||||||
|
"clip-old",
|
||||||
|
"catbox",
|
||||||
|
"uploaded",
|
||||||
|
Some("https://example.test/old.mp4"),
|
||||||
|
None,
|
||||||
|
SystemTime::now(),
|
||||||
|
)
|
||||||
|
.expect("v2 table usable");
|
||||||
|
let _ = std::fs::remove_file(db_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn round_trips_clip_records() {
|
||||||
|
let db_path = temp_database_path("roundtrip");
|
||||||
let database = ClipDatabase::open(&db_path).expect("database");
|
let database = ClipDatabase::open(&db_path).expect("database");
|
||||||
let clip = Clip {
|
let clip = Clip {
|
||||||
id: "clip-1".to_string(),
|
id: "clip-1".to_string(),
|
||||||
@@ -293,8 +433,52 @@ mod tests {
|
|||||||
SystemTime::now(),
|
SystemTime::now(),
|
||||||
)
|
)
|
||||||
.expect("upload history");
|
.expect("upload history");
|
||||||
|
let history = database.load_upload_history().expect("load upload history");
|
||||||
|
assert_eq!(history.len(), 1);
|
||||||
|
assert_eq!(history[0].clip_id, "clip-1");
|
||||||
database.delete_clip("clip-1").expect("delete");
|
database.delete_clip("clip-1").expect("delete");
|
||||||
assert!(database.load_clips().expect("load empty").is_empty());
|
assert!(database.load_clips().expect("load empty").is_empty());
|
||||||
let _ = std::fs::remove_file(db_path);
|
let _ = std::fs::remove_file(db_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rewrites_stored_paths_to_new_library_root() {
|
||||||
|
let db_path = temp_database_path("rewrite");
|
||||||
|
let database = ClipDatabase::open(&db_path).expect("database");
|
||||||
|
let clip = Clip {
|
||||||
|
id: "clip-1".to_string(),
|
||||||
|
title: None,
|
||||||
|
session_id: "session-1".to_string(),
|
||||||
|
game_id: "counter-strike-2".to_string(),
|
||||||
|
path: PathBuf::from("C:/Old/ClipForge/clips/counter-strike-2/2026-09/clip-1.mp4"),
|
||||||
|
thumbnail_path: Some(PathBuf::from(
|
||||||
|
"C:/Old/ClipForge/thumbs/clip-1.jpg",
|
||||||
|
)),
|
||||||
|
created_at: UNIX_EPOCH + Duration::from_secs(10),
|
||||||
|
duration: Duration::from_secs(60),
|
||||||
|
source: ClipSource::ManualHotkey,
|
||||||
|
event_type: None,
|
||||||
|
tags: Vec::new(),
|
||||||
|
upload_url: None,
|
||||||
|
upload_provider: None,
|
||||||
|
};
|
||||||
|
database.upsert_clip(&clip).expect("upsert");
|
||||||
|
|
||||||
|
let updated = database
|
||||||
|
.rewrite_path_prefix("C:/Old/ClipForge", "C:/Users/alvin/Documents/ClipForge")
|
||||||
|
.expect("rewrite");
|
||||||
|
assert_eq!(updated, 1);
|
||||||
|
|
||||||
|
let loaded = database.load_clips().expect("load");
|
||||||
|
assert_eq!(loaded.len(), 1);
|
||||||
|
assert_eq!(
|
||||||
|
loaded[0].path,
|
||||||
|
PathBuf::from("C:/Users/alvin/Documents/ClipForge/clips/counter-strike-2/2026-09/clip-1.mp4")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
loaded[0].thumbnail_path.as_deref(),
|
||||||
|
Some(Path::new("C:/Users/alvin/Documents/ClipForge/thumbs/clip-1.jpg"))
|
||||||
|
);
|
||||||
|
let _ = std::fs::remove_file(db_path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+268
-6
@@ -170,6 +170,8 @@ impl GameIntegration for ValveGsiIntegration {
|
|||||||
GameEventType::RoundWin
|
GameEventType::RoundWin
|
||||||
} else if lower.contains("match_end") {
|
} else if lower.contains("match_end") {
|
||||||
GameEventType::MatchWin
|
GameEventType::MatchWin
|
||||||
|
} else if lower.contains("match_start") {
|
||||||
|
GameEventType::Bookmark
|
||||||
} else if lower.contains("bomb") {
|
} else if lower.contains("bomb") {
|
||||||
GameEventType::Objective
|
GameEventType::Objective
|
||||||
} else if lower.contains("mvp") {
|
} else if lower.contains("mvp") {
|
||||||
@@ -194,6 +196,10 @@ pub fn valve_gsi_raw_events(
|
|||||||
let mut events = Vec::new();
|
let mut events = Vec::new();
|
||||||
|
|
||||||
// Round events
|
// Round events
|
||||||
|
let round_number = value
|
||||||
|
.pointer("/map/round")
|
||||||
|
.and_then(Value::as_u64)
|
||||||
|
.unwrap_or_default();
|
||||||
if let Some(round_phase) = value
|
if let Some(round_phase) = value
|
||||||
.pointer("/round/phase")
|
.pointer("/round/phase")
|
||||||
.and_then(Value::as_str)
|
.and_then(Value::as_str)
|
||||||
@@ -206,7 +212,19 @@ pub fn valve_gsi_raw_events(
|
|||||||
name: "round_win".to_string(),
|
name: "round_win".to_string(),
|
||||||
timestamp: now,
|
timestamp: now,
|
||||||
player: None,
|
player: None,
|
||||||
metadata: [("win_team".to_string(), win_team.to_string())].into(),
|
metadata: [
|
||||||
|
("win_team".to_string(), win_team.to_string()),
|
||||||
|
("round".to_string(), round_number.to_string()),
|
||||||
|
(
|
||||||
|
"ct_score".to_string(),
|
||||||
|
map_stat_string(&value, "/map/team_ct/score"),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"t_score".to_string(),
|
||||||
|
map_stat_string(&value, "/map/team_t/score"),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
.into(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,11 +234,33 @@ pub fn valve_gsi_raw_events(
|
|||||||
name: "round_start".to_string(),
|
name: "round_start".to_string(),
|
||||||
timestamp: now,
|
timestamp: now,
|
||||||
player: None,
|
player: None,
|
||||||
metadata: BTreeMap::new(),
|
metadata: [("round".to_string(), round_number.to_string())].into(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
"live" => {
|
"live" => {
|
||||||
// Round is live, could track bomb events
|
// Round is live, could track bomb events. A fresh match is live on round 1.
|
||||||
|
if round_number == 1 {
|
||||||
|
events.push(RawGameEvent {
|
||||||
|
event_id: format!("match_start:{}", millis(now)),
|
||||||
|
name: "match_start".to_string(),
|
||||||
|
timestamp: now,
|
||||||
|
player: value
|
||||||
|
.pointer("/player/name")
|
||||||
|
.and_then(Value::as_str)
|
||||||
|
.map(ToString::to_string),
|
||||||
|
metadata: [
|
||||||
|
(
|
||||||
|
"map".to_string(),
|
||||||
|
map_stat_string(&value, "/map/name"),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"mode".to_string(),
|
||||||
|
map_stat_string(&value, "/map/mode"),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
.into(),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@@ -228,6 +268,15 @@ pub fn valve_gsi_raw_events(
|
|||||||
|
|
||||||
// Bomb events (CS2)
|
// Bomb events (CS2)
|
||||||
if let Some(bomb_state) = value.pointer("/round/bomb").and_then(Value::as_str) {
|
if let Some(bomb_state) = value.pointer("/round/bomb").and_then(Value::as_str) {
|
||||||
|
let bomb_region = map_stat_string(&value, "/map/region");
|
||||||
|
let bomb_metadata = |region: String| {
|
||||||
|
let mut metadata = BTreeMap::new();
|
||||||
|
metadata.insert("round".to_string(), round_number.to_string());
|
||||||
|
if !region.is_empty() {
|
||||||
|
metadata.insert("region".to_string(), region);
|
||||||
|
}
|
||||||
|
metadata
|
||||||
|
};
|
||||||
match bomb_state {
|
match bomb_state {
|
||||||
"planted" => {
|
"planted" => {
|
||||||
events.push(RawGameEvent {
|
events.push(RawGameEvent {
|
||||||
@@ -238,7 +287,7 @@ pub fn valve_gsi_raw_events(
|
|||||||
.pointer("/player/name")
|
.pointer("/player/name")
|
||||||
.and_then(Value::as_str)
|
.and_then(Value::as_str)
|
||||||
.map(ToString::to_string),
|
.map(ToString::to_string),
|
||||||
metadata: BTreeMap::new(),
|
metadata: bomb_metadata(bomb_region),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
"defused" => {
|
"defused" => {
|
||||||
@@ -250,7 +299,7 @@ pub fn valve_gsi_raw_events(
|
|||||||
.pointer("/player/name")
|
.pointer("/player/name")
|
||||||
.and_then(Value::as_str)
|
.and_then(Value::as_str)
|
||||||
.map(ToString::to_string),
|
.map(ToString::to_string),
|
||||||
metadata: BTreeMap::new(),
|
metadata: bomb_metadata(bomb_region),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
"exploded" => {
|
"exploded" => {
|
||||||
@@ -259,7 +308,7 @@ pub fn valve_gsi_raw_events(
|
|||||||
name: "bomb_exploded".to_string(),
|
name: "bomb_exploded".to_string(),
|
||||||
timestamp: now,
|
timestamp: now,
|
||||||
player: None,
|
player: None,
|
||||||
metadata: BTreeMap::new(),
|
metadata: bomb_metadata(bomb_region),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@@ -344,6 +393,54 @@ pub fn valve_gsi_raw_events(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dota 2 game-state transitions (GSI posts a periodic snapshot; the auto-clip merge
|
||||||
|
// window collapses repeated posts into a single event)
|
||||||
|
if let Some(game_state) = value.pointer("/map/game_state").and_then(Value::as_str) {
|
||||||
|
let game_time = value
|
||||||
|
.pointer("/map/game_time")
|
||||||
|
.and_then(Value::as_u64)
|
||||||
|
.unwrap_or_default();
|
||||||
|
match game_state {
|
||||||
|
"DOTA_GAMERULES_STATE_GAME_IN_PROGRESS" if game_time < 10 => {
|
||||||
|
events.push(RawGameEvent {
|
||||||
|
event_id: format!("dota_match_start:{}", millis(now)),
|
||||||
|
name: "match_start".to_string(),
|
||||||
|
timestamp: now,
|
||||||
|
player: None,
|
||||||
|
metadata: [
|
||||||
|
("map".to_string(), map_stat_string(&value, "/map/name")),
|
||||||
|
("game_time".to_string(), game_time.to_string()),
|
||||||
|
]
|
||||||
|
.into(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
"DOTA_GAMERULES_STATE_POST_GAME" => {
|
||||||
|
events.push(RawGameEvent {
|
||||||
|
event_id: format!("dota_match_end:{}", millis(now)),
|
||||||
|
name: "match_end".to_string(),
|
||||||
|
timestamp: now,
|
||||||
|
player: None,
|
||||||
|
metadata: [
|
||||||
|
(
|
||||||
|
"radiant_score".to_string(),
|
||||||
|
map_stat_string(&value, "/map/radiant_score"),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"dire_score".to_string(),
|
||||||
|
map_stat_string(&value, "/map/dire_score"),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"win_team".to_string(),
|
||||||
|
map_stat_string(&value, "/map/win_team"),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
.into(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Match end events
|
// Match end events
|
||||||
if let Some(phase) = value.pointer("/map/phase").and_then(Value::as_str) {
|
if let Some(phase) = value.pointer("/map/phase").and_then(Value::as_str) {
|
||||||
if phase == "gameover" {
|
if phase == "gameover" {
|
||||||
@@ -432,6 +529,18 @@ fn millis(time: SystemTime) -> u128 {
|
|||||||
.as_millis()
|
.as_millis()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn map_stat_string(value: &Value, pointer: &str) -> String {
|
||||||
|
match value.pointer(pointer) {
|
||||||
|
Some(inner) => inner
|
||||||
|
.as_str()
|
||||||
|
.map(ToString::to_string)
|
||||||
|
.or_else(|| inner.as_u64().map(|n| n.to_string()))
|
||||||
|
.or_else(|| inner.as_i64().map(|n| n.to_string()))
|
||||||
|
.unwrap_or_default(),
|
||||||
|
None => String::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -486,4 +595,157 @@ mod tests {
|
|||||||
assert_eq!(events[0].name, "triple_kill");
|
assert_eq!(events[0].name, "triple_kill");
|
||||||
assert_eq!(events[0].player.as_deref(), Some("Alvin"));
|
assert_eq!(events[0].player.as_deref(), Some("Alvin"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parses_valve_gsi_round_metadata_and_match_start() {
|
||||||
|
let body = r#"{
|
||||||
|
"round": {"phase": "over", "win_team": "CT"},
|
||||||
|
"map": {
|
||||||
|
"round": 5,
|
||||||
|
"phase": "live",
|
||||||
|
"name": "de_mirage",
|
||||||
|
"mode": "competitive",
|
||||||
|
"team_ct": {"score": 3},
|
||||||
|
"team_t": {"score": 2}
|
||||||
|
}
|
||||||
|
}"#;
|
||||||
|
|
||||||
|
let events = valve_gsi_raw_events(body, SystemTime::UNIX_EPOCH).expect("events");
|
||||||
|
|
||||||
|
let round_win = events
|
||||||
|
.iter()
|
||||||
|
.find(|event| event.name == "round_win")
|
||||||
|
.expect("round win event");
|
||||||
|
assert_eq!(round_win.metadata.get("win_team").map(String::as_str), Some("CT"));
|
||||||
|
assert_eq!(round_win.metadata.get("round").map(String::as_str), Some("5"));
|
||||||
|
assert_eq!(
|
||||||
|
round_win.metadata.get("ct_score").map(String::as_str),
|
||||||
|
Some("3")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
round_win.metadata.get("t_score").map(String::as_str),
|
||||||
|
Some("2")
|
||||||
|
);
|
||||||
|
assert!(!events.iter().any(|event| event.name == "match_start"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parses_valve_gsi_match_start_on_fresh_live_round() {
|
||||||
|
let body = r#"{
|
||||||
|
"round": {"phase": "live"},
|
||||||
|
"map": {"round": 1, "phase": "live", "name": "de_inferno", "mode": "casual"},
|
||||||
|
"player": {"name": "Alvin"}
|
||||||
|
}"#;
|
||||||
|
|
||||||
|
let events = valve_gsi_raw_events(body, SystemTime::UNIX_EPOCH).expect("events");
|
||||||
|
|
||||||
|
let match_start = events
|
||||||
|
.iter()
|
||||||
|
.find(|event| event.name == "match_start")
|
||||||
|
.expect("match start event");
|
||||||
|
assert_eq!(match_start.player.as_deref(), Some("Alvin"));
|
||||||
|
assert_eq!(
|
||||||
|
match_start.metadata.get("map").map(String::as_str),
|
||||||
|
Some("de_inferno")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
match_start.metadata.get("mode").map(String::as_str),
|
||||||
|
Some("casual")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parses_valve_gsi_bomb_plant_region() {
|
||||||
|
let body = r#"{
|
||||||
|
"round": {"phase": "live", "bomb": "planted"},
|
||||||
|
"map": {"round": 2, "region": "b"},
|
||||||
|
"player": {"name": "Alvin"}
|
||||||
|
}"#;
|
||||||
|
|
||||||
|
let events = valve_gsi_raw_events(body, SystemTime::UNIX_EPOCH).expect("events");
|
||||||
|
|
||||||
|
let bomb = events
|
||||||
|
.iter()
|
||||||
|
.find(|event| event.name == "bomb_planted")
|
||||||
|
.expect("bomb planted event");
|
||||||
|
assert_eq!(bomb.player.as_deref(), Some("Alvin"));
|
||||||
|
assert_eq!(
|
||||||
|
bomb.metadata.get("region").map(String::as_str),
|
||||||
|
Some("b")
|
||||||
|
);
|
||||||
|
assert_eq!(bomb.metadata.get("round").map(String::as_str), Some("2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parses_dota2_match_end_with_score_metadata() {
|
||||||
|
let body = r#"{
|
||||||
|
"map": {
|
||||||
|
"game_state": "DOTA_GAMERULES_STATE_POST_GAME",
|
||||||
|
"game_time": 2543,
|
||||||
|
"name": "dota",
|
||||||
|
"radiant_score": 28,
|
||||||
|
"dire_score": 14,
|
||||||
|
"win_team": "radiant"
|
||||||
|
}
|
||||||
|
}"#;
|
||||||
|
|
||||||
|
let events = valve_gsi_raw_events(body, SystemTime::UNIX_EPOCH).expect("events");
|
||||||
|
|
||||||
|
let match_end = events
|
||||||
|
.iter()
|
||||||
|
.find(|event| event.name == "match_end")
|
||||||
|
.expect("match_end event");
|
||||||
|
assert_eq!(
|
||||||
|
match_end.metadata.get("radiant_score").map(String::as_str),
|
||||||
|
Some("28")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
match_end.metadata.get("dire_score").map(String::as_str),
|
||||||
|
Some("14")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
match_end.metadata.get("win_team").map(String::as_str),
|
||||||
|
Some("radiant")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parses_dota2_match_start_on_game_in_progress() {
|
||||||
|
let body = r#"{
|
||||||
|
"map": {
|
||||||
|
"game_state": "DOTA_GAMERULES_STATE_GAME_IN_PROGRESS",
|
||||||
|
"game_time": 4,
|
||||||
|
"name": "dota"
|
||||||
|
}
|
||||||
|
}"#;
|
||||||
|
|
||||||
|
let events = valve_gsi_raw_events(body, SystemTime::UNIX_EPOCH).expect("events");
|
||||||
|
|
||||||
|
let start = events
|
||||||
|
.iter()
|
||||||
|
.find(|event| event.name == "match_start")
|
||||||
|
.expect("match_start event");
|
||||||
|
assert_eq!(
|
||||||
|
start.metadata.get("map").map(String::as_str),
|
||||||
|
Some("dota")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
start.metadata.get("game_time").map(String::as_str),
|
||||||
|
Some("4")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn dota2_ignores_match_start_after_initial_snapshot() {
|
||||||
|
let body = r#"{
|
||||||
|
"map": {
|
||||||
|
"game_state": "DOTA_GAMERULES_STATE_GAME_IN_PROGRESS",
|
||||||
|
"game_time": 30
|
||||||
|
}
|
||||||
|
}"#;
|
||||||
|
|
||||||
|
let events = valve_gsi_raw_events(body, SystemTime::UNIX_EPOCH).expect("events");
|
||||||
|
|
||||||
|
assert!(!events.iter().any(|event| event.name == "match_start"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
|
pub mod screenshot;
|
||||||
pub mod audio;
|
pub mod audio;
|
||||||
pub mod capture;
|
pub mod capture;
|
||||||
|
pub mod crashlog;
|
||||||
pub mod database;
|
pub mod database;
|
||||||
pub mod game_detection;
|
pub mod game_detection;
|
||||||
pub mod game_watcher;
|
pub mod game_watcher;
|
||||||
@@ -12,9 +14,11 @@ pub mod media;
|
|||||||
pub mod models;
|
pub mod models;
|
||||||
pub mod native_audio;
|
pub mod native_audio;
|
||||||
pub mod native_wgc;
|
pub mod native_wgc;
|
||||||
|
pub mod proc;
|
||||||
pub mod recorder;
|
pub mod recorder;
|
||||||
pub mod settings;
|
pub mod settings;
|
||||||
pub mod storage;
|
pub mod storage;
|
||||||
|
pub mod updater;
|
||||||
pub mod upload;
|
pub mod upload;
|
||||||
|
|
||||||
pub use models::{Clip, ClipSource, GameEvent, GameEventType, RecordingStatus, UploadProvider};
|
pub use models::{Clip, ClipSource, GameEvent, GameEventType, RecordingStatus, UploadProvider};
|
||||||
|
|||||||
+4
-4
@@ -1,7 +1,7 @@
|
|||||||
|
use crate::proc::hidden_command;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Command;
|
|
||||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
@@ -96,7 +96,7 @@ pub fn concat_segments(
|
|||||||
}
|
}
|
||||||
fs::write(&list_path, list)?;
|
fs::write(&list_path, list)?;
|
||||||
|
|
||||||
let status = Command::new(ffmpeg)
|
let status = hidden_command(ffmpeg)
|
||||||
.args([
|
.args([
|
||||||
"-y",
|
"-y",
|
||||||
"-hide_banner",
|
"-hide_banner",
|
||||||
@@ -137,7 +137,7 @@ pub fn trim_clip(
|
|||||||
fs::create_dir_all(parent)?;
|
fs::create_dir_all(parent)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let status = Command::new(ffmpeg)
|
let status = hidden_command(ffmpeg)
|
||||||
.args([
|
.args([
|
||||||
"-y",
|
"-y",
|
||||||
"-hide_banner",
|
"-hide_banner",
|
||||||
@@ -168,7 +168,7 @@ pub fn generate_thumbnail(ffmpeg: &Path, input: &Path, output: &Path) -> Result<
|
|||||||
fs::create_dir_all(parent)?;
|
fs::create_dir_all(parent)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let status = Command::new(ffmpeg)
|
let status = hidden_command(ffmpeg)
|
||||||
.args([
|
.args([
|
||||||
"-y",
|
"-y",
|
||||||
"-hide_banner",
|
"-hide_banner",
|
||||||
|
|||||||
@@ -111,6 +111,17 @@ pub struct Clip {
|
|||||||
pub upload_provider: Option<UploadProvider>,
|
pub upload_provider: Option<UploadProvider>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct UploadHistoryEntry {
|
||||||
|
pub id: i64,
|
||||||
|
pub clip_id: String,
|
||||||
|
pub provider: String,
|
||||||
|
pub status: String,
|
||||||
|
pub url: Option<String>,
|
||||||
|
pub error: Option<String>,
|
||||||
|
pub attempted_at: SystemTime,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum RecordingStatus {
|
pub enum RecordingStatus {
|
||||||
WaitingForGame,
|
WaitingForGame,
|
||||||
|
|||||||
+63
-13
@@ -1,6 +1,33 @@
|
|||||||
use crate::capture::{CaptureBackend, CaptureConfig, CaptureError};
|
use crate::capture::{CaptureBackend, CaptureConfig, CaptureError};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
pub(crate) fn downscale_to_cap(
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
cap_width: u32,
|
||||||
|
cap_height: u32,
|
||||||
|
) -> (u32, u32) {
|
||||||
|
if width == 0 || height == 0 || cap_width == 0 || cap_height == 0 {
|
||||||
|
return (even_capped_dimension(width, cap_width), even_capped_dimension(height, cap_height));
|
||||||
|
}
|
||||||
|
let scale = (cap_width as f32 / width as f32).min(cap_height as f32 / height as f32);
|
||||||
|
if scale >= 1.0 {
|
||||||
|
return (
|
||||||
|
even_capped_dimension(width, cap_width),
|
||||||
|
even_capped_dimension(height, cap_height),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
(
|
||||||
|
even_capped_dimension((width as f32 * scale).round() as u32, cap_width),
|
||||||
|
even_capped_dimension((height as f32 * scale).round() as u32, cap_height),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn even_capped_dimension(value: u32, cap: u32) -> u32 {
|
||||||
|
let value = value.min(cap).max(2);
|
||||||
|
value - (value % 2)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
mod windows_impl {
|
mod windows_impl {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -488,10 +515,6 @@ mod windows_impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn even_dimension(value: u32) -> u32 {
|
|
||||||
value.saturating_sub(value % 2).max(2)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_window_for_source(
|
fn find_window_for_source(
|
||||||
source: &crate::capture::CaptureSource,
|
source: &crate::capture::CaptureSource,
|
||||||
) -> Result<Option<Window>, HandlerError> {
|
) -> Result<Option<Window>, HandlerError> {
|
||||||
@@ -526,25 +549,24 @@ mod windows_impl {
|
|||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn window_size(window: Window, fallback_width: u32, fallback_height: u32) -> (u32, u32) {
|
fn window_size(window: Window, cap_width: u32, cap_height: u32) -> (u32, u32) {
|
||||||
let width = window
|
let width = window
|
||||||
.width()
|
.width()
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|value| u32::try_from(value.max(0)).ok())
|
.and_then(|value| u32::try_from(value.max(0)).ok())
|
||||||
.unwrap_or(fallback_width);
|
.unwrap_or(cap_width);
|
||||||
let height = window
|
let height = window
|
||||||
.height()
|
.height()
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|value| u32::try_from(value.max(0)).ok())
|
.and_then(|value| u32::try_from(value.max(0)).ok())
|
||||||
.unwrap_or(fallback_height);
|
.unwrap_or(cap_height);
|
||||||
(even_dimension(width), even_dimension(height))
|
downscale_to_cap(width, height, cap_width, cap_height)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn monitor_size(monitor: Monitor, fallback_width: u32, fallback_height: u32) -> (u32, u32) {
|
fn monitor_size(monitor: Monitor, cap_width: u32, cap_height: u32) -> (u32, u32) {
|
||||||
(
|
let width = monitor.width().unwrap_or(cap_width);
|
||||||
even_dimension(monitor.width().unwrap_or(fallback_width)),
|
let height = monitor.height().unwrap_or(cap_height);
|
||||||
even_dimension(monitor.height().unwrap_or(fallback_height)),
|
downscale_to_cap(width, height, cap_width, cap_height)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recording_settings<T: TryInto<GraphicsCaptureItemType> + Send + 'static>(
|
fn recording_settings<T: TryInto<GraphicsCaptureItemType> + Send + 'static>(
|
||||||
@@ -669,6 +691,34 @@ impl CaptureBackend for NativeWgcReplayCaptureBackend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod downscale_tests {
|
||||||
|
use super::downscale_to_cap;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn keeps_resolution_at_or_below_the_cap() {
|
||||||
|
assert_eq!(downscale_to_cap(2560, 1440, 1280, 720), (1280, 720));
|
||||||
|
assert_eq!(downscale_to_cap(1920, 1080, 1280, 720), (1280, 720));
|
||||||
|
assert_eq!(downscale_to_cap(3840, 2160, 1920, 1080), (1920, 1080));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn leaves_smaller_sources_unchanged() {
|
||||||
|
assert_eq!(downscale_to_cap(800, 600, 1280, 720), (800, 600));
|
||||||
|
assert_eq!(downscale_to_cap(1280, 720, 1280, 720), (1280, 720));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn preserves_aspect_ratio_and_even_dimensions_when_downscaling() {
|
||||||
|
let (width, height) = downscale_to_cap(2000, 1000, 1000, 600);
|
||||||
|
assert_eq!(width % 2, 0);
|
||||||
|
assert_eq!(height % 2, 0);
|
||||||
|
assert!(width <= 1000);
|
||||||
|
assert!(height <= 600);
|
||||||
|
assert_eq!(width as f32 / height as f32, 2000.0 / 1000.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(all(test, target_os = "windows"))]
|
#[cfg(all(test, target_os = "windows"))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
use std::path::Path;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
/// Builds a `Command` that never shows a console window on Windows. FFmpeg and other
|
||||||
|
/// console subprocesses otherwise flash a terminal window each time they start from a
|
||||||
|
/// GUI (Tauri) process, which looks like the app constantly opening and closing.
|
||||||
|
pub fn hidden_command(program: impl AsRef<Path>) -> Command {
|
||||||
|
let mut command = Command::new(program.as_ref());
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
use std::os::windows::process::CommandExt;
|
||||||
|
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
|
||||||
|
command.creation_flags(CREATE_NO_WINDOW);
|
||||||
|
}
|
||||||
|
command
|
||||||
|
}
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
use crate::capture::{CaptureConfig, CaptureError, CaptureMethod, CaptureSource, EncoderPreference};
|
||||||
|
use crate::proc::hidden_command;
|
||||||
|
use dirs;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
|
impl Default for ScreenshotCapture {
|
||||||
|
fn default() -> Self {
|
||||||
|
let output_dir = default_screenshot_dir();
|
||||||
|
Self {
|
||||||
|
executable: default_ffmpeg_executable(),
|
||||||
|
output_dir,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_ffmpeg_executable() -> PathBuf {
|
||||||
|
let bundled = std::env::current_exe()
|
||||||
|
.ok()
|
||||||
|
.and_then(|path| path.parent().map(|parent| parent.to_path_buf()))
|
||||||
|
.map(|parent| parent.join("ffmpeg-x86_64-pc-windows-msvc.exe"));
|
||||||
|
if let Some(path) = bundled {
|
||||||
|
if path.exists() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PathBuf::from("ffmpeg")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_screenshot_dir() -> PathBuf {
|
||||||
|
let home = dirs::home_dir().unwrap_or_else(|| PathBuf::from("."));
|
||||||
|
home.join("Pictures").join("ClipForge")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn screenshot_dir() -> PathBuf {
|
||||||
|
default_screenshot_dir()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn list_screenshots() -> Vec<PathBuf> {
|
||||||
|
let dir = default_screenshot_dir();
|
||||||
|
let Ok(entries) = std::fs::read_dir(&dir) else {
|
||||||
|
return Vec::new();
|
||||||
|
};
|
||||||
|
let mut screenshots = entries
|
||||||
|
.flatten()
|
||||||
|
.map(|entry| entry.path())
|
||||||
|
.filter(|path| {
|
||||||
|
path.is_file()
|
||||||
|
&& path
|
||||||
|
.extension()
|
||||||
|
.map(|ext| {
|
||||||
|
ext.eq_ignore_ascii_case("png")
|
||||||
|
|| ext.eq_ignore_ascii_case("jpg")
|
||||||
|
|| ext.eq_ignore_ascii_case("jpeg")
|
||||||
|
})
|
||||||
|
.unwrap_or(false)
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
screenshots.sort_by_key(|path| {
|
||||||
|
std::fs::metadata(path)
|
||||||
|
.and_then(|meta| meta.created())
|
||||||
|
.ok()
|
||||||
|
});
|
||||||
|
screenshots
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn take_screenshot() -> Result<PathBuf, CaptureError> {
|
||||||
|
let capture = ScreenshotCapture::default();
|
||||||
|
let config = CaptureConfig {
|
||||||
|
source: CaptureSource::Desktop,
|
||||||
|
method: CaptureMethod::DesktopDuplication,
|
||||||
|
width: 1920,
|
||||||
|
height: 1080,
|
||||||
|
fps: 30,
|
||||||
|
bitrate_kbps: 6000,
|
||||||
|
encoder: EncoderPreference::HardwareH264,
|
||||||
|
system_audio_enabled: false,
|
||||||
|
mic_enabled: false,
|
||||||
|
system_audio_device: None,
|
||||||
|
mic_device: None,
|
||||||
|
separate_audio_tracks: false,
|
||||||
|
};
|
||||||
|
capture.capture(&config)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct ScreenshotCapture {
|
||||||
|
executable: PathBuf,
|
||||||
|
output_dir: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ScreenshotCapture {
|
||||||
|
pub fn new(executable: impl Into<PathBuf>, output_dir: impl Into<PathBuf>) -> Self {
|
||||||
|
Self {
|
||||||
|
executable: executable.into(),
|
||||||
|
output_dir: output_dir.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn capture(&self, config: &CaptureConfig) -> Result<PathBuf, CaptureError> {
|
||||||
|
let now = SystemTime::now();
|
||||||
|
let timestamp = now.duration_since(UNIX_EPOCH).unwrap_or_default().as_millis();
|
||||||
|
let output_path = self.output_dir.join(format!("screenshot-{}.png", timestamp));
|
||||||
|
|
||||||
|
std::fs::create_dir_all(&self.output_dir).map_err(|e| CaptureError::DeviceUnavailable(e.to_string()))?;
|
||||||
|
|
||||||
|
let size = format!("{}x{}", config.width, config.height);
|
||||||
|
let fps = config.fps.to_string();
|
||||||
|
|
||||||
|
let mut args = vec![
|
||||||
|
"-y".to_string(),
|
||||||
|
"-hide_banner".to_string(),
|
||||||
|
"-loglevel".to_string(),
|
||||||
|
"error".to_string(),
|
||||||
|
];
|
||||||
|
|
||||||
|
match config.method {
|
||||||
|
CaptureMethod::DesktopDuplication => {
|
||||||
|
args.extend([
|
||||||
|
"-f".to_string(),
|
||||||
|
"lavfi".to_string(),
|
||||||
|
"-i".to_string(),
|
||||||
|
format!("ddagrab=framerate={fps}:video_size={size},hwdownload,format=bgra"),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
CaptureMethod::GdiGrab => {
|
||||||
|
args.extend([
|
||||||
|
"-f".to_string(),
|
||||||
|
"gdigrab".to_string(),
|
||||||
|
"-framerate".to_string(),
|
||||||
|
fps,
|
||||||
|
"-video_size".to_string(),
|
||||||
|
size,
|
||||||
|
"-i".to_string(),
|
||||||
|
"desktop".to_string(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
args.extend([
|
||||||
|
"-vframes".to_string(),
|
||||||
|
"1".to_string(),
|
||||||
|
"-update".to_string(),
|
||||||
|
"1".to_string(),
|
||||||
|
output_path.display().to_string(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
let status = hidden_command(&self.executable)
|
||||||
|
.args(&args)
|
||||||
|
.status()
|
||||||
|
.map_err(|e| CaptureError::DeviceUnavailable(e.to_string()))?;
|
||||||
|
|
||||||
|
if !status.success() {
|
||||||
|
return Err(CaptureError::DeviceUnavailable("FFmpeg screenshot failed".to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(output_path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::capture::{CaptureMethod, CaptureSource, EncoderPreference};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_screenshot_args() {
|
||||||
|
let _config = CaptureConfig {
|
||||||
|
source: CaptureSource::Desktop,
|
||||||
|
method: CaptureMethod::GdiGrab,
|
||||||
|
width: 1920,
|
||||||
|
height: 1080,
|
||||||
|
fps: 30,
|
||||||
|
bitrate_kbps: 6000,
|
||||||
|
encoder: EncoderPreference::HardwareH264,
|
||||||
|
system_audio_enabled: false,
|
||||||
|
mic_enabled: false,
|
||||||
|
system_audio_device: None,
|
||||||
|
mic_device: None,
|
||||||
|
separate_audio_tracks: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
let capture = ScreenshotCapture::new("ffmpeg", "screenshots");
|
||||||
|
assert_eq!(capture.output_dir, PathBuf::from("screenshots"));
|
||||||
|
assert_eq!(capture.executable, PathBuf::from("ffmpeg"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -89,6 +89,10 @@ pub struct AppSettings {
|
|||||||
pub auto_clip: AutoClipSettings,
|
pub auto_clip: AutoClipSettings,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub upload: UploadSettings,
|
pub upload: UploadSettings,
|
||||||
|
#[serde(default)]
|
||||||
|
pub quality_overrides_by_game: BTreeMap<String, QualityPreset>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub onboarding_complete: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppSettings {
|
impl AppSettings {
|
||||||
@@ -134,9 +138,17 @@ impl AppSettings {
|
|||||||
enabled_events_by_game: BTreeMap::new(),
|
enabled_events_by_game: BTreeMap::new(),
|
||||||
},
|
},
|
||||||
upload: UploadSettings::default(),
|
upload: UploadSettings::default(),
|
||||||
|
quality_overrides_by_game: BTreeMap::new(),
|
||||||
|
onboarding_complete: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn effective_quality_for(&self, game_id: &str) -> &QualityPreset {
|
||||||
|
self.quality_overrides_by_game
|
||||||
|
.get(game_id)
|
||||||
|
.unwrap_or(&self.quality)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn clamp_replay_buffer(&mut self) {
|
pub fn clamp_replay_buffer(&mut self) {
|
||||||
self.replay_buffer = self
|
self.replay_buffer = self
|
||||||
.replay_buffer
|
.replay_buffer
|
||||||
@@ -219,6 +231,36 @@ mod tests {
|
|||||||
let _ = fs::remove_dir_all(root);
|
let _ = fs::remove_dir_all(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn quality_overrides_round_trip_and_apply_per_game() {
|
||||||
|
let root = std::env::temp_dir().join(format!(
|
||||||
|
"clipforge-settings-overrides-{}",
|
||||||
|
SystemTimeCompat::millis()
|
||||||
|
));
|
||||||
|
let mut settings = AppSettings::default_for_root(&root);
|
||||||
|
settings.quality_overrides_by_game.insert(
|
||||||
|
"counter-strike-2".to_string(),
|
||||||
|
QualityPreset {
|
||||||
|
name: "Competitive 1080p60".to_string(),
|
||||||
|
width: 1920,
|
||||||
|
height: 1080,
|
||||||
|
fps: 60,
|
||||||
|
bitrate_kbps: 12_000,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
save_settings(&root, &settings).expect("save");
|
||||||
|
let loaded = load_or_create_settings(&root).expect("load");
|
||||||
|
|
||||||
|
let override_quality = loaded
|
||||||
|
.effective_quality_for("counter-strike-2");
|
||||||
|
assert_eq!(override_quality.width, 1920);
|
||||||
|
assert_eq!(override_quality.fps, 60);
|
||||||
|
assert_eq!(loaded.effective_quality_for("league-of-leagues").width, 1280);
|
||||||
|
assert!(loaded.quality_overrides_by_game.contains_key("counter-strike-2"));
|
||||||
|
let _ = fs::remove_dir_all(root);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn legacy_settings_migrate_upload_defaults() {
|
fn legacy_settings_migrate_upload_defaults() {
|
||||||
let root = std::env::temp_dir().join(format!(
|
let root = std::env::temp_dir().join(format!(
|
||||||
@@ -247,6 +289,31 @@ mod tests {
|
|||||||
let _ = fs::remove_dir_all(root);
|
let _ = fs::remove_dir_all(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn new_install_starts_onboarding_and_legacy_config_upgrades_it() {
|
||||||
|
let root = std::env::temp_dir().join(format!(
|
||||||
|
"clipforge-settings-onboarding-{}",
|
||||||
|
SystemTimeCompat::millis()
|
||||||
|
));
|
||||||
|
fs::create_dir_all(&root).expect("settings root");
|
||||||
|
let mut value =
|
||||||
|
serde_json::to_value(AppSettings::default_for_root(&root)).expect("settings json");
|
||||||
|
value
|
||||||
|
.as_object_mut()
|
||||||
|
.expect("settings object")
|
||||||
|
.remove("onboarding_complete");
|
||||||
|
fs::write(
|
||||||
|
settings_path(&root),
|
||||||
|
serde_json::to_string_pretty(&value).expect("legacy settings"),
|
||||||
|
)
|
||||||
|
.expect("write legacy settings");
|
||||||
|
|
||||||
|
let loaded = load_or_create_settings(&root).expect("load migrated settings");
|
||||||
|
|
||||||
|
assert!(!loaded.onboarding_complete);
|
||||||
|
let _ = fs::remove_dir_all(root);
|
||||||
|
}
|
||||||
|
|
||||||
struct SystemTimeCompat;
|
struct SystemTimeCompat;
|
||||||
|
|
||||||
impl SystemTimeCompat {
|
impl SystemTimeCompat {
|
||||||
|
|||||||
+204
@@ -114,6 +114,69 @@ pub struct StorageCleanupReport {
|
|||||||
pub remaining_bytes: u64,
|
pub remaining_bytes: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum StorageLevel {
|
||||||
|
Ok,
|
||||||
|
Warning,
|
||||||
|
Critical,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub struct StorageSpace {
|
||||||
|
pub total_bytes: u64,
|
||||||
|
pub available_bytes: u64,
|
||||||
|
pub level: StorageLevel,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StorageSpace {
|
||||||
|
pub fn free_gb(&self) -> f64 {
|
||||||
|
self.available_bytes as f64 / (1024.0 * 1024.0 * 1024.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn check_storage_space(root: &Path) -> StorageSpace {
|
||||||
|
let disks = sysinfo::Disks::new_with_refreshed_list();
|
||||||
|
let mount = disks
|
||||||
|
.list()
|
||||||
|
.iter()
|
||||||
|
.find(|disk| path_is_on_mount(root, disk.mount_point()))
|
||||||
|
.or_else(|| disks.list().first());
|
||||||
|
let valid = |disk: Option<&sysinfo::Disk>| -> Option<(u64, u64)> {
|
||||||
|
disk.map(|disk| (disk.total_space(), disk.available_space()))
|
||||||
|
};
|
||||||
|
let (total, available) = valid(mount).unwrap_or((0, 0));
|
||||||
|
let warning_at = bytes_for_gb(5);
|
||||||
|
let critical_at = bytes_for_gb(2);
|
||||||
|
let level = if available < critical_at {
|
||||||
|
StorageLevel::Critical
|
||||||
|
} else if available < warning_at {
|
||||||
|
StorageLevel::Warning
|
||||||
|
} else {
|
||||||
|
StorageLevel::Ok
|
||||||
|
};
|
||||||
|
StorageSpace {
|
||||||
|
total_bytes: total,
|
||||||
|
available_bytes: available,
|
||||||
|
level,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bytes_for_gb(gb: u64) -> u64 {
|
||||||
|
gb * 1024 * 1024 * 1024
|
||||||
|
}
|
||||||
|
|
||||||
|
fn path_is_on_mount(path: &Path, mount: &Path) -> bool {
|
||||||
|
let path = path
|
||||||
|
.to_str()
|
||||||
|
.map(|value| value.to_ascii_lowercase())
|
||||||
|
.unwrap_or_default();
|
||||||
|
let mount = mount
|
||||||
|
.to_str()
|
||||||
|
.map(|value| value.to_ascii_lowercase())
|
||||||
|
.unwrap_or_default();
|
||||||
|
path == mount || path.starts_with(&mount)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn cleanup_oldest_files_until_under_limit(
|
pub fn cleanup_oldest_files_until_under_limit(
|
||||||
root: &Path,
|
root: &Path,
|
||||||
max_bytes: u64,
|
max_bytes: u64,
|
||||||
@@ -173,6 +236,82 @@ fn collect_files(root: &Path) -> io::Result<Vec<FileFact>> {
|
|||||||
Ok(files)
|
Ok(files)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn default_library_root() -> PathBuf {
|
||||||
|
dirs::document_dir()
|
||||||
|
.map(|docs| docs.join("ClipForge"))
|
||||||
|
.or_else(|| dirs::home_dir().map(|home| home.join("ClipForge")))
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
std::env::current_dir()
|
||||||
|
.unwrap_or_else(|_| PathBuf::from("."))
|
||||||
|
.join("clipforge-library")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct LibraryResolution {
|
||||||
|
pub root: PathBuf,
|
||||||
|
pub migrated_from: Option<PathBuf>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn resolve_library_root() -> io::Result<LibraryResolution> {
|
||||||
|
let target = default_library_root();
|
||||||
|
let legacy = legacy_library_in_working_dir();
|
||||||
|
if let Some(legacy) = legacy {
|
||||||
|
if legacy != target && !library_has_content(&target) {
|
||||||
|
migrate_library(&legacy, &target)?;
|
||||||
|
return Ok(LibraryResolution {
|
||||||
|
root: target,
|
||||||
|
migrated_from: Some(legacy),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(LibraryResolution {
|
||||||
|
root: target,
|
||||||
|
migrated_from: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn legacy_library_in_working_dir() -> Option<PathBuf> {
|
||||||
|
let cwd = std::env::current_dir().ok()?;
|
||||||
|
let candidate = cwd.join("clipforge-library");
|
||||||
|
candidate.is_dir().then_some(candidate)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn library_has_content(path: &Path) -> bool {
|
||||||
|
if path.join("settings.json").exists() || path.join("library.sqlite").exists() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if let Ok(mut entries) = fs::read_dir(path) {
|
||||||
|
return entries.next().is_some();
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
fn migrate_library(from: &Path, to: &Path) -> io::Result<()> {
|
||||||
|
if let Some(parent) = to.parent() {
|
||||||
|
fs::create_dir_all(parent)?;
|
||||||
|
}
|
||||||
|
if fs::rename(from, to).is_ok() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
copy_dir_all(from, to)?;
|
||||||
|
fs::remove_dir_all(from)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn copy_dir_all(from: &Path, to: &Path) -> io::Result<()> {
|
||||||
|
fs::create_dir_all(to)?;
|
||||||
|
for entry in fs::read_dir(from)? {
|
||||||
|
let entry = entry?;
|
||||||
|
let target = to.join(entry.file_name());
|
||||||
|
if entry.file_type()?.is_dir() {
|
||||||
|
copy_dir_all(&entry.path(), &target)?;
|
||||||
|
} else {
|
||||||
|
fs::copy(entry.path(), &target)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -206,4 +345,69 @@ mod tests {
|
|||||||
assert_eq!(report.remaining_bytes, 10);
|
assert_eq!(report.remaining_bytes, 10);
|
||||||
let _ = fs::remove_dir_all(root);
|
let _ = fs::remove_dir_all(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn storage_space_reports_metrics_for_root() {
|
||||||
|
let root = env::temp_dir();
|
||||||
|
let space = check_storage_space(&root);
|
||||||
|
assert!(space.total_bytes > 0);
|
||||||
|
assert!(space.available_bytes <= space.total_bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn path_is_on_mount_matches_drive_prefix() {
|
||||||
|
let root = if cfg!(windows) {
|
||||||
|
Path::new("C:/Users/ClipForge/Clips")
|
||||||
|
} else {
|
||||||
|
Path::new("/home/clipforge/clips")
|
||||||
|
};
|
||||||
|
let mount = if cfg!(windows) {
|
||||||
|
Path::new("C:")
|
||||||
|
} else {
|
||||||
|
Path::new("/home")
|
||||||
|
};
|
||||||
|
assert!(path_is_on_mount(root, mount));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn default_library_root_prefers_documents_dir() {
|
||||||
|
let root = default_library_root();
|
||||||
|
let docs = dirs::document_dir().expect("documents dir");
|
||||||
|
let expected = docs.join("ClipForge");
|
||||||
|
assert_eq!(root, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn migrates_legacy_library_to_target() {
|
||||||
|
let temp_ns = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.unwrap_or_default()
|
||||||
|
.as_nanos();
|
||||||
|
let from = std::env::temp_dir().join(format!("clipforge-from-{temp_ns}"));
|
||||||
|
let to = std::env::temp_dir().join(format!("clipforge-to-{temp_ns}"));
|
||||||
|
fs::create_dir_all(&from).expect("from");
|
||||||
|
fs::write(from.join("settings.json"), "{}").expect("settings");
|
||||||
|
fs::create_dir_all(to.parent().unwrap()).expect("parent");
|
||||||
|
assert!(from.exists());
|
||||||
|
assert!(!to.exists());
|
||||||
|
|
||||||
|
migrate_library(&from, &to).expect("migrate");
|
||||||
|
|
||||||
|
assert!(!from.exists());
|
||||||
|
assert!(to.join("settings.json").exists());
|
||||||
|
assert!(library_has_content(&to));
|
||||||
|
let _ = fs::remove_dir_all(to);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn library_has_content_reports_empty_directory() {
|
||||||
|
let temp_ns = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.unwrap_or_default()
|
||||||
|
.as_nanos();
|
||||||
|
let dir = std::env::temp_dir().join(format!("clipforge-hascontent-{temp_ns}"));
|
||||||
|
fs::create_dir_all(&dir).expect("dir");
|
||||||
|
assert!(!library_has_content(&dir));
|
||||||
|
let _ = fs::remove_dir_all(dir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+312
@@ -0,0 +1,312 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
use std::fmt;
|
||||||
|
use std::io;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
pub const DEFAULT_UPDATE_REPO: &str = "Alvin-Zilverstand/clipforge-game-clipper";
|
||||||
|
const UPDATE_TIMEOUT_SECS: u64 = 30;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
pub struct GitHubRelease {
|
||||||
|
pub tag_name: String,
|
||||||
|
#[serde(default)]
|
||||||
|
pub published_at: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub body: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub assets: Vec<GitHubAsset>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
|
pub struct GitHubAsset {
|
||||||
|
pub name: String,
|
||||||
|
#[serde(default)]
|
||||||
|
pub size: Option<u64>,
|
||||||
|
pub browser_download_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, PartialEq)]
|
||||||
|
pub struct UpdateCheck {
|
||||||
|
pub update_available: bool,
|
||||||
|
pub latest_version: String,
|
||||||
|
pub installer_file: Option<String>,
|
||||||
|
pub download_url: Option<String>,
|
||||||
|
pub published_at: Option<String>,
|
||||||
|
pub release_notes: Option<String>,
|
||||||
|
pub message: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum UpdateCheckError {
|
||||||
|
Http(String),
|
||||||
|
Json(String),
|
||||||
|
NoReleaseFound,
|
||||||
|
NoInstallerAsset(String),
|
||||||
|
Io(io::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for UpdateCheckError {
|
||||||
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Http(message) => write!(formatter, "Update check HTTP error: {message}"),
|
||||||
|
Self::Json(message) => write!(formatter, "Could not parse update response: {message}"),
|
||||||
|
Self::NoReleaseFound => write!(formatter, "No published releases found yet."),
|
||||||
|
Self::NoInstallerAsset(version) => write!(
|
||||||
|
formatter,
|
||||||
|
"Release {version} has no MSI or NSIS installer asset."
|
||||||
|
),
|
||||||
|
Self::Io(error) => write!(formatter, "Update file error: {error}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for UpdateCheckError {}
|
||||||
|
|
||||||
|
impl From<io::Error> for UpdateCheckError {
|
||||||
|
fn from(error: io::Error) -> Self {
|
||||||
|
Self::Io(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn http_client(current_version: &str) -> Result<reqwest::blocking::Client, UpdateCheckError> {
|
||||||
|
reqwest::blocking::Client::builder()
|
||||||
|
.user_agent(format!("ClipForge/{current_version}"))
|
||||||
|
.timeout(Duration::from_secs(UPDATE_TIMEOUT_SECS))
|
||||||
|
.build()
|
||||||
|
.map_err(|error| UpdateCheckError::Http(error.to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn check_for_updates(
|
||||||
|
repo: &str,
|
||||||
|
current_version: &str,
|
||||||
|
) -> Result<UpdateCheck, UpdateCheckError> {
|
||||||
|
let client = http_client(current_version)?;
|
||||||
|
let url = format!("https://api.github.com/repos/{repo}/releases/latest");
|
||||||
|
let response = client
|
||||||
|
.get(&url)
|
||||||
|
.send()
|
||||||
|
.map_err(|error| UpdateCheckError::Http(error.to_string()))?;
|
||||||
|
|
||||||
|
if response.status() == reqwest::StatusCode::NOT_FOUND {
|
||||||
|
return Err(UpdateCheckError::NoReleaseFound);
|
||||||
|
}
|
||||||
|
if !response.status().is_success() {
|
||||||
|
return Err(UpdateCheckError::Http(format!(
|
||||||
|
"GitHub returned {} for {}",
|
||||||
|
response.status(),
|
||||||
|
url
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
let release: GitHubRelease = response
|
||||||
|
.json()
|
||||||
|
.map_err(|error| UpdateCheckError::Json(error.to_string()))?;
|
||||||
|
|
||||||
|
build_update_check(current_version, &release)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn build_update_check(
|
||||||
|
current_version: &str,
|
||||||
|
release: &GitHubRelease,
|
||||||
|
) -> Result<UpdateCheck, UpdateCheckError> {
|
||||||
|
let latest_version = normalize_version(&release.tag_name);
|
||||||
|
let update_available = compare_versions(current_version, &latest_version) == Ordering::Less;
|
||||||
|
let installer = select_installer_asset(&release.assets);
|
||||||
|
|
||||||
|
let message = if update_available {
|
||||||
|
let file = installer
|
||||||
|
.as_ref()
|
||||||
|
.map(|asset| asset.name.as_str())
|
||||||
|
.unwrap_or("installer");
|
||||||
|
format!(
|
||||||
|
"A newer version ({latest_version}) is available — {file}, ready to download."
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
"You are on the latest version.".to_string()
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(UpdateCheck {
|
||||||
|
update_available,
|
||||||
|
latest_version,
|
||||||
|
installer_file: installer.as_ref().map(|asset| asset.name.clone()),
|
||||||
|
download_url: installer.map(|asset| asset.browser_download_url),
|
||||||
|
published_at: release.published_at.clone(),
|
||||||
|
release_notes: release.body.clone(),
|
||||||
|
message,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn select_installer_asset(assets: &[GitHubAsset]) -> Option<GitHubAsset> {
|
||||||
|
assets
|
||||||
|
.iter()
|
||||||
|
.find(|asset| asset.name.ends_with(".msi"))
|
||||||
|
.or_else(|| {
|
||||||
|
assets.iter().find(|asset| {
|
||||||
|
asset.name.ends_with(".exe") && !asset.name.to_lowercase().contains("uninstall")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.cloned()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn download_installer(
|
||||||
|
url: &str,
|
||||||
|
destination_dir: &Path,
|
||||||
|
file_name: &str,
|
||||||
|
current_version: &str,
|
||||||
|
) -> Result<PathBuf, UpdateCheckError> {
|
||||||
|
std::fs::create_dir_all(destination_dir)?;
|
||||||
|
let destination = destination_dir.join(file_name);
|
||||||
|
let client = http_client(current_version)?;
|
||||||
|
let mut response = client
|
||||||
|
.get(url)
|
||||||
|
.send()
|
||||||
|
.map_err(|error| UpdateCheckError::Http(error.to_string()))?;
|
||||||
|
if !response.status().is_success() {
|
||||||
|
return Err(UpdateCheckError::Http(format!(
|
||||||
|
"Download failed with {}",
|
||||||
|
response.status()
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut file = std::fs::File::create(&destination)?;
|
||||||
|
io::copy(&mut response, &mut file)
|
||||||
|
.map_err(|error| UpdateCheckError::Io(error))?;
|
||||||
|
Ok(destination)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn normalize_version(tag: &str) -> String {
|
||||||
|
tag.trim().trim_start_matches('v').to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn compare_versions(current: &str, latest: &str) -> Ordering {
|
||||||
|
numeric_parts(current).cmp(&numeric_parts(latest))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn numeric_parts(version: &str) -> Vec<u32> {
|
||||||
|
version
|
||||||
|
.trim_start_matches('v')
|
||||||
|
.split('.')
|
||||||
|
.map(|segment| {
|
||||||
|
segment
|
||||||
|
.chars()
|
||||||
|
.take_while(|character| character.is_ascii_digit())
|
||||||
|
.collect::<String>()
|
||||||
|
.parse::<u32>()
|
||||||
|
.unwrap_or(0)
|
||||||
|
})
|
||||||
|
.take(3)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn new_version_is_newer_than_current() {
|
||||||
|
assert_eq!(compare_versions("0.1.0", "0.2.0"), Ordering::Less);
|
||||||
|
assert_eq!(compare_versions("0.1.9", "0.2.0"), Ordering::Less);
|
||||||
|
assert_eq!(compare_versions("0.9.9", "1.0.0"), Ordering::Less);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn old_version_is_not_newer() {
|
||||||
|
assert_eq!(compare_versions("0.2.0", "0.1.0"), Ordering::Greater);
|
||||||
|
assert_eq!(compare_versions("0.3.0", "0.3.0"), Ordering::Equal);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn leading_v_and_prerelease_tags_are_ignored() {
|
||||||
|
assert_eq!(compare_versions("v0.1.0", "v0.2.0"), Ordering::Less);
|
||||||
|
assert_eq!(compare_versions("v0.2.0", "0.2.0"), Ordering::Equal);
|
||||||
|
assert_eq!(compare_versions("0.2.0", "0.2.0-beta.1"), Ordering::Equal);
|
||||||
|
assert_eq!(compare_versions("0.1.0", "0.2.0-beta.1"), Ordering::Less);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn msi_asset_is_preferred_over_exe() {
|
||||||
|
let assets = vec![
|
||||||
|
GitHubAsset {
|
||||||
|
name: "ClipForge_0.2.0_x64-setup.exe".to_string(),
|
||||||
|
size: Some(1),
|
||||||
|
browser_download_url: "https://example.test/setup.exe".to_string(),
|
||||||
|
},
|
||||||
|
GitHubAsset {
|
||||||
|
name: "ClipForge_0.2.0_x64_en-US.msi".to_string(),
|
||||||
|
size: Some(2),
|
||||||
|
browser_download_url: "https://example.test/setup.msi".to_string(),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
let selected = select_installer_asset(&assets).expect("asset");
|
||||||
|
assert_eq!(selected.name, "ClipForge_0.2.0_x64_en-US.msi");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn exe_asset_is_selected_when_no_msi_exists() {
|
||||||
|
let assets = vec![GitHubAsset {
|
||||||
|
name: "ClipForge_0.2.0_x64-setup.exe".to_string(),
|
||||||
|
size: Some(1),
|
||||||
|
browser_download_url: "https://example.test/setup.exe".to_string(),
|
||||||
|
}];
|
||||||
|
let selected = select_installer_asset(&assets).expect("asset");
|
||||||
|
assert_eq!(selected.name, "ClipForge_0.2.0_x64-setup.exe");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn uninstaller_and_unknown_assets_are_rejected() {
|
||||||
|
let assets = vec![
|
||||||
|
GitHubAsset {
|
||||||
|
name: "ClipForge_0.2.0_x64_uninstall.exe".to_string(),
|
||||||
|
size: Some(1),
|
||||||
|
browser_download_url: "https://example.test/uninstall.exe".to_string(),
|
||||||
|
},
|
||||||
|
GitHubAsset {
|
||||||
|
name: "linux-port.AppImage".to_string(),
|
||||||
|
size: Some(1),
|
||||||
|
browser_download_url: "https://example.test/linux.AppImage".to_string(),
|
||||||
|
},
|
||||||
|
GitHubAsset {
|
||||||
|
name: "checksums.txt".to_string(),
|
||||||
|
size: Some(1),
|
||||||
|
browser_download_url: "https://example.test/checksums.txt".to_string(),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
assert!(select_installer_asset(&assets).is_none());
|
||||||
|
assert_eq!(normalize_version("v0.2.0"), "0.2.0");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn update_check_marks_latest_github_release_as_available() {
|
||||||
|
let release = GitHubRelease {
|
||||||
|
tag_name: "v0.2.0".to_string(),
|
||||||
|
published_at: Some("2026-09-01T00:00:00Z".to_string()),
|
||||||
|
body: Some("Update notes".to_string()),
|
||||||
|
assets: vec![GitHubAsset {
|
||||||
|
name: "ClipForge_0.2.0_x64-setup.exe".to_string(),
|
||||||
|
size: Some(1_000_000),
|
||||||
|
browser_download_url: "https://example.test/ClipForge_0.2.0.exe".to_string(),
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
let check = build_update_check("0.1.0", &release).expect("check");
|
||||||
|
assert!(check.update_available);
|
||||||
|
assert_eq!(check.latest_version, "0.2.0");
|
||||||
|
assert_eq!(
|
||||||
|
check.installer_file.as_deref(),
|
||||||
|
Some("ClipForge_0.2.0_x64-setup.exe")
|
||||||
|
);
|
||||||
|
assert_eq!(check.published_at.as_deref(), Some("2026-09-01T00:00:00Z"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore = "requires live network access to the GitHub API"]
|
||||||
|
fn live_check_against_github_repo() {
|
||||||
|
let check = check_for_updates(DEFAULT_UPDATE_REPO, "0.0.1").expect("check");
|
||||||
|
assert!(
|
||||||
|
check.download_url.as_deref().filter(|value| !value.is_empty()).is_some()
|
||||||
|
|| !check.update_available
|
||||||
|
);
|
||||||
|
assert!(!check.latest_version.is_empty());
|
||||||
|
}
|
||||||
|
}
|
||||||
+802
-82
File diff suppressed because it is too large.
Load diff
+185
@@ -164,6 +164,11 @@ h3 {
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.status-pill.warn {
|
||||||
|
background: #7f1d1d;
|
||||||
|
color: #fecaca;
|
||||||
|
}
|
||||||
|
|
||||||
.icon-button,
|
.icon-button,
|
||||||
.record-button,
|
.record-button,
|
||||||
.actions button {
|
.actions button {
|
||||||
@@ -427,6 +432,19 @@ textarea {
|
|||||||
color: #f5f7fb;
|
color: #f5f7fb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.field-row {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
margin-top: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-row label {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
.toggle {
|
.toggle {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -470,6 +488,39 @@ textarea {
|
|||||||
color: #9ba7b8;
|
color: #9ba7b8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.upload-history {
|
||||||
|
display: grid;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 12px;
|
||||||
|
border: 1px solid #2c3140;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #12161d;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-row-main {
|
||||||
|
display: grid;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-row.failed {
|
||||||
|
border-color: #7f1d1d;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-row.uploaded {
|
||||||
|
border-color: #14532d;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-row .status-pill {
|
||||||
|
justify-self: start;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 900px) {
|
@media (max-width: 900px) {
|
||||||
.app-shell,
|
.app-shell,
|
||||||
.content-grid,
|
.content-grid,
|
||||||
@@ -490,3 +541,137 @@ textarea {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Onboarding wizard */
|
||||||
|
.onboarding-shell {
|
||||||
|
grid-template-columns: minmax(0, 1fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
.onboarding-workspace {
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
padding: 40px 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-card {
|
||||||
|
width: min(560px, 100%);
|
||||||
|
background: #17191f;
|
||||||
|
border: 1px solid #2a2e38;
|
||||||
|
border-radius: 16px;
|
||||||
|
padding: 28px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 14px;
|
||||||
|
margin-bottom: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-header h1 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-steps {
|
||||||
|
display: flex;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0 0 22px;
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-steps li {
|
||||||
|
flex: 1;
|
||||||
|
padding: 8px 6px;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #242a36;
|
||||||
|
color: #9ca3af;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-steps li.active {
|
||||||
|
background: #064e3b;
|
||||||
|
color: #6ee7b7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-steps li.done {
|
||||||
|
color: #34d399;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-body h2 {
|
||||||
|
margin: 0 0 8px;
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-body .muted {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-options {
|
||||||
|
display: grid;
|
||||||
|
gap: 4px;
|
||||||
|
margin: 18px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-actions {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
margin-top: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ghost-button,
|
||||||
|
.primary-button {
|
||||||
|
padding: 10px 18px;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ghost-button {
|
||||||
|
background: transparent;
|
||||||
|
border: 1px solid #374151;
|
||||||
|
color: #d1d5db;
|
||||||
|
}
|
||||||
|
|
||||||
|
.primary-button {
|
||||||
|
background: #10b981;
|
||||||
|
border: 1px solid #10b981;
|
||||||
|
color: #06281f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.primary-button:hover {
|
||||||
|
background: #34d399;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hotkey-list {
|
||||||
|
list-style: none;
|
||||||
|
margin: 18px 0 0;
|
||||||
|
padding: 0;
|
||||||
|
display: grid;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hotkey-list li {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
background: #242a36;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hotkey-list kbd {
|
||||||
|
background: #101114;
|
||||||
|
border: 1px solid #374151;
|
||||||
|
border-bottom-width: 2px;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 4px 10px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #f5f7fb;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user