This commit is contained in:
2026-03-30 23:38:47 +02:00
commit c2d1587c82
41 changed files with 1572 additions and 0 deletions

41
.gitignore vendored Normal file
View File

@@ -0,0 +1,41 @@
.settings
.project
.idea
Cargo.lock
package-lock.json
/gen/
# Generated by Cargo
# will have compiled files and executables
/target/
# Generated by Tauri
# will have schema files for capabilities auto-completion
/gen/schemas
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

37
Cargo.toml Normal file
View File

@@ -0,0 +1,37 @@
[package]
name = "tauri-video03"
version = "0.1.0"
description = "A Tauri Video App"
authors = ["sinus@sasedev.net"]
edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
# The `_lib` suffix may seem redundant but it is necessary
# to make the lib name unique and wouldn't conflict with the bin name.
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
name = "tauri_video03_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "2", features = [] }
[dependencies]
base64 = { version = "^0.22", features = [] }
chrono = { version = "^0.4", features = ["clock", "serde"] }
dirs = { version = "^6.0", features = [] }
futures-util = { version = "^0.3", features = [] }
gstreamer = { version = "^0.25", features = ["serde"] }
gstreamer-app = { version = "^0.25", features = [] }
serde = { version = "^1.0", features = ["derive"] }
serde_json = { version = "^1.0", features = [] }
tauri = { version = "^2.10", features = ["default"] }
tauri-plugin-opener = { version = "^2.5", features = [] }
tokio = { version = "^1.50", features = ["full"] }
tokio-tungstenite = { version = "^0.29", features = ["rustls", "tokio-rustls", "url"] }
tracing = { version = "^0.1", features = ["async-await", "log"] }
tracing-subscriber = { version = "^0.3", features = ["ansi", "env-filter", "chrono", "serde", "json"] }
ts-rs = { version = "^12.0", features = [] }
uuid = { version = "^1.23", features = [] }
webrtc = { version = "^0.17", features = [] }

7
README.md Normal file
View File

@@ -0,0 +1,7 @@
# Tauri + Vanilla TS
This template should help get you started developing with Tauri in vanilla HTML, CSS and Typescript.
## Recommended IDE Setup
- [VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)

3
build.rs Normal file
View File

@@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}

10
capabilities/default.json Normal file
View File

@@ -0,0 +1,10 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"core:default",
"opener:default"
]
}

View File

@@ -0,0 +1,6 @@
<svg width="206" height="231" viewBox="0 0 206 231" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M143.143 84C143.143 96.1503 133.293 106 121.143 106C108.992 106 99.1426 96.1503 99.1426 84C99.1426 71.8497 108.992 62 121.143 62C133.293 62 143.143 71.8497 143.143 84Z" fill="#FFC131"/>
<ellipse cx="84.1426" cy="147" rx="22" ry="22" transform="rotate(180 84.1426 147)" fill="#24C8DB"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M166.738 154.548C157.86 160.286 148.023 164.269 137.757 166.341C139.858 160.282 141 153.774 141 147C141 144.543 140.85 142.121 140.558 139.743C144.975 138.204 149.215 136.139 153.183 133.575C162.73 127.404 170.292 118.608 174.961 108.244C179.63 97.8797 181.207 86.3876 179.502 75.1487C177.798 63.9098 172.884 53.4021 165.352 44.8883C157.82 36.3744 147.99 30.2165 137.042 27.1546C126.095 24.0926 114.496 24.2568 103.64 27.6274C92.7839 30.998 83.1319 37.4317 75.8437 46.1553C74.9102 47.2727 74.0206 48.4216 73.176 49.5993C61.9292 50.8488 51.0363 54.0318 40.9629 58.9556C44.2417 48.4586 49.5653 38.6591 56.679 30.1442C67.0505 17.7298 80.7861 8.57426 96.2354 3.77762C111.685 -1.01901 128.19 -1.25267 143.769 3.10474C159.348 7.46215 173.337 16.2252 184.056 28.3411C194.775 40.457 201.767 55.4101 204.193 71.404C206.619 87.3978 204.374 103.752 197.73 118.501C191.086 133.25 180.324 145.767 166.738 154.548ZM41.9631 74.275L62.5557 76.8042C63.0459 72.813 63.9401 68.9018 65.2138 65.1274C57.0465 67.0016 49.2088 70.087 41.9631 74.275Z" fill="#FFC131"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M38.4045 76.4519C47.3493 70.6709 57.2677 66.6712 67.6171 64.6132C65.2774 70.9669 64 77.8343 64 85.0001C64 87.1434 64.1143 89.26 64.3371 91.3442C60.0093 92.8732 55.8533 94.9092 51.9599 97.4256C42.4128 103.596 34.8505 112.392 30.1816 122.756C25.5126 133.12 23.9357 144.612 25.6403 155.851C27.3449 167.09 32.2584 177.598 39.7906 186.112C47.3227 194.626 57.153 200.784 68.1003 203.846C79.0476 206.907 90.6462 206.743 101.502 203.373C112.359 200.002 122.011 193.568 129.299 184.845C130.237 183.722 131.131 182.567 131.979 181.383C143.235 180.114 154.132 176.91 164.205 171.962C160.929 182.49 155.596 192.319 148.464 200.856C138.092 213.27 124.357 222.426 108.907 227.222C93.458 232.019 76.9524 232.253 61.3736 227.895C45.7948 223.538 31.8055 214.775 21.0867 202.659C10.3679 190.543 3.37557 175.59 0.949823 159.596C-1.47592 143.602 0.768139 127.248 7.41237 112.499C14.0566 97.7497 24.8183 85.2327 38.4045 76.4519ZM163.062 156.711L163.062 156.711C162.954 156.773 162.846 156.835 162.738 156.897C162.846 156.835 162.954 156.773 163.062 156.711Z" fill="#24C8DB"/>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="512.000000pt" height="512.000000pt" viewBox="0 0 512.000000 512.000000"
preserveAspectRatio="xMidYMid meet">
<g transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)"
fill="#2D79C7" stroke="none">
<path d="M430 5109 c-130 -19 -248 -88 -325 -191 -53 -71 -83 -147 -96 -247
-6 -49 -9 -813 -7 -2166 l3 -2090 22 -65 c54 -159 170 -273 328 -323 l70 -22
2140 0 2140 0 66 23 c160 55 272 169 322 327 l22 70 0 2135 0 2135 -22 70
c-49 157 -155 265 -319 327 l-59 23 -2115 1 c-1163 1 -2140 -2 -2170 -7z
m3931 -2383 c48 -9 120 -26 160 -39 l74 -23 3 -237 c1 -130 0 -237 -2 -237 -3
0 -26 14 -53 30 -61 38 -197 84 -310 106 -110 20 -293 15 -368 -12 -111 -39
-175 -110 -175 -193 0 -110 97 -197 335 -300 140 -61 309 -146 375 -189 30
-20 87 -68 126 -107 119 -117 164 -234 164 -426 0 -310 -145 -518 -430 -613
-131 -43 -248 -59 -445 -60 -243 -1 -405 24 -577 90 l-68 26 0 242 c0 175 -3
245 -12 254 -9 9 -9 12 0 12 7 0 12 -4 12 -9 0 -17 139 -102 223 -138 136 -57
233 -77 382 -76 145 0 224 19 295 68 75 52 100 156 59 242 -41 84 -135 148
-374 253 -367 161 -522 300 -581 520 -23 86 -23 253 -1 337 73 275 312 448
682 492 109 13 401 6 506 -13z m-1391 -241 l0 -205 -320 0 -320 0 0 -915 0
-915 -255 0 -255 0 0 915 0 915 -320 0 -320 0 0 205 0 205 895 0 895 0 0 -205z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

1
frontend/assets/vite.svg Normal file
View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

61
frontend/index.html Normal file
View File

@@ -0,0 +1,61 @@
<!doctype html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="styles.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; connect-src 'self';" />
<title>Tauri GST Record + Preview</title>
</head>
<body>
<main class="container">
<h1>POC 2 - Recording + Preview</h1>
<section class="card">
<h2>Video Preview</h2>
<div class="preview-wrap">
<img id="video-preview" alt="Video preview" />
</div>
</section>
<section class="card">
<h2>Audio + Video</h2>
<div class="actions">
<button id="start-av-btn" type="button">Start AV</button>
<button id="stop-av-btn" type="button" disabled>Stop AV</button>
</div>
<pre id="av-status">Ready.</pre>
</section>
<section class="card">
<h2>Video</h2>
<div class="actions">
<button id="start-video-btn" type="button">Start video</button>
<button id="stop-video-btn" type="button" disabled>Stop
video</button>
</div>
<pre id="video-status">Ready.</pre>
</section>
<section class="card">
<h2>Audio</h2>
<div class="actions">
<button id="start-audio-btn" type="button">Start audio</button>
<button id="stop-audio-btn" type="button" disabled>Stop
audio</button>
</div>
<pre id="audio-status">Ready.</pre>
</section>
</main>
<script type="module" src="main.ts" defer></script>
</body>
</html>

322
frontend/main.ts Normal file
View File

@@ -0,0 +1,322 @@
import { invoke } from "@tauri-apps/api/core";
import { AvStartResponse } from './ts/bindings/AvStartResponse';
import { AvStopResponse } from './ts/bindings/AvStopResponse';
type Mode = "idle" | "audio" | "video" | "av";
const startAudioBtn = document.querySelector<HTMLButtonElement>("#start-audio-btn");
const stopAudioBtn = document.querySelector<HTMLButtonElement>("#stop-audio-btn");
const audioStatus = document.querySelector<HTMLElement>("#audio-status");
const startVideoBtn = document.querySelector<HTMLButtonElement>("#start-video-btn");
const stopVideoBtn = document.querySelector<HTMLButtonElement>("#stop-video-btn");
const videoStatus = document.querySelector<HTMLElement>("#video-status");
const startAvBtn = document.querySelector<HTMLButtonElement>("#start-av-btn");
const stopAvBtn = document.querySelector<HTMLButtonElement>("#stop-av-btn");
const avStatus = document.querySelector<HTMLElement>("#av-status");
const previewElement = document.querySelector<HTMLImageElement>("#video-preview");
if (
startAudioBtn === null ||
stopAudioBtn === null ||
audioStatus === null ||
startVideoBtn === null ||
stopVideoBtn === null ||
videoStatus === null ||
startAvBtn === null ||
stopAvBtn === null ||
avStatus === null ||
previewElement === null
) {
throw new Error("missing UI elements");
}
let currentMode: Mode = "idle";
let previewTimer: number | null = null;
let previewRequestInFlight = false;
let previewObjectUrl: string | null = null;
function setAudioStatus(message: string): void {
if (audioStatus)
audioStatus.textContent = message;
}
function setVideoStatus(message: string): void {
if (videoStatus)
videoStatus.textContent = message;
}
function setAvStatus(message: string): void {
if (avStatus)
avStatus.textContent = message;
}
function setAudioButtons(isRecording: boolean): void {
if (startAudioBtn)
startAudioBtn.disabled = isRecording;
if (stopAudioBtn)
stopAudioBtn.disabled = !isRecording;
}
function setVideoButtons(isRecording: boolean): void {
if (startVideoBtn)
startVideoBtn.disabled = isRecording;
if (stopVideoBtn)
stopVideoBtn.disabled = !isRecording;
}
function setAvButtons(isRecording: boolean): void {
if (startAvBtn)
startAvBtn.disabled = isRecording;
if (stopAvBtn)
stopAvBtn.disabled = !isRecording;
}
function setAllButtonsForMode(mode: Mode): void {
if (mode === "idle") {
setAudioButtons(false);
setVideoButtons(false);
setAvButtons(false);
return;
}
setAudioButtons(mode === "audio");
setVideoButtons(mode === "video");
setAvButtons(mode === "av");
if (mode !== "audio") {
if (stopAudioBtn)
stopAudioBtn.disabled = true;
if (startAudioBtn)
startAudioBtn.disabled = true;
}
if (mode !== "video") {
if (stopVideoBtn)
stopVideoBtn.disabled = true;
if (startVideoBtn)
startVideoBtn.disabled = true;
}
if (mode !== "av") {
if (stopAvBtn)
stopAvBtn.disabled = true;
if (startAvBtn)
startAvBtn.disabled = true;
}
}
function setCurrentMode(mode: Mode): void {
currentMode = mode;
setAllButtonsForMode(mode);
}
function base64ToUint8Array(base64: string): Uint8Array {
const binary = window.atob(base64);
const bytes = new Uint8Array(binary.length);
let index = 0;
while (index < binary.length) {
bytes[index] = binary.charCodeAt(index);
index += 1;
}
return bytes;
}
function updatePreviewImageFromBase64(encoded: string): void {
const bytes = base64ToUint8Array(encoded);
const copied = new Uint8Array(bytes.byteLength);
copied.set(bytes);
const blob = new Blob([copied.buffer], { type: "image/jpeg" });
const objectUrl = URL.createObjectURL(blob);
if (previewObjectUrl !== null) {
URL.revokeObjectURL(previewObjectUrl);
}
previewObjectUrl = objectUrl;
if (previewElement)
previewElement.src = objectUrl;
}
async function refreshPreviewFrame(): Promise<void> {
if (previewRequestInFlight) {
return;
}
if (currentMode !== "video" && currentMode !== "av") {
return;
}
previewRequestInFlight = true;
try {
const encoded = await invoke<string | null>("get_video_preview_frame_base64");
if (encoded !== null && encoded.length > 0) {
updatePreviewImageFromBase64(encoded);
}
} catch (error) {
console.error("preview refresh failed", error);
} finally {
previewRequestInFlight = false;
}
}
function startPreviewPolling(): void {
if (previewTimer !== null) {
return;
}
window.setTimeout(() => {
void refreshPreviewFrame();
}, 120);
previewTimer = window.setInterval(() => {
void refreshPreviewFrame();
}, 200);
}
function stopPreviewPolling(): void {
if (previewTimer !== null) {
window.clearInterval(previewTimer);
previewTimer = null;
}
previewRequestInFlight = false;
if (previewObjectUrl !== null) {
URL.revokeObjectURL(previewObjectUrl);
previewObjectUrl = null;
}
if (previewElement)
previewElement.removeAttribute("src");
}
startAudioBtn.addEventListener("click", async () => {
if (currentMode !== "idle") {
setAudioStatus("Another mode is already running.");
return;
}
setCurrentMode("audio");
try {
const path = await invoke<string>("start_audio_recording");
setAudioStatus(`Audio recording started.\nOutput: ${path}`);
} catch (error) {
setAudioStatus(`Start audio failed.\n${String(error)}`);
setCurrentMode("idle");
}
});
stopAudioBtn.addEventListener("click", async () => {
if (currentMode !== "audio") {
setAudioStatus("Audio mode is not running.");
return;
}
stopAudioBtn.disabled = true;
try {
const path = await invoke<string>("stop_audio_recording");
setAudioStatus(`Audio recording stopped.\nSaved file: ${path}`);
setCurrentMode("idle");
} catch (error) {
setAudioStatus(`Stop audio failed.\n${String(error)}`);
setCurrentMode("audio");
}
});
startVideoBtn.addEventListener("click", async () => {
if (currentMode !== "idle") {
setVideoStatus("Another mode is already running.");
return;
}
setCurrentMode("video");
try {
const path = await invoke<string>("start_video_recording");
setVideoStatus(`Video recording started.\nOutput: ${path}`);
startPreviewPolling();
} catch (error) {
setVideoStatus(`Start video failed.\n${String(error)}`);
stopPreviewPolling();
setCurrentMode("idle");
}
});
stopVideoBtn.addEventListener("click", async () => {
if (currentMode !== "video") {
setVideoStatus("Video mode is not running.");
return;
}
stopVideoBtn.disabled = true;
try {
const path = await invoke<string>("stop_video_recording");
setVideoStatus(`Video recording stopped.\nSaved file: ${path}`);
stopPreviewPolling();
setCurrentMode("idle");
} catch (error) {
setVideoStatus(`Stop video failed.\n${String(error)}`);
setCurrentMode("video");
}
});
startAvBtn.addEventListener("click", async () => {
if (currentMode !== "idle") {
setAvStatus("Another mode is already running.");
return;
}
setCurrentMode("av");
try {
const result = await invoke<AvStartResponse>("start_av_recording");
setAvStatus(
`AV recording started.\nAudio: ${result.audio_path}\nVideo: ${result.video_path}`
);
startPreviewPolling();
} catch (error) {
setAvStatus(`Start AV failed.\n${String(error)}`);
stopPreviewPolling();
setCurrentMode("idle");
}
});
stopAvBtn.addEventListener("click", async () => {
if (currentMode !== "av") {
setAvStatus("AV mode is not running.");
return;
}
stopAvBtn.disabled = true;
try {
const result = await invoke<AvStopResponse>("stop_av_recording");
setAvStatus(
`AV recording stopped.\nAudio: ${result.audio_path}\nVideo: ${result.video_path}`
);
stopPreviewPolling();
setCurrentMode("idle");
} catch (error) {
setAvStatus(`Stop AV failed.\n${String(error)}`);
setCurrentMode("av");
}
});
setCurrentMode("idle");

73
frontend/styles.css Normal file
View File

@@ -0,0 +1,73 @@
:root {
color-scheme: dark;
font-family: Arial, Helvetica, sans-serif;
}
body {
margin: 0;
background: #111827;
color: #f9fafb;
}
.container {
max-width: 980px;
margin: 0 auto;
padding: 24px;
}
.card {
background: #1f2937;
border: 1px solid #374151;
border-radius: 12px;
padding: 20px;
margin-bottom: 20px;
}
.actions {
display: flex;
gap: 12px;
margin-bottom: 16px;
flex-wrap: wrap;
}
button {
border: 0;
border-radius: 8px;
padding: 10px 16px;
cursor: pointer;
font-size: 16px;
}
button:disabled {
opacity: 0.6;
cursor: default;
}
.preview-wrap {
width: 100%;
aspect-ratio: 16/9;
min-height: 240px;
background: #0b1220;
border: 1px solid #374151;
border-radius: 8px;
overflow: hidden;
margin-bottom: 16px;
display: flex;
align-items: center;
justify-content: center;
}
.preview-wrap img {
width: 100%;
height: 100%;
object-fit: contain;
display: block;
}
pre {
background: #0b1220;
border: 1px solid #374151;
border-radius: 8px;
padding: 12px;
white-space: pre-wrap;
}

View File

@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type AvStartResponse = { audio_path: string, video_path: string, };

View File

@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type AvStopResponse = { audio_path: string, video_path: string, };

BIN
icons/128x128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
icons/128x128@2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

BIN
icons/32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

BIN
icons/Square107x107Logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
icons/Square142x142Logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

BIN
icons/Square150x150Logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
icons/Square284x284Logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

BIN
icons/Square30x30Logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

BIN
icons/Square310x310Logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

BIN
icons/Square44x44Logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
icons/Square71x71Logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
icons/Square89x89Logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
icons/StoreLogo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
icons/icon.icns Normal file

Binary file not shown.

BIN
icons/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
icons/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

23
package.json Normal file
View File

@@ -0,0 +1,23 @@
{
"name": "tauri-video03",
"private": true,
"version": "0.1.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"tauri": "tauri"
},
"dependencies": {
"@tauri-apps/api": "^2.10",
"@tauri-apps/plugin-opener": "^2.5"
},
"devDependencies": {
"@tauri-apps/cli": "^2.10",
"@types/node": "^25.3",
"sass-embedded": "^1.97",
"typescript": "^5.9",
"vite": "npm:rolldown-vite@^7.3"
}
}

75
src/app_state.rs Normal file
View File

@@ -0,0 +1,75 @@
// file: src/app_state.rs
pub struct AudioRecorderState {
pub is_recording: bool,
pub output_path: Option<std::path::PathBuf>,
pub pipeline: Option<gstreamer::Pipeline>,
}
impl AudioRecorderState {
pub fn new() -> Self {
Self {
is_recording: false,
output_path: None,
pipeline: None,
}
}
}
pub struct VideoRecorderState {
pub is_recording: bool,
pub output_path: Option<std::path::PathBuf>,
pub pipeline: Option<gstreamer::Pipeline>,
}
impl VideoRecorderState {
pub fn new() -> Self {
Self {
is_recording: false,
output_path: None,
pipeline: None,
}
}
}
pub struct PreviewState {
pub latest_jpeg: std::sync::Arc<std::sync::Mutex<Option<Vec<u8>>>>,
}
impl PreviewState {
pub fn new() -> Self {
Self {
latest_jpeg: std::sync::Arc::new(std::sync::Mutex::new(None)),
}
}
}
pub struct AvRecorderState {
pub is_recording: bool,
}
impl AvRecorderState {
pub fn new() -> Self {
Self {
is_recording: false,
}
}
}
pub struct AppState {
pub audio: std::sync::Mutex<AudioRecorderState>,
pub video: std::sync::Mutex<VideoRecorderState>,
pub preview: PreviewState,
pub av: std::sync::Mutex<AvRecorderState>,
}
impl AppState {
pub fn new() -> Self {
Self {
audio: std::sync::Mutex::new(AudioRecorderState::new()),
video: std::sync::Mutex::new(VideoRecorderState::new()),
preview: PreviewState::new(),
av: std::sync::Mutex::new(AvRecorderState::new()),
}
}
}

75
src/commands.rs Normal file
View File

@@ -0,0 +1,75 @@
// file: src/commands.rs
use crate::app_state::AppState;
use crate::media_audio;
use crate::media_av;
use crate::media_video;
#[tauri::command]
pub async fn start_audio_recording(state: tauri::State<'_, AppState>) -> Result<String, String> {
let result = media_audio::start_audio_recording(&state);
match result {
Ok(path) => Ok(path),
Err(error) => Err(error.to_user_message()),
}
}
#[tauri::command]
pub async fn stop_audio_recording(state: tauri::State<'_, AppState>) -> Result<String, String> {
let result = media_audio::stop_audio_recording(&state);
match result {
Ok(path) => Ok(path),
Err(error) => Err(error.to_user_message()),
}
}
#[tauri::command]
pub async fn start_video_recording(state: tauri::State<'_, AppState>) -> Result<String, String> {
let result = media_video::start_video_recording(&state);
match result {
Ok(path) => Ok(path),
Err(error) => Err(error.to_user_message()),
}
}
#[tauri::command]
pub async fn stop_video_recording(state: tauri::State<'_, AppState>) -> Result<String, String> {
let result = media_video::stop_video_recording(&state);
match result {
Ok(path) => Ok(path),
Err(error) => Err(error.to_user_message()),
}
}
#[tauri::command]
pub async fn get_video_preview_frame_base64(
state: tauri::State<'_, AppState>,
) -> Result<Option<String>, String> {
let result = media_video::get_video_preview_frame_base64(&state);
match result {
Ok(value) => Ok(value),
Err(error) => Err(error.to_user_message()),
}
}
#[tauri::command]
pub async fn start_av_recording(
state: tauri::State<'_, AppState>,
) -> Result<media_av::AvStartResponse, String> {
let result = media_av::start_av_recording(&state);
match result {
Ok(value) => Ok(value),
Err(error) => Err(error.to_user_message()),
}
}
#[tauri::command]
pub async fn stop_av_recording(
state: tauri::State<'_, AppState>,
) -> Result<media_av::AvStopResponse, String> {
let result = media_av::stop_av_recording(&state);
match result {
Ok(value) => Ok(value),
Err(error) => Err(error.to_user_message()),
}
}

18
src/error.rs Normal file
View File

@@ -0,0 +1,18 @@
// file: src/error.rs
#[derive(Debug)]
pub enum AppError {
Gst(String),
Io(String),
State(String),
}
impl AppError {
pub fn to_user_message(&self) -> String {
match self {
AppError::Gst(message) => format!("gstreamer error: {message}"),
AppError::Io(message) => format!("io error: {message}"),
AppError::State(message) => format!("state error: {message}"),
}
}
}

52
src/lib.rs Normal file
View File

@@ -0,0 +1,52 @@
// file: src/lib.rs
mod app_state;
mod commands;
mod error;
mod media_audio;
mod media_av;
mod media_video;
fn init_tracing() {
let subscriber_result = tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
)
.try_init();
if let Err(error) = subscriber_result {
eprintln!("failed to init tracing: {error}");
}
}
fn init_gstreamer() {
let init_result = gstreamer::init();
if let Err(error) = init_result {
panic!("failed to init gstreamer: {error}");
}
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
init_tracing();
init_gstreamer();
let builder = tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.manage(app_state::AppState::new())
.invoke_handler(tauri::generate_handler![
commands::start_audio_recording,
commands::stop_audio_recording,
commands::start_video_recording,
commands::stop_video_recording,
commands::get_video_preview_frame_base64,
commands::start_av_recording,
commands::stop_av_recording,
]);
let run_result = builder.run(tauri::generate_context!());
if let Err(error) = run_result {
tracing::error!(%error, "tauri run failed");
}
}

8
src/main.rs Normal file
View File

@@ -0,0 +1,8 @@
// file: src/main.rs
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
tauri_video03_lib::run()
}

178
src/media_audio.rs Normal file
View File

@@ -0,0 +1,178 @@
// file: src/media_audio.rs
use crate::app_state::AppState;
use crate::error::AppError;
use gst::prelude::*;
use gstreamer as gst;
fn build_output_dir() -> Result<std::path::PathBuf, AppError> {
let app_data_dir = dirs::data_local_dir();
let Some(mut base_dir) = app_data_dir else {
return Err(AppError::Io(
"unable to resolve local data directory".to_string(),
));
};
base_dir.push("tauri-video03");
base_dir.push("records");
let create_dir_result = std::fs::create_dir_all(&base_dir);
if let Err(error) = create_dir_result {
return Err(AppError::Io(format!(
"unable to create output directory '{}': {error}",
base_dir.display()
)));
}
Ok(base_dir)
}
fn build_output_path() -> Result<std::path::PathBuf, AppError> {
let build_dir_result = build_output_dir();
let mut dir = match build_dir_result {
Ok(value) => value,
Err(error) => return Err(error),
};
let timestamp = chrono::Local::now().format("%Y%m%d-%H%M%S").to_string();
dir.push(format!("audio-{timestamp}.wav"));
Ok(dir)
}
fn build_pipeline(output_path: &std::path::Path) -> Result<gst::Pipeline, AppError> {
let location = output_path
.to_string_lossy()
.replace('\\', "\\\\")
.replace('"', "\\\"");
let pipeline_str = format!(
"autoaudiosrc ! audioconvert ! audioresample ! wavenc ! filesink location=\"{}\"",
location
);
tracing::info!(pipeline = %pipeline_str, "building audio pipeline");
let element_result = gst::parse::launch(&pipeline_str);
let element = match element_result {
Ok(value) => value,
Err(error) => {
return Err(AppError::Gst(format!("unable to parse pipeline: {error}")));
}
};
let downcast_result = element.downcast::<gst::Pipeline>();
match downcast_result {
Ok(pipeline) => Ok(pipeline),
Err(_) => Err(AppError::Gst(
"parsed element is not a pipeline".to_string(),
)),
}
}
pub fn start_audio_recording(state: &tauri::State<'_, AppState>) -> Result<String, AppError> {
let mut guard = match state.audio.lock() {
Ok(value) => value,
Err(_) => {
return Err(AppError::State("audio state lock poisoned".to_string()));
}
};
if guard.is_recording {
return Err(AppError::State(
"audio recording is already running".to_string(),
));
}
let output_path = match build_output_path() {
Ok(value) => value,
Err(error) => return Err(error),
};
let pipeline = match build_pipeline(&output_path) {
Ok(value) => value,
Err(error) => return Err(error),
};
let set_state_result = pipeline.set_state(gst::State::Playing);
match set_state_result {
Ok(_) => {}
Err(error) => {
return Err(AppError::Gst(format!(
"unable to set pipeline to playing: {error:?}"
)));
}
}
tracing::info!(path = %output_path.display(), "audio recording started");
guard.is_recording = true;
guard.output_path = Some(output_path.clone());
guard.pipeline = Some(pipeline);
Ok(output_path.display().to_string())
}
pub fn stop_audio_recording(state: &tauri::State<'_, AppState>) -> Result<String, AppError> {
let mut guard = match state.audio.lock() {
Ok(value) => value,
Err(_) => {
return Err(AppError::State("audio state lock poisoned".to_string()));
}
};
if !guard.is_recording {
return Err(AppError::State(
"audio recording is not running".to_string(),
));
}
let pipeline = match guard.pipeline.take() {
Some(value) => value,
None => {
return Err(AppError::State(
"missing pipeline while recording flag is set".to_string(),
));
}
};
let output_path = match guard.output_path.clone() {
Some(value) => value,
None => {
return Err(AppError::State(
"missing output path while recording flag is set".to_string(),
));
}
};
let send_event_result = pipeline.send_event(gst::event::Eos::new());
if !send_event_result {
tracing::warn!("failed to send EOS event to audio pipeline");
}
let bus = pipeline.bus();
if let Some(bus_ref) = bus {
let _ = bus_ref.timed_pop_filtered(
gst::ClockTime::from_seconds(5),
&[gst::MessageType::Eos, gst::MessageType::Error],
);
}
let set_state_result = pipeline.set_state(gst::State::Null);
match set_state_result {
Ok(_) => {}
Err(error) => {
return Err(AppError::Gst(format!(
"unable to set pipeline to null: {error:?}"
)));
}
}
tracing::info!(path = %output_path.display(), "audio recording stopped");
guard.is_recording = false;
guard.output_path = None;
guard.pipeline = None;
Ok(output_path.display().to_string())
}

120
src/media_av.rs Normal file
View File

@@ -0,0 +1,120 @@
// file: src/media_av.rs
use crate::app_state::AppState;
use crate::error::AppError;
use crate::media_audio;
use crate::media_video;
#[derive(serde::Serialize, ts_rs::TS)]
#[ts(export, export_to = "../frontend/ts/bindings/")]
pub struct AvStartResponse {
pub audio_path: String,
pub video_path: String,
}
#[derive(serde::Serialize, ts_rs::TS)]
#[ts(export, export_to = "../frontend/ts/bindings/")]
pub struct AvStopResponse {
pub audio_path: String,
pub video_path: String,
}
pub fn start_av_recording(state: &tauri::State<'_, AppState>) -> Result<AvStartResponse, AppError> {
let mut av_guard = match state.av.lock() {
Ok(value) => value,
Err(_) => {
return Err(AppError::State("av state lock poisoned".to_string()));
}
};
if av_guard.is_recording {
return Err(AppError::State(
"av recording is already running".to_string(),
));
}
let audio_guard_result = state.audio.lock();
match audio_guard_result {
Ok(audio_guard) => {
if audio_guard.is_recording {
return Err(AppError::State("audio already running".to_string()));
}
}
Err(_) => {
return Err(AppError::State("audio state lock poisoned".to_string()));
}
}
let video_guard_result = state.video.lock();
match video_guard_result {
Ok(video_guard) => {
if video_guard.is_recording {
return Err(AppError::State("video already running".to_string()));
}
}
Err(_) => {
return Err(AppError::State("video state lock poisoned".to_string()));
}
}
let audio_start_result = media_audio::start_audio_recording(state);
let audio_path = match audio_start_result {
Ok(value) => value,
Err(error) => return Err(error),
};
let video_start_result = media_video::start_video_recording(state);
let video_path = match video_start_result {
Ok(value) => value,
Err(error) => {
let rollback_result = media_audio::stop_audio_recording(state);
if let Err(rollback_error) = rollback_result {
tracing::warn!(
error = %rollback_error.to_user_message(),
"failed to rollback audio after video start failure"
);
}
return Err(error);
}
};
av_guard.is_recording = true;
Ok(AvStartResponse {
audio_path,
video_path,
})
}
pub fn stop_av_recording(state: &tauri::State<'_, AppState>) -> Result<AvStopResponse, AppError> {
let mut av_guard = match state.av.lock() {
Ok(value) => value,
Err(_) => {
return Err(AppError::State("av state lock poisoned".to_string()));
}
};
if !av_guard.is_recording {
return Err(AppError::State("av recording is not running".to_string()));
}
let audio_stop_result = media_audio::stop_audio_recording(state);
let audio_path = match audio_stop_result {
Ok(value) => value,
Err(error) => return Err(error),
};
let video_stop_result = media_video::stop_video_recording(state);
let video_path = match video_stop_result {
Ok(value) => value,
Err(error) => return Err(error),
};
av_guard.is_recording = false;
Ok(AvStopResponse {
audio_path,
video_path,
})
}

292
src/media_video.rs Normal file
View File

@@ -0,0 +1,292 @@
// file: src/media_video.rs
use crate::app_state::AppState;
use crate::error::AppError;
use gst::prelude::*;
use gstreamer as gst;
use gstreamer_app as gst_app;
fn build_output_dir() -> Result<std::path::PathBuf, AppError> {
let app_data_dir = dirs::data_local_dir();
let Some(mut base_dir) = app_data_dir else {
return Err(AppError::Io(
"unable to resolve local data directory".to_string(),
));
};
base_dir.push("tauri-video03");
base_dir.push("records");
let create_dir_result = std::fs::create_dir_all(&base_dir);
if let Err(error) = create_dir_result {
return Err(AppError::Io(format!(
"unable to create output directory '{}': {error}",
base_dir.display()
)));
}
Ok(base_dir)
}
fn build_output_path() -> Result<std::path::PathBuf, AppError> {
let build_dir_result = build_output_dir();
let mut dir = match build_dir_result {
Ok(value) => value,
Err(error) => return Err(error),
};
let timestamp = chrono::Local::now().format("%Y%m%d-%H%M%S").to_string();
dir.push(format!("video-{timestamp}.webm"));
Ok(dir)
}
fn build_pipeline(output_path: &std::path::Path) -> Result<gst::Pipeline, AppError> {
let location = output_path
.to_string_lossy()
.replace('\\', "\\\\")
.replace('"', "\\\"");
let pipeline_str = format!(
concat!(
"autovideosrc ! videoconvert ! tee name=t ",
"t. ! queue ! vp8enc deadline=1 ! webmmux ! filesink location=\"{}\" ",
"t. ! queue leaky=downstream max-size-buffers=1 ! videoconvert ! ",
"jpegenc quality=80 ! appsink name=preview_sink max-buffers=1 drop=true sync=false"
),
location
);
tracing::info!(pipeline = %pipeline_str, "building video pipeline");
let element_result = gst::parse::launch(&pipeline_str);
let element = match element_result {
Ok(value) => value,
Err(error) => {
return Err(AppError::Gst(format!("unable to parse pipeline: {error}")));
}
};
let downcast_result = element.downcast::<gst::Pipeline>();
match downcast_result {
Ok(pipeline) => Ok(pipeline),
Err(_) => Err(AppError::Gst(
"parsed element is not a pipeline".to_string(),
)),
}
}
fn attach_preview_callbacks(
pipeline: &gst::Pipeline,
preview_store: std::sync::Arc<std::sync::Mutex<Option<Vec<u8>>>>,
) -> Result<(), AppError> {
let element_option = pipeline.by_name("preview_sink");
let Some(element) = element_option else {
return Err(AppError::Gst(
"preview sink not found in video pipeline".to_string(),
));
};
let downcast_result = element.downcast::<gst_app::AppSink>();
let app_sink = match downcast_result {
Ok(value) => value,
Err(_) => {
return Err(AppError::Gst("preview sink is not an appsink".to_string()));
}
};
let callbacks = gst_app::AppSinkCallbacks::builder()
.new_sample(move |sink| {
let sample_result = sink.pull_sample();
let sample = match sample_result {
Ok(value) => value,
Err(error) => {
tracing::warn!(%error, "failed to pull preview sample");
return Err(gst::FlowError::Error);
}
};
let buffer_option = sample.buffer();
let Some(buffer_ref) = buffer_option else {
tracing::warn!("preview sample without buffer");
return Ok(gst::FlowSuccess::Ok);
};
let map_result = buffer_ref.map_readable();
let map = match map_result {
Ok(value) => value,
Err(error) => {
tracing::warn!(%error, "failed to map preview buffer");
return Err(gst::FlowError::Error);
}
};
let bytes = map.as_slice().to_vec();
let lock_result = preview_store.lock();
match lock_result {
Ok(mut guard) => {
*guard = Some(bytes);
}
Err(_) => {
tracing::warn!("preview state lock poisoned");
return Err(gst::FlowError::Error);
}
}
Ok(gst::FlowSuccess::Ok)
})
.build();
app_sink.set_callbacks(callbacks);
Ok(())
}
pub fn start_video_recording(state: &tauri::State<'_, AppState>) -> Result<String, AppError> {
let mut guard = match state.video.lock() {
Ok(value) => value,
Err(_) => {
return Err(AppError::State("video state lock poisoned".to_string()));
}
};
if guard.is_recording {
return Err(AppError::State(
"video recording is already running".to_string(),
));
}
let preview_lock_result = state.preview.latest_jpeg.lock();
match preview_lock_result {
Ok(mut preview_guard) => {
*preview_guard = None;
}
Err(_) => {
return Err(AppError::State("preview state lock poisoned".to_string()));
}
}
let output_path = match build_output_path() {
Ok(value) => value,
Err(error) => return Err(error),
};
let pipeline = match build_pipeline(&output_path) {
Ok(value) => value,
Err(error) => return Err(error),
};
let attach_result = attach_preview_callbacks(&pipeline, state.preview.latest_jpeg.clone());
if let Err(error) = attach_result {
return Err(error);
}
let set_state_result = pipeline.set_state(gst::State::Playing);
match set_state_result {
Ok(_) => {}
Err(error) => {
return Err(AppError::Gst(format!(
"unable to set pipeline to playing: {error:?}"
)));
}
}
tracing::info!(path = %output_path.display(), "video recording started");
guard.is_recording = true;
guard.output_path = Some(output_path.clone());
guard.pipeline = Some(pipeline);
Ok(output_path.display().to_string())
}
pub fn stop_video_recording(state: &tauri::State<'_, AppState>) -> Result<String, AppError> {
let mut guard = match state.video.lock() {
Ok(value) => value,
Err(_) => {
return Err(AppError::State("video state lock poisoned".to_string()));
}
};
if !guard.is_recording {
return Err(AppError::State(
"video recording is not running".to_string(),
));
}
let pipeline = match guard.pipeline.take() {
Some(value) => value,
None => {
return Err(AppError::State(
"missing video pipeline while recording flag is set".to_string(),
));
}
};
let output_path = match guard.output_path.clone() {
Some(value) => value,
None => {
return Err(AppError::State(
"missing video output path while recording flag is set".to_string(),
));
}
};
let send_event_result = pipeline.send_event(gst::event::Eos::new());
if !send_event_result {
tracing::warn!("failed to send EOS event to video pipeline");
}
let bus = pipeline.bus();
if let Some(bus_ref) = bus {
let _ = bus_ref.timed_pop_filtered(
gst::ClockTime::from_seconds(5),
&[gst::MessageType::Eos, gst::MessageType::Error],
);
}
let set_state_result = pipeline.set_state(gst::State::Null);
match set_state_result {
Ok(_) => {}
Err(error) => {
return Err(AppError::Gst(format!(
"unable to set video pipeline to null: {error:?}"
)));
}
}
let preview_lock_result = state.preview.latest_jpeg.lock();
if let Ok(mut preview_guard) = preview_lock_result {
*preview_guard = None;
}
tracing::info!(path = %output_path.display(), "video recording stopped");
guard.is_recording = false;
guard.output_path = None;
guard.pipeline = None;
Ok(output_path.display().to_string())
}
pub fn get_video_preview_frame_base64(
state: &tauri::State<'_, AppState>,
) -> Result<Option<String>, AppError> {
use base64::Engine;
let lock_result = state.preview.latest_jpeg.lock();
let guard = match lock_result {
Ok(value) => value,
Err(_) => {
return Err(AppError::State("preview state lock poisoned".to_string()));
}
};
let Some(bytes) = guard.as_ref() else {
return Ok(None);
};
let encoded = base64::engine::general_purpose::STANDARD.encode(bytes);
Ok(Some(encoded))
}

36
tauri.conf.json Normal file
View File

@@ -0,0 +1,36 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "tauri-video03",
"version": "0.1.0",
"identifier": "com.sinus.tauri-video03",
"build": {
"beforeDevCommand": "npm run dev",
"devUrl": "http://localhost:1420",
"beforeBuildCommand": "npm run build",
"frontendDist": "./dist"
},
"app": {
"withGlobalTauri": true,
"windows": [
{
"title": "tauri-video03",
"width": 800,
"height": 600
}
],
"security": {
"csp": null
}
},
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
}
}

26
tsconfig.json Normal file
View File

@@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": [
"ES2020",
"DOM",
"DOM.Iterable"
],
"skipLibCheck": true,
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"baseUrl": "./frontend"
},
"include": [
"frontend"
]
}

77
vite.config.ts Normal file
View File

@@ -0,0 +1,77 @@
import { defineConfig, normalizePath } from "vite";
import { NodePackageImporter } from "sass-embedded";
import { resolve } from 'path';
const host = process.env.TAURI_DEV_HOST;
// https://vite.dev/config/
export default defineConfig(async () => ({
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
//
// 1. prevent Vite from obscuring rust errors
clearScreen: false,
root: 'frontend', // Set this to your frontend directory
publicDir: 'public',
build: {
outDir: './dist', // Output directory for the build
emptyOutDir: true,
rollupOptions: {
input: {
"main": normalizePath(resolve(__dirname, 'frontend/index.html'))
},
output: {
entryFileNames: 'js/[name]-[hash].js',
chunkFileNames: 'js/chunks/[name]-[hash].js',
assetFileNames: (assetInfo) => {
const originalName = assetInfo.name ?? '';
const ext = originalName.substring(originalName.lastIndexOf('.') + 1).toLowerCase();
if (ext === 'js') {
return 'js/[name]-[hash][extname]';
}
// CSS
if (ext === 'css') {
return 'css/[name]-[hash][extname]';
}
if (['eot', 'otf', 'ttf', 'woff', 'woff2'].includes(ext)) {
return 'fonts/[name]-[hash][extname]';
}
if (['png', 'jpg', 'jpeg', 'gif', 'svg', 'webp', 'ico'].includes(ext)) {
return 'imgs/[name][extname]';
}
if (['mp4', 'webm'].includes(ext)) {
return 'videos/[name][extname]';
}
return 'otherassets/[name][extname]';
},
},
},
minify: true,
sourcemap: false,
cssCodeSplit: true
},
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
importers: [new NodePackageImporter()],
}
}
},
// 2. tauri expects a fixed port, fail if that port is not available
server: {
port: 1420,
strictPort: true,
host: host || false,
hmr: host
? {
protocol: "ws",
host,
port: 1421,
}
: undefined,
watch: {
ignored: ["**/src/**"],
},
},
}));