Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de504fbcb4 | ||
|
|
69dc6b8fac | ||
|
|
291f4950e8 | ||
|
|
9a65f42f51 | ||
|
|
a3e4fa4ec7 | ||
|
|
897f2ec0c2 | ||
|
|
e24b448c6c | ||
|
|
4e9a1fd038 | ||
|
|
31f59ba4a2 | ||
|
|
b848154942 | ||
|
|
79db6adf45 | ||
|
|
a06e473e85 | ||
|
|
79f509951c | ||
|
|
f61bcf1cc3 | ||
|
|
52ccd7ee03 | ||
|
|
d266de942a |
130
README.md
130
README.md
@@ -1,83 +1,94 @@
|
|||||||
# Hearbit AI 🦉🎙️
|
# Hearbit AI 🦉🎙️
|
||||||
|
|
||||||
**Hearbit AI** is your professional meeting assistant for macOS. It records both your microphone and system audio (e.g., Teams, Zoom), transcribes it with high precision using Infomaniak's Whisper API, and generates intelligent, structured summaries.
|
**Hearbit AI** is your professional meeting assistant for macOS. It records both your microphone and system audio (e.g., Teams, Zoom, 3CX, Talk), transcribes it with high precision using Infomaniak's Whisper API, and generates intelligent, structured summaries.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## ✨ Features
|
## ✨ New in v1.2.x
|
||||||
|
|
||||||
* **🎙️ Dual-Channel Recording**: seamlessly capture your voice and meeting audio from apps like Microsoft Teams, Zoom, or Google Meet.
|
### v1.2.3: App Blocking & Selective Recording 🚫🎧
|
||||||
* **🧠 Powered by Infomaniak AI**:
|
* **🔇 App Blocking (Selective Recording)**: You can now exclude specific applications from being captured by the system audio recording.
|
||||||
* **Precision Transcription**: Standard-compliant formatting with **second-by-second timestamps** (e.g., `[00:12]`).
|
* **🧠 Smart Matching**: Uses prefix-based matching (e.g., `com.apple.Safari`) to reliably block main apps AND their background/helper processes (e.g., "Safari Web Content").
|
||||||
* **Smart Summaries**: Uses advanced LLMs (Mixtral, Llama 3) to create actionable meeting notes.
|
* **🚀 Quick Select Presets**: Quickly block common background apps like **Spotify, Apple Music, VLC, Safari, or Chrome** with one click.
|
||||||
* **📝 Professional Templates**: Comes with 3 built-in expert prompts:
|
* **🔍 Live App List**: Filter any currently running application directly from the new **Apps** tab in Settings.
|
||||||
* **Meeting Protocol**: For general business meetings.
|
* **🔄 Robust Auto-Refresh**: The capture filter automatically updates every 5 seconds to account for newly opened browsers or media players.
|
||||||
* **1:1 / Jour Fixe**: For confidential personnel discussions.
|
|
||||||
* **Client Meeting**: For official, client-ready documentation.
|
|
||||||
* **💾 Auto-Save**: All recordings and summaries are saved locally to your history.
|
|
||||||
* **🔒 Privacy-First**: Data is processed securely via your own Infomaniak API keys.
|
|
||||||
|
|
||||||
---
|
### v1.2.0: Native Audio & Auto-Loop 🦉
|
||||||
|
* **🎧 Native System Audio**: No more BlackHole driver needed! Captures Teams, Zoom, 3CX, and Talk audio directly via macOS ScreenCaptureKit.
|
||||||
|
* **🔁 Auto-Loop (Standby Mode)**: Automatically "re-arms" after a call finishes.
|
||||||
|
* **⚡ Smart VAD & Pre-Roll**: 3-second pre-roll and noise filtering.
|
||||||
|
* **🛡️ Empty Audio Guard**: Automatically discards silent recordings.
|
||||||
|
* **💾 Daily Security Backups**: Automatic JSON history backups every 24 hours.
|
||||||
|
|
||||||
## 🚀 Getting Started
|
## 🚀 Key Features
|
||||||
|
|
||||||
### 1. Prerequisites
|
* **🎙️ Dual-Channel Recording**: Seamlessly capture your voice and meeting audio.
|
||||||
* **macOS** (Apple Silicon or Intel).
|
* **📁 Import Audio Files**: Upload existing recordings (MP3, WAV, M4A, etc.).
|
||||||
* **Infomaniak AI Account**: You need an API Key and Product ID from the [Infomaniak Developer Portal](https://manager.infomaniak.com/).
|
* **⏱️ Long Meeting Support**: Handles meetings 2+ hours with automatic chunking.
|
||||||
|
* **📅 Microsoft 365 Integration**: View upcoming meetings and join with one click.
|
||||||
### 2. Installation
|
* **💾 Persistent History**: Automatically saves all transcripts and summaries locally.
|
||||||
1. Download the latest `.dmg` file from the [Releases page](#).
|
* **✉️ Email Summaries**: Send formatted HTML summaries via your own SMTP server.
|
||||||
2. Open the `.dmg` and drag **Hearbit AI** to your Applications folder.
|
* **🎨 White-Labeling**: Upload your custom company logo.
|
||||||
3. Launch the app.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 🎧 Recording System Audio (Teams, Zoom, etc.)
|
|
||||||
|
|
||||||
To record clear meeting audio from other applications, you need a "virtual cable". We recommend **BlackHole 2ch**.
|
|
||||||
|
|
||||||
1. **Install BlackHole**: Download and install [BlackHole 2ch](https://existential.audio/blackhole/).
|
|
||||||
2. **Create a Multi-Output Device** (So you can hear the audio too!):
|
|
||||||
* Open **Audio MIDI Setup** on your Mac.
|
|
||||||
* Create a "Multi-Output Device".
|
|
||||||
* Select both **BlackHole 2ch** AND your **Headphones/Speakers**.
|
|
||||||
* *Tip: Use this Multi-Output Device as your SPEAKER in Teams/Zoom.*
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
3. **Create Aggregate Device (Optional)**:
|
|
||||||
* If you want to record BOTH your Microphone and System Audio, create an **Aggregate Device**.
|
|
||||||
* Select **BlackHole 2ch** AND your **Microphone**.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
4. **Select Input in Hearbit AI**:
|
|
||||||
* In Hearbit AI, select **BlackHole 2ch** (or your new Aggregate Device) as the **Input Device**.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🛠️ Usage Guide
|
## 🛠️ Usage Guide
|
||||||
|
|
||||||
1. **Configuration**:
|
### 1. Installation
|
||||||
* Click the **Settings** (gear icon).
|
1. Download the latest `.dmg` file from the [Releases page](#).
|
||||||
* Enter your **Infomaniak API Key** and **Product ID**.
|
2. Open the `.dmg` and drag **Hearbit AI** to your Applications folder.
|
||||||
* (Optional) Customize where recordings are saved.
|
3. **Permission Check**: On first launch, grant "Screen Recording" permission (required for capturing System Audio).
|
||||||
|
|
||||||
2. **Recording**:
|
### 2. Configuration
|
||||||
* Choose your **Template** (e.g., "Meeting Protocol").
|
1. Click **Settings** (gear icon).
|
||||||
* Select your **Input Device**.
|
2. Enter your **Infomaniak API Key** and **Product ID**.
|
||||||
* Click **Start Recording**.
|
3. (Optional) Configure **SMTP** for email sending and **Microsoft 365** for calendar integration.
|
||||||
|
|
||||||
3. **Processing**:
|
### 3. Recording a Meeting
|
||||||
* Click **Stop** when finished.
|
1. **Select Mode**: Choose "Meeting" (captures Mic + System) or "Voice Memo" (Mic only).
|
||||||
* The app will transcribe the audio (with timestamps!) and generate a summary based on your selected template.
|
2. **Auto-Start Logic**:
|
||||||
* You will be automatically taken to the **Transcription** tab to review the results.
|
- **Meeting Mode**: Triggers only when the call actually starts (system audio detected).
|
||||||
|
- **Voice Memo**: Triggers immediately when you start speaking.
|
||||||
|
3. **Standby**: Click "Standby (Auto-Start)". The app waits silently.
|
||||||
|
4. **Join Call**: Join your Teams/Zoom call.
|
||||||
|
5. **Trigger**: Hearbit starts recording automatically based on the selected mode.
|
||||||
|
6. **Finish**: When the call ends (silence > 25s), Hearbit stops, transcribes, summarizes, and **goes back to Standby** for the next call.
|
||||||
|
|
||||||
|
### 4. Optimal Setup (MS Teams / Zoom / 3CX)
|
||||||
|
For the best experience without changing any software settings:
|
||||||
|
* **Hearbit App**: Select your **real microphone** (e.g., "MacBook Mic" or Headset).
|
||||||
|
* **Meeting Software**: Use your standard output (Speakers/Headset).
|
||||||
|
* *How it works*: Hearbit captures your voice via mic and the other side via macOS System Audio Capture automatically.
|
||||||
|
|
||||||
|
*Note: If you choose "Hearbit Audio" (Aggregate Device) in the app, you MUST set your Teams/Zoom/3CX speaker output to "Hearbit Audio" as well.*
|
||||||
|
|
||||||
|
### 5. Customizing Prompts
|
||||||
|
You can create custom AI templates in Settings -> Prompts. Example:
|
||||||
|
* **"Sales Call"**: Focus on budget, timeline, and decision makers.
|
||||||
|
* **"Daily Standup"**: Extract blockers and next steps.
|
||||||
|
* **"General Protocol"**: Standard meeting minutes.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ❓ Troubleshooting
|
||||||
|
|
||||||
|
### "Hearbit AI is damaged and can't be opened"
|
||||||
|
If macOS blocks the app because it's not notarized:
|
||||||
|
1. Open **Terminal**.
|
||||||
|
2. Run: `sudo xattr -cr /Applications/Hearbit\ AI.app`
|
||||||
|
3. Enter your password and try again.
|
||||||
|
|
||||||
|
### Audio cuts off at the start?
|
||||||
|
v1.2.0 includes a **3-second buffer**. The Meeting mode now uses a more sensitive trigger (0.005 energy) to catch even quiet participants.
|
||||||
|
|
||||||
|
### "Batch processing failed"
|
||||||
|
This means the audio was empty or too short. Check the **Logs** tab for detailed error messages from Infomaniak. The most common cause is selecting the wrong input device or a lack of Screen Recording permissions.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 👨💻 Development
|
## 👨💻 Development
|
||||||
|
|
||||||
Built with **Tauri**, **React**, and **TypeScript**.
|
Built with **Tauri v2**, **React**, and **TypeScript**.
|
||||||
|
|
||||||
### Setup
|
### Setup
|
||||||
```bash
|
```bash
|
||||||
@@ -93,7 +104,6 @@ npm run tauri dev
|
|||||||
```bash
|
```bash
|
||||||
npm run tauri build
|
npm run tauri build
|
||||||
```
|
```
|
||||||
*The build artifact will be located in `src-tauri/target/release/bundle/dmg/*`*
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
81
RELEASE_NOTES_1.1.0.md
Normal file
81
RELEASE_NOTES_1.1.0.md
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
# Release Notes - Version 1.1.0
|
||||||
|
|
||||||
|
**Release Date**: January 21, 2026
|
||||||
|
|
||||||
|
## 🎉 What's New
|
||||||
|
|
||||||
|
### Import Audio Files Feature
|
||||||
|
|
||||||
|
We've added a powerful new **Import** tab that allows you to upload and process existing audio/video files!
|
||||||
|
|
||||||
|
**Key Features:**
|
||||||
|
- **Drag-and-Drop Upload**: Simply drag your audio files into the app
|
||||||
|
- **8 Format Support**: MP3, MP4, WAV, M4A, FLAC, OGG, AAC, WMA
|
||||||
|
- **Smart Metadata Display**: See file duration, size, and format before processing
|
||||||
|
- **Editable Meeting Titles**: Customize the name (defaults to filename)
|
||||||
|
- **Progress Tracking**: Visual indicators for each stage (Validating → Transcribing → Summarizing)
|
||||||
|
- **Same AI Power**: Uses the same AI templates and Smart Select as live recordings
|
||||||
|
- **Auto-Navigation**: Seamlessly transition to Transcription view when complete
|
||||||
|
|
||||||
|
**Use Cases:**
|
||||||
|
- Process pre-recorded meetings you forgot to record live
|
||||||
|
- Batch process voice memos
|
||||||
|
- Import recordings from other devices
|
||||||
|
- Archive and transcribe old meeting recordings
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📝 Documentation Updates
|
||||||
|
|
||||||
|
### README Enhancements
|
||||||
|
- Added mandatory **BlackHole 2ch Driver** requirement to Prerequisites
|
||||||
|
- Clarified **Teams/Zoom configuration** (Speaker vs. Microphone settings)
|
||||||
|
- Added detailed setup instructions for meeting audio capture
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 Technical Improvements
|
||||||
|
|
||||||
|
- Added `get_audio_metadata` Rust command for file metadata extraction
|
||||||
|
- Improved tab navigation with new Import tab
|
||||||
|
- Enhanced error handling for file validation
|
||||||
|
- Code optimizations and cleanup
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📦 Installation
|
||||||
|
|
||||||
|
Download the DMG file:
|
||||||
|
```
|
||||||
|
Hearbit_AI_1.1.0_aarch64.dmg
|
||||||
|
```
|
||||||
|
|
||||||
|
**Location**: `src-tauri/target/release/bundle/dmg/`
|
||||||
|
|
||||||
|
### First-time Installation
|
||||||
|
If you see "Hearbit AI is damaged and can't be opened":
|
||||||
|
```bash
|
||||||
|
sudo xattr -cr /Applications/Hearbit\ AI.app
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🐛 Known Issues
|
||||||
|
|
||||||
|
None reported for this release.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🙏 Credits
|
||||||
|
|
||||||
|
Built with ❤️ by the Livtec team using Tauri, React, and TypeScript.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## What's Next?
|
||||||
|
|
||||||
|
Potential future enhancements:
|
||||||
|
- Meeting auto-stop when meeting ends (via M365 API)
|
||||||
|
- Batch file import
|
||||||
|
- Audio preview player
|
||||||
|
- More audio format conversions
|
||||||
22
RELEASE_NOTES_1.2.0.md
Normal file
22
RELEASE_NOTES_1.2.0.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# Release Notes - Hearbit AI v1.2.0
|
||||||
|
|
||||||
|
## 🚀 Neuheiten
|
||||||
|
|
||||||
|
### Native System Audio (ScreenCaptureKit)
|
||||||
|
Wir haben die Audio-Engine komplett erneuert!
|
||||||
|
- **Keine Treiber mehr:** Sie müssen BlackHole nicht mehr installieren.
|
||||||
|
- **Funktioniert überall:** Egal ob Teams, Zoom, Webex, Nextcloud Talk oder 3CX – die App hört jetzt nativ mit.
|
||||||
|
- **Berechtigung:** Die App fragt beim ersten Start nach der "Bildschirmaufnahme"-Berechtigung. Dies ist der moderne Apple-Standard für Audio-Capture.
|
||||||
|
|
||||||
|
### Smart VAD (Intelligente Spracherkennung)
|
||||||
|
- **Ignoriert Musik:** Die App unterscheidet jetzt präzise zwischen menschlicher Sprache und Musik.
|
||||||
|
- **Wartebereich-Filter:** Musik im Teams-Wartebereich wird nicht mehr aufgenommen. Die Aufnahme startet erst, wenn wirklich gesprochen wird.
|
||||||
|
|
||||||
|
### UI Verbesserungen
|
||||||
|
- **Neuer Setup-Flow:** Das komplizierte Audio-Setup wurde entfernt.
|
||||||
|
- **Freie Wahl:** Nutzen Sie jedes Mikrofon, das Sie möchten.
|
||||||
|
|
||||||
|
## 🛠️ Technische Änderungen
|
||||||
|
- Update auf `screencapturekit` Framework (macOS 12.3+ erforderlich).
|
||||||
|
- BlackHole-Abhängigkeit entfernt.
|
||||||
|
- Audio-Mixing direkt in der App.
|
||||||
14
package-lock.json
generated
14
package-lock.json
generated
@@ -1,16 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "hearbit-ai",
|
"name": "hearbit-ai",
|
||||||
"version": "0.1.0",
|
"version": "1.2.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "hearbit-ai",
|
"name": "hearbit-ai",
|
||||||
"version": "0.1.0",
|
"version": "1.2.2",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tailwindcss/postcss": "^4.1.18",
|
"@tailwindcss/postcss": "^4.1.18",
|
||||||
"@tauri-apps/api": "^2",
|
"@tauri-apps/api": "^2",
|
||||||
"@tauri-apps/plugin-dialog": "^2.6.0",
|
"@tauri-apps/plugin-dialog": "^2.6.0",
|
||||||
|
"@tauri-apps/plugin-fs": "^2.4.5",
|
||||||
"@tauri-apps/plugin-opener": "^2",
|
"@tauri-apps/plugin-opener": "^2",
|
||||||
"jimp": "^1.6.0",
|
"jimp": "^1.6.0",
|
||||||
"lucide-react": "^0.562.0",
|
"lucide-react": "^0.562.0",
|
||||||
@@ -2086,6 +2087,15 @@
|
|||||||
"@tauri-apps/api": "^2.8.0"
|
"@tauri-apps/api": "^2.8.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@tauri-apps/plugin-fs": {
|
||||||
|
"version": "2.4.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-fs/-/plugin-fs-2.4.5.tgz",
|
||||||
|
"integrity": "sha512-dVxWWGE6VrOxC7/jlhyE+ON/Cc2REJlM35R3PJX3UvFw2XwYhLGQVAIyrehenDdKjotipjYEVc4YjOl3qq90fA==",
|
||||||
|
"license": "MIT OR Apache-2.0",
|
||||||
|
"dependencies": {
|
||||||
|
"@tauri-apps/api": "^2.8.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@tauri-apps/plugin-opener": {
|
"node_modules/@tauri-apps/plugin-opener": {
|
||||||
"version": "2.5.3",
|
"version": "2.5.3",
|
||||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-opener/-/plugin-opener-2.5.3.tgz",
|
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-opener/-/plugin-opener-2.5.3.tgz",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "hearbit-ai",
|
"name": "hearbit-ai",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.0",
|
"version": "1.2.3",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
"@tailwindcss/postcss": "^4.1.18",
|
"@tailwindcss/postcss": "^4.1.18",
|
||||||
"@tauri-apps/api": "^2",
|
"@tauri-apps/api": "^2",
|
||||||
"@tauri-apps/plugin-dialog": "^2.6.0",
|
"@tauri-apps/plugin-dialog": "^2.6.0",
|
||||||
|
"@tauri-apps/plugin-fs": "^2.4.5",
|
||||||
"@tauri-apps/plugin-opener": "^2",
|
"@tauri-apps/plugin-opener": "^2",
|
||||||
"jimp": "^1.6.0",
|
"jimp": "^1.6.0",
|
||||||
"lucide-react": "^0.562.0",
|
"lucide-react": "^0.562.0",
|
||||||
|
|||||||
1685
src-tauri/Cargo.lock
generated
1685
src-tauri/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "hearbit-ai"
|
name = "hearbit-ai"
|
||||||
version = "0.1.0"
|
version = "1.2.1"
|
||||||
description = "A Tauri App"
|
description = "A Tauri App"
|
||||||
authors = ["you"]
|
authors = ["you"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
@@ -18,7 +18,7 @@ crate-type = ["staticlib", "cdylib", "rlib"]
|
|||||||
tauri-build = { version = "2", features = [] }
|
tauri-build = { version = "2", features = [] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tauri = { version = "2", features = [] }
|
tauri = { version = "2", features = ["tray-icon"] }
|
||||||
tauri-plugin-opener = "2"
|
tauri-plugin-opener = "2"
|
||||||
tauri-plugin-dialog = "2"
|
tauri-plugin-dialog = "2"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
@@ -26,5 +26,20 @@ serde_json = "1.0"
|
|||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
cpal = "0.17.1"
|
cpal = "0.17.1"
|
||||||
hound = "3.5.1"
|
hound = "3.5.1"
|
||||||
reqwest = { version = "0.13.1", features = ["json", "multipart"] }
|
reqwest = { version = "0.11", features = ["json", "multipart"] }
|
||||||
tokio = { version = "1.40.0", features = ["full"] }
|
tokio = { version = "1.40.0", features = ["full"] }
|
||||||
|
tauri-plugin-fs = "2.4.5"
|
||||||
|
voice_activity_detector = "0.2.1"
|
||||||
|
rubato = "0.14.1"
|
||||||
|
tauri-plugin-oauth = "2.0.0"
|
||||||
|
oauth2 = "4.4"
|
||||||
|
url = "2.5"
|
||||||
|
lettre = { version = "0.11", features = ["tokio1", "tokio1-native-tls", "builder"] }
|
||||||
|
tauri-plugin-log = "2.0.0"
|
||||||
|
tauri-plugin-shell = "2.3.4"
|
||||||
|
base64 = "0.22"
|
||||||
|
screencapturekit = "0.2.0"
|
||||||
|
screencapturekit-sys = "0.2.8"
|
||||||
|
cocoa = "0.26.1"
|
||||||
|
objc = "0.2.7"
|
||||||
|
core-foundation = "0.10.1"
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"permissions": [
|
"permissions": [
|
||||||
"core:default",
|
"core:default",
|
||||||
"opener:default",
|
"opener:default",
|
||||||
"dialog:default"
|
"dialog:default",
|
||||||
|
"fs:default"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
191
src-tauri/resources/create_hearbit_audio.swift
Normal file
191
src-tauri/resources/create_hearbit_audio.swift
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
#!/usr/bin/env swift
|
||||||
|
import Foundation
|
||||||
|
import CoreAudio
|
||||||
|
|
||||||
|
// Extensions and Helpers
|
||||||
|
extension Int32 {
|
||||||
|
var fourCC: String {
|
||||||
|
let utf16 = [
|
||||||
|
UInt16((self >> 24) & 0xFF),
|
||||||
|
UInt16((self >> 16) & 0xFF),
|
||||||
|
UInt16((self >> 8) & 0xFF),
|
||||||
|
UInt16(self & 0xFF)
|
||||||
|
]
|
||||||
|
return String(utf16CodeUnits: utf16, count: 4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Safer Property Getter
|
||||||
|
func getPropertyData<T>(objectID: AudioObjectID, selector: AudioObjectPropertySelector, initialValue: T) -> T? {
|
||||||
|
var address = AudioObjectPropertyAddress(
|
||||||
|
mSelector: selector,
|
||||||
|
mScope: kAudioObjectPropertyScopeGlobal,
|
||||||
|
mElement: kAudioObjectPropertyElementMain
|
||||||
|
)
|
||||||
|
var size = UInt32(MemoryLayout<T>.size)
|
||||||
|
var value = initialValue
|
||||||
|
|
||||||
|
let status = AudioObjectGetPropertyData(objectID, &address, 0, nil, &size, &value)
|
||||||
|
if status == noErr {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CFString Helper
|
||||||
|
func getStringProperty(objectID: AudioObjectID, selector: AudioObjectPropertySelector) -> String? {
|
||||||
|
var address = AudioObjectPropertyAddress(
|
||||||
|
mSelector: selector,
|
||||||
|
mScope: kAudioObjectPropertyScopeGlobal,
|
||||||
|
mElement: kAudioObjectPropertyElementMain
|
||||||
|
)
|
||||||
|
// CFStringRef is just a pointer, so size of Optional<Unmanaged<CFString>> is pointer size
|
||||||
|
var size = UInt32(MemoryLayout<Unmanaged<CFString>?>.size)
|
||||||
|
var value: Unmanaged<CFString>?
|
||||||
|
|
||||||
|
let status = AudioObjectGetPropertyData(objectID, &address, 0, nil, &size, &value)
|
||||||
|
if status == noErr, let existingValue = value {
|
||||||
|
return existingValue.takeRetainedValue() as String
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func findDeviceByName(_ name: String) -> AudioObjectID? {
|
||||||
|
// System Object is 1
|
||||||
|
let systemID = AudioObjectID(kAudioObjectSystemObject)
|
||||||
|
|
||||||
|
// Get all devices
|
||||||
|
var address = AudioObjectPropertyAddress(
|
||||||
|
mSelector: kAudioHardwarePropertyDevices,
|
||||||
|
mScope: kAudioObjectPropertyScopeGlobal,
|
||||||
|
mElement: kAudioObjectPropertyElementMain
|
||||||
|
)
|
||||||
|
var size: UInt32 = 0
|
||||||
|
guard AudioObjectGetPropertyDataSize(systemID, &address, 0, nil, &size) == noErr else { return nil }
|
||||||
|
|
||||||
|
let count = Int(size) / MemoryLayout<AudioObjectID>.size
|
||||||
|
var deviceIDs = [AudioObjectID](repeating: 0, count: count)
|
||||||
|
guard AudioObjectGetPropertyData(systemID, &address, 0, nil, &size, &deviceIDs) == noErr else { return nil }
|
||||||
|
|
||||||
|
for id in deviceIDs {
|
||||||
|
if let devName = getStringProperty(objectID: id, selector: kAudioDevicePropertyDeviceNameCFString) {
|
||||||
|
if devName == name {
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func findDeviceByUID(_ uid: String) -> AudioObjectID? {
|
||||||
|
let systemID = AudioObjectID(kAudioObjectSystemObject)
|
||||||
|
var address = AudioObjectPropertyAddress(
|
||||||
|
mSelector: kAudioHardwarePropertyDevices,
|
||||||
|
mScope: kAudioObjectPropertyScopeGlobal,
|
||||||
|
mElement: kAudioObjectPropertyElementMain
|
||||||
|
)
|
||||||
|
var size: UInt32 = 0
|
||||||
|
guard AudioObjectGetPropertyDataSize(systemID, &address, 0, nil, &size) == noErr else { return nil }
|
||||||
|
|
||||||
|
let count = Int(size) / MemoryLayout<AudioObjectID>.size
|
||||||
|
var deviceIDs = [AudioObjectID](repeating: 0, count: count)
|
||||||
|
guard AudioObjectGetPropertyData(systemID, &address, 0, nil, &size, &deviceIDs) == noErr else { return nil }
|
||||||
|
|
||||||
|
for id in deviceIDs {
|
||||||
|
if let devUID = getStringProperty(objectID: id, selector: kAudioDevicePropertyDeviceUID) {
|
||||||
|
if devUID == uid {
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func createAggregateDevice() {
|
||||||
|
print("Searching for devices...")
|
||||||
|
|
||||||
|
guard let blackHoleID = findDeviceByName("BlackHole 2ch") else {
|
||||||
|
print("Error: BlackHole 2ch not found. Please install it first.")
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
print("Found BlackHole 2ch (ID: \(blackHoleID))")
|
||||||
|
|
||||||
|
// --- PART 1: Hearbit Audio (Input: Mic + BlackHole) ---
|
||||||
|
print("\n--- Creating 'Hearbit Audio' (Input) ---")
|
||||||
|
|
||||||
|
// Default Input
|
||||||
|
var defaultInputID: AudioObjectID = 0
|
||||||
|
var size = UInt32(MemoryLayout<AudioObjectID>.size)
|
||||||
|
var address = AudioObjectPropertyAddress(
|
||||||
|
mSelector: kAudioHardwarePropertyDefaultInputDevice,
|
||||||
|
mScope: kAudioObjectPropertyScopeGlobal,
|
||||||
|
mElement: kAudioObjectPropertyElementMain
|
||||||
|
)
|
||||||
|
|
||||||
|
if AudioObjectGetPropertyData(AudioObjectID(kAudioObjectSystemObject), &address, 0, nil, &size, &defaultInputID) != noErr {
|
||||||
|
print("Error: Could not find default input.")
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
print("Found Default Input (ID: \(defaultInputID))")
|
||||||
|
|
||||||
|
// Check for existing "Hearbit Audio"
|
||||||
|
let inputUID = "hearbit_audio_aggregate_v1"
|
||||||
|
if let existingID = findDeviceByUID(inputUID) {
|
||||||
|
print("Found existing Hearbit Audio (ID: \(existingID)). Destroying...")
|
||||||
|
AudioHardwareDestroyAggregateDevice(existingID)
|
||||||
|
Thread.sleep(forTimeInterval: 0.5)
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let bhUID = getStringProperty(objectID: blackHoleID, selector: kAudioDevicePropertyDeviceUID) else {
|
||||||
|
print("Error: Could not get BlackHole UID.")
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
guard let micUID = getStringProperty(objectID: defaultInputID, selector: kAudioDevicePropertyDeviceUID) else {
|
||||||
|
print("Error: Could not get Default Input UID.")
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
var subDevicesUIDs = [bhUID]
|
||||||
|
if micUID != bhUID {
|
||||||
|
subDevicesUIDs.append(micUID)
|
||||||
|
}
|
||||||
|
|
||||||
|
let subDevicesArray = subDevicesUIDs.map { [kAudioSubDeviceUIDKey: $0] }
|
||||||
|
let inputDesc: [String: Any] = [
|
||||||
|
kAudioAggregateDeviceNameKey: "Hearbit Audio",
|
||||||
|
kAudioAggregateDeviceUIDKey: inputUID,
|
||||||
|
kAudioAggregateDeviceIsPrivateKey: Int(0),
|
||||||
|
kAudioAggregateDeviceIsStackedKey: Int(0),
|
||||||
|
kAudioAggregateDeviceSubDeviceListKey: subDevicesArray
|
||||||
|
]
|
||||||
|
|
||||||
|
var outInputID: AudioObjectID = 0
|
||||||
|
let errIn = AudioHardwareCreateAggregateDevice(inputDesc as CFDictionary, &outInputID)
|
||||||
|
if errIn == noErr {
|
||||||
|
print("Success! Created 'Hearbit Audio' with ID: \(outInputID)")
|
||||||
|
} else {
|
||||||
|
print("Failed to create 'Hearbit Audio'. Error: \(errIn)")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// --- PART 2: Cleanup Unstable "Hearbit Speakers" ---
|
||||||
|
// The previous "Hearbit Speakers" device caused MS Teams to crash.
|
||||||
|
// We strictly remove it here to restore stability.
|
||||||
|
print("\n--- Cleaning up Unstable Devices ---")
|
||||||
|
let stopOutputUID = "hearbit_speakers_aggregate_v1"
|
||||||
|
if let existingOutID = findDeviceByUID(stopOutputUID) {
|
||||||
|
print("Found unstable 'Hearbit Speakers' (ID: \(existingOutID)). Removing to fix Teams crash...")
|
||||||
|
let errDist = AudioHardwareDestroyAggregateDevice(existingOutID)
|
||||||
|
if errDist == noErr {
|
||||||
|
print("Successfully removed unstable device.")
|
||||||
|
} else {
|
||||||
|
print("Warning: Failed to remove device. Error: \(errDist)")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print("No unstable 'Hearbit Speakers' found. System is clean.")
|
||||||
|
}
|
||||||
|
|
||||||
|
exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
createAggregateDevice()
|
||||||
65
src-tauri/src/apps.rs
Normal file
65
src-tauri/src/apps.rs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
use cocoa::base::{id, nil};
|
||||||
|
use cocoa::foundation::{NSArray, NSAutoreleasePool, NSString};
|
||||||
|
use objc::{msg_send, sel, sel_impl};
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
#[derive(Serialize, Debug)]
|
||||||
|
pub struct RunningApp {
|
||||||
|
pub name: String,
|
||||||
|
pub bundle_id: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_running_applications() -> Vec<RunningApp> {
|
||||||
|
let mut apps = Vec::new();
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
let pool = NSAutoreleasePool::new(nil);
|
||||||
|
|
||||||
|
// [NSWorkspace sharedWorkspace]
|
||||||
|
let workspace_class = objc::runtime::Class::get("NSWorkspace").unwrap();
|
||||||
|
let shared_workspace: id = msg_send![workspace_class, sharedWorkspace];
|
||||||
|
|
||||||
|
// [sharedWorkspace runningApplications]
|
||||||
|
let running_apps: id = msg_send![shared_workspace, runningApplications];
|
||||||
|
let count: usize = msg_send![running_apps, count];
|
||||||
|
|
||||||
|
for i in 0..count {
|
||||||
|
let app: id = msg_send![running_apps, objectAtIndex: i];
|
||||||
|
|
||||||
|
// Check if it's a regular GUI application
|
||||||
|
// activationPolicy: 0 = regular, 1 = accessory, 2 = prohibited
|
||||||
|
let policy: isize = msg_send![app, activationPolicy];
|
||||||
|
if policy != 0 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let bundle_id_ns: id = msg_send![app, bundleIdentifier];
|
||||||
|
let name_ns: id = msg_send![app, localizedName];
|
||||||
|
|
||||||
|
if bundle_id_ns != nil && name_ns != nil {
|
||||||
|
let bundle_id = nsstring_to_string(bundle_id_ns);
|
||||||
|
let name = nsstring_to_string(name_ns);
|
||||||
|
|
||||||
|
apps.push(RunningApp { name, bundle_id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We don't drain the pool here as it might be handled by Tauri's main loop if we are called frequently,
|
||||||
|
// but for a one-off command it's safer.
|
||||||
|
let _: () = msg_send![pool, release];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort by name for better UI experience
|
||||||
|
apps.sort_by(|a, b| a.name.to_lowercase().cmp(&b.name.to_lowercase()));
|
||||||
|
apps
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn nsstring_to_string(ns_string: id) -> String {
|
||||||
|
let char_ptr: *const std::os::raw::c_char = msg_send![ns_string, UTF8String];
|
||||||
|
if char_ptr.is_null() {
|
||||||
|
return String::new();
|
||||||
|
}
|
||||||
|
std::ffi::CStr::from_ptr(char_ptr)
|
||||||
|
.to_string_lossy()
|
||||||
|
.into_owned()
|
||||||
|
}
|
||||||
312
src-tauri/src/audio_processor.rs
Normal file
312
src-tauri/src/audio_processor.rs
Normal file
@@ -0,0 +1,312 @@
|
|||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use tauri::{AppHandle, Emitter};
|
||||||
|
use crate::emit_log;
|
||||||
|
use cpal::Sample;
|
||||||
|
use hound::WavWriter;
|
||||||
|
use rubato::{Resampler, FastFixedIn, PolynomialDegree};
|
||||||
|
use voice_activity_detector::VoiceActivityDetector;
|
||||||
|
|
||||||
|
pub struct AudioProcessor {
|
||||||
|
// VAD
|
||||||
|
vad: VoiceActivityDetector,
|
||||||
|
vad_chunk_size: usize,
|
||||||
|
vad_buffer: Vec<f32>,
|
||||||
|
|
||||||
|
// Audio Config
|
||||||
|
channel_count: u16,
|
||||||
|
|
||||||
|
// Resampler
|
||||||
|
resampler: FastFixedIn<f32>,
|
||||||
|
resample_input_buffer: Vec<f32>,
|
||||||
|
resample_output_buffer: Vec<f32>,
|
||||||
|
|
||||||
|
// State
|
||||||
|
is_speech_active: bool,
|
||||||
|
last_speech_time: u64, // In samples or frames
|
||||||
|
hangover_samples: u64,
|
||||||
|
|
||||||
|
// Waiting Mode
|
||||||
|
waiting_for_speech: bool,
|
||||||
|
|
||||||
|
// Ring Buffer (for pre-roll)
|
||||||
|
ring_buffer: Vec<f32>,
|
||||||
|
ring_pos: usize,
|
||||||
|
ring_size: usize,
|
||||||
|
|
||||||
|
// Output
|
||||||
|
writer: Arc<Mutex<WavWriter<std::io::BufWriter<std::fs::File>>>>,
|
||||||
|
sample_rate: u32,
|
||||||
|
total_processed_samples: u64,
|
||||||
|
// Event Emission
|
||||||
|
app_handle: Option<AppHandle>,
|
||||||
|
last_event_time: std::time::Instant,
|
||||||
|
|
||||||
|
// System Audio Queue for Mixing
|
||||||
|
pub system_queue: Arc<Mutex<std::collections::VecDeque<f32>>>,
|
||||||
|
|
||||||
|
// Recording Mode (voice or meeting)
|
||||||
|
recording_mode: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AudioProcessor {
|
||||||
|
pub fn new(
|
||||||
|
sample_rate: u32,
|
||||||
|
channel_count: u16,
|
||||||
|
writer: Arc<Mutex<WavWriter<std::io::BufWriter<std::fs::File>>>>,
|
||||||
|
app_handle: AppHandle,
|
||||||
|
wait_for_speech: bool,
|
||||||
|
recording_mode: String,
|
||||||
|
) -> Result<Self, String> {
|
||||||
|
let vad_sample_rate = 16000;
|
||||||
|
let vad_chunk_size = 512;
|
||||||
|
|
||||||
|
// Initialize VAD
|
||||||
|
let vad = VoiceActivityDetector::builder()
|
||||||
|
.sample_rate(vad_sample_rate as u32)
|
||||||
|
.chunk_size(vad_chunk_size)
|
||||||
|
.build()
|
||||||
|
.map_err(|e| format!("Failed to init VAD: {:?}", e))?;
|
||||||
|
|
||||||
|
// Initialize Resampler (Input Rate -> 16000)
|
||||||
|
let resampler = FastFixedIn::<f32>::new(
|
||||||
|
16000.0 / sample_rate as f64,
|
||||||
|
1.0,
|
||||||
|
PolynomialDegree::Septic,
|
||||||
|
1024,
|
||||||
|
1
|
||||||
|
).map_err(|e| format!("Failed to init Resampler: {:?}", e))?;
|
||||||
|
|
||||||
|
// Pre-roll buffer (3.0 seconds) * Channels (interleaved store)
|
||||||
|
let ring_curr_seconds = 3.0;
|
||||||
|
// WavWriter writes interleaved, so we store interleaved.
|
||||||
|
let ring_size = (sample_rate as f32 * ring_curr_seconds) as usize * channel_count as usize;
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
vad,
|
||||||
|
vad_chunk_size,
|
||||||
|
vad_buffer: Vec::new(),
|
||||||
|
channel_count,
|
||||||
|
resampler,
|
||||||
|
resample_input_buffer: Vec::new(),
|
||||||
|
resample_output_buffer: Vec::new(),
|
||||||
|
is_speech_active: false,
|
||||||
|
last_speech_time: 0,
|
||||||
|
// Hangover counts "processed samples" which are actually frames * channels in current logic?
|
||||||
|
// Actually total_processed_samples usually counts FRAMES in audio terminology, but here we count elements.
|
||||||
|
// Let's stick to elements to match existing logic logic.
|
||||||
|
hangover_samples: (sample_rate as f32 * 1.5 * channel_count as f32) as u64,
|
||||||
|
waiting_for_speech: wait_for_speech,
|
||||||
|
ring_buffer: vec![0.0; ring_size],
|
||||||
|
ring_pos: 0,
|
||||||
|
ring_size,
|
||||||
|
writer,
|
||||||
|
sample_rate,
|
||||||
|
total_processed_samples: 0,
|
||||||
|
app_handle: Some(app_handle),
|
||||||
|
last_event_time: std::time::Instant::now(),
|
||||||
|
system_queue: Arc::new(Mutex::new(std::collections::VecDeque::new())),
|
||||||
|
recording_mode,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn process(&mut self, input_data: &[f32]) {
|
||||||
|
// MIXING LOGIC:
|
||||||
|
// We have `input_data` (Microphone). We check `system_queue` for System Audio.
|
||||||
|
// System Audio is hardcoded to 2 channels (Stereo) in sc_audio.rs.
|
||||||
|
// Microphone `self.channel_count` can be 1 (Mono) or 2 (Stereo).
|
||||||
|
|
||||||
|
let mic_channels = self.channel_count as usize;
|
||||||
|
let mut mixed_data = input_data.to_vec();
|
||||||
|
let mut max_system_energy = 0.0;
|
||||||
|
|
||||||
|
let gain_mic = 1.0;
|
||||||
|
let gain_sys = 0.8; // Slightly lower system audio to prioritize speaker
|
||||||
|
|
||||||
|
if let Ok(mut queue) = self.system_queue.lock() {
|
||||||
|
let frames = mixed_data.len() / mic_channels;
|
||||||
|
|
||||||
|
for f in 0..frames {
|
||||||
|
// system_queue is always stereo (L, R, L, R...)
|
||||||
|
if let (Some(l), Some(r)) = (queue.pop_front(), queue.pop_front()) {
|
||||||
|
let abs_l = l.abs();
|
||||||
|
let abs_r = r.abs();
|
||||||
|
let current_sys_max = if abs_l > abs_r { abs_l } else { abs_r };
|
||||||
|
if current_sys_max > max_system_energy {
|
||||||
|
max_system_energy = current_sys_max;
|
||||||
|
}
|
||||||
|
|
||||||
|
if mic_channels == 1 {
|
||||||
|
// Mic is Mono: Mix System L+R down to Mono
|
||||||
|
let sys_mono = (l + r) / 2.0;
|
||||||
|
let mixed = (mixed_data[f] * gain_mic) + (sys_mono * gain_sys);
|
||||||
|
mixed_data[f] = mixed.max(-1.0).min(1.0);
|
||||||
|
} else {
|
||||||
|
// Mic is Stereo: Mix L-to-L and R-to-R
|
||||||
|
let f_start = f * 2;
|
||||||
|
let mixed_l = (mixed_data[f_start] * gain_mic) + (l * gain_sys);
|
||||||
|
let mixed_r = (mixed_data[f_start + 1] * gain_mic) + (r * gain_sys);
|
||||||
|
mixed_data[f_start] = mixed_l.max(-1.0).min(1.0);
|
||||||
|
mixed_data[f_start + 1] = mixed_r.max(-1.0).min(1.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let data = &mixed_data;
|
||||||
|
|
||||||
|
// 1. Add to Ring Buffer (Interleaved data - Record EVERYTHING)
|
||||||
|
for &sample in data {
|
||||||
|
self.ring_buffer[self.ring_pos] = sample;
|
||||||
|
self.ring_pos = (self.ring_pos + 1) % self.ring_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Prepare VAD Signal (Mono Mixdown)
|
||||||
|
// FRESH START LOGIC (v0.2.0):
|
||||||
|
// We expect standard Stereo Input.
|
||||||
|
|
||||||
|
let channels = self.channel_count as usize;
|
||||||
|
let frame_count = data.len() / channels;
|
||||||
|
let mut vad_input_chunk = Vec::with_capacity(frame_count);
|
||||||
|
|
||||||
|
for i in 0..frame_count {
|
||||||
|
let frame_start = i * channels;
|
||||||
|
|
||||||
|
let mix_sample = if channels >= 2 {
|
||||||
|
// Stereo -> Average L + R
|
||||||
|
(data[frame_start] + data[frame_start + 1]) / 2.0
|
||||||
|
} else {
|
||||||
|
// Mono -> Take as is
|
||||||
|
data[frame_start]
|
||||||
|
};
|
||||||
|
|
||||||
|
vad_input_chunk.push(mix_sample);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 3. Resample for VAD
|
||||||
|
self.resample_input_buffer.extend_from_slice(&vad_input_chunk);
|
||||||
|
|
||||||
|
let needed = self.resampler.input_frames_next();
|
||||||
|
while self.resample_input_buffer.len() >= needed {
|
||||||
|
let chunk: Vec<f32> = self.resample_input_buffer.drain(0..needed).collect();
|
||||||
|
// Resample (mono)
|
||||||
|
let waves_in = vec![chunk];
|
||||||
|
// Allocate output (approx)
|
||||||
|
let mut waves_out = vec![vec![0.0; (needed as f64 * (16000.0 / self.sample_rate as f64)).ceil() as usize + 10]; 1]; // +10 padding
|
||||||
|
|
||||||
|
if let Ok((_in_len, out_len)) = self.resampler.process_into_buffer(&waves_in, &mut waves_out, None) {
|
||||||
|
if out_len > 0 {
|
||||||
|
self.vad_buffer.extend_from_slice(&waves_out[0][0..out_len]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Process VAD
|
||||||
|
while self.vad_buffer.len() >= self.vad_chunk_size {
|
||||||
|
let vad_chunk: Vec<f32> = self.vad_buffer.drain(0..self.vad_chunk_size).collect();
|
||||||
|
// Run Detection
|
||||||
|
let probability = self.vad.predict(vad_chunk.clone());
|
||||||
|
|
||||||
|
let system_is_active = max_system_energy > 0.005; // Lowered to match trigger
|
||||||
|
let is_speech = probability > 0.9;
|
||||||
|
|
||||||
|
if is_speech || system_is_active {
|
||||||
|
self.is_speech_active = true;
|
||||||
|
self.last_speech_time = self.total_processed_samples;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Emit VAD event periodically
|
||||||
|
if self.last_event_time.elapsed().as_millis() > 500 {
|
||||||
|
if let Some(app) = &self.app_handle {
|
||||||
|
#[derive(Clone, serde::Serialize)]
|
||||||
|
struct VadEvent {
|
||||||
|
is_speech: bool,
|
||||||
|
probability: f32,
|
||||||
|
}
|
||||||
|
let _ = app.emit("vad-event", VadEvent {
|
||||||
|
probability,
|
||||||
|
is_speech: self.is_speech_active,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
self.last_event_time = std::time::Instant::now();
|
||||||
|
self.is_speech_active = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 4. Update Hangover and Check Write condition
|
||||||
|
if self.waiting_for_speech {
|
||||||
|
// TRIGGER CONDITION:
|
||||||
|
// 1. VAD says speech (Someone is talking)
|
||||||
|
// 2. AND System Audio has energy (Meaning audio is coming from the PC, i.e., Call started)
|
||||||
|
// Threshold 0.01 is roughly -40dB, should cover ringtones/speech easily but ignore silence/hiss.
|
||||||
|
|
||||||
|
let system_active = max_system_energy > 0.005;
|
||||||
|
|
||||||
|
// Periodically log energy to help debug why meeting mode might not start
|
||||||
|
if self.last_event_time.elapsed().as_millis() > 2000 && self.recording_mode == "meeting" {
|
||||||
|
if let Some(app) = &self.app_handle {
|
||||||
|
emit_log(app, "DEBUG", &format!("Waiting for Meeting... Current System Energy: {:.4} (Threshold: 0.005)", max_system_energy));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MODE-SPECIFIC TRIGGER LOGIC:
|
||||||
|
// "voice" -> Trigger if user speaks (is_speech_active)
|
||||||
|
// "meeting" -> Trigger ONLY if system audio energy detected (Call starting)
|
||||||
|
let trigger = if self.recording_mode == "voice" {
|
||||||
|
self.is_speech_active
|
||||||
|
} else {
|
||||||
|
system_active
|
||||||
|
};
|
||||||
|
|
||||||
|
if trigger {
|
||||||
|
// Trigger Detected!
|
||||||
|
println!("Auto-Start: Call detected (SysEnergy: {}). Flushing pre-roll...", max_system_energy);
|
||||||
|
self.waiting_for_speech = false;
|
||||||
|
|
||||||
|
// Flush Ring Buffer (Orderly: from ring_pos to end, then 0 to ring_pos)
|
||||||
|
let mut guard = self.writer.lock().unwrap();
|
||||||
|
let amplitude = i16::MAX as f32;
|
||||||
|
|
||||||
|
// Part 1: ring_pos to end
|
||||||
|
for i in self.ring_pos..self.ring_size {
|
||||||
|
let sample = self.ring_buffer[i];
|
||||||
|
guard.write_sample((sample * amplitude) as i16).ok();
|
||||||
|
}
|
||||||
|
// Part 2: 0 to ring_pos
|
||||||
|
for i in 0..self.ring_pos {
|
||||||
|
let sample = self.ring_buffer[i];
|
||||||
|
guard.write_sample((sample * amplitude) as i16).ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Emit event to notify frontend that "real" recording started
|
||||||
|
if let Some(app) = &self.app_handle {
|
||||||
|
let _ = app.emit("auto-recording-triggered", ());
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Still waiting, do not write to file.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Standard Recording Logic (Active or Hangover)
|
||||||
|
let time_since_speech = self.total_processed_samples.saturating_sub(self.last_speech_time);
|
||||||
|
|
||||||
|
// We write to file if:
|
||||||
|
// 1. VAD thinks someone is speaking (Mic or System)
|
||||||
|
// 2. OR System audio energy is currently above threshold (Ensures calls are captured)
|
||||||
|
// 3. OR we are within the hangover period
|
||||||
|
let system_is_active = max_system_energy > 0.005;
|
||||||
|
|
||||||
|
if self.is_speech_active || system_is_active || time_since_speech < self.hangover_samples {
|
||||||
|
let mut guard = self.writer.lock().unwrap();
|
||||||
|
for &sample in data {
|
||||||
|
let amplitude = i16::MAX as f32;
|
||||||
|
guard.write_sample((sample * amplitude) as i16).ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.total_processed_samples += data.len() as u64;
|
||||||
|
}
|
||||||
|
}
|
||||||
112
src-tauri/src/auth.rs
Normal file
112
src-tauri/src/auth.rs
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
use tauri::{AppHandle, Runtime};
|
||||||
|
use tauri_plugin_opener::OpenerExt;
|
||||||
|
use tauri_plugin_oauth::start;
|
||||||
|
use url::Url;
|
||||||
|
use oauth2::{
|
||||||
|
basic::BasicClient, AuthUrl, ClientId, CsrfToken, PkceCodeChallenge, RedirectUrl, Scope,
|
||||||
|
TokenResponse, TokenUrl,
|
||||||
|
};
|
||||||
|
use oauth2::reqwest::async_http_client;
|
||||||
|
|
||||||
|
// const CLIENT_ID: &str = "YOUR_CLIENT_ID_HERE";
|
||||||
|
const AUTH_URL: &str = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize";
|
||||||
|
const TOKEN_URL: &str = "https://login.microsoftonline.com/common/oauth2/v2.0/token";
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn start_auth_flow<R: Runtime>(app: AppHandle<R>, client_id: String) -> Result<String, String> {
|
||||||
|
// 1. Start Localhost Server
|
||||||
|
let (tx, rx) = std::sync::mpsc::channel();
|
||||||
|
|
||||||
|
// tauri-plugin-oauth start() returns a port and stops server when callback received
|
||||||
|
let port = start(move |url| {
|
||||||
|
// Ignore favicon requests to avoid triggering early
|
||||||
|
if url.contains("favicon.ico") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let _ = tx.send(url);
|
||||||
|
})
|
||||||
|
.map_err(|e| format!("Failed to start oauth server: {}", e))?;
|
||||||
|
|
||||||
|
let redirect_uri = format!("http://localhost:{}/auth/callback", port);
|
||||||
|
|
||||||
|
// 2. Setup OAuth Client
|
||||||
|
let client = BasicClient::new(
|
||||||
|
ClientId::new(client_id),
|
||||||
|
None, // No client secret for PKCE public client
|
||||||
|
AuthUrl::new(AUTH_URL.to_string()).map_err(|e| e.to_string())?,
|
||||||
|
Some(TokenUrl::new(TOKEN_URL.to_string()).map_err(|e| e.to_string())?),
|
||||||
|
)
|
||||||
|
.set_redirect_uri(RedirectUrl::new(redirect_uri.clone()).map_err(|e| e.to_string())?);
|
||||||
|
|
||||||
|
// 3. Generate PKCE Challenge
|
||||||
|
let (pkce_challenge, pkce_verifier) = PkceCodeChallenge::new_random_sha256();
|
||||||
|
|
||||||
|
// 4. Generate Auth URL
|
||||||
|
let (auth_url, _csrf_token) = client
|
||||||
|
.authorize_url(CsrfToken::new_random)
|
||||||
|
.add_scope(Scope::new("User.Read".to_string()))
|
||||||
|
.add_scope(Scope::new("Calendars.Read".to_string()))
|
||||||
|
.set_pkce_challenge(pkce_challenge)
|
||||||
|
.url();
|
||||||
|
|
||||||
|
// 5. Open Browser
|
||||||
|
app.opener().open_url(auth_url.as_str(), None::<&str>)
|
||||||
|
.map_err(|e| format!("Failed to open browser: {}", e))?;
|
||||||
|
|
||||||
|
// 6. Wait for Callback
|
||||||
|
let received_url_str = rx.recv().map_err(|e| format!("Failed to receive auth code: {}", e))?;
|
||||||
|
|
||||||
|
// 7. Parse Code from URL
|
||||||
|
// Actually we need to parse the query params from received_url_str
|
||||||
|
let parsed_url = Url::parse(&received_url_str).map_err(|e| e.to_string())?;
|
||||||
|
let pairs: std::collections::HashMap<_, _> = parsed_url.query_pairs().into_owned().collect();
|
||||||
|
|
||||||
|
if let Some(err) = pairs.get("error") {
|
||||||
|
let desc = pairs.get("error_description").map(|s| s.as_str()).unwrap_or("No description");
|
||||||
|
return Err(format!("OAuth Error: {} ({})", err, desc));
|
||||||
|
}
|
||||||
|
|
||||||
|
let code = pairs.get("code").ok_or_else(|| format!("No code in redirect callback. Received URL: {}", received_url_str))?;
|
||||||
|
|
||||||
|
// 8. Exchange Code for Token
|
||||||
|
let token_result = client
|
||||||
|
.exchange_code(oauth2::AuthorizationCode::new(code.clone()))
|
||||||
|
.set_pkce_verifier(pkce_verifier)
|
||||||
|
.request_async(async_http_client)
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("Failed to exchange token: {}", e))?;
|
||||||
|
|
||||||
|
let access_token = token_result.access_token().secret();
|
||||||
|
|
||||||
|
// Save token? Or just return it.
|
||||||
|
// Ideally we save it in key storage, but for MVP return it.
|
||||||
|
|
||||||
|
Ok(access_token.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn get_calendar_events(token: String) -> Result<Vec<serde_json::Value>, String> {
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let res = client
|
||||||
|
.get("https://graph.microsoft.com/v1.0/me/calendarView")
|
||||||
|
.bearer_auth(token)
|
||||||
|
.query(&[
|
||||||
|
("startDateTime", chrono::Utc::now().to_rfc3339()),
|
||||||
|
("endDateTime", (chrono::Utc::now() + chrono::Duration::days(7)).to_rfc3339()),
|
||||||
|
("$select", "id,subject,start,end,location,onlineMeeting,bodyPreview,body,attendees".to_string())
|
||||||
|
])
|
||||||
|
.header("Prefer", "outlook.timezone=\"UTC\"")
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(|e| e.to_string())?
|
||||||
|
.json::<serde_json::Value>()
|
||||||
|
.await
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
// Extract 'value' array
|
||||||
|
if let Some(events) = res.get("value").and_then(|v| v.as_array()) {
|
||||||
|
Ok(events.clone())
|
||||||
|
} else {
|
||||||
|
Ok(vec![])
|
||||||
|
}
|
||||||
|
}
|
||||||
96
src-tauri/src/email.rs
Normal file
96
src-tauri/src/email.rs
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
use tauri::AppHandle;
|
||||||
|
use lettre::{Message, SmtpTransport, Transport, AsyncTransport};
|
||||||
|
use lettre::transport::smtp::authentication::Credentials;
|
||||||
|
use lettre::transport::smtp::AsyncSmtpTransport;
|
||||||
|
use lettre::Tokio1Executor;
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
pub struct SmtpConfig {
|
||||||
|
host: String,
|
||||||
|
port: u16,
|
||||||
|
username: String,
|
||||||
|
password: String,
|
||||||
|
sender_email: String,
|
||||||
|
sender_name: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
pub struct EmailMessage {
|
||||||
|
to: Vec<String>,
|
||||||
|
subject: String,
|
||||||
|
body_html: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn send_smtp_email(app: AppHandle, config: SmtpConfig, message: EmailMessage) -> Result<String, String> {
|
||||||
|
println!("SMTP: Preparing to send email to {:?}", message.to);
|
||||||
|
|
||||||
|
// 1. Build Message
|
||||||
|
let sender_str = if let Some(name) = &config.sender_name {
|
||||||
|
format!("{} <{}>", name, config.sender_email)
|
||||||
|
} else {
|
||||||
|
config.sender_email.clone()
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut builder = Message::builder()
|
||||||
|
.from(sender_str.parse().map_err(|e: lettre::address::AddressError| e.to_string())?)
|
||||||
|
.subject(message.subject);
|
||||||
|
|
||||||
|
for recipient in message.to {
|
||||||
|
builder = builder.to(recipient.parse().map_err(|e: lettre::address::AddressError| e.to_string())?);
|
||||||
|
}
|
||||||
|
|
||||||
|
let email = builder
|
||||||
|
.header(lettre::message::header::ContentType::TEXT_HTML)
|
||||||
|
.body(message.body_html)
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
// 2. Build Transport
|
||||||
|
println!("SMTP: Connecting to {}:{}...", config.host, config.port);
|
||||||
|
let creds = Credentials::new(config.username, config.password);
|
||||||
|
|
||||||
|
// TLS Configuration
|
||||||
|
// Proton Mail and others on 465 require Implicit TLS (Wrapper).
|
||||||
|
// Others on 587 use STARTTLS (Opportunistic).
|
||||||
|
|
||||||
|
use lettre::transport::smtp::client::{Tls, TlsParameters};
|
||||||
|
|
||||||
|
let tls_params = TlsParameters::builder(config.host.clone())
|
||||||
|
.build()
|
||||||
|
.map_err(|e| format!("TLS Params error: {}", e))?;
|
||||||
|
|
||||||
|
let builder = AsyncSmtpTransport::<Tokio1Executor>::relay(&config.host)
|
||||||
|
.map_err(|e| e.to_string())?
|
||||||
|
.port(config.port)
|
||||||
|
.credentials(creds);
|
||||||
|
|
||||||
|
let mailer: AsyncSmtpTransport<Tokio1Executor> = if config.port == 465 {
|
||||||
|
println!("SMTP: Using Implicit TLS (Wrapper) for port 465");
|
||||||
|
builder.tls(Tls::Wrapper(tls_params)).build()
|
||||||
|
} else {
|
||||||
|
println!("SMTP: Using Opportunistic TLS (STARTTLS) for port {}", config.port);
|
||||||
|
builder.tls(Tls::Opportunistic(tls_params)).build()
|
||||||
|
};
|
||||||
|
|
||||||
|
// 3. Send with Timeout
|
||||||
|
println!("SMTP: Sending...");
|
||||||
|
let send_task = mailer.send(email);
|
||||||
|
|
||||||
|
match tokio::time::timeout(std::time::Duration::from_secs(15), send_task).await {
|
||||||
|
Ok(result) => match result {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("SMTP: Success!");
|
||||||
|
Ok("Email sent successfully".to_string())
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
println!("SMTP: Failed: {}", e);
|
||||||
|
// Hint at common issues
|
||||||
|
Err(format!("Failed to send: {}. (Check Host/Port/Password)", e))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(_) => {
|
||||||
|
println!("SMTP: Timeout");
|
||||||
|
Err("Connection timed out after 15s. Try changing Port (465 vs 587) or check VPN/Firewall.".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
984
src-tauri/src/lib.rs.bak
Normal file
984
src-tauri/src/lib.rs.bak
Normal file
@@ -0,0 +1,984 @@
|
|||||||
|
use tauri::{
|
||||||
|
AppHandle, Manager, State, Emitter,
|
||||||
|
menu::{Menu, MenuItem},
|
||||||
|
tray::{TrayIconBuilder, TrayIconEvent},
|
||||||
|
WindowEvent
|
||||||
|
};
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use std::process::Command;
|
||||||
|
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||||
|
use std::time::Duration;
|
||||||
|
use tokio::time::sleep;
|
||||||
|
use base64::Engine;
|
||||||
|
|
||||||
|
mod audio_processor;
|
||||||
|
use audio_processor::AudioProcessor;
|
||||||
|
mod auth;
|
||||||
|
mod email;
|
||||||
|
mod sc_audio;
|
||||||
|
|
||||||
|
// State to hold the active recording stream
|
||||||
|
struct AppState {
|
||||||
|
recording_stream: Mutex<Option<cpal::Stream>>,
|
||||||
|
recording_file_path: Mutex<Option<String>>,
|
||||||
|
system_capture: Mutex<Option<sc_audio::SystemAudioCapture>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Serialize)]
|
||||||
|
struct AudioDevice {
|
||||||
|
id: String,
|
||||||
|
name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Serialize, Clone)]
|
||||||
|
struct LogEvent {
|
||||||
|
level: String,
|
||||||
|
message: String,
|
||||||
|
timestamp: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn emit_log(app: &AppHandle, level: &str, message: &str) {
|
||||||
|
let log = LogEvent {
|
||||||
|
level: level.to_string(),
|
||||||
|
message: message.to_string(),
|
||||||
|
timestamp: chrono::Local::now().format("%H:%M:%S").to_string(),
|
||||||
|
};
|
||||||
|
let _ = app.emit("log-event", log);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn greet(name: &str) -> String {
|
||||||
|
format!("Hello, {}! You've been greeted from Rust!", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn get_input_devices() -> Result<Vec<AudioDevice>, String> {
|
||||||
|
let host = cpal::default_host();
|
||||||
|
let devices = host.input_devices().map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
let mut result = Vec::new();
|
||||||
|
for device in devices {
|
||||||
|
#[allow(deprecated)]
|
||||||
|
if let Ok(name) = device.name() {
|
||||||
|
// macOS often produces weird names, but let's just use what we get
|
||||||
|
result.push(AudioDevice {
|
||||||
|
id: name.clone(), // Using name as ID for simplicity in this MVP
|
||||||
|
name,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn start_recording(app: AppHandle, state: State<'_, AppState>, device_id: String, save_path: Option<String>, custom_filename: Option<String>, wait_for_speech: Option<bool>, mode: String) -> Result<(), String> {
|
||||||
|
emit_log(&app, "INFO", &format!("Starting recording [Mode: {}] on device: {}", mode, device_id));
|
||||||
|
let host = cpal::default_host();
|
||||||
|
|
||||||
|
// Find device by name (using name as ID)
|
||||||
|
#[allow(deprecated)]
|
||||||
|
let device = host.input_devices()
|
||||||
|
.map_err(|e| e.to_string())?
|
||||||
|
.find(|d| d.name().map(|n| n == device_id).unwrap_or(false))
|
||||||
|
.or_else(|| host.default_input_device())
|
||||||
|
.ok_or("No input device found")?;
|
||||||
|
|
||||||
|
// Select the configuration with the MAXIMUM number of channels
|
||||||
|
// This is crucial for "Hearbit Audio" (Aggregate) which lists 3 channels but might default to 2.
|
||||||
|
// Select Audio Configuration
|
||||||
|
// We prioritize 48kHz because System Audio (ScreenCaptureKit) acts best at 48k.
|
||||||
|
let supported_configs: Vec<_> = device.supported_input_configs().map_err(|e| e.to_string())?.collect();
|
||||||
|
|
||||||
|
// Try to find 48kHz specifically
|
||||||
|
// Note: cpal::SampleRate is likely a type alias for u32 here, so we pass 48000 directly.
|
||||||
|
let config = supported_configs.iter()
|
||||||
|
.find(|c| c.min_sample_rate() <= 48000 && c.max_sample_rate() >= 48000)
|
||||||
|
.map(|c| c.with_sample_rate(48000))
|
||||||
|
.or_else(|| {
|
||||||
|
// Fallback: Max sample rate
|
||||||
|
supported_configs.iter()
|
||||||
|
.max_by_key(|c| c.channels())
|
||||||
|
.map(|c| c.with_max_sample_rate())
|
||||||
|
})
|
||||||
|
.ok_or("No supported input configurations found")?;
|
||||||
|
|
||||||
|
emit_log(&app, "INFO", &format!("Selected Audio Config: {} Channels, {} Hz", config.channels(), config.sample_rate()));
|
||||||
|
|
||||||
|
let spec = hound::WavSpec {
|
||||||
|
channels: config.channels(),
|
||||||
|
sample_rate: config.sample_rate(),
|
||||||
|
bits_per_sample: 16,
|
||||||
|
sample_format: hound::SampleFormat::Int,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Determine file path: User provided or Temp
|
||||||
|
let filename = if let Some(name) = custom_filename {
|
||||||
|
// Sanitize filename
|
||||||
|
let safe_name: String = name.chars().map(|x| if x.is_alphanumeric() || x == ' ' || x == '-' || x == '_' { x } else { '_' }).collect();
|
||||||
|
format!("{}.wav", safe_name)
|
||||||
|
} else {
|
||||||
|
format!("recording_{}.wav", std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs())
|
||||||
|
};
|
||||||
|
|
||||||
|
let file_path = if let Some(path) = save_path {
|
||||||
|
if path.trim().is_empty() {
|
||||||
|
std::env::temp_dir().join(&filename)
|
||||||
|
} else {
|
||||||
|
std::path::PathBuf::from(path).join(&filename)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::env::temp_dir().join(&filename)
|
||||||
|
};
|
||||||
|
|
||||||
|
let file_path_str = file_path.to_string_lossy().to_string();
|
||||||
|
emit_log(&app, "INFO", &format!("Saving recording to: {}", file_path_str));
|
||||||
|
|
||||||
|
let writer = hound::WavWriter::create(&file_path, spec).map_err(|e| e.to_string())?;
|
||||||
|
let writer = Arc::new(Mutex::new(writer));
|
||||||
|
let writer_clone = writer.clone();
|
||||||
|
|
||||||
|
// Initialize AudioProcessor (VAD)
|
||||||
|
// We pass the writer to it.
|
||||||
|
let should_wait = wait_for_speech.unwrap_or(false);
|
||||||
|
if should_wait {
|
||||||
|
emit_log(&app, "INFO", &format!("Recording started in WAITING mode (Trigger: {}).", if mode == "voice" { "Speech" } else { "System Audio" }));
|
||||||
|
}
|
||||||
|
|
||||||
|
let processor = AudioProcessor::new(config.sample_rate(), config.channels(), writer.clone(), app.clone(), should_wait, mode)
|
||||||
|
.map_err(|e| format!("Failed to create AudioProcessor: {}", e))?;
|
||||||
|
|
||||||
|
// Wrap processor in Arc<Mutex> so we can share/move it into callback
|
||||||
|
// Actually, cpal callback takes ownership of its closure state usually if 'move'.
|
||||||
|
// Since stream is on another thread, we need Send. AudioProcessor should be Send.
|
||||||
|
// However, the callback is called repeatedly. We need to keep state.
|
||||||
|
// The workaround is to wrap it in a Mutex.
|
||||||
|
let processor = Arc::new(Mutex::new(processor));
|
||||||
|
let processor_clone = processor.clone();
|
||||||
|
|
||||||
|
// --- SYSTEM AUDIO CAPTURE START ---
|
||||||
|
// Prevent Doubling: If user selected an aggregate device (Hearbit Audio/BlackHole),
|
||||||
|
// it ALREADY contains system audio. In that case, we don't need internal SCK capture.
|
||||||
|
let is_aggregate = device_id.contains("Hearbit") || device_id.contains("BlackHole");
|
||||||
|
|
||||||
|
if is_aggregate {
|
||||||
|
emit_log(&app, "INFO", "Aggregate device detected. Disabling internal System Audio Capture to prevent doubling.");
|
||||||
|
} else {
|
||||||
|
let mut sys_capture = sc_audio::SystemAudioCapture::new(config.sample_rate());
|
||||||
|
|
||||||
|
// Get the queue to share with the capture callback
|
||||||
|
let queue_clone = {
|
||||||
|
let p = processor.lock().unwrap();
|
||||||
|
p.system_queue.clone() // Access the pub field we added
|
||||||
|
};
|
||||||
|
|
||||||
|
let sys_callback = move |data: &[f32]| {
|
||||||
|
// Push to queue
|
||||||
|
if let Ok(mut q) = queue_clone.lock() {
|
||||||
|
q.extend(data.iter());
|
||||||
|
|
||||||
|
// Limit queue size to avoid memory leaks if main process loop is slow
|
||||||
|
while q.len() > 48000 * 5 { // 5 seconds buffer
|
||||||
|
q.pop_front();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match sys_capture.start(sys_callback).await {
|
||||||
|
Ok(_) => emit_log(&app, "INFO", "System Audio Capture started."),
|
||||||
|
Err(e) => emit_log(&app, "WARN", &format!("System Audio Capture failed (Permissions?): {}", e)),
|
||||||
|
}
|
||||||
|
|
||||||
|
*state.system_capture.lock().unwrap() = Some(sys_capture);
|
||||||
|
}
|
||||||
|
// --- SYSTEM AUDIO CAPTURE END ---
|
||||||
|
|
||||||
|
let app_handle = app.clone();
|
||||||
|
let err_fn = move |err| {
|
||||||
|
eprintln!("an error occurred on stream: {}", err);
|
||||||
|
emit_log(&app_handle, "ERROR", &format!("Stream error: {}", err));
|
||||||
|
};
|
||||||
|
|
||||||
|
let stream = match config.sample_format() {
|
||||||
|
cpal::SampleFormat::F32 => device.build_input_stream(
|
||||||
|
&config.into(),
|
||||||
|
move |data: &[f32], _: &_| {
|
||||||
|
if let Ok(mut p) = processor_clone.lock() {
|
||||||
|
p.process(data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
err_fn,
|
||||||
|
None
|
||||||
|
),
|
||||||
|
// For I16 and U16 we need to convert to F32 for our processor
|
||||||
|
cpal::SampleFormat::I16 => device.build_input_stream(
|
||||||
|
&config.into(),
|
||||||
|
move |data: &[i16], _: &_| {
|
||||||
|
// Convert i16 to f32
|
||||||
|
let f32_data: Vec<f32> = data.iter().map(|&s| s as f32 / i16::MAX as f32).collect();
|
||||||
|
if let Ok(mut p) = processor_clone.lock() {
|
||||||
|
p.process(&f32_data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
err_fn,
|
||||||
|
None
|
||||||
|
),
|
||||||
|
cpal::SampleFormat::U16 => device.build_input_stream(
|
||||||
|
&config.into(),
|
||||||
|
move |data: &[u16], _: &_| {
|
||||||
|
// Convert u16 to f32
|
||||||
|
let f32_data: Vec<f32> = data.iter().map(|&s| (s as i32 - 32768) as f32 / 32768.0).collect();
|
||||||
|
if let Ok(mut p) = processor_clone.lock() {
|
||||||
|
p.process(&f32_data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
err_fn,
|
||||||
|
None
|
||||||
|
),
|
||||||
|
_ => return Err("Unsupported sample format".to_string()),
|
||||||
|
}.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
stream.play().map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
// Store state
|
||||||
|
*state.recording_stream.lock().unwrap() = Some(stream);
|
||||||
|
*state.recording_file_path.lock().unwrap() = Some(file_path_str.clone());
|
||||||
|
|
||||||
|
emit_log(&app, "SUCCESS", &format!("Recording started. File: {}", file_path_str));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn stop_recording(app: AppHandle, state: State<'_, AppState>) -> Result<String, String> {
|
||||||
|
emit_log(&app, "INFO", "Stopping recording...");
|
||||||
|
// Drop stream to stop recording
|
||||||
|
{
|
||||||
|
let mut stream_guard = state.recording_stream.lock().unwrap();
|
||||||
|
// Also stop System Capture
|
||||||
|
let mut sys_guard = state.system_capture.lock().unwrap();
|
||||||
|
if let Some(sys) = sys_guard.as_mut() {
|
||||||
|
sys.stop();
|
||||||
|
}
|
||||||
|
*sys_guard = None;
|
||||||
|
|
||||||
|
if stream_guard.is_none() {
|
||||||
|
return Err("Not recording".to_string());
|
||||||
|
}
|
||||||
|
*stream_guard = None; // This drops the stream and stops recording
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return file path
|
||||||
|
let mut path_guard = state.recording_file_path.lock().unwrap();
|
||||||
|
let path = path_guard.take().ok_or("No recording path found".to_string())?;
|
||||||
|
emit_log(&app, "SUCCESS", &format!("Recording stopped. Saved to: {}", path));
|
||||||
|
Ok(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn pause_recording(app: AppHandle, state: State<'_, AppState>) -> Result<(), String> {
|
||||||
|
emit_log(&app, "INFO", "Pausing recording...");
|
||||||
|
let stream_guard = state.recording_stream.lock().unwrap();
|
||||||
|
if let Some(stream) = stream_guard.as_ref() {
|
||||||
|
stream.pause().map_err(|e| e.to_string())?;
|
||||||
|
emit_log(&app, "SUCCESS", "Recording paused.");
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err("Not recording".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn resume_recording(app: AppHandle, state: State<'_, AppState>) -> Result<(), String> {
|
||||||
|
emit_log(&app, "INFO", "Resuming recording...");
|
||||||
|
let stream_guard = state.recording_stream.lock().unwrap();
|
||||||
|
if let Some(stream) = stream_guard.as_ref() {
|
||||||
|
stream.play().map_err(|e| e.to_string())?;
|
||||||
|
emit_log(&app, "SUCCESS", "Recording resumed.");
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err("Not recording".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct ModelListResponse {
|
||||||
|
data: Vec<ModelData>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct ModelData {
|
||||||
|
id: String,
|
||||||
|
#[allow(dead_code)]
|
||||||
|
owned_by: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Structs for Infomaniak API responses
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct WhisperResponse {
|
||||||
|
text: Option<String>,
|
||||||
|
batch_id: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct ChatCompletionResponse {
|
||||||
|
choices: Vec<Choice>,
|
||||||
|
}
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct Choice {
|
||||||
|
message: Message,
|
||||||
|
}
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct Message {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
content: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Serialize)]
|
||||||
|
struct ModelInfo {
|
||||||
|
id: String,
|
||||||
|
name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn get_available_models(app: AppHandle, api_key: String, product_id: String) -> Result<Vec<ModelInfo>, String> {
|
||||||
|
emit_log(&app, "INFO", "Fetching available models from Infomaniak...");
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
// Use the v2/openai compliant endpoint as per docs
|
||||||
|
let url = format!("https://api.infomaniak.com/2/ai/{}/openai/v1/models", product_id);
|
||||||
|
|
||||||
|
emit_log(&app, "DEBUG", &format!("GET {}", url));
|
||||||
|
|
||||||
|
let res = client.get(&url)
|
||||||
|
.header("Authorization", format!("Bearer {}", api_key))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
let msg = format!("Network error fetching models: {}", e);
|
||||||
|
emit_log(&app, "ERROR", &msg);
|
||||||
|
msg
|
||||||
|
})?;
|
||||||
|
|
||||||
|
if res.status().is_success() {
|
||||||
|
let raw_body = res.text().await.map_err(|e| e.to_string())?;
|
||||||
|
// println!("Models Raw Response: {}", raw_body);
|
||||||
|
let list: ModelListResponse = serde_json::from_str(&raw_body)
|
||||||
|
.map_err(|e| format!("Failed to parse models: {}. Body: {}", e, raw_body))?;
|
||||||
|
|
||||||
|
let models = list.data.into_iter()
|
||||||
|
.filter(|m| !m.id.to_lowercase().contains("mini_lm") && !m.id.to_lowercase().contains("bert") && !m.id.to_lowercase().contains("embedding"))
|
||||||
|
.map(|m| ModelInfo {
|
||||||
|
id: m.id.clone(),
|
||||||
|
name: m.id, // Use ID as name for now, or fetch more details if available
|
||||||
|
}).collect::<Vec<ModelInfo>>();
|
||||||
|
|
||||||
|
emit_log(&app, "SUCCESS", &format!("Loaded {} models.", models.len()));
|
||||||
|
Ok(models)
|
||||||
|
} else {
|
||||||
|
let err = res.text().await.unwrap_or_default();
|
||||||
|
emit_log(&app, "ERROR", &format!("Failed to fetch models: {}", err));
|
||||||
|
Err(format!("Failed to fetch models: {}", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct WhisperVerboseResponse {
|
||||||
|
text: Option<String>,
|
||||||
|
segments: Option<Vec<Segment>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct Segment {
|
||||||
|
start: f64,
|
||||||
|
end: f64,
|
||||||
|
text: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn transcribe_audio(app: AppHandle, file_path: String, api_key: String, product_id: String) -> Result<String, String> {
|
||||||
|
emit_log(&app, "INFO", "Starting transcription with timestamps...");
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
|
||||||
|
// Prepare file part
|
||||||
|
let file_bytes = std::fs::read(&file_path).map_err(|e| e.to_string())?;
|
||||||
|
// We must use a known file name for the part, Infomaniak might care, or not.
|
||||||
|
let file_part = reqwest::multipart::Part::bytes(file_bytes)
|
||||||
|
.file_name("recording.wav")
|
||||||
|
.mime_str("audio/wav")
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
let form = reqwest::multipart::Form::new()
|
||||||
|
.part("file", file_part)
|
||||||
|
.text("model", "whisper")
|
||||||
|
.text("response_format", "verbose_json")
|
||||||
|
.text("timestamp_granularities[]", "segment"); // Crucial for accurate segments
|
||||||
|
|
||||||
|
let url = format!("https://api.infomaniak.com/1/ai/{}/openai/audio/transcriptions", product_id);
|
||||||
|
|
||||||
|
emit_log(&app, "DEBUG", &format!("POST {}", url));
|
||||||
|
|
||||||
|
let res = client.post(&url)
|
||||||
|
.header("Authorization", format!("Bearer {}", api_key))
|
||||||
|
.multipart(form)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
let msg = format!("Network error during transcription: {}", e);
|
||||||
|
emit_log(&app, "ERROR", &msg);
|
||||||
|
msg
|
||||||
|
})?;
|
||||||
|
|
||||||
|
if res.status().is_success() {
|
||||||
|
let raw_body = res.text().await.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
// Check if we got a batch ID
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct BatchResponse {
|
||||||
|
batch_id: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try parsing as batch response first (Infomaniak specific behavior)
|
||||||
|
if let Ok(batch_res) = serde_json::from_str::<BatchResponse>(&raw_body) {
|
||||||
|
if let Some(batch_id) = batch_res.batch_id {
|
||||||
|
emit_log(&app, "INFO", &format!("Transcription queued. Batch ID: {}", batch_id));
|
||||||
|
return poll_transcription(&app, &client, &api_key, &product_id, &batch_id).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If not batch, try parsing verbose response directly
|
||||||
|
// Log the raw body so we can see why it fails
|
||||||
|
emit_log(&app, "DEBUG", &format!("Direct Response (first 500 chars): {:.500}", raw_body));
|
||||||
|
|
||||||
|
let response: WhisperVerboseResponse = serde_json::from_str(&raw_body)
|
||||||
|
.map_err(|e| format!("Failed to decode JSON: {}. Body: {}", e, raw_body))?;
|
||||||
|
|
||||||
|
if let Some(segments) = response.segments {
|
||||||
|
emit_log(&app, "INFO", &format!("Found {} segments (Direct).", segments.len()));
|
||||||
|
for (i, seg) in segments.iter().take(3).enumerate() {
|
||||||
|
emit_log(&app, "DEBUG", &format!("Seg {}: start={}", i, seg.start));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format timestamps: [MM:SS] Text
|
||||||
|
let mut formatted_transcript = String::new();
|
||||||
|
for segment in segments {
|
||||||
|
let start_mins = (segment.start / 60.0).floor() as u64;
|
||||||
|
let start_secs = (segment.start % 60.0).floor() as u64;
|
||||||
|
formatted_transcript.push_str(&format!("[{:02}:{:02}] {}\n", start_mins, start_secs, segment.text.trim()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to raw text if segments empty
|
||||||
|
if formatted_transcript.trim().is_empty() {
|
||||||
|
if let Some(text) = response.text {
|
||||||
|
emit_log(&app, "SUCCESS", "Segments missing, using raw text.");
|
||||||
|
return Ok(text);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
emit_log(&app, "SUCCESS", "Transcription received with timestamps.");
|
||||||
|
return Ok(formatted_transcript);
|
||||||
|
}
|
||||||
|
} else if let Some(text) = response.text {
|
||||||
|
emit_log(&app, "SUCCESS", "Segments missing, using raw text.");
|
||||||
|
return Ok(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
emit_log(&app, "ERROR", "Response contained no recognized content.");
|
||||||
|
Err(format!("Response contained no recognized content. Body: {}", raw_body))
|
||||||
|
} else {
|
||||||
|
let error_text = res.text().await.unwrap_or_default();
|
||||||
|
emit_log(&app, "ERROR", &format!("Transcription failed: {}", error_text));
|
||||||
|
Err(format!("Transcription failed: {}", error_text))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn poll_transcription(app: &AppHandle, client: &reqwest::Client, api_key: &str, product_id: &str, batch_id: &str) -> Result<String, String> {
|
||||||
|
let status_url = format!("https://api.infomaniak.com/1/ai/{}/results/{}", product_id, batch_id);
|
||||||
|
|
||||||
|
let mut attempts = 0;
|
||||||
|
while attempts < 40 { // 40 * 2s = 80s timeout
|
||||||
|
attempts += 1;
|
||||||
|
sleep(Duration::from_secs(2)).await;
|
||||||
|
|
||||||
|
emit_log(app, "DEBUG", &format!("Polling status... Attempt {}", attempts));
|
||||||
|
let res = client.get(&status_url)
|
||||||
|
.header("Authorization", format!("Bearer {}", api_key))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("Polling error: {}", e))?;
|
||||||
|
|
||||||
|
if res.status().is_success() {
|
||||||
|
let json: serde_json::Value = res.json().await.map_err(|e| e.to_string())?;
|
||||||
|
// Check 'status'
|
||||||
|
if let Some(status) = json.get("status").and_then(|s| s.as_str()) {
|
||||||
|
if status == "success" {
|
||||||
|
// Download the result
|
||||||
|
let download_url = format!("https://api.infomaniak.com/1/ai/{}/results/{}/download", product_id, batch_id);
|
||||||
|
let dl_res = client.get(&download_url)
|
||||||
|
.header("Authorization", format!("Bearer {}", api_key))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
if dl_res.status().is_success() {
|
||||||
|
let content = dl_res.text().await.map_err(|e| e.to_string())?;
|
||||||
|
emit_log(app, "DEBUG", &format!("Poll Raw Content (first 500 chars): {:.500}", content));
|
||||||
|
|
||||||
|
// Try to parse as Verbose JSON to get timestamps
|
||||||
|
if let Ok(response) = serde_json::from_str::<WhisperVerboseResponse>(&content) {
|
||||||
|
if let Some(segments) = response.segments {
|
||||||
|
emit_log(app, "INFO", &format!("Found {} segments.", segments.len()));
|
||||||
|
// Log first 3 segments start times
|
||||||
|
for (i, seg) in segments.iter().take(3).enumerate() {
|
||||||
|
emit_log(app, "DEBUG", &format!("Seg {}: start={}", i, seg.start));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut formatted_transcript = String::new();
|
||||||
|
for segment in segments {
|
||||||
|
let start_mins = (segment.start / 60.0).floor() as u64;
|
||||||
|
let start_secs = (segment.start % 60.0).floor() as u64;
|
||||||
|
formatted_transcript.push_str(&format!("[{:02}:{:02}] {}\n", start_mins, start_secs, segment.text.trim()));
|
||||||
|
}
|
||||||
|
if !formatted_transcript.trim().is_empty() {
|
||||||
|
emit_log(app, "SUCCESS", "Transcription completed (async) with timestamps.");
|
||||||
|
return Ok(formatted_transcript);
|
||||||
|
} else {
|
||||||
|
emit_log(app, "WARN", "Segments found but empty content.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
emit_log(app, "WARN", "Verbose parsed but no segments found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(text) = response.text {
|
||||||
|
emit_log(app, "SUCCESS", "Transcription completed (async) - raw text (segments missing).");
|
||||||
|
return Ok(text);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
emit_log(app, "WARN", "Failed to parse poll content as WhisperVerboseResponse");
|
||||||
|
}
|
||||||
|
|
||||||
|
emit_log(app, "SUCCESS", "Transcription completed - returning raw content.");
|
||||||
|
// If not JSON or no text field, return raw content
|
||||||
|
return Ok(content);
|
||||||
|
} else {
|
||||||
|
emit_log(app, "ERROR", "Failed to download transcription results.");
|
||||||
|
return Err(format!("Download failed: {}", dl_res.status()));
|
||||||
|
}
|
||||||
|
} else if status == "failed" || status == "error" {
|
||||||
|
let err_msg = format!("Batch processing failed [Status: {}]. Full Response: {:?}", status, json);
|
||||||
|
emit_log(app, "ERROR", &err_msg);
|
||||||
|
return Err(err_msg);
|
||||||
|
}
|
||||||
|
// If 'processing' or 'pending', continue loop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
emit_log(app, "ERROR", "Transcription timed out after 80s.");
|
||||||
|
Err("Transcription timed out".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn summarize_text(app: AppHandle, text: String, api_key: String, product_id: String, prompt: String, model: String) -> Result<String, String> {
|
||||||
|
emit_log(&app, "INFO", "Starting summarization...");
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let url = format!("https://api.infomaniak.com/2/ai/{}/openai/v1/chat/completions", product_id);
|
||||||
|
|
||||||
|
let messages = serde_json::json!([
|
||||||
|
{ "role": "system", "content": prompt },
|
||||||
|
{ "role": "user", "content": text }
|
||||||
|
]);
|
||||||
|
|
||||||
|
let model_to_use = if model.is_empty() { "mixtral".to_string() } else { model };
|
||||||
|
|
||||||
|
let body = serde_json::json!({
|
||||||
|
"model": model_to_use,
|
||||||
|
"messages": messages
|
||||||
|
});
|
||||||
|
|
||||||
|
emit_log(&app, "DEBUG", &format!("POST {}", url));
|
||||||
|
|
||||||
|
let res = client.post(&url)
|
||||||
|
.header("Authorization", format!("Bearer {}", api_key))
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.json(&body)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
let msg = format!("Network error during summarization: {}", e);
|
||||||
|
emit_log(&app, "ERROR", &msg);
|
||||||
|
msg
|
||||||
|
})?;
|
||||||
|
|
||||||
|
if res.status().is_success() {
|
||||||
|
let raw_body = res.text().await.map_err(|e| e.to_string())?;
|
||||||
|
// println!("Summarization Raw Response: {}", raw_body);
|
||||||
|
|
||||||
|
let response_body: ChatCompletionResponse = serde_json::from_str(&raw_body)
|
||||||
|
.map_err(|e| format!("Failed to decode JSON: {}. Body: {}", e, raw_body))?;
|
||||||
|
|
||||||
|
if let Some(choice) = response_body.choices.first() {
|
||||||
|
emit_log(&app, "SUCCESS", "Summarization received.");
|
||||||
|
Ok(choice.message.content.clone())
|
||||||
|
} else {
|
||||||
|
emit_log(&app, "WARN", "No summary generated in response.");
|
||||||
|
Err("No summary generated".to_string())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let error_text = res.text().await.unwrap_or_default();
|
||||||
|
emit_log(&app, "ERROR", &format!("Summarization failed: {}", error_text));
|
||||||
|
Err(format!("Summarization failed: {}", error_text))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Serialize)]
|
||||||
|
struct AudioMetadata {
|
||||||
|
duration: f64,
|
||||||
|
size: u64,
|
||||||
|
format: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper to find ffmpeg/ffprobe in common paths
|
||||||
|
fn resolve_binary_path(binary_name: &str) -> String {
|
||||||
|
let common_paths = [
|
||||||
|
format!("/opt/homebrew/bin/{}", binary_name),
|
||||||
|
format!("/usr/local/bin/{}", binary_name),
|
||||||
|
format!("/usr/bin/{}", binary_name),
|
||||||
|
];
|
||||||
|
|
||||||
|
for path in common_paths.iter() {
|
||||||
|
if std::path::Path::new(path).exists() {
|
||||||
|
return path.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to expecting it in PATH
|
||||||
|
binary_name.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn get_audio_metadata(app: AppHandle, file_path: String) -> Result<AudioMetadata, String> {
|
||||||
|
emit_log(&app, "INFO", &format!("Getting metadata for: {}", file_path));
|
||||||
|
|
||||||
|
let path = std::path::Path::new(&file_path);
|
||||||
|
if !path.exists() {
|
||||||
|
return Err(format!("File not found: {}", file_path));
|
||||||
|
}
|
||||||
|
|
||||||
|
let size = std::fs::metadata(&file_path)
|
||||||
|
.map_err(|e| e.to_string())?
|
||||||
|
.len();
|
||||||
|
|
||||||
|
// Use ffprobe to get duration
|
||||||
|
// Try resolved path first
|
||||||
|
let ffprobe_cmd = resolve_binary_path("ffprobe");
|
||||||
|
|
||||||
|
let output = Command::new(&ffprobe_cmd)
|
||||||
|
.args([
|
||||||
|
"-v", "error",
|
||||||
|
"-show_entries", "format=duration",
|
||||||
|
"-of", "default=noprint_wrappers=1:nokey=1",
|
||||||
|
&file_path
|
||||||
|
])
|
||||||
|
.output()
|
||||||
|
.map_err(|e| format!("Failed to execute ffprobe at '{}': {}", ffprobe_cmd, e))?;
|
||||||
|
|
||||||
|
let duration_str = String::from_utf8_lossy(&output.stdout);
|
||||||
|
let duration: f64 = duration_str.trim().parse().unwrap_or(0.0);
|
||||||
|
|
||||||
|
// Extension as format
|
||||||
|
let format = path.extension()
|
||||||
|
.and_then(|e| e.to_str())
|
||||||
|
.unwrap_or("unknown")
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
Ok(AudioMetadata {
|
||||||
|
duration,
|
||||||
|
size,
|
||||||
|
format,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn convert_to_mp3(app: AppHandle, wav_path: String) -> Result<String, String> {
|
||||||
|
emit_log(&app, "INFO", &format!("Converting to MP3: {}", wav_path));
|
||||||
|
|
||||||
|
let mp3_path = wav_path.replace(".wav", ".mp3");
|
||||||
|
let ffmpeg_cmd = resolve_binary_path("ffmpeg");
|
||||||
|
|
||||||
|
let output = Command::new(&ffmpeg_cmd)
|
||||||
|
.args([
|
||||||
|
"-i", &wav_path,
|
||||||
|
"-codec:a", "libmp3lame",
|
||||||
|
"-b:a", "64k",
|
||||||
|
"-y", // overwrite
|
||||||
|
&mp3_path
|
||||||
|
])
|
||||||
|
.output()
|
||||||
|
.map_err(|e| format!("Failed to execute ffmpeg at '{}': {}", ffmpeg_cmd, e))?;
|
||||||
|
|
||||||
|
if output.status.success() {
|
||||||
|
emit_log(&app, "SUCCESS", &format!("MP3 created: {}", mp3_path));
|
||||||
|
Ok(mp3_path)
|
||||||
|
} else {
|
||||||
|
let error = String::from_utf8_lossy(&output.stderr);
|
||||||
|
emit_log(&app, "ERROR", &format!("MP3 conversion failed: {}", error));
|
||||||
|
Err(format!("MP3 conversion failed: {}", error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn chunk_audio(app: AppHandle, file_path: String, chunk_minutes: u32) -> Result<Vec<String>, String> {
|
||||||
|
emit_log(&app, "INFO", &format!("Chunking audio: {} ({}min chunks)", file_path, chunk_minutes));
|
||||||
|
|
||||||
|
let chunk_seconds = chunk_minutes * 60;
|
||||||
|
let ffprobe_cmd = resolve_binary_path("ffprobe");
|
||||||
|
let ffmpeg_cmd = resolve_binary_path("ffmpeg");
|
||||||
|
|
||||||
|
// Get total duration using ffprobe
|
||||||
|
let duration_output = Command::new(&ffprobe_cmd)
|
||||||
|
.args([
|
||||||
|
"-v", "error",
|
||||||
|
"-show_entries", "format=duration",
|
||||||
|
"-of", "default=noprint_wrappers=1:nokey=1",
|
||||||
|
&file_path
|
||||||
|
])
|
||||||
|
.output()
|
||||||
|
.map_err(|e| format!("Failed to get duration with '{}': {}", ffprobe_cmd, e))?;
|
||||||
|
|
||||||
|
let duration_str = String::from_utf8_lossy(&duration_output.stdout);
|
||||||
|
let duration: f64 = duration_str.trim().parse()
|
||||||
|
.map_err(|_| "Failed to parse duration".to_string())?;
|
||||||
|
|
||||||
|
let num_chunks = (duration / chunk_seconds as f64).ceil() as usize;
|
||||||
|
emit_log(&app, "INFO", &format!("Total duration: {}s, creating {} chunks", duration, num_chunks));
|
||||||
|
|
||||||
|
let mut chunk_paths = Vec::new();
|
||||||
|
let base_path = file_path.replace(".mp3", "");
|
||||||
|
|
||||||
|
for i in 0..num_chunks {
|
||||||
|
let start_time = i as u32 * chunk_seconds;
|
||||||
|
let chunk_path = format!("{}_chunk_{}.mp3", base_path, i);
|
||||||
|
|
||||||
|
let output = Command::new(&ffmpeg_cmd)
|
||||||
|
.args([
|
||||||
|
"-i", &file_path,
|
||||||
|
"-ss", &start_time.to_string(),
|
||||||
|
"-t", &chunk_seconds.to_string(),
|
||||||
|
"-c", "copy",
|
||||||
|
"-y",
|
||||||
|
&chunk_path
|
||||||
|
])
|
||||||
|
.output()
|
||||||
|
.map_err(|e| format!("Failed to create chunk {} with '{}': {}", i, ffmpeg_cmd, e))?;
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
let error = String::from_utf8_lossy(&output.stderr);
|
||||||
|
return Err(format!("Chunk {} failed: {}", i, error));
|
||||||
|
}
|
||||||
|
|
||||||
|
chunk_paths.push(chunk_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
emit_log(&app, "SUCCESS", &format!("Created {} chunks", chunk_paths.len()));
|
||||||
|
Ok(chunk_paths)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn read_image_as_base64(app: AppHandle, file_path: String) -> Result<String, String> {
|
||||||
|
emit_log(&app, "INFO", &format!("Reading image as base64: {}", file_path));
|
||||||
|
|
||||||
|
let bytes = std::fs::read(&file_path)
|
||||||
|
.map_err(|e| format!("Failed to read file: {}", e))?;
|
||||||
|
|
||||||
|
// Detect image type from extension
|
||||||
|
let extension = std::path::Path::new(&file_path)
|
||||||
|
.extension()
|
||||||
|
.and_then(|e| e.to_str())
|
||||||
|
.unwrap_or("png")
|
||||||
|
.to_lowercase();
|
||||||
|
|
||||||
|
let mime_type = match extension.as_str() {
|
||||||
|
"jpg" | "jpeg" => "image/jpeg",
|
||||||
|
"png" => "image/png",
|
||||||
|
"svg" => "image/svg+xml",
|
||||||
|
"gif" => "image/gif",
|
||||||
|
_ => "image/png"
|
||||||
|
};
|
||||||
|
|
||||||
|
// Use base64 encoding
|
||||||
|
let base64_str = base64::prelude::BASE64_STANDARD.encode(&bytes);
|
||||||
|
let data_url = format!("data:{};base64,{}", mime_type, base64_str);
|
||||||
|
|
||||||
|
emit_log(&app, "SUCCESS", &format!("Image converted to base64 ({} bytes)", base64_str.len()));
|
||||||
|
Ok(data_url)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn open_audio_midi_setup() -> Result<(), String> {
|
||||||
|
Command::new("open")
|
||||||
|
.arg("-a")
|
||||||
|
.arg("Audio MIDI Setup")
|
||||||
|
.spawn()
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn create_hearbit_audio_device(app: AppHandle) -> Result<String, String> {
|
||||||
|
emit_log(&app, "INFO", "Attempting to create Hearbit Audio device...");
|
||||||
|
|
||||||
|
// Resolve resource path
|
||||||
|
let resource_path = app.path().resource_dir()
|
||||||
|
.map_err(|e| e.to_string())?
|
||||||
|
.join("resources/create_hearbit_audio.swift");
|
||||||
|
|
||||||
|
if !resource_path.exists() {
|
||||||
|
// Fallback for dev environment where resources might not be bundled yet or different path
|
||||||
|
emit_log(&app, "WARN", &format!("Resource script not found at {:?}. Trying local src-tauri path.", resource_path));
|
||||||
|
}
|
||||||
|
|
||||||
|
// For now, in dev mode, we might need to point to the source location if bundle isn't active
|
||||||
|
// But let's try running it.
|
||||||
|
|
||||||
|
let output = Command::new("swift")
|
||||||
|
.arg(resource_path)
|
||||||
|
.output()
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
let stdout = String::from_utf8_lossy(&output.stdout).to_string();
|
||||||
|
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
|
||||||
|
|
||||||
|
emit_log(&app, "DEBUG", &format!("Script Output: {}", stdout));
|
||||||
|
if !stderr.is_empty() {
|
||||||
|
emit_log(&app, "WARN", &format!("Script Stderr: {}", stderr));
|
||||||
|
}
|
||||||
|
|
||||||
|
if output.status.success() {
|
||||||
|
emit_log(&app, "SUCCESS", "Hearbit Audio device created successfully.");
|
||||||
|
Ok("Device created successfully".to_string())
|
||||||
|
} else {
|
||||||
|
emit_log(&app, "ERROR", "Failed to create device.");
|
||||||
|
Err(format!("Failed to create device: {} {}", stdout, stderr))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn check_screen_recording_permission() -> bool {
|
||||||
|
sc_audio::check_permissions().await
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn save_text_file(app: AppHandle, path: String, content: String) -> Result<(), String> {
|
||||||
|
emit_log(&app, "INFO", &format!("Saving text file to: {}", path));
|
||||||
|
match std::fs::write(&path, content) {
|
||||||
|
Ok(_) => {
|
||||||
|
emit_log(&app, "SUCCESS", "File saved successfully.");
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
emit_log(&app, "ERROR", &format!("Failed to save file: {}", e));
|
||||||
|
Err(e.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn read_log_file(app: AppHandle) -> Result<String, String> {
|
||||||
|
let log_path = app.path().app_log_dir().map_err(|e| e.to_string())?.join("hearbit-ai.log");
|
||||||
|
if log_path.exists() {
|
||||||
|
let content = std::fs::read_to_string(&log_path).map_err(|e| e.to_string())?;
|
||||||
|
Ok(content)
|
||||||
|
} else {
|
||||||
|
Ok("No log file found yet.".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
|
pub fn run() {
|
||||||
|
tauri::Builder::default()
|
||||||
|
.setup(|app| {
|
||||||
|
// Setup Tray Icon
|
||||||
|
let quit_i = MenuItem::with_id(app, "quit", "Quit Hearbit AI", true, None::<&str>).unwrap();
|
||||||
|
let show_i = MenuItem::with_id(app, "show", "Show Window", true, None::<&str>).unwrap();
|
||||||
|
let menu = Menu::with_items(app, &[&show_i, &quit_i]).unwrap();
|
||||||
|
|
||||||
|
let _tray = TrayIconBuilder::new()
|
||||||
|
.icon(app.default_window_icon().unwrap().clone())
|
||||||
|
.menu(&menu)
|
||||||
|
.show_menu_on_left_click(true)
|
||||||
|
.on_menu_event(|app, event| {
|
||||||
|
match event.id.as_ref() {
|
||||||
|
"quit" => app.exit(0),
|
||||||
|
"show" => {
|
||||||
|
if let Some(window) = app.get_webview_window("main") {
|
||||||
|
let _ = window.show();
|
||||||
|
let _ = window.set_focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on_tray_icon_event(|tray, event| {
|
||||||
|
if let TrayIconEvent::Click { .. } = event {
|
||||||
|
let app = tray.app_handle();
|
||||||
|
if let Some(window) = app.get_webview_window("main") {
|
||||||
|
let _ = window.show();
|
||||||
|
let _ = window.set_focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.build(app)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.on_window_event(|window, event| {
|
||||||
|
if let WindowEvent::CloseRequested { api, .. } = event {
|
||||||
|
// Prevent window from closing, just hide it
|
||||||
|
window.hide().unwrap();
|
||||||
|
api.prevent_close();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.plugin(tauri_plugin_shell::init())
|
||||||
|
.plugin(tauri_plugin_log::Builder::default()
|
||||||
|
.targets([
|
||||||
|
tauri_plugin_log::Target::new(tauri_plugin_log::TargetKind::Stdout),
|
||||||
|
tauri_plugin_log::Target::new(tauri_plugin_log::TargetKind::LogDir { file_name: Some("hearbit-ai.log".to_string()) }),
|
||||||
|
])
|
||||||
|
.build())
|
||||||
|
.plugin(tauri_plugin_opener::init())
|
||||||
|
.plugin(tauri_plugin_dialog::init())
|
||||||
|
.plugin(tauri_plugin_fs::init())
|
||||||
|
.plugin(tauri_plugin_oauth::init())
|
||||||
|
.manage(AppState {
|
||||||
|
recording_stream: Mutex::new(None),
|
||||||
|
recording_file_path: Mutex::new(None),
|
||||||
|
system_capture: Mutex::new(None),
|
||||||
|
})
|
||||||
|
.invoke_handler(tauri::generate_handler![
|
||||||
|
greet,
|
||||||
|
get_input_devices,
|
||||||
|
start_recording,
|
||||||
|
stop_recording,
|
||||||
|
pause_recording,
|
||||||
|
resume_recording,
|
||||||
|
transcribe_audio,
|
||||||
|
summarize_text,
|
||||||
|
get_available_models,
|
||||||
|
open_audio_midi_setup,
|
||||||
|
create_hearbit_audio_device,
|
||||||
|
check_screen_recording_permission,
|
||||||
|
auth::start_auth_flow,
|
||||||
|
auth::get_calendar_events,
|
||||||
|
save_text_file,
|
||||||
|
read_log_file,
|
||||||
|
get_audio_metadata,
|
||||||
|
convert_to_mp3,
|
||||||
|
chunk_audio,
|
||||||
|
read_image_as_base64,
|
||||||
|
email::send_smtp_email
|
||||||
|
])
|
||||||
|
.run(tauri::generate_context!())
|
||||||
|
.expect("error while running tauri application");
|
||||||
|
}
|
||||||
171
src-tauri/src/sc_audio.rs
Normal file
171
src-tauri/src/sc_audio.rs
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
use cocoa::base::nil;
|
||||||
|
use objc::{msg_send, sel, sel_impl};
|
||||||
|
use screencapturekit_sys::{
|
||||||
|
cm_sample_buffer_ref::CMSampleBufferRef,
|
||||||
|
content_filter::{UnsafeContentFilter, UnsafeInitParams},
|
||||||
|
os_types::rc::Id,
|
||||||
|
shareable_content::{UnsafeSCRunningApplication, UnsafeSCShareableContent},
|
||||||
|
stream::UnsafeSCStream,
|
||||||
|
stream_configuration::UnsafeStreamConfiguration,
|
||||||
|
stream_error_handler::UnsafeSCStreamError,
|
||||||
|
stream_output_handler::UnsafeSCStreamOutput,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct SystemAudioCapture {
|
||||||
|
stream: Option<Id<UnsafeSCStream>>,
|
||||||
|
sample_rate: u32,
|
||||||
|
excluded_apps: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AudioOutputWrapper {
|
||||||
|
callback: Box<dyn Fn(&[f32]) + Send + Sync>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UnsafeSCStreamOutput for AudioOutputWrapper {
|
||||||
|
fn did_output_sample_buffer(&self, sample: Id<CMSampleBufferRef>, of_type: u8) {
|
||||||
|
if of_type == 1 {
|
||||||
|
// Audio
|
||||||
|
let buffers = sample.get_av_audio_buffer_list();
|
||||||
|
for buffer in buffers {
|
||||||
|
let data_u8 = buffer.data;
|
||||||
|
let data_f32: &[f32] = unsafe {
|
||||||
|
std::slice::from_raw_parts(data_u8.as_ptr() as *const f32, data_u8.len() / 4)
|
||||||
|
};
|
||||||
|
|
||||||
|
(self.callback)(data_f32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ErrorHandler;
|
||||||
|
impl UnsafeSCStreamError for ErrorHandler {
|
||||||
|
fn handle_error(&self) {
|
||||||
|
// eprintln!("Stream Error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn check_permissions() -> bool {
|
||||||
|
UnsafeSCShareableContent::get().is_ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SystemAudioCapture {
|
||||||
|
pub fn new(sample_rate: u32, excluded_apps: Vec<String>) -> Self {
|
||||||
|
Self {
|
||||||
|
stream: None,
|
||||||
|
sample_rate,
|
||||||
|
excluded_apps,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn build_filter(&self) -> Result<Id<UnsafeContentFilter>, String> {
|
||||||
|
let content =
|
||||||
|
UnsafeSCShareableContent::get().map_err(|_| format!("Failed to get content"))?;
|
||||||
|
let displays = content.displays();
|
||||||
|
let display = displays.first().ok_or("No display found")?;
|
||||||
|
|
||||||
|
if self.excluded_apps.is_empty() {
|
||||||
|
return Ok(UnsafeContentFilter::init(UnsafeInitParams::Display(
|
||||||
|
display.clone(),
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut apps_to_exclude = Vec::new();
|
||||||
|
let all_apps = content.applications();
|
||||||
|
|
||||||
|
// Prepare lowercase excluded list for case-insensitive matching
|
||||||
|
let excluded_lower: Vec<String> = self
|
||||||
|
.excluded_apps
|
||||||
|
.iter()
|
||||||
|
.map(|s| s.to_lowercase())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
for app in all_apps {
|
||||||
|
if let Some(bid) = app.get_bundle_identifier() {
|
||||||
|
let bid_lower = bid.to_lowercase();
|
||||||
|
// Smart match: check if the running app's ID starts with any blocked ID
|
||||||
|
// e.g., "com.apple.Safari.WebContent" starts with "com.apple.Safari"
|
||||||
|
if excluded_lower
|
||||||
|
.iter()
|
||||||
|
.any(|excluded| bid_lower.starts_with(excluded))
|
||||||
|
{
|
||||||
|
apps_to_exclude.push(app);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: In screencapturekit-sys 0.2.8, DisplayIncludingApplicationsExceptingWindows
|
||||||
|
// actually calls initWithDisplay:excludingApplications: (it's a bug in the crate)
|
||||||
|
let filter_init = UnsafeInitParams::DisplayIncludingApplicationsExceptingWindows(
|
||||||
|
display.clone(),
|
||||||
|
apps_to_exclude,
|
||||||
|
Vec::new(),
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(UnsafeContentFilter::init(filter_init))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn start<F>(&mut self, callback: F) -> Result<(), String>
|
||||||
|
where
|
||||||
|
F: Fn(&[f32]) + Send + Sync + 'static,
|
||||||
|
{
|
||||||
|
let filter = self.build_filter().await?;
|
||||||
|
|
||||||
|
let mut config = UnsafeStreamConfiguration::default();
|
||||||
|
config.width = 100;
|
||||||
|
config.height = 100;
|
||||||
|
config.captures_audio = 1;
|
||||||
|
config.sample_rate = self.sample_rate;
|
||||||
|
config.channel_count = 2;
|
||||||
|
config.excludes_current_process_audio = 1;
|
||||||
|
|
||||||
|
let output_wrapper = AudioOutputWrapper {
|
||||||
|
callback: Box::new(callback),
|
||||||
|
};
|
||||||
|
|
||||||
|
let stream = UnsafeSCStream::init(filter, config.into(), ErrorHandler);
|
||||||
|
stream.add_stream_output(output_wrapper, 1); // 1 = Audio
|
||||||
|
|
||||||
|
stream
|
||||||
|
.start_capture()
|
||||||
|
.map_err(|_| "Failed to start capture".to_string())?;
|
||||||
|
|
||||||
|
self.stream = Some(stream);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stop(&mut self) {
|
||||||
|
if let Some(stream) = &self.stream {
|
||||||
|
let _ = stream.stop_capture();
|
||||||
|
}
|
||||||
|
self.stream = None;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn refresh_filter(&mut self) -> Result<(), String> {
|
||||||
|
let stream = match &self.stream {
|
||||||
|
Some(s) => s,
|
||||||
|
None => return Ok(()),
|
||||||
|
};
|
||||||
|
|
||||||
|
let filter = self.build_filter().await?;
|
||||||
|
|
||||||
|
// Call updateContentFilter:completionHandler:
|
||||||
|
// screencapturekit-sys 0.2.8 does not have this method exposed yet in UnsafeSCStream.
|
||||||
|
// We use msg_send! to call it directly on the underlying object.
|
||||||
|
unsafe {
|
||||||
|
// Get raw pointer to the underlying Objective-C objects.
|
||||||
|
// Since we don't have easy access to the inner pointer of Id<T> via methods,
|
||||||
|
// we cast the pointer to the Id wrapper itself to a pointer to a pointer.
|
||||||
|
// This assumes Id<T> is a transparent wrapper around a pointer.
|
||||||
|
let stream_ptr =
|
||||||
|
*(stream as *const Id<UnsafeSCStream> as *const *mut objc::runtime::Object);
|
||||||
|
let filter_ptr =
|
||||||
|
*(&filter as *const Id<UnsafeContentFilter> as *const *mut objc::runtime::Object);
|
||||||
|
|
||||||
|
let _: () =
|
||||||
|
msg_send![stream_ptr, updateContentFilter: filter_ptr completionHandler: nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
103
src-tauri/src/sc_audio.rs.bak
Normal file
103
src-tauri/src/sc_audio.rs.bak
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
use screencapturekit_sys::{
|
||||||
|
os_types::rc::Id,
|
||||||
|
shareable_content::UnsafeSCShareableContent,
|
||||||
|
content_filter::{UnsafeContentFilter, UnsafeInitParams},
|
||||||
|
stream_configuration::UnsafeStreamConfiguration,
|
||||||
|
stream::UnsafeSCStream,
|
||||||
|
stream_error_handler::UnsafeSCStreamError,
|
||||||
|
stream_output_handler::UnsafeSCStreamOutput,
|
||||||
|
cm_sample_buffer_ref::CMSampleBufferRef,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct SystemAudioCapture {
|
||||||
|
stream: Option<Id<UnsafeSCStream>>,
|
||||||
|
sample_rate: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AudioOutputWrapper {
|
||||||
|
callback: Box<dyn Fn(&[f32]) + Send + Sync>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UnsafeSCStreamOutput for AudioOutputWrapper {
|
||||||
|
fn did_output_sample_buffer(&self, sample: Id<CMSampleBufferRef>, of_type: u8) {
|
||||||
|
if of_type == 1 { // Audio
|
||||||
|
let buffers = sample.get_av_audio_buffer_list();
|
||||||
|
for buffer in buffers {
|
||||||
|
// Buffer data is u8, we usually get F32 from SCK if configured.
|
||||||
|
// Assuming f32 (Floating Point) based on our config.
|
||||||
|
// We need to convert [u8] to [f32].
|
||||||
|
let data_u8 = buffer.data;
|
||||||
|
let data_f32: &[f32] = unsafe {
|
||||||
|
std::slice::from_raw_parts(
|
||||||
|
data_u8.as_ptr() as *const f32,
|
||||||
|
data_u8.len() / 4,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
(self.callback)(data_f32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ErrorHandler;
|
||||||
|
impl UnsafeSCStreamError for ErrorHandler {
|
||||||
|
fn handle_error(&self) {
|
||||||
|
// eprintln!("Stream Error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn check_permissions() -> bool {
|
||||||
|
UnsafeSCShareableContent::get().is_ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SystemAudioCapture {
|
||||||
|
pub fn new(sample_rate: u32) -> Self {
|
||||||
|
Self { stream: None, sample_rate }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn start<F>(&mut self, callback: F) -> Result<(), String>
|
||||||
|
where F: Fn(&[f32]) + Send + Sync + 'static {
|
||||||
|
|
||||||
|
let content = UnsafeSCShareableContent::get().map_err(|e| format!("Failed to get content"))?;
|
||||||
|
let displays = content.displays();
|
||||||
|
let display = displays.first().ok_or("No display found")?;
|
||||||
|
|
||||||
|
let filter_init = UnsafeInitParams::Display(display.clone());
|
||||||
|
let filter = UnsafeContentFilter::init(filter_init);
|
||||||
|
|
||||||
|
// Wait, 'pixel_format' is OSType. b"BGRA" is &[u8;4].
|
||||||
|
// FourCharCode::from_chars exists in crate::os_types::four_char_code but we didn't import it.
|
||||||
|
// Actually, we can just use the Default and overwrite fields.
|
||||||
|
// But better: use Default and only set what we need.
|
||||||
|
|
||||||
|
let mut config = UnsafeStreamConfiguration::default();
|
||||||
|
config.width = 100;
|
||||||
|
config.height = 100;
|
||||||
|
config.captures_audio = 1;
|
||||||
|
config.sample_rate = self.sample_rate;
|
||||||
|
config.channel_count = 2;
|
||||||
|
config.excludes_current_process_audio = 0;
|
||||||
|
|
||||||
|
let output_wrapper = AudioOutputWrapper {
|
||||||
|
callback: Box::new(callback),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Convert config to Id<UnsafeStreamConfigurationRef> using Into
|
||||||
|
let stream = UnsafeSCStream::init(filter, config.into(), ErrorHandler);
|
||||||
|
|
||||||
|
stream.add_stream_output(output_wrapper, 1); // 1 = Audio
|
||||||
|
|
||||||
|
stream.start_capture().map_err(|e| "Failed to start capture".to_string())?;
|
||||||
|
|
||||||
|
self.stream = Some(stream);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stop(&mut self) {
|
||||||
|
if let Some(stream) = &self.stream {
|
||||||
|
stream.stop_capture();
|
||||||
|
}
|
||||||
|
self.stream = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "Hearbit AI",
|
"productName": "Hearbit AI",
|
||||||
"version": "0.1.0",
|
"version": "1.2.3",
|
||||||
"identifier": "com.hearbit-ai.desktop",
|
"identifier": "com.hearbit-ai.desktop",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": "npm run dev",
|
"beforeDevCommand": "npm run dev",
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
"icons/icon.ico"
|
"icons/icon.ico"
|
||||||
],
|
],
|
||||||
"resources": [
|
"resources": [
|
||||||
"resources/BlackHole2ch.v0.6.1.pkg"
|
"resources/*"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
370
src/App.tsx
370
src/App.tsx
@@ -1,26 +1,79 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect, useCallback } from 'react';
|
||||||
import { listen } from "@tauri-apps/api/event";
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
import { Settings as SettingsIcon } from "lucide-react";
|
import { Settings as SettingsIcon } from "lucide-react";
|
||||||
import Settings from "./components/Settings";
|
import Settings, { SmtpConfig, AzureConfig } from "./components/Settings";
|
||||||
import Recorder from "./components/Recorder";
|
import Recorder from "./components/Recorder";
|
||||||
import LogViewer, { LogEntry } from "./components/LogViewer";
|
|
||||||
import TranscriptionView from "./components/TranscriptionView";
|
import TranscriptionView from "./components/TranscriptionView";
|
||||||
import Tabs from "./components/Tabs";
|
import Tabs from "./components/Tabs";
|
||||||
|
import MeetingsView from "./components/MeetingsView";
|
||||||
|
import HistoryView from "./components/HistoryView";
|
||||||
|
import Import from "./components/Import";
|
||||||
|
import ToastContainer, { ToastMessage, ToastType } from "./components/ui/Toast";
|
||||||
|
|
||||||
export interface PromptTemplate {
|
export interface PromptTemplate {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
content: string;
|
content: string;
|
||||||
|
keywords?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EmailTemplate {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
subject: string;
|
||||||
|
body: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [view, setView] = useState<'recorder' | 'logs' | 'settings' | 'transcription'>('recorder');
|
const [view, setView] = useState<'recorder' | 'settings' | 'transcription' | 'meetings' | 'history' | 'import'>('recorder');
|
||||||
// Keep track of the *previous* tab to return to from settings
|
const [lastTab, setLastTab] = useState<'recorder' | 'transcription' | 'meetings' | 'history' | 'import'>('recorder');
|
||||||
const [lastTab, setLastTab] = useState<'recorder' | 'logs' | 'transcription'>('recorder');
|
|
||||||
|
|
||||||
|
|
||||||
|
// Auto-start recording state to handle "Join & Record" transition
|
||||||
|
const [autoStartRecording, setAutoStartRecording] = useState(false);
|
||||||
|
const [recordingSubject, setRecordingSubject] = useState<string>('');
|
||||||
|
|
||||||
|
// Toast State
|
||||||
|
const [toasts, setToasts] = useState<ToastMessage[]>([]);
|
||||||
|
|
||||||
|
const addToast = (message: string, type: ToastType = 'info', duration = 3000) => {
|
||||||
|
const id = Date.now().toString() + Math.random().toString();
|
||||||
|
setToasts(prev => [...prev, { id, message, type, duration }]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeToast = (id: string) => {
|
||||||
|
setToasts(prev => prev.filter(t => t.id !== id));
|
||||||
|
};
|
||||||
const [apiKey, setApiKey] = useState(localStorage.getItem('infomaniak_api_key') || '');
|
const [apiKey, setApiKey] = useState(localStorage.getItem('infomaniak_api_key') || '');
|
||||||
const [productId, setProductId] = useState(localStorage.getItem('infomaniak_product_id') || '');
|
const [productId, setProductId] = useState(localStorage.getItem('infomaniak_product_id') || '');
|
||||||
const [savePath, setSavePath] = useState(localStorage.getItem('infomaniak_save_path') || '');
|
const [savePath, setSavePath] = useState(localStorage.getItem('infomaniak_save_path') || '');
|
||||||
|
const [smtpConfig, setSmtpConfig] = useState<SmtpConfig>(() => {
|
||||||
|
const saved = localStorage.getItem('hearbit_smtp_config');
|
||||||
|
return saved ? JSON.parse(saved) : { host: '', port: '587', user: '', pass: '', sender: '', senderName: '' };
|
||||||
|
});
|
||||||
|
const [azureConfig, setAzureConfig] = useState<AzureConfig>(() => {
|
||||||
|
const saved = localStorage.getItem('hearbit_azure_config');
|
||||||
|
return saved ? JSON.parse(saved) : { clientId: '', tenantId: '' };
|
||||||
|
});
|
||||||
|
|
||||||
|
const [selectedModel, setSelectedModel] = useState<string>(() => {
|
||||||
|
return localStorage.getItem('hearbit_selected_model') || 'mixtral';
|
||||||
|
});
|
||||||
|
|
||||||
|
// Daily Backup State
|
||||||
|
const [dailyBackupEnabled, setDailyBackupEnabled] = useState(() => localStorage.getItem('hearbit_daily_backup_enabled') === 'true');
|
||||||
|
const [dailyBackupPath, setDailyBackupPath] = useState(() => localStorage.getItem('hearbit_daily_backup_path') || '');
|
||||||
|
const [lastBackupDate, setLastBackupDate] = useState(() => localStorage.getItem('hearbit_last_backup_date') || '');
|
||||||
|
const [blockedApps, setBlockedApps] = useState<string[]>(() => {
|
||||||
|
const saved = localStorage.getItem('hearbit_blocked_apps');
|
||||||
|
return saved ? JSON.parse(saved) : [];
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleModelChange = (model: string) => {
|
||||||
|
setSelectedModel(model);
|
||||||
|
localStorage.setItem('hearbit_selected_model', model);
|
||||||
|
};
|
||||||
|
|
||||||
// Default prompts if none exist
|
// Default prompts if none exist
|
||||||
/* eslint-disable no-useless-escape */ // Escape quotes in prompts
|
/* eslint-disable no-useless-escape */ // Escape quotes in prompts
|
||||||
@@ -61,7 +114,8 @@ Kurze Stichpunkte zu Themen, die besprochen, aber noch nicht final geklärt wurd
|
|||||||
| [Aufgabe 2] | [Name] | [Datum] |
|
| [Aufgabe 2] | [Name] | [Datum] |
|
||||||
|
|
||||||
## 5. Nächste Schritte / Nächstes Meeting
|
## 5. Nächste Schritte / Nächstes Meeting
|
||||||
Kurze Info zum weiteren Vorgehen.`
|
Kurze Info zum weiteren Vorgehen.`,
|
||||||
|
keywords: ['protokoll', 'meeting', 'team', 'daily', 'weekly']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '2',
|
id: '2',
|
||||||
@@ -96,7 +150,8 @@ Thema B: [Kurze Zusammenfassung]
|
|||||||
| Wer? | Was ist zu tun / zu beachten? | Bis wann? |
|
| Wer? | Was ist zu tun / zu beachten? | Bis wann? |
|
||||||
| :--- | :--- | :--- |
|
| :--- | :--- | :--- |
|
||||||
| [Name] | [Aufgabe] | [Datum] |
|
| [Name] | [Aufgabe] | [Datum] |
|
||||||
| [Name] | [Aufgabe] | [Datum] |`
|
| [Name] | [Aufgabe] | [Datum] |`,
|
||||||
|
keywords: ['personal', 'privat', 'vertraulich', 'entwicklungsgespräch', 'feedback', 'unter vier augen']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '3',
|
id: '3',
|
||||||
@@ -138,7 +193,37 @@ Teilnehmer: [Namen Kunden] & [Namen Intern]
|
|||||||
[ ] [Aufgabe, z.B. Zugangdaten senden, Design freigeben] (bis [Datum])
|
[ ] [Aufgabe, z.B. Zugangdaten senden, Design freigeben] (bis [Datum])
|
||||||
|
|
||||||
## 5. Nächster Termin / Timeline
|
## 5. Nächster Termin / Timeline
|
||||||
Wann findet das nächste Meeting statt oder was ist der nächste Meilenstein?`
|
Wann findet das nächste Meeting statt oder was ist der nächste Meilenstein?`,
|
||||||
|
keywords: ['beratung', 'kunde', 'client', 'angebot', 'projekt', 'extern']
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
// Default Email Templates
|
||||||
|
const defaultEmailTemplates: EmailTemplate[] = [
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
name: 'Meeting Summary (Standard)',
|
||||||
|
subject: 'Meeting Summary: {{subject}}',
|
||||||
|
body: `Hi everyone,
|
||||||
|
|
||||||
|
Here is the summary of our meeting "{{subject}}" from {{date}}.
|
||||||
|
|
||||||
|
{{summary}}
|
||||||
|
|
||||||
|
Best regards,
|
||||||
|
Hearbit Assistant`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
name: 'Action Items Only',
|
||||||
|
subject: 'Action Items: {{subject}}',
|
||||||
|
body: `Hi Team,
|
||||||
|
|
||||||
|
Please find below the action items from our call on {{date}}:
|
||||||
|
|
||||||
|
{{summary}}
|
||||||
|
|
||||||
|
Thanks!`
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -147,15 +232,47 @@ Wann findet das nächste Meeting statt oder was ist der nächste Meilenstein?`
|
|||||||
return saved ? JSON.parse(saved) : defaultPrompts;
|
return saved ? JSON.parse(saved) : defaultPrompts;
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSaveSettings = (newApiKey: string, newProductId: string, newPrompts: PromptTemplate[], newSavePath: string) => {
|
const [emailTemplates, setEmailTemplates] = useState<EmailTemplate[]>(() => {
|
||||||
|
const saved = localStorage.getItem('hearbit_email_templates');
|
||||||
|
return saved ? JSON.parse(saved) : defaultEmailTemplates;
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSaveSettings = (
|
||||||
|
newApiKey: string,
|
||||||
|
newProductId: string,
|
||||||
|
newPrompts: PromptTemplate[],
|
||||||
|
newSavePath: string,
|
||||||
|
newSmtp: SmtpConfig,
|
||||||
|
newAzure: AzureConfig,
|
||||||
|
newEmailTemplates: EmailTemplate[],
|
||||||
|
newDailyBackupEnabled: boolean,
|
||||||
|
newDailyBackupPath: string,
|
||||||
|
newBlockedApps: string[]
|
||||||
|
) => {
|
||||||
setApiKey(newApiKey);
|
setApiKey(newApiKey);
|
||||||
setProductId(newProductId);
|
setProductId(newProductId);
|
||||||
setPrompts(newPrompts);
|
setPrompts(newPrompts);
|
||||||
setSavePath(newSavePath);
|
setSavePath(newSavePath);
|
||||||
localStorage.setItem('infomaniak_api_key', newApiKey);
|
setSmtpConfig(newSmtp);
|
||||||
localStorage.setItem('infomaniak_product_id', newProductId);
|
setAzureConfig(newAzure);
|
||||||
localStorage.setItem('infomaniak_prompts', JSON.stringify(newPrompts));
|
setEmailTemplates(newEmailTemplates);
|
||||||
localStorage.setItem('infomaniak_save_path', newSavePath);
|
|
||||||
|
setDailyBackupEnabled(newDailyBackupEnabled);
|
||||||
|
setDailyBackupPath(newDailyBackupPath);
|
||||||
|
setBlockedApps(newBlockedApps);
|
||||||
|
|
||||||
|
localStorage.setItem('hearbit_api_key', newApiKey);
|
||||||
|
localStorage.setItem('hearbit_product_id', newProductId);
|
||||||
|
localStorage.setItem('hearbit_prompts', JSON.stringify(newPrompts));
|
||||||
|
localStorage.setItem('hearbit_save_path', newSavePath);
|
||||||
|
localStorage.setItem('hearbit_smtp_config', JSON.stringify(newSmtp));
|
||||||
|
localStorage.setItem('hearbit_azure_config', JSON.stringify(newAzure));
|
||||||
|
localStorage.setItem('hearbit_email_templates', JSON.stringify(newEmailTemplates));
|
||||||
|
|
||||||
|
localStorage.setItem('hearbit_daily_backup_enabled', String(newDailyBackupEnabled));
|
||||||
|
localStorage.setItem('hearbit_daily_backup_path', newDailyBackupPath);
|
||||||
|
localStorage.setItem('hearbit_blocked_apps', JSON.stringify(newBlockedApps));
|
||||||
|
|
||||||
setView(lastTab);
|
setView(lastTab);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -168,6 +285,8 @@ Wann findet das nächste Meeting statt oder was ist der nächste Meilenstein?`
|
|||||||
date: string;
|
date: string;
|
||||||
transcription: string;
|
transcription: string;
|
||||||
summary: string;
|
summary: string;
|
||||||
|
subject?: string;
|
||||||
|
filename?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [history, setHistory] = useState<HistoryItem[]>(() => {
|
const [history, setHistory] = useState<HistoryItem[]>(() => {
|
||||||
@@ -179,16 +298,47 @@ Wann findet das nächste Meeting statt oder was ist der nächste Meilenstein?`
|
|||||||
const transToSave = t !== undefined ? t : transcription;
|
const transToSave = t !== undefined ? t : transcription;
|
||||||
const sumToSave = s !== undefined ? s : summary;
|
const sumToSave = s !== undefined ? s : summary;
|
||||||
|
|
||||||
|
// Sanitize subject for filename
|
||||||
|
const safeSubject = recordingSubject
|
||||||
|
? recordingSubject.replace(/[^a-zA-Z0-9_-]/g, '_')
|
||||||
|
: `Meeting_${Date.now()}`;
|
||||||
|
const filename = `${safeSubject}.md`;
|
||||||
|
|
||||||
if (!transToSave && !sumToSave) return;
|
if (!transToSave && !sumToSave) return;
|
||||||
|
|
||||||
const newItem: HistoryItem = {
|
const newItem: HistoryItem = {
|
||||||
id: Date.now().toString(),
|
id: Date.now().toString(),
|
||||||
date: new Date().toLocaleString(),
|
date: new Date().toLocaleString(),
|
||||||
transcription: transToSave,
|
transcription: transToSave,
|
||||||
summary: sumToSave
|
summary: sumToSave,
|
||||||
|
subject: recordingSubject || "Untitled Recording",
|
||||||
|
filename: filename
|
||||||
};
|
};
|
||||||
const newHistory = [newItem, ...history];
|
const newHistory = [newItem, ...history];
|
||||||
setHistory(newHistory);
|
setHistory(newHistory);
|
||||||
localStorage.setItem('infomaniak_history', JSON.stringify(newHistory));
|
localStorage.setItem('infomaniak_history', JSON.stringify(newHistory));
|
||||||
|
|
||||||
|
// Persist to Disk (Markdown)
|
||||||
|
const content = `# ${newItem.subject}\nDate: ${newItem.date}\n\n## Summary\n${sumToSave}\n\n## Transcription\n${transToSave}`;
|
||||||
|
// If savePath is set, we use it. If not, backend defaults to temp. Here we want to save text.
|
||||||
|
// Let's assume savePath is set or we default to Documents/Hearbit (if we could).
|
||||||
|
// For now, if savePath is set, use it.
|
||||||
|
if (savePath) {
|
||||||
|
// We need invoke to save text
|
||||||
|
import("@tauri-apps/api/core").then(({ invoke }) => {
|
||||||
|
invoke('save_text_file', { path: `${savePath}/${filename}`, content })
|
||||||
|
.then(() => addToast('Transcript saved to file', 'success'))
|
||||||
|
.catch(e => addToast(`Failed to save file: ${e}`, 'error'));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRenameHistory = (id: string, newSubject: string) => {
|
||||||
|
const newHistory = history.map(item =>
|
||||||
|
item.id === id ? { ...item, subject: newSubject } : item
|
||||||
|
);
|
||||||
|
setHistory(newHistory);
|
||||||
|
localStorage.setItem('infomaniak_history', JSON.stringify(newHistory));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteHistory = (id: string) => {
|
const handleDeleteHistory = (id: string) => {
|
||||||
@@ -200,21 +350,84 @@ Wann findet das nächste Meeting statt oder was ist der nächste Meilenstein?`
|
|||||||
const handleLoadHistory = (item: HistoryItem) => {
|
const handleLoadHistory = (item: HistoryItem) => {
|
||||||
setTranscription(item.transcription);
|
setTranscription(item.transcription);
|
||||||
setSummary(item.summary);
|
setSummary(item.summary);
|
||||||
setView('recorder'); // Ensure we go back to recorder to see it
|
setView('transcription'); // Switch to Transcription view to see content
|
||||||
};
|
};
|
||||||
|
|
||||||
// Logs State
|
const performBackup = useCallback(async (isAuto = false) => {
|
||||||
const [logs, setLogs] = useState<LogEntry[]>([]);
|
try {
|
||||||
|
if (isAuto && !dailyBackupEnabled) return;
|
||||||
|
|
||||||
|
const dataToBackup = {
|
||||||
|
apiKey,
|
||||||
|
productId,
|
||||||
|
prompts,
|
||||||
|
savePath,
|
||||||
|
smtp: smtpConfig,
|
||||||
|
azure: azureConfig,
|
||||||
|
emailTemplates,
|
||||||
|
history, // Including history!
|
||||||
|
// Also include daily backup settings so they persist on restore
|
||||||
|
dailyBackup: {
|
||||||
|
enabled: dailyBackupEnabled,
|
||||||
|
path: dailyBackupPath,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Always save as JSON (no encryption)
|
||||||
|
const content = JSON.stringify(dataToBackup, null, 2);
|
||||||
|
|
||||||
|
const dateStr = new Date().toISOString().slice(0, 10);
|
||||||
|
const fileName = `hearbit_backup_${isAuto ? 'auto_' : ''}${dateStr}.json`;
|
||||||
|
|
||||||
|
// Determine path: use specific daily backup path, or general savePath
|
||||||
|
const targetDir = (isAuto ? dailyBackupPath : savePath) || savePath;
|
||||||
|
|
||||||
|
if (!targetDir) {
|
||||||
|
if (!isAuto) addToast('No backup path configured.', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fullPath = `${targetDir}/${fileName}`;
|
||||||
|
|
||||||
|
await invoke('save_text_file', { path: fullPath, content });
|
||||||
|
|
||||||
|
if (isAuto) {
|
||||||
|
const now = new Date().toISOString();
|
||||||
|
setLastBackupDate(now);
|
||||||
|
localStorage.setItem('hearbit_last_backup_date', now);
|
||||||
|
console.log("Auto-backup completed:", fullPath);
|
||||||
|
} else {
|
||||||
|
addToast(`Backup saved to ${fullPath}`, 'success');
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Backup failed:", e);
|
||||||
|
if (!isAuto) addToast(`Backup failed: ${e}`, 'error');
|
||||||
|
}
|
||||||
|
}, [apiKey, productId, prompts, savePath, smtpConfig, azureConfig, emailTemplates, history, dailyBackupEnabled, dailyBackupPath]);
|
||||||
|
|
||||||
|
// Check for Daily Backup on Mount / State Change
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const unlisten = listen<LogEntry>('log-event', (event) => {
|
if (!dailyBackupEnabled) return;
|
||||||
setLogs((prevLogs) => [...prevLogs, event.payload]);
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => {
|
const check = async () => {
|
||||||
unlisten.then(f => f());
|
const today = new Date().toISOString().slice(0, 10);
|
||||||
|
const last = lastBackupDate ? lastBackupDate.slice(0, 10) : '';
|
||||||
|
|
||||||
|
if (last !== today) {
|
||||||
|
// Perform backup
|
||||||
|
await performBackup(true);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}, []);
|
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
check();
|
||||||
|
}, 5000); // Check 5s after load to allow state to settle
|
||||||
|
|
||||||
|
return () => clearTimeout(timer);
|
||||||
|
}, [dailyBackupEnabled, lastBackupDate, performBackup]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-background text-foreground flex flex-col select-none overflow-hidden">
|
<div className="min-h-screen bg-background text-foreground flex flex-col select-none overflow-hidden">
|
||||||
@@ -224,7 +437,7 @@ Wann findet das nächste Meeting statt oder was ist der nächste Meilenstein?`
|
|||||||
<div className="absolute right-4 top-4">
|
<div className="absolute right-4 top-4">
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setLastTab(view === 'logs' ? 'logs' : 'recorder');
|
setLastTab(view === 'history' ? view : 'recorder');
|
||||||
setView('settings');
|
setView('settings');
|
||||||
}}
|
}}
|
||||||
className="p-2 text-muted-foreground hover:text-foreground hover:bg-secondary rounded-full transition-colors"
|
className="p-2 text-muted-foreground hover:text-foreground hover:bg-secondary rounded-full transition-colors"
|
||||||
@@ -234,14 +447,16 @@ Wann findet das nächste Meeting statt oder was ist der nächste Meilenstein?`
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Tabs
|
<Tabs
|
||||||
currentTab={view as 'recorder' | 'logs' | 'transcription'}
|
currentTab={view as 'recorder' | 'transcription' | 'meetings' | 'history' | 'import'}
|
||||||
onTabChange={(t) => setView(t)}
|
onTabChange={(t) => setView(t)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<div className="flex-1 flex h-full overflow-hidden relative">
|
||||||
<div className="flex-1 flex flex-col h-full overflow-hidden relative">
|
<div className="flex-1 flex flex-col h-full overflow-hidden relative">
|
||||||
{view === 'recorder' && (
|
{/* Recorder - Persistent (Hidden via CSS to keep recording alive) */}
|
||||||
|
<div className="flex-1 flex flex-col h-full overflow-hidden" style={{ display: view === 'recorder' ? 'flex' : 'none' }}>
|
||||||
<Recorder
|
<Recorder
|
||||||
apiKey={apiKey}
|
apiKey={apiKey}
|
||||||
productId={productId}
|
productId={productId}
|
||||||
@@ -259,18 +474,91 @@ Wann findet das nächste Meeting statt oder was ist der nächste Meilenstein?`
|
|||||||
onDeleteHistory={handleDeleteHistory}
|
onDeleteHistory={handleDeleteHistory}
|
||||||
onLoadHistory={handleLoadHistory}
|
onLoadHistory={handleLoadHistory}
|
||||||
savePath={savePath}
|
savePath={savePath}
|
||||||
|
|
||||||
onRecordingComplete={() => setView('transcription')}
|
onRecordingComplete={() => setView('transcription')}
|
||||||
|
autoStart={autoStartRecording}
|
||||||
|
recordingSubject={recordingSubject}
|
||||||
|
onAutoStartHandled={() => setAutoStartRecording(false)}
|
||||||
|
addToast={addToast}
|
||||||
|
selectedModel={selectedModel}
|
||||||
|
onModelChange={handleModelChange}
|
||||||
|
isVisible={view === 'recorder'}
|
||||||
|
blockedApps={blockedApps}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{view === 'transcription' && (
|
||||||
|
<TranscriptionView
|
||||||
|
transcription={transcription}
|
||||||
|
summary={summary}
|
||||||
|
smtpConfig={smtpConfig}
|
||||||
|
apiKey={apiKey}
|
||||||
|
productId={productId}
|
||||||
|
prompts={prompts}
|
||||||
|
emailTemplates={emailTemplates}
|
||||||
|
onUpdateSummary={(newSummary) => {
|
||||||
|
setSummary(newSummary); // Update view
|
||||||
|
// Also update history item if it exists
|
||||||
|
// We identify by transcription content match (simple heuristic) or we should track currentId
|
||||||
|
const histIdx = history.findIndex(h => h.transcription === transcription);
|
||||||
|
if (histIdx >= 0) {
|
||||||
|
const newHist = [...history];
|
||||||
|
newHist[histIdx] = { ...newHist[histIdx], summary: newSummary };
|
||||||
|
setHistory(newHist);
|
||||||
|
localStorage.setItem('infomaniak_history', JSON.stringify(newHist));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
addToast={addToast}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{view === 'transcription' && (
|
{view === 'history' && (
|
||||||
<TranscriptionView transcription={transcription} summary={summary} />
|
<HistoryView
|
||||||
|
history={history}
|
||||||
|
onLoad={handleLoadHistory}
|
||||||
|
onDelete={handleDeleteHistory}
|
||||||
|
onRename={handleRenameHistory}
|
||||||
|
smtpConfig={smtpConfig}
|
||||||
|
emailTemplates={emailTemplates}
|
||||||
|
addToast={addToast}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{view === 'logs' && (
|
{view === 'meetings' && (
|
||||||
<LogViewer logs={logs} />
|
|
||||||
|
<MeetingsView
|
||||||
|
azureClientId={azureConfig.clientId}
|
||||||
|
onStartRecording={(subject) => {
|
||||||
|
setView('recorder');
|
||||||
|
setRecordingSubject(subject || '');
|
||||||
|
setAutoStartRecording(true);
|
||||||
|
}}
|
||||||
|
apiKey={apiKey}
|
||||||
|
productId={productId}
|
||||||
|
selectedModel={selectedModel}
|
||||||
|
onModelChange={handleModelChange}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{view === 'import' && (
|
||||||
|
<Import
|
||||||
|
apiKey={apiKey}
|
||||||
|
productId={productId}
|
||||||
|
prompts={prompts}
|
||||||
|
selectedModel={selectedModel}
|
||||||
|
onSaveToHistory={handleSaveToHistory}
|
||||||
|
onComplete={() => setView('transcription')}
|
||||||
|
addToast={addToast}
|
||||||
|
setTranscription={setTranscription}
|
||||||
|
setSummary={setSummary}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{view === 'settings' && (
|
{view === 'settings' && (
|
||||||
<Settings
|
<Settings
|
||||||
onSave={handleSaveSettings}
|
onSave={handleSaveSettings}
|
||||||
@@ -279,9 +567,27 @@ Wann findet das nächste Meeting statt oder was ist der nächste Meilenstein?`
|
|||||||
productId={productId}
|
productId={productId}
|
||||||
prompts={prompts}
|
prompts={prompts}
|
||||||
savePath={savePath}
|
savePath={savePath}
|
||||||
|
smtpConfig={smtpConfig}
|
||||||
|
azureConfig={azureConfig}
|
||||||
|
emailTemplates={emailTemplates}
|
||||||
|
|
||||||
|
// Pass new backup props
|
||||||
|
dailyBackupEnabled={dailyBackupEnabled}
|
||||||
|
dailyBackupPath={dailyBackupPath}
|
||||||
|
lastBackupDate={lastBackupDate}
|
||||||
|
|
||||||
|
// Pass history and update callback
|
||||||
|
history={history}
|
||||||
|
onHistoryUpdate={(newHistory) => {
|
||||||
|
setHistory(newHistory);
|
||||||
|
localStorage.setItem('infomaniak_history', JSON.stringify(newHistory));
|
||||||
|
}}
|
||||||
|
blockedApps={blockedApps}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
<ToastContainer toasts={toasts} removeToast={removeToast} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
288
src/components/EmailPreviewModal.tsx
Normal file
288
src/components/EmailPreviewModal.tsx
Normal file
@@ -0,0 +1,288 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import { Mail, X, Send } from 'lucide-react';
|
||||||
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
|
|
||||||
|
import { EmailTemplate } from '../App';
|
||||||
|
|
||||||
|
interface EmailPreviewModalProps {
|
||||||
|
isOpen: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
initialRecipients: string[];
|
||||||
|
initialSubject: string;
|
||||||
|
initialBody: string;
|
||||||
|
emailTemplates: EmailTemplate[]; // New prop
|
||||||
|
smtpConfig: {
|
||||||
|
host: string;
|
||||||
|
port: number;
|
||||||
|
user: string;
|
||||||
|
pass: string;
|
||||||
|
sender: string;
|
||||||
|
senderName?: string;
|
||||||
|
} | null;
|
||||||
|
addToast: (msg: string, type: 'success' | 'error' | 'info') => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Basic Markdown to HTML converter for email body
|
||||||
|
const formatMarkdownToHtml = (markdown: string): string => {
|
||||||
|
let html = markdown
|
||||||
|
// Headers
|
||||||
|
.replace(/^# (.*$)/gim, '<h1 style="color: #1a1a1a; font-size: 24px; margin-top: 20px; margin-bottom: 10px; border-bottom: 2px solid #eaeaea; padding-bottom: 10px;">$1</h1>')
|
||||||
|
.replace(/^## (.*$)/gim, '<h2 style="color: #2d2d2d; font-size: 20px; margin-top: 25px; margin-bottom: 10px;">$1</h2>')
|
||||||
|
.replace(/^### (.*$)/gim, '<h3 style="color: #404040; font-size: 18px; margin-top: 20px; margin-bottom: 8px;">$1</h3>')
|
||||||
|
|
||||||
|
// Bold
|
||||||
|
.replace(/\*\*(.*?)\*\*/gim, '<strong>$1</strong>')
|
||||||
|
|
||||||
|
// Lists
|
||||||
|
.replace(/^\s*-\s+(.*$)/gim, '<li style="margin-bottom: 5px;">$1</li>')
|
||||||
|
// Wrap lists (simple heuristic)
|
||||||
|
.replace(/(<li.*<\/li>)/gim, '<ul>$1</ul>')
|
||||||
|
.replace(/<\/ul>\s*<ul>/gim, '') // Merge adjacent lists
|
||||||
|
|
||||||
|
// Tables (Basic support for the format used in prompts)
|
||||||
|
.replace(/\| (.*?) \| (.*?) \| (.*?) \|/gim, '<tr><td style="border: 1px solid #ddd; padding: 8px;">$1</td><td style="border: 1px solid #ddd; padding: 8px;">$2</td><td style="border: 1px solid #ddd; padding: 8px;">$3</td></tr>')
|
||||||
|
.replace(/\| :--- \| :--- \| :--- \|/gim, '') // Remove separator row
|
||||||
|
// Tables wrapping (heuristic)
|
||||||
|
.replace(/(<tr>.*<\/tr>)/gim, '<table style="width: 100%; border-collapse: collapse; margin-top: 10px; margin-bottom: 20px;">$1</table>')
|
||||||
|
.replace(/<\/table>\s*<table.*?>/gim, '') // Merge adjacent tables
|
||||||
|
|
||||||
|
// Paragraphs (double newlines)
|
||||||
|
.replace(/\n\n/gim, '<br><br>');
|
||||||
|
|
||||||
|
return html;
|
||||||
|
};
|
||||||
|
|
||||||
|
const EmailPreviewModal: React.FC<EmailPreviewModalProps> = ({
|
||||||
|
isOpen, onClose, initialRecipients, initialSubject, initialBody, smtpConfig, addToast, emailTemplates
|
||||||
|
}) => {
|
||||||
|
const [recipients, setRecipients] = useState<string>(initialRecipients.join(', '));
|
||||||
|
const [subject, setSubject] = useState(initialSubject);
|
||||||
|
const [body, setBody] = useState(initialBody);
|
||||||
|
const [sending, setSending] = useState(false);
|
||||||
|
const [selectedTemplateId, setSelectedTemplateId] = useState<string>('');
|
||||||
|
|
||||||
|
const [activeTab, setActiveTab] = useState<'preview' | 'source'>('preview');
|
||||||
|
|
||||||
|
const generateHtmlBody = (content: string, title: string) => {
|
||||||
|
// Check if it's a full HTML document
|
||||||
|
if (/^\s*<!DOCTYPE html/i.test(content) || /^\s*<html/i.test(content)) {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simple heuristic: if it looks like HTML fragment (div, p, table), treat as HTML. Otherwise, markdown.
|
||||||
|
const isHtmlFragment = /^\s*<(div|p|table|section|header|footer)/i.test(content);
|
||||||
|
const formattedBody = isHtmlFragment ? content : formatMarkdownToHtml(content);
|
||||||
|
|
||||||
|
return `
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<body style="margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; background-color: #f4f4f5; color: #333;">
|
||||||
|
<div style="max-width: 640px; margin: 40px auto; background-color: #ffffff; border-radius: 12px; overflow: hidden; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);">
|
||||||
|
<!-- Header -->
|
||||||
|
<div style="background-color: #000000; padding: 30px 40px;">
|
||||||
|
<h1 style="color: #ffffff; margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -0.5px;">${title}</h1>
|
||||||
|
</div>
|
||||||
|
<!-- Content -->
|
||||||
|
<div style="padding: 40px; line-height: 1.6;">
|
||||||
|
${formattedBody}
|
||||||
|
</div>
|
||||||
|
<!-- Footer -->
|
||||||
|
<div style="background-color: #f9fafb; padding: 20px 40px; text-align: center; border-top: 1px solid #e5e7eb;">
|
||||||
|
<p style="margin: 0; font-size: 12px; color: #6b7280;">
|
||||||
|
Generated by <strong>Hearbit AI</strong> • Secure & Local Meeting Intelligence
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>`;
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen) {
|
||||||
|
setRecipients(initialRecipients.join(', '));
|
||||||
|
setSubject(initialSubject);
|
||||||
|
// Default: Wrap initialBody in our HTML template
|
||||||
|
setBody(generateHtmlBody(initialBody, initialSubject));
|
||||||
|
setSelectedTemplateId('');
|
||||||
|
}
|
||||||
|
}, [isOpen, initialRecipients, initialSubject, initialBody]);
|
||||||
|
|
||||||
|
const handleTemplateChange = (tmplId: string) => {
|
||||||
|
setSelectedTemplateId(tmplId);
|
||||||
|
if (!tmplId) return;
|
||||||
|
|
||||||
|
const tmpl = emailTemplates.find(t => t.id === tmplId);
|
||||||
|
if (tmpl) {
|
||||||
|
// Replace placeholders
|
||||||
|
const dateStr = new Date().toLocaleDateString();
|
||||||
|
let newSub = tmpl.subject.replace(/{{date}}/g, dateStr).replace(/{{subject}}/g, "Meeting");
|
||||||
|
|
||||||
|
// Clean up JSON if necessary (e.g. remove markdown code blocks ```json ... ```)
|
||||||
|
let cleanSummary = initialBody;
|
||||||
|
if (initialBody.trim().startsWith('```')) {
|
||||||
|
cleanSummary = initialBody.replace(/^```(json)?/i, '').replace(/```$/, '').trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
let newBody = tmpl.body
|
||||||
|
.replace(/{{date}}/g, dateStr)
|
||||||
|
.replace(/{{subject}}/g, "the meeting")
|
||||||
|
.replace(/{{summary}}/g, cleanSummary);
|
||||||
|
|
||||||
|
setSubject(newSub);
|
||||||
|
setBody(generateHtmlBody(newBody, newSub));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!isOpen) return null;
|
||||||
|
|
||||||
|
const handleSend = async () => {
|
||||||
|
if (!smtpConfig || !smtpConfig.host) {
|
||||||
|
addToast("SMTP Settings not configured. Please go to Settings.", "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setSending(true);
|
||||||
|
try {
|
||||||
|
// Split recipients by comma/semicolon and clean
|
||||||
|
const toList = recipients.split(/[,;]/).map(s => s.trim()).filter(s => s.length > 0);
|
||||||
|
|
||||||
|
await invoke('send_smtp_email', {
|
||||||
|
config: {
|
||||||
|
host: smtpConfig.host,
|
||||||
|
port: Number(smtpConfig.port),
|
||||||
|
username: smtpConfig.user,
|
||||||
|
password: smtpConfig.pass,
|
||||||
|
sender_email: smtpConfig.sender,
|
||||||
|
sender_name: smtpConfig.senderName
|
||||||
|
},
|
||||||
|
message: {
|
||||||
|
to: toList,
|
||||||
|
subject: subject,
|
||||||
|
body_html: body
|
||||||
|
}
|
||||||
|
});
|
||||||
|
addToast("Email sent successfully!", "success");
|
||||||
|
onClose();
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
addToast(`Failed to send email: ${e}`, "error");
|
||||||
|
} finally {
|
||||||
|
setSending(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="fixed inset-0 z-50 bg-black/50 flex items-center justify-center p-4">
|
||||||
|
<div className="bg-background border border-border rounded-xl shadow-2xl w-full max-w-3xl flex flex-col h-[90vh]">
|
||||||
|
<div className="p-4 border-b border-border flex justify-between items-center shrink-0">
|
||||||
|
<h3 className="font-semibold flex items-center gap-2">
|
||||||
|
<Mail size={18} /> Send Summary via Email
|
||||||
|
</h3>
|
||||||
|
<button onClick={onClose} className="text-muted-foreground hover:text-foreground">
|
||||||
|
<X size={20} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="p-4 space-y-4 overflow-y-auto flex-1 flex flex-col">
|
||||||
|
{/* Template Selector */}
|
||||||
|
{emailTemplates.length > 0 && (
|
||||||
|
<div className="bg-secondary/20 p-3 rounded-lg border border-border/50">
|
||||||
|
<label className="block text-xs font-semibold text-muted-foreground mb-1 uppercase tracking-wide">
|
||||||
|
Load Template
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
value={selectedTemplateId}
|
||||||
|
onChange={(e) => handleTemplateChange(e.target.value)}
|
||||||
|
className="w-full text-sm p-2 rounded border border-border bg-background outline-none focus:ring-2 focus:ring-primary"
|
||||||
|
>
|
||||||
|
<option value="">-- Select a Template --</option>
|
||||||
|
{emailTemplates.map(t => (
|
||||||
|
<option key={t.id} value={t.id}>{t.name}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<div>
|
||||||
|
<label className="block text-xs font-semibold text-muted-foreground mb-1">To</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={recipients}
|
||||||
|
onChange={(e) => setRecipients(e.target.value)}
|
||||||
|
className="w-full p-2 rounded border border-border bg-secondary text-sm focus:ring-2 focus:ring-primary outline-none"
|
||||||
|
placeholder="email@example.com, other@example.com"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-xs font-semibold text-muted-foreground mb-1">Subject</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={subject}
|
||||||
|
onChange={(e) => setSubject(e.target.value)}
|
||||||
|
className="w-full p-2 rounded border border-border bg-secondary text-sm focus:ring-2 focus:ring-primary outline-none"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex-1 flex flex-col min-h-0 border border-border rounded-lg overflow-hidden">
|
||||||
|
{/* Tabs */}
|
||||||
|
<div className="flex border-b border-border bg-secondary/30">
|
||||||
|
<button
|
||||||
|
onClick={() => setActiveTab('preview')}
|
||||||
|
className={`px-4 py-2 text-sm font-medium transition-colors ${activeTab === 'preview' ? 'bg-background text-primary border-r border-border' : 'text-muted-foreground hover:text-foreground'}`}
|
||||||
|
>
|
||||||
|
Preview
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => setActiveTab('source')}
|
||||||
|
className={`px-4 py-2 text-sm font-medium transition-colors ${activeTab === 'source' ? 'bg-background text-primary border-l border-r border-border' : 'text-muted-foreground hover:text-foreground'}`}
|
||||||
|
>
|
||||||
|
HTML Source
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Content */}
|
||||||
|
<div className="flex-1 bg-background overflow-hidden relative">
|
||||||
|
{activeTab === 'preview' ? (
|
||||||
|
<div className="w-full h-full bg-white text-black">
|
||||||
|
<iframe
|
||||||
|
srcDoc={body}
|
||||||
|
className="w-full h-full border-none"
|
||||||
|
title="Email Preview"
|
||||||
|
sandbox="allow-same-origin allow-scripts"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<textarea
|
||||||
|
value={body}
|
||||||
|
onChange={(e) => setBody(e.target.value)}
|
||||||
|
className="w-full h-full p-4 text-sm font-mono resize-none focus:outline-none bg-background text-foreground"
|
||||||
|
placeholder="<html>...</html>"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="p-4 border-t border-border flex justify-end gap-2 bg-secondary/10 rounded-b-xl">
|
||||||
|
<button
|
||||||
|
onClick={onClose}
|
||||||
|
className="px-4 py-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={handleSend}
|
||||||
|
disabled={sending}
|
||||||
|
className="px-4 py-2 text-sm font-medium bg-primary text-primary-foreground rounded-lg hover:bg-primary/90 transition-all flex items-center gap-2 disabled:opacity-50"
|
||||||
|
>
|
||||||
|
{sending ? 'Sending...' : <><Send size={16} /> Send Email</>}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EmailPreviewModal;
|
||||||
216
src/components/EmailTemplateEditor.tsx
Normal file
216
src/components/EmailTemplateEditor.tsx
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import { X, Eye, Send, Code } from 'lucide-react';
|
||||||
|
import { EmailTemplate } from '../App';
|
||||||
|
import { SmtpConfig } from './Settings';
|
||||||
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
|
|
||||||
|
interface EmailTemplateEditorProps {
|
||||||
|
isOpen: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
template: EmailTemplate | null;
|
||||||
|
onSave: (template: EmailTemplate) => void;
|
||||||
|
smtpConfig: SmtpConfig;
|
||||||
|
addToast: (msg: string, type: 'success' | 'error' | 'info') => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EmailTemplateEditor: React.FC<EmailTemplateEditorProps> = ({
|
||||||
|
isOpen, onClose, template, onSave, smtpConfig, addToast
|
||||||
|
}) => {
|
||||||
|
const [name, setName] = useState('');
|
||||||
|
const [subject, setSubject] = useState('');
|
||||||
|
const [body, setBody] = useState('');
|
||||||
|
const [activeTab, setActiveTab] = useState<'edit' | 'preview'>('edit');
|
||||||
|
const [testEmail, setTestEmail] = useState('');
|
||||||
|
const [sendingTest, setSendingTest] = useState(false);
|
||||||
|
|
||||||
|
// Load template data when it changes or opens
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (template) {
|
||||||
|
setName(template.name);
|
||||||
|
setSubject(template.subject);
|
||||||
|
setBody(template.body);
|
||||||
|
} else {
|
||||||
|
// New template defaults
|
||||||
|
setName('New Template');
|
||||||
|
setSubject('Subject: {{subject}}');
|
||||||
|
setBody('{{summary}}');
|
||||||
|
}
|
||||||
|
}, [template, isOpen]);
|
||||||
|
|
||||||
|
if (!isOpen) return null;
|
||||||
|
|
||||||
|
const handleSave = () => {
|
||||||
|
if (!template) {
|
||||||
|
// Create new
|
||||||
|
onSave({
|
||||||
|
id: Date.now().toString(),
|
||||||
|
name,
|
||||||
|
subject,
|
||||||
|
body
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Update existing
|
||||||
|
onSave({
|
||||||
|
...template,
|
||||||
|
name,
|
||||||
|
subject,
|
||||||
|
body
|
||||||
|
});
|
||||||
|
}
|
||||||
|
onClose();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSendTest = async () => {
|
||||||
|
if (!testEmail) {
|
||||||
|
addToast('Please enter a test email address', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!smtpConfig.host) {
|
||||||
|
addToast('SMTP settings missing in main settings', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setSendingTest(true);
|
||||||
|
try {
|
||||||
|
// Basic substitution for preview
|
||||||
|
// Basic substitution for preview
|
||||||
|
// If markdown (simple check), convert? For now, we assume user is writing HTML or we leave it raw if they want.
|
||||||
|
// But the request is to "use HTML format".
|
||||||
|
// If it looks like HTML, use it. If not, maybe wrap in <p>?
|
||||||
|
// For the test email, we pass it as body_html.
|
||||||
|
|
||||||
|
await invoke('send_smtp_email', {
|
||||||
|
config: {
|
||||||
|
host: smtpConfig.host,
|
||||||
|
port: Number(smtpConfig.port),
|
||||||
|
username: smtpConfig.user,
|
||||||
|
password: smtpConfig.pass,
|
||||||
|
sender_email: smtpConfig.sender,
|
||||||
|
sender_name: smtpConfig.senderName
|
||||||
|
},
|
||||||
|
message: {
|
||||||
|
to: [testEmail],
|
||||||
|
subject: `[TEST] ${subject}`,
|
||||||
|
body_html: body // Send raw body (HTML)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
addToast('Test email sent!', 'success');
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
addToast(`Failed to send test: ${e}`, 'error');
|
||||||
|
} finally {
|
||||||
|
setSendingTest(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="fixed inset-0 z-[60] bg-black/50 flex items-center justify-center p-4">
|
||||||
|
<div className="bg-background border border-border rounded-lg shadow-xl w-full max-w-4xl flex flex-col h-[85vh]">
|
||||||
|
{/* Header */}
|
||||||
|
<div className="p-4 border-b border-border flex justify-between items-center bg-secondary/20">
|
||||||
|
<h3 className="font-semibold text-lg flex items-center gap-2">
|
||||||
|
{template ? 'Edit Email Template' : 'Create Email Template'}
|
||||||
|
</h3>
|
||||||
|
<button onClick={onClose} className="text-muted-foreground hover:text-foreground">
|
||||||
|
<X size={20} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Content */}
|
||||||
|
<div className="flex-1 flex flex-col min-h-0 container mx-auto p-4 gap-4">
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<div>
|
||||||
|
<label className="block text-xs font-semibold text-muted-foreground mb-1">Template Name</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={name}
|
||||||
|
onChange={(e) => setName(e.target.value)}
|
||||||
|
className="w-full p-2 rounded border border-border bg-background focus:ring-2 focus:ring-primary outline-none"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-xs font-semibold text-muted-foreground mb-1">Subject Pattern</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={subject}
|
||||||
|
onChange={(e) => setSubject(e.target.value)}
|
||||||
|
className="w-full p-2 rounded border border-border bg-background focus:ring-2 focus:ring-primary outline-none"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex bg-secondary/30 border border-border rounded-t-lg mt-2">
|
||||||
|
<button
|
||||||
|
onClick={() => setActiveTab('edit')}
|
||||||
|
className={`px-4 py-2 text-sm font-medium flex items-center gap-2 ${activeTab === 'edit' ? 'bg-background border-b-0 text-primary' : 'text-muted-foreground hover:text-foreground'}`}
|
||||||
|
>
|
||||||
|
<Code size={16} /> Edit HTML
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => setActiveTab('preview')}
|
||||||
|
className={`px-4 py-2 text-sm font-medium flex items-center gap-2 ${activeTab === 'preview' ? 'bg-background border-b-0 text-primary' : 'text-muted-foreground hover:text-foreground'}`}
|
||||||
|
>
|
||||||
|
<Eye size={16} /> Preview
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex-1 border border-t-0 border-border rounded-b-lg bg-background overflow-hidden relative">
|
||||||
|
{activeTab === 'edit' ? (
|
||||||
|
<textarea
|
||||||
|
value={body}
|
||||||
|
onChange={(e) => setBody(e.target.value)}
|
||||||
|
className="w-full h-full p-4 font-mono text-sm resize-none focus:outline-none bg-background text-foreground"
|
||||||
|
placeholder="<html><body>...</body></html> or Markdown"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="w-full h-full bg-white text-black">
|
||||||
|
<iframe
|
||||||
|
srcDoc={body}
|
||||||
|
className="w-full h-full border-none"
|
||||||
|
title="Email Preview"
|
||||||
|
sandbox="allow-same-origin"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Test Email Section */}
|
||||||
|
<div className="flex items-center gap-2 pt-2 border-t border-border/50">
|
||||||
|
<input
|
||||||
|
type="email"
|
||||||
|
value={testEmail}
|
||||||
|
onChange={(e) => setTestEmail(e.target.value)}
|
||||||
|
placeholder="test@example.com"
|
||||||
|
className="flex-1 p-2 rounded border border-border bg-secondary/50 text-sm focus:ring-2 focus:ring-primary outline-none"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
onClick={handleSendTest}
|
||||||
|
disabled={sendingTest || !testEmail}
|
||||||
|
className="px-4 py-2 text-sm font-medium bg-secondary hover:bg-secondary/80 text-foreground rounded border border-border transition-colors disabled:opacity-50 flex items-center gap-2"
|
||||||
|
>
|
||||||
|
{sendingTest ? 'Sending...' : <><Send size={14} /> Send Test</>}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Footer */}
|
||||||
|
<div className="p-4 border-t border-border flex justify-end gap-2 bg-secondary/10">
|
||||||
|
<button
|
||||||
|
onClick={onClose}
|
||||||
|
className="px-4 py-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={handleSave}
|
||||||
|
className="px-6 py-2 text-sm font-medium bg-primary text-primary-foreground rounded hover:bg-primary/90 transition-colors"
|
||||||
|
>
|
||||||
|
Save Template
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EmailTemplateEditor;
|
||||||
149
src/components/HistoryView.tsx
Normal file
149
src/components/HistoryView.tsx
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
import { FileText, Trash2, Calendar, Pencil, Check, X, Mail } from 'lucide-react';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import EmailPreviewModal from './EmailPreviewModal';
|
||||||
|
import { SmtpConfig } from './Settings';
|
||||||
|
import { EmailTemplate } from '../App';
|
||||||
|
import { ToastType } from './ui/Toast';
|
||||||
|
|
||||||
|
interface HistoryItem {
|
||||||
|
id: string;
|
||||||
|
date: string;
|
||||||
|
transcription: string; // This might be raw text or path?
|
||||||
|
summary: string;
|
||||||
|
subject?: string;
|
||||||
|
filename?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface HistoryViewProps {
|
||||||
|
history: HistoryItem[];
|
||||||
|
onLoad: (item: HistoryItem) => void;
|
||||||
|
onDelete: (id: string) => void;
|
||||||
|
onRename: (id: string, newSubject: string) => void;
|
||||||
|
smtpConfig: SmtpConfig;
|
||||||
|
emailTemplates: EmailTemplate[];
|
||||||
|
addToast: (message: string, type: ToastType, duration?: number) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function HistoryView({ history, onLoad, onDelete, onRename, smtpConfig, emailTemplates, addToast }: HistoryViewProps) {
|
||||||
|
const [editingId, setEditingId] = useState<string | null>(null);
|
||||||
|
const [editValue, setEditValue] = useState("");
|
||||||
|
const [emailModalItem, setEmailModalItem] = useState<HistoryItem | null>(null);
|
||||||
|
|
||||||
|
const startEditing = (item: HistoryItem) => {
|
||||||
|
setEditingId(item.id);
|
||||||
|
setEditValue(item.subject || "Untitled Recording");
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveEdit = () => {
|
||||||
|
if (editingId && editValue.trim()) {
|
||||||
|
onRename(editingId, editValue.trim());
|
||||||
|
setEditingId(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const cancelEdit = () => {
|
||||||
|
setEditingId(null);
|
||||||
|
setEditValue("");
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col w-full h-full bg-background p-6">
|
||||||
|
<h1 className="text-2xl font-bold mb-6 flex items-center gap-2">
|
||||||
|
<FileText className="w-8 h-8" />
|
||||||
|
Recording History
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
{history.length === 0 ? (
|
||||||
|
<div className="flex-1 flex flex-col items-center justify-center text-muted-foreground">
|
||||||
|
<FileText size={48} className="mb-4 opacity-20" />
|
||||||
|
<p>No history found.</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="flex-1 overflow-y-auto space-y-3 pr-2">
|
||||||
|
{history.map(item => (
|
||||||
|
<div key={item.id} className="bg-card border border-border rounded-xl p-4 hover:shadow-md transition-all group">
|
||||||
|
<div className="flex justify-between items-start">
|
||||||
|
<div className="flex-1">
|
||||||
|
{editingId === item.id ? (
|
||||||
|
<div className="flex items-center gap-2 mb-2" onClick={(e) => e.stopPropagation()}>
|
||||||
|
<input
|
||||||
|
autoFocus
|
||||||
|
type="text"
|
||||||
|
className="flex-1 bg-background border border-input rounded px-2 py-1 text-sm font-semibold focus:outline-none focus:ring-1 focus:ring-ring"
|
||||||
|
value={editValue}
|
||||||
|
onChange={(e) => setEditValue(e.target.value)}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === 'Enter') saveEdit();
|
||||||
|
if (e.key === 'Escape') cancelEdit();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<button onClick={saveEdit} className="p-1 text-green-500 hover:bg-green-500/10 rounded">
|
||||||
|
<Check size={16} />
|
||||||
|
</button>
|
||||||
|
<button onClick={cancelEdit} className="p-1 text-muted-foreground hover:bg-muted rounded">
|
||||||
|
<X size={16} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div
|
||||||
|
className="cursor-pointer"
|
||||||
|
onClick={() => onLoad(item)}
|
||||||
|
>
|
||||||
|
<h3 className="text-lg font-semibold group-hover:text-primary transition-colors mb-1 flex items-center gap-2">
|
||||||
|
{item.subject || "Untitled Recording"}
|
||||||
|
<button
|
||||||
|
onClick={(e) => { e.stopPropagation(); startEditing(item); }}
|
||||||
|
className="opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-foreground p-1 rounded hover:bg-muted transition-all"
|
||||||
|
title="Rename"
|
||||||
|
>
|
||||||
|
<Pencil size={14} />
|
||||||
|
</button>
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2 text-xs text-muted-foreground mb-2" onClick={() => !editingId && onLoad(item)}>
|
||||||
|
<Calendar size={12} />
|
||||||
|
{item.date}
|
||||||
|
{item.filename && <span className="bg-secondary px-1.5 py-0.5 rounded text-[10px] font-mono">{item.filename}</span>}
|
||||||
|
</div>
|
||||||
|
<p className="text-sm text-foreground/70 line-clamp-2 cursor-pointer" onClick={() => !editingId && onLoad(item)}>
|
||||||
|
{item.summary ? item.summary.substring(0, 150) + "..." : "No summary available."}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<button
|
||||||
|
onClick={(e) => { e.stopPropagation(); setEmailModalItem(item); }}
|
||||||
|
className="text-muted-foreground hover:text-primary p-2 rounded-lg hover:bg-primary/10 transition-colors opacity-0 group-hover:opacity-100"
|
||||||
|
title="Send Email"
|
||||||
|
>
|
||||||
|
<Mail size={18} />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={(e) => { e.stopPropagation(); onDelete(item.id); }}
|
||||||
|
className="text-muted-foreground hover:text-destructive p-2 rounded-lg hover:bg-destructive/10 transition-colors opacity-0 group-hover:opacity-100"
|
||||||
|
title="Delete"
|
||||||
|
>
|
||||||
|
<Trash2 size={18} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<EmailPreviewModal
|
||||||
|
isOpen={emailModalItem !== null}
|
||||||
|
onClose={() => setEmailModalItem(null)}
|
||||||
|
initialRecipients={[]}
|
||||||
|
initialSubject={emailModalItem?.subject || "Meeting Summary"}
|
||||||
|
initialBody={emailModalItem?.summary || ""}
|
||||||
|
emailTemplates={emailTemplates}
|
||||||
|
smtpConfig={smtpConfig ? { ...smtpConfig, port: Number(smtpConfig.port) } : null}
|
||||||
|
addToast={addToast}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
411
src/components/Import.tsx
Normal file
411
src/components/Import.tsx
Normal file
@@ -0,0 +1,411 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import { Upload, FileAudio, X, Check, Loader2 } from 'lucide-react';
|
||||||
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
import { open } from '@tauri-apps/plugin-dialog';
|
||||||
|
import logo from '../assets/logo.png';
|
||||||
|
|
||||||
|
interface PromptTemplate {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
content: string;
|
||||||
|
keywords?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ImportProps {
|
||||||
|
apiKey: string;
|
||||||
|
productId: string;
|
||||||
|
prompts: PromptTemplate[];
|
||||||
|
selectedModel: string;
|
||||||
|
onSaveToHistory: (transcription: string, summary: string) => void;
|
||||||
|
onComplete: () => void; // Navigate to Transcription view
|
||||||
|
addToast: (msg: string, type: 'success' | 'error' | 'info', duration?: number) => void;
|
||||||
|
setTranscription: (text: string) => void;
|
||||||
|
setSummary: (text: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AudioMetadata {
|
||||||
|
duration: number;
|
||||||
|
size: number;
|
||||||
|
format: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProcessingStage = 'idle' | 'validating' | 'transcribing' | 'summarizing' | 'complete';
|
||||||
|
|
||||||
|
const SUPPORTED_FORMATS = ['mp3', 'mp4', 'm4a', 'wav', 'flac', 'ogg', 'aac', 'wma'];
|
||||||
|
|
||||||
|
const Import: React.FC<ImportProps> = ({
|
||||||
|
apiKey,
|
||||||
|
productId,
|
||||||
|
prompts,
|
||||||
|
selectedModel,
|
||||||
|
onSaveToHistory,
|
||||||
|
onComplete,
|
||||||
|
addToast,
|
||||||
|
setTranscription,
|
||||||
|
setSummary
|
||||||
|
}) => {
|
||||||
|
const [selectedFile, setSelectedFile] = useState<string | null>(null);
|
||||||
|
const [metadata, setMetadata] = useState<AudioMetadata | null>(null);
|
||||||
|
const [meetingTitle, setMeetingTitle] = useState('');
|
||||||
|
const [stage, setStage] = useState<ProcessingStage>('idle');
|
||||||
|
const [selectedPromptId, setSelectedPromptId] = useState<string>('');
|
||||||
|
|
||||||
|
// Set default prompt
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (prompts.length > 0 && !selectedPromptId) {
|
||||||
|
setSelectedPromptId(prompts[0].id);
|
||||||
|
}
|
||||||
|
}, [prompts, selectedPromptId]);
|
||||||
|
|
||||||
|
const validateFile = (filePath: string): boolean => {
|
||||||
|
const extension = filePath.split('.').pop()?.toLowerCase();
|
||||||
|
if (!extension || !SUPPORTED_FORMATS.includes(extension)) {
|
||||||
|
addToast(`Unsupported format. Supported: ${SUPPORTED_FORMATS.join(', ').toUpperCase()}`, 'error', 5000);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const extractFilename = (path: string): string => {
|
||||||
|
const parts = path.split(/[/\\]/);
|
||||||
|
const filename = parts[parts.length - 1];
|
||||||
|
return filename.replace(/\.[^/.]+$/, ''); // Remove extension
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatDuration = (seconds: number): string => {
|
||||||
|
const mins = Math.floor(seconds / 60);
|
||||||
|
const secs = Math.floor(seconds % 60);
|
||||||
|
return `${mins}:${secs.toString().padStart(2, '0')}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatSize = (bytes: number): string => {
|
||||||
|
if (bytes < 1024 * 1024) {
|
||||||
|
return `${(bytes / 1024).toFixed(1)} KB`;
|
||||||
|
}
|
||||||
|
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFileSelect = async (filePath: string) => {
|
||||||
|
if (!validateFile(filePath)) return;
|
||||||
|
|
||||||
|
setStage('validating');
|
||||||
|
setSelectedFile(filePath);
|
||||||
|
setMeetingTitle(extractFilename(filePath));
|
||||||
|
|
||||||
|
try {
|
||||||
|
const meta = await invoke<AudioMetadata>('get_audio_metadata', { filePath });
|
||||||
|
setMetadata(meta);
|
||||||
|
setStage('idle');
|
||||||
|
addToast('File loaded successfully', 'success', 2000);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Metadata error:', e);
|
||||||
|
setMetadata(null);
|
||||||
|
setStage('idle');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleManualSelect = async () => {
|
||||||
|
try {
|
||||||
|
const selected = await open({
|
||||||
|
multiple: false,
|
||||||
|
filters: [{
|
||||||
|
name: 'Audio/Video',
|
||||||
|
extensions: SUPPORTED_FORMATS
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
if (selected && typeof selected === 'string') {
|
||||||
|
handleFileSelect(selected);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('File picker error:', e);
|
||||||
|
addToast('Failed to open file picker', 'error');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleProcess = async () => {
|
||||||
|
if (!selectedFile) return;
|
||||||
|
if (!apiKey || !productId) {
|
||||||
|
addToast('Please configure API key in Settings', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Check file extension
|
||||||
|
const isWav = selectedFile.toLowerCase().endsWith('.wav');
|
||||||
|
let processFile = selectedFile;
|
||||||
|
|
||||||
|
// Convert WAV to MP3 if needed
|
||||||
|
if (isWav) {
|
||||||
|
setStage('validating');
|
||||||
|
addToast('Converting WAV to MP3...', 'info', 2000);
|
||||||
|
processFile = await invoke<string>('convert_to_mp3', { wavPath: selectedFile });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get file size to check if chunking needed
|
||||||
|
const metadata = await invoke<AudioMetadata>('get_audio_metadata', { filePath: processFile });
|
||||||
|
const sizeMB = metadata.size / (1024 * 1024);
|
||||||
|
|
||||||
|
let transText = '';
|
||||||
|
|
||||||
|
// Check if chunking needed for large files
|
||||||
|
if (sizeMB >= 18) {
|
||||||
|
// CHUNKING PATH for large files
|
||||||
|
setStage('validating');
|
||||||
|
addToast(`Large file (${sizeMB.toFixed(1)}MB). Splitting into chunks...`, 'info', 4000);
|
||||||
|
|
||||||
|
const chunks = await invoke<string[]>('chunk_audio', {
|
||||||
|
filePath: processFile,
|
||||||
|
chunkMinutes: 10
|
||||||
|
});
|
||||||
|
|
||||||
|
addToast(`Processing ${chunks.length} chunks...`, 'info', 4000);
|
||||||
|
|
||||||
|
let allTranscriptions: string[] = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < chunks.length; i++) {
|
||||||
|
setStage('transcribing');
|
||||||
|
addToast(`Transcribing chunk ${i + 1}/${chunks.length}...`, 'info', 2000);
|
||||||
|
const chunkText = await invoke<string>('transcribe_audio', {
|
||||||
|
filePath: chunks[i],
|
||||||
|
apiKey,
|
||||||
|
productId
|
||||||
|
});
|
||||||
|
allTranscriptions.push(chunkText);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge transcriptions
|
||||||
|
transText = allTranscriptions.join('\n\n--- Next Segment ---\n\n');
|
||||||
|
addToast('All chunks transcribed successfully!', 'success', 3000);
|
||||||
|
} else {
|
||||||
|
// NORMAL PATH for small files
|
||||||
|
setStage('transcribing');
|
||||||
|
transText = await invoke<string>('transcribe_audio', {
|
||||||
|
filePath: processFile,
|
||||||
|
apiKey,
|
||||||
|
productId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setTranscription(transText);
|
||||||
|
|
||||||
|
if (!transText || transText.trim().length === 0) {
|
||||||
|
addToast('No speech detected in file', 'error');
|
||||||
|
setStage('idle');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Smart prompt selection (copied from Recorder.tsx)
|
||||||
|
let activePrompt = prompts.find(p => p.id === selectedPromptId);
|
||||||
|
const lowerText = transText.toLowerCase();
|
||||||
|
let bestMatchId = selectedPromptId;
|
||||||
|
let maxMatches = 0;
|
||||||
|
|
||||||
|
for (const p of prompts) {
|
||||||
|
if (!p.keywords) continue;
|
||||||
|
let matches = 0;
|
||||||
|
for (const kw of p.keywords) {
|
||||||
|
if (lowerText.includes(kw.toLowerCase())) {
|
||||||
|
matches++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (matches > maxMatches) {
|
||||||
|
maxMatches = matches;
|
||||||
|
bestMatchId = p.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bestMatchId !== selectedPromptId) {
|
||||||
|
const newPrompt = prompts.find(p => p.id === bestMatchId);
|
||||||
|
if (newPrompt) {
|
||||||
|
addToast(`Smart Select: Switched to "${newPrompt.name}"`, 'info', 3000);
|
||||||
|
activePrompt = newPrompt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const promptContent = activePrompt ? activePrompt.content : "Summarize this.";
|
||||||
|
|
||||||
|
setStage('summarizing');
|
||||||
|
const sumText = await invoke<string>('summarize_text', {
|
||||||
|
text: transText,
|
||||||
|
apiKey,
|
||||||
|
productId,
|
||||||
|
prompt: promptContent,
|
||||||
|
model: selectedModel
|
||||||
|
});
|
||||||
|
setSummary(sumText);
|
||||||
|
|
||||||
|
// Save to history
|
||||||
|
onSaveToHistory(transText, sumText);
|
||||||
|
|
||||||
|
setStage('complete');
|
||||||
|
addToast('Import complete!', 'success', 3000);
|
||||||
|
|
||||||
|
// Navigate to Transcription view
|
||||||
|
setTimeout(() => {
|
||||||
|
onComplete();
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Processing error:', e);
|
||||||
|
addToast(`Error: ${e}`, 'error');
|
||||||
|
setStage('idle');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleReset = () => {
|
||||||
|
setSelectedFile(null);
|
||||||
|
setMetadata(null);
|
||||||
|
setMeetingTitle('');
|
||||||
|
setStage('idle');
|
||||||
|
};
|
||||||
|
|
||||||
|
const getStageInfo = () => {
|
||||||
|
switch (stage) {
|
||||||
|
case 'validating': return { icon: Loader2, text: 'Validating file...', color: 'text-blue-500' };
|
||||||
|
case 'transcribing': return { icon: Loader2, text: 'Transcribing audio...', color: 'text-purple-500' };
|
||||||
|
case 'summarizing': return { icon: Loader2, text: 'Generating summary...', color: 'text-green-500' };
|
||||||
|
case 'complete': return { icon: Check, text: 'Complete!', color: 'text-green-500' };
|
||||||
|
default: return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const stageInfo = getStageInfo();
|
||||||
|
const isProcessing = stage !== 'idle' && stage !== 'complete';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col w-full h-full bg-background relative">
|
||||||
|
{/* Header */}
|
||||||
|
<div className="w-full flex justify-center items-center p-4 shrink-0">
|
||||||
|
<img src={localStorage.getItem('customLogo') || logo} alt="Logo" className="h-10 object-contain" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Main Content */}
|
||||||
|
<div className="flex-1 overflow-y-auto px-6 pb-6 flex flex-col items-center">
|
||||||
|
<h1 className="text-xl font-bold mb-2 text-foreground">Import Audio File</h1>
|
||||||
|
<p className="text-muted-foreground mb-6 text-center text-sm">
|
||||||
|
Select an audio file for transcription and summarization
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{/* File Selection Zone */}
|
||||||
|
<div
|
||||||
|
className={`w-full max-w-md border-2 border-dashed rounded-lg p-8 mb-6 transition-all ${selectedFile
|
||||||
|
? 'border-green-500 bg-green-500/5'
|
||||||
|
: 'border-border bg-secondary/30'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<div className="flex flex-col items-center justify-center gap-4">
|
||||||
|
{selectedFile ? (
|
||||||
|
<>
|
||||||
|
<FileAudio size={48} className="text-green-500" />
|
||||||
|
<div className="text-center">
|
||||||
|
<p className="font-semibold text-foreground">{meetingTitle}</p>
|
||||||
|
{metadata && (
|
||||||
|
<p className="text-xs text-muted-foreground mt-1">
|
||||||
|
{formatDuration(metadata.duration)} • {formatSize(metadata.size)} • {metadata.format.toUpperCase()}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onClick={handleReset}
|
||||||
|
className="text-xs text-muted-foreground hover:text-foreground flex items-center gap-1"
|
||||||
|
>
|
||||||
|
<X size={14} /> Change file
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Upload size={48} className="text-muted-foreground" />
|
||||||
|
<div className="text-center">
|
||||||
|
<p className="font-semibold text-foreground">Select Audio File</p>
|
||||||
|
<p className="text-xs text-muted-foreground mt-1">
|
||||||
|
Click below to browse your files
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onClick={handleManualSelect}
|
||||||
|
disabled={isProcessing}
|
||||||
|
className="px-6 py-3 bg-primary text-primary-foreground rounded-lg hover:bg-primary/90 disabled:opacity-50 text-base font-semibold transition-all shadow-md hover:shadow-lg"
|
||||||
|
>
|
||||||
|
Browse Files
|
||||||
|
</button>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Supported: MP3, MP4, WAV, M4A, FLAC, OGG, AAC, WMA
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Configuration Section */}
|
||||||
|
{selectedFile && (
|
||||||
|
<div className="w-full max-w-md space-y-4">
|
||||||
|
{/* Meeting Title */}
|
||||||
|
<div>
|
||||||
|
<label className="text-xs font-semibold text-muted-foreground uppercase tracking-wider block mb-1">
|
||||||
|
Meeting Title
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={meetingTitle}
|
||||||
|
onChange={(e) => setMeetingTitle(e.target.value)}
|
||||||
|
disabled={isProcessing}
|
||||||
|
className="w-full p-2 text-sm bg-secondary rounded border border-border outline-none focus:ring-2 focus:ring-primary disabled:opacity-50"
|
||||||
|
placeholder="Enter meeting title..."
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* AI Template */}
|
||||||
|
<div>
|
||||||
|
<label className="text-xs font-semibold text-muted-foreground uppercase tracking-wider block mb-1">
|
||||||
|
AI Template
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
value={selectedPromptId}
|
||||||
|
onChange={(e) => setSelectedPromptId(e.target.value)}
|
||||||
|
disabled={isProcessing || prompts.length === 0}
|
||||||
|
className="w-full p-2 text-sm bg-secondary rounded border border-border outline-none focus:ring-2 focus:ring-primary disabled:opacity-50"
|
||||||
|
>
|
||||||
|
{prompts.map(p => (
|
||||||
|
<option key={p.id} value={p.id}>{p.name}</option>
|
||||||
|
))}
|
||||||
|
{prompts.length === 0 && <option value="">No templates</option>}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Process Button */}
|
||||||
|
<button
|
||||||
|
onClick={handleProcess}
|
||||||
|
disabled={!selectedFile || isProcessing || !apiKey}
|
||||||
|
className="w-full py-3 text-base font-semibold bg-primary text-primary-foreground rounded-lg hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-all shadow-md hover:shadow-lg flex items-center justify-center gap-2"
|
||||||
|
>
|
||||||
|
{isProcessing ? (
|
||||||
|
<>
|
||||||
|
<Loader2 size={20} className="animate-spin" />
|
||||||
|
Processing...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Upload size={20} />
|
||||||
|
Transcribe & Summarize
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{/* Progress Indicator */}
|
||||||
|
{stageInfo && (
|
||||||
|
<div className="flex items-center justify-center gap-2 p-3 bg-secondary/50 rounded-lg border border-border">
|
||||||
|
<stageInfo.icon size={16} className={`${stageInfo.color} ${stage !== 'complete' ? 'animate-spin' : ''}`} />
|
||||||
|
<span className={`text-sm font-medium ${stageInfo.color}`}>
|
||||||
|
{stageInfo.text}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Import;
|
||||||
351
src/components/MeetingsView.tsx
Normal file
351
src/components/MeetingsView.tsx
Normal file
@@ -0,0 +1,351 @@
|
|||||||
|
import { useState, useEffect } from 'react';
|
||||||
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
|
import { Calendar, RefreshCw, LogIn, Video } from 'lucide-react';
|
||||||
|
import { openUrl } from '@tauri-apps/plugin-opener';
|
||||||
|
|
||||||
|
interface CalendarEvent {
|
||||||
|
id: string;
|
||||||
|
subject: string;
|
||||||
|
start: { dateTime: string, timeZone: string };
|
||||||
|
end: { dateTime: string, timeZone: string };
|
||||||
|
onlineMeeting?: { joinUrl: string };
|
||||||
|
location?: { displayName: string };
|
||||||
|
bodyPreview?: string; // Text preview
|
||||||
|
body?: { content: string, contentType: string }; // Full HTML/Text
|
||||||
|
attendees?: { emailAddress: { name: string, address: string }, type: string, status: { response: string } }[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MeetingsViewProps {
|
||||||
|
onStartRecording: (subject?: string) => void;
|
||||||
|
azureClientId: string;
|
||||||
|
apiKey: string;
|
||||||
|
productId: string;
|
||||||
|
selectedModel: string;
|
||||||
|
onModelChange: (model: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function MeetingsView({ onStartRecording, azureClientId, apiKey, productId, selectedModel, onModelChange }: MeetingsViewProps) {
|
||||||
|
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
||||||
|
const [token, setToken] = useState(localStorage.getItem('m365_token') || '');
|
||||||
|
// const [clientId, setClientId] = useState(azureClientId); // Use prop directly
|
||||||
|
|
||||||
|
// Sync prop to state if needed, or just use prop.
|
||||||
|
// Let's us prop directly in startAuthFlow
|
||||||
|
|
||||||
|
const [events, setEvents] = useState<CalendarEvent[]>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [error, setError] = useState('');
|
||||||
|
const [expandedIds, setExpandedIds] = useState<Set<string>>(new Set());
|
||||||
|
|
||||||
|
const [availableModels, setAvailableModels] = useState<Array<{ id: string, name: string }>>([]);
|
||||||
|
|
||||||
|
const toggleExpand = (id: string) => {
|
||||||
|
const newSet = new Set(expandedIds);
|
||||||
|
if (newSet.has(id)) {
|
||||||
|
newSet.delete(id);
|
||||||
|
} else {
|
||||||
|
newSet.add(id);
|
||||||
|
}
|
||||||
|
setExpandedIds(newSet);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (apiKey && productId) {
|
||||||
|
loadModels();
|
||||||
|
}
|
||||||
|
}, [apiKey, productId]);
|
||||||
|
|
||||||
|
const loadModels = async () => {
|
||||||
|
try {
|
||||||
|
const models = await invoke<Array<{ id: string, name: string }>>('get_available_models', { apiKey, productId });
|
||||||
|
if (models && models.length > 0) {
|
||||||
|
models.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
|
setAvailableModels(models);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to load models:", e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (token) {
|
||||||
|
setIsAuthenticated(true);
|
||||||
|
fetchEvents(token);
|
||||||
|
}
|
||||||
|
}, [token]);
|
||||||
|
|
||||||
|
const handleLogin = async () => {
|
||||||
|
if (!azureClientId) {
|
||||||
|
setError("Please configure Client ID in Settings");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
localStorage.setItem('m365_client_id', azureClientId);
|
||||||
|
|
||||||
|
setLoading(true);
|
||||||
|
setError('');
|
||||||
|
try {
|
||||||
|
const accessToken = await invoke<string>('start_auth_flow', { clientId: azureClientId });
|
||||||
|
setToken(accessToken);
|
||||||
|
localStorage.setItem('m365_token', accessToken);
|
||||||
|
setIsAuthenticated(true);
|
||||||
|
fetchEvents(accessToken);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Auth failed", err);
|
||||||
|
setError(String(err)); // Use String() to safely convert error object
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchEvents = async (authToken: string) => {
|
||||||
|
setLoading(true);
|
||||||
|
setError('');
|
||||||
|
try {
|
||||||
|
const data = await invoke<CalendarEvent[]>('get_calendar_events', { token: authToken });
|
||||||
|
// Sort by start time
|
||||||
|
const sorted = data.sort((a, b) => new Date(a.start.dateTime).getTime() - new Date(b.start.dateTime).getTime());
|
||||||
|
setEvents(sorted);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Fetch failed", err);
|
||||||
|
setError(`Fetch failed: ${err}`);
|
||||||
|
// If error is 401, logout
|
||||||
|
if (String(err).includes('401')) {
|
||||||
|
logout();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const logout = () => {
|
||||||
|
setToken('');
|
||||||
|
localStorage.removeItem('m365_token');
|
||||||
|
setIsAuthenticated(false);
|
||||||
|
setEvents([]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleJoin = async (joinUrl?: string, subject?: string) => {
|
||||||
|
if (!joinUrl) return;
|
||||||
|
try {
|
||||||
|
// 1. Open URL
|
||||||
|
await openUrl(joinUrl);
|
||||||
|
// 2. Start Recording (wait a sec for app focus switch?)
|
||||||
|
// Actually user might want to confirm recording? Protocol says "one-click".
|
||||||
|
onStartRecording(subject);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to join", e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatTime = (isoString: string) => {
|
||||||
|
return new Date(isoString).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatDate = (isoString: string) => {
|
||||||
|
const date = new Date(isoString);
|
||||||
|
const today = new Date();
|
||||||
|
const tomorrow = new Date(today);
|
||||||
|
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||||
|
|
||||||
|
if (date.toDateString() === today.toDateString()) return "Today";
|
||||||
|
if (date.toDateString() === tomorrow.toDateString()) return "Tomorrow";
|
||||||
|
return date.toLocaleDateString([], { weekday: 'long', month: 'long', day: 'numeric' });
|
||||||
|
};
|
||||||
|
|
||||||
|
// Group events by date
|
||||||
|
const groupedEvents = events.reduce((groups, event) => {
|
||||||
|
const dateKey = formatDate(event.start.dateTime);
|
||||||
|
if (!groups[dateKey]) {
|
||||||
|
groups[dateKey] = [];
|
||||||
|
}
|
||||||
|
groups[dateKey].push(event);
|
||||||
|
return groups;
|
||||||
|
}, {} as Record<string, CalendarEvent[]>);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col w-full h-full bg-background p-6">
|
||||||
|
<h1 className="text-2xl font-bold mb-6 flex items-center gap-2">
|
||||||
|
<Calendar className="w-8 h-8" />
|
||||||
|
Upcoming Meetings
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
{/* Auth Section */}
|
||||||
|
{!isAuthenticated ? (
|
||||||
|
<div className="flex flex-col items-center justify-center flex-1 gap-6 text-center max-w-md mx-auto">
|
||||||
|
<div className="bg-secondary/30 p-8 rounded-xl border border-border">
|
||||||
|
<Calendar className="w-16 h-16 text-muted-foreground mx-auto mb-4" />
|
||||||
|
<h2 className="text-lg font-semibold mb-2">Connect Microsoft 365</h2>
|
||||||
|
<p className="text-sm text-muted-foreground mb-6">
|
||||||
|
Connect your account to see upcoming Teams & Zoom meetings and join them with one click.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="flex flex-col gap-3">
|
||||||
|
<div className="text-sm p-3 bg-secondary/50 rounded border border-border text-center">
|
||||||
|
{azureClientId ? (
|
||||||
|
<span className="text-green-600 font-medium">Client ID Configured</span>
|
||||||
|
) : (
|
||||||
|
<span className="text-destructive font-medium">Client ID Missing in Settings</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={handleLogin}
|
||||||
|
disabled={loading || !azureClientId}
|
||||||
|
className="bg-primary text-primary-foreground px-4 py-2 rounded-md text-sm flex items-center justify-center gap-2 hover:opacity-90 disabled:opacity-50 w-full transition-all"
|
||||||
|
>
|
||||||
|
{loading ? <RefreshCw className="animate-spin" size={16} /> : <LogIn size={16} />}
|
||||||
|
Connect Account
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<div className="mt-4 p-3 bg-destructive/10 text-destructive text-xs rounded-md text-left break-all">
|
||||||
|
<strong>Error:</strong> {error}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<p className="text-[10px] text-muted-foreground mt-4 px-2">
|
||||||
|
Note: Requires an Azure App Registration (Multitenant) with redirect URI: <br />
|
||||||
|
<code className="bg-secondary px-1 rounded">http://localhost:14200/auth/callback</code>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="flex flex-col flex-1 overflow-hidden">
|
||||||
|
<div className="flex justify-between items-center mb-4 px-1">
|
||||||
|
<span className="text-sm text-muted-foreground font-medium">Next 7 Days</span>
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
{/* Model Selector */}
|
||||||
|
<div className="flex items-center gap-2 bg-secondary/50 p-1 rounded-lg border border-border/50">
|
||||||
|
<span className="text-[10px] uppercase font-bold text-muted-foreground pl-2">Using:</span>
|
||||||
|
<select
|
||||||
|
value={selectedModel}
|
||||||
|
onChange={(e) => onModelChange(e.target.value)}
|
||||||
|
className="bg-transparent text-xs font-medium outline-none text-foreground cursor-pointer"
|
||||||
|
>
|
||||||
|
{availableModels.map(m => (
|
||||||
|
<option key={m.id} value={m.id}>{m.name}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button onClick={() => fetchEvents(token)} disabled={loading} className="text-muted-foreground hover:text-foreground p-1 rounded hover:bg-secondary transition-colors" title="Refresh">
|
||||||
|
<RefreshCw size={16} className={loading ? 'animate-spin' : ''} />
|
||||||
|
</button>
|
||||||
|
<button onClick={logout} className="text-muted-foreground hover:text-destructive p-1 rounded hover:bg-destructive/10 transition-colors" title="Logout">
|
||||||
|
<LogIn size={16} className="rotate-180" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{events.length === 0 && !loading && (
|
||||||
|
<div className="flex-1 flex flex-col items-center justify-center text-muted-foreground">
|
||||||
|
{/* No meetings empty state (only if no error) */}
|
||||||
|
<Calendar size={48} className="mb-4 opacity-20" />
|
||||||
|
<p>No upcoming meetings found for the next 7 days.</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<div className="m-4 p-3 bg-destructive/10 text-destructive text-sm rounded-md flex items-center justify-between">
|
||||||
|
<span>{error}</span>
|
||||||
|
<button onClick={() => fetchEvents(token)} className="underline hover:no-underline ml-2">Retry</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="flex-1 overflow-y-auto pr-2 space-y-6 pb-20">
|
||||||
|
{Object.entries(groupedEvents).map(([dateLabel, dateEvents]) => (
|
||||||
|
<div key={dateLabel} className="space-y-3">
|
||||||
|
<div className="sticky top-0 z-10 bg-background/95 backdrop-blur py-2 border-b border-border/50 text-xs font-bold uppercase tracking-wider text-muted-foreground">
|
||||||
|
{dateLabel}
|
||||||
|
</div>
|
||||||
|
{dateEvents.map(event => (
|
||||||
|
<div key={event.id} className="bg-card border border-border rounded-xl p-4 hover:shadow-md transition-all group">
|
||||||
|
<div className="flex justify-between items-start">
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<div className="flex items-baseline gap-2">
|
||||||
|
<span className="text-lg font-mono font-medium text-foreground">
|
||||||
|
{formatTime(event.start.dateTime)}
|
||||||
|
</span>
|
||||||
|
<span className="text-xs text-muted-foreground">
|
||||||
|
- {formatTime(event.end.dateTime)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<h3 className="text-base font-semibold group-hover:text-primary transition-colors leading-tight">
|
||||||
|
{event.subject}
|
||||||
|
</h3>
|
||||||
|
{event.location?.displayName && (
|
||||||
|
<div className="text-xs text-muted-foreground flex items-center gap-1">
|
||||||
|
📍 {event.location.displayName}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{event.onlineMeeting?.joinUrl ? (
|
||||||
|
<button
|
||||||
|
onClick={() => handleJoin(event.onlineMeeting?.joinUrl, event.subject)}
|
||||||
|
className="shrink-0 bg-green-600 hover:bg-green-700 text-white p-2 rounded-lg shadow-sm hover:shadow transition-all flex flex-col items-center justify-center gap-0.5 min-w-[70px]"
|
||||||
|
title={`Join & Summarize with ${selectedModel}`}
|
||||||
|
>
|
||||||
|
<Video size={16} />
|
||||||
|
<span className="text-[10px] font-bold">JOIN</span>
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<div className="px-2 py-1 bg-secondary text-muted-foreground text-[10px] rounded italic">
|
||||||
|
No Link
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Expand/Collapse Button */}
|
||||||
|
<button
|
||||||
|
onClick={() => toggleExpand(event.id)}
|
||||||
|
className="text-[10px] text-muted-foreground hover:text-primary mt-2 flex items-center gap-1 transition-colors w-full justify-center py-0.5 bg-secondary/30 hover:bg-secondary/50 rounded"
|
||||||
|
>
|
||||||
|
{expandedIds.has(event.id) ? "Hide Details" : "Show Details"}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{/* Expanded Content */}
|
||||||
|
{expandedIds.has(event.id) && (
|
||||||
|
<div className="mt-2 text-xs text-foreground/80 bg-background/50 p-3 rounded border border-border/50 animate-in fade-in slide-in-from-top-1">
|
||||||
|
{event.body?.content ? (
|
||||||
|
<div
|
||||||
|
className="prose prose-xs dark:prose-invert max-w-none break-words"
|
||||||
|
dangerouslySetInnerHTML={{ __html: event.body.content }}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<p className="whitespace-pre-wrap">{event.bodyPreview || "No details available."}</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{event.attendees && event.attendees.length > 0 && (
|
||||||
|
<div className="mt-3 pt-3 border-t border-border/50">
|
||||||
|
<h4 className="text-xs font-semibold text-foreground mb-2 flex items-center gap-2">
|
||||||
|
👥 Attendees ({event.attendees.length})
|
||||||
|
</h4>
|
||||||
|
<div className="flex flex-wrap gap-1.5">
|
||||||
|
{event.attendees.map((att, i) => (
|
||||||
|
<div key={i} className="flex items-center gap-1.5 bg-secondary/50 border border-border/50 px-2 py-1 rounded text-xs transition-colors">
|
||||||
|
<div className={`w-1.5 h-1.5 rounded-full shrink-0 ${att.status.response === 'accepted' ? 'bg-green-500 shadow-[0_0_4px_rgba(34,197,94,0.4)]' :
|
||||||
|
att.status.response === 'declined' ? 'bg-red-500' : 'bg-yellow-500'
|
||||||
|
}`} title={`Status: ${att.status.response}`} />
|
||||||
|
<span className="truncate max-w-[150px]" title={att.emailAddress.address}>
|
||||||
|
{att.emailAddress.name || att.emailAddress.address}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect, useRef } from 'react';
|
||||||
import { Mic, Square } from 'lucide-react';
|
import { Mic, Square, Users, Headphones } from 'lucide-react';
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
import { listen } from '@tauri-apps/api/event';
|
||||||
import logo from '../assets/logo.png'; // Import logo
|
import logo from '../assets/logo.png'; // Import logo
|
||||||
|
|
||||||
interface PromptTemplate {
|
interface PromptTemplate {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
content: string;
|
content: string;
|
||||||
|
keywords?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface HistoryItem {
|
interface HistoryItem {
|
||||||
@@ -32,7 +34,16 @@ interface RecorderProps {
|
|||||||
onDeleteHistory: (id: string) => void;
|
onDeleteHistory: (id: string) => void;
|
||||||
onLoadHistory: (item: HistoryItem) => void;
|
onLoadHistory: (item: HistoryItem) => void;
|
||||||
savePath: string | null;
|
savePath: string | null;
|
||||||
|
|
||||||
onRecordingComplete: () => void;
|
onRecordingComplete: () => void;
|
||||||
|
autoStart?: boolean;
|
||||||
|
recordingSubject?: string;
|
||||||
|
onAutoStartHandled?: () => void;
|
||||||
|
addToast: (msg: string, type: 'success' | 'error' | 'info', duration?: number) => void;
|
||||||
|
selectedModel: string;
|
||||||
|
onModelChange: (model: string) => void;
|
||||||
|
isVisible: boolean;
|
||||||
|
blockedApps: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AudioDevice {
|
interface AudioDevice {
|
||||||
@@ -43,16 +54,28 @@ interface AudioDevice {
|
|||||||
const Recorder: React.FC<RecorderProps> = ({
|
const Recorder: React.FC<RecorderProps> = ({
|
||||||
apiKey, productId, prompts,
|
apiKey, productId, prompts,
|
||||||
setTranscription, setSummary,
|
setTranscription, setSummary,
|
||||||
onSaveToHistory, savePath, onRecordingComplete
|
onSaveToHistory, savePath, onRecordingComplete,
|
||||||
|
onOpenSettings, addToast, selectedModel, onModelChange, blockedApps, ...props
|
||||||
}) => {
|
}) => {
|
||||||
const [isRecording, setIsRecording] = useState(false);
|
const [isRecording, setIsRecording] = useState(false);
|
||||||
|
const [isStopping, setIsStopping] = useState(false); // New lock state
|
||||||
const [isPaused, setIsPaused] = useState(false);
|
const [isPaused, setIsPaused] = useState(false);
|
||||||
|
const [isWaiting, setIsWaiting] = useState(false); // New state for Auto-Start
|
||||||
|
const [hasSpeechDetected, setHasSpeechDetected] = useState(false); // New tracking state
|
||||||
|
const [autoStartEnabled, setAutoStartEnabled] = useState(false); // Toggle state
|
||||||
|
|
||||||
const [status, setStatus] = useState<string>('Ready to record');
|
const [status, setStatus] = useState<string>('Ready to record');
|
||||||
const [selectedDevice, setSelectedDevice] = useState<string>('');
|
const [selectedDevice, setSelectedDevice] = useState<string>('');
|
||||||
const [selectedPromptId, setSelectedPromptId] = useState<string>('');
|
const [selectedPromptId, setSelectedPromptId] = useState<string>('');
|
||||||
const [selectedModel, setSelectedModel] = useState<string>('mixtral');
|
// selectedModel is now a prop
|
||||||
|
const [recordingMode, setRecordingMode] = useState<'voice' | 'meeting'>('voice');
|
||||||
const [devices, setDevices] = useState<AudioDevice[]>([]);
|
const [devices, setDevices] = useState<AudioDevice[]>([]);
|
||||||
const [availableModels, setAvailableModels] = useState<Array<{ id: string, name: string }>>([]);
|
const [availableModels, setAvailableModels] = useState<Array<{ id: string, name: string }>>([]);
|
||||||
|
const [lastSpeechTime, setLastSpeechTime] = useState<number>(Date.now());
|
||||||
|
const [silenceDuration, setSilenceDuration] = useState(0);
|
||||||
|
|
||||||
|
// Show all devices for both modes now (System Audio is captured natively)
|
||||||
|
const filteredDevices = devices;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadDevices();
|
loadDevices();
|
||||||
@@ -95,13 +118,25 @@ const Recorder: React.FC<RecorderProps> = ({
|
|||||||
setDevices(aliasedDevs);
|
setDevices(aliasedDevs);
|
||||||
|
|
||||||
// Select Hearbit mic by default if available and no selection made
|
// Select Hearbit mic by default if available and no selection made
|
||||||
|
// Smart Auto-select based on mode
|
||||||
if (!selectedDevice) {
|
if (!selectedDevice) {
|
||||||
const vb = aliasedDevs.find(d => d.name.includes('Hearbit Virtual Mic'));
|
// Prioritize "Hearbit Audio" (Aggregate) over "Hearbit Virtual Mic" (BlackHole)
|
||||||
if (vb) {
|
const aggregateDev = aliasedDevs.find(d => d.name === 'Hearbit Audio');
|
||||||
setSelectedDevice(vb.id);
|
const virtualDev = aliasedDevs.find(d => d.name.includes('Hearbit Virtual'));
|
||||||
|
|
||||||
|
if (recordingMode === 'meeting') {
|
||||||
|
if (aggregateDev) {
|
||||||
|
setSelectedDevice(aggregateDev.id);
|
||||||
|
} else if (virtualDev) {
|
||||||
|
setSelectedDevice(virtualDev.id);
|
||||||
} else if (aliasedDevs.length > 0) {
|
} else if (aliasedDevs.length > 0) {
|
||||||
setSelectedDevice(aliasedDevs[0].id);
|
setSelectedDevice(aliasedDevs[0].id);
|
||||||
}
|
}
|
||||||
|
} else if (aliasedDevs.length > 0) {
|
||||||
|
// Voice mode: just pick first non-virtual if possible, otherwise first
|
||||||
|
const physicalMic = aliasedDevs.find(d => !d.name.includes('Hearbit') && !d.name.includes('BlackHole'));
|
||||||
|
setSelectedDevice(physicalMic ? physicalMic.id : aliasedDevs[0].id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to load devices', e);
|
console.error('Failed to load devices', e);
|
||||||
@@ -113,26 +148,185 @@ const Recorder: React.FC<RecorderProps> = ({
|
|||||||
await invoke('open_audio_midi_setup');
|
await invoke('open_audio_midi_setup');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
addToast('Failed to open Audio Setup', 'error');
|
||||||
setStatus('Failed to open Audio Setup');
|
setStatus('Failed to open Audio Setup');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const startRecording = async () => {
|
const startRecording = async (deviceIdOverride?: string) => {
|
||||||
try {
|
try {
|
||||||
setStatus('Starting...');
|
setStatus('Starting...');
|
||||||
await invoke('start_recording', { deviceId: selectedDevice, savePath: savePath || null });
|
// Check override or state
|
||||||
|
const targetDeviceId = deviceIdOverride || selectedDevice;
|
||||||
|
|
||||||
|
// Pass customFilename (camelCase key maps to snake_case in Rust automatically or we need to check Tauri mapping, usually it maps camel to camel? Rust expects snake. Let's use snake_case in invoke args to be safe)
|
||||||
|
await invoke('start_recording', {
|
||||||
|
deviceId: targetDeviceId,
|
||||||
|
savePath: savePath || null,
|
||||||
|
customFilename: props.recordingSubject || null,
|
||||||
|
waitForSpeech: autoStartEnabled, // Pass the toggle state
|
||||||
|
mode: recordingMode,
|
||||||
|
excludedApps: blockedApps
|
||||||
|
});
|
||||||
|
|
||||||
setIsRecording(true);
|
setIsRecording(true);
|
||||||
setIsPaused(false);
|
setIsPaused(false);
|
||||||
setTranscription('');
|
setTranscription('');
|
||||||
setSummary('');
|
setSummary('');
|
||||||
|
setHasSpeechDetected(false); // Reset check for new session
|
||||||
|
|
||||||
|
if (autoStartEnabled) {
|
||||||
|
setIsWaiting(true);
|
||||||
|
setStatus('Waiting for audio...');
|
||||||
|
addToast('Standing by for audio...', 'info', 3000);
|
||||||
|
} else {
|
||||||
|
setIsWaiting(false);
|
||||||
setStatus('Recording...');
|
setStatus('Recording...');
|
||||||
|
addToast('Recording started', 'success', 2000);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
setStatus(`Error: ${e}`);
|
setStatus(`Error: ${e}`);
|
||||||
|
addToast(`Error starting recording: ${e}`, 'error');
|
||||||
setIsRecording(false);
|
setIsRecording(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Refs for interval access to avoid dependency cycles and stale closures
|
||||||
|
const lastSpeechTimeRef = useRef<number>(Date.now());
|
||||||
|
const isStoppingRef = useRef(false);
|
||||||
|
const autoStartEnabledRef = useRef(autoStartEnabled);
|
||||||
|
|
||||||
|
// Update refs when state changes
|
||||||
|
useEffect(() => {
|
||||||
|
lastSpeechTimeRef.current = lastSpeechTime;
|
||||||
|
}, [lastSpeechTime]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
isStoppingRef.current = isStopping;
|
||||||
|
}, [isStopping]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
autoStartEnabledRef.current = autoStartEnabled;
|
||||||
|
}, [autoStartEnabled]);
|
||||||
|
|
||||||
|
// 1. Event Listeners Effect (Run ONCE when recording starts)
|
||||||
|
useEffect(() => {
|
||||||
|
let unlistenVAD: () => void;
|
||||||
|
let unlistenTrigger: () => void;
|
||||||
|
|
||||||
|
const setupListeners = async () => {
|
||||||
|
if (!isRecording) return;
|
||||||
|
|
||||||
|
console.log("Setting up VAD listeners...");
|
||||||
|
// VAD Event Listener
|
||||||
|
unlistenVAD = await listen<{ is_speech: boolean, probability: number }>('vad-event', (event) => {
|
||||||
|
if (event.payload.is_speech) {
|
||||||
|
setLastSpeechTime(Date.now());
|
||||||
|
lastSpeechTimeRef.current = Date.now();
|
||||||
|
setSilenceDuration(0);
|
||||||
|
setHasSpeechDetected(true); // Track positive speech
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Auto-Start Trigger Listener
|
||||||
|
unlistenTrigger = await listen('auto-recording-triggered', () => {
|
||||||
|
console.log("Auto-Start Triggered from Backend!");
|
||||||
|
setHasSpeechDetected(true); // Trigger counts as speech
|
||||||
|
setIsWaiting((prev) => {
|
||||||
|
if (prev) {
|
||||||
|
addToast("Audio detected! Recording started.", 'success', 4000);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return prev;
|
||||||
|
});
|
||||||
|
setStatus('Recording (Auto-Started)...');
|
||||||
|
setLastSpeechTime(Date.now());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isRecording) {
|
||||||
|
setupListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
// Cleanup listeners
|
||||||
|
if (unlistenVAD) unlistenVAD();
|
||||||
|
if (unlistenTrigger) unlistenTrigger();
|
||||||
|
};
|
||||||
|
}, [isRecording, addToast]); // Dependencies for listener setup
|
||||||
|
|
||||||
|
// Ref for visibility to avoid closure staleness in interval
|
||||||
|
const isVisibleRef = useRef(props.isVisible);
|
||||||
|
useEffect(() => {
|
||||||
|
isVisibleRef.current = props.isVisible;
|
||||||
|
}, [props.isVisible]);
|
||||||
|
|
||||||
|
// Auto-Stop Interval Effect
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isRecording || isPaused || isWaiting) return;
|
||||||
|
|
||||||
|
const interval = setInterval(() => {
|
||||||
|
const now = Date.now();
|
||||||
|
const timeSinceSpeech = (now - lastSpeechTimeRef.current) / 1000;
|
||||||
|
setSilenceDuration(timeSinceSpeech);
|
||||||
|
|
||||||
|
// AUTO STOP Logic
|
||||||
|
// Use Ref to get LATEST visibility instantly
|
||||||
|
if (isVisibleRef.current && timeSinceSpeech > 25 && !isStoppingRef.current) {
|
||||||
|
console.log("Auto-stopping due to silence...");
|
||||||
|
isStoppingRef.current = true;
|
||||||
|
addToast('Auto-stopped due to silence', 'info');
|
||||||
|
stopRecording();
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, [isRecording, isPaused, isWaiting, recordingMode, addToast]); // Removed props.isVisible dependency (using Ref)
|
||||||
|
|
||||||
|
// Handle Auto Start Prop
|
||||||
|
useEffect(() => {
|
||||||
|
if (props.autoStart && !isRecording && devices.length > 0) {
|
||||||
|
// Force meeting mode for auto-joins
|
||||||
|
if (recordingMode !== 'meeting') {
|
||||||
|
setRecordingMode('meeting');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find best device (Race condition fix: we can't rely on selectedDevice state update being instant)
|
||||||
|
const aggregateDev = devices.find(d => d.name === 'Hearbit Audio');
|
||||||
|
const virtualDev = devices.find(d => d.name.includes('Hearbit Virtual'));
|
||||||
|
const bestDevice = aggregateDev || virtualDev;
|
||||||
|
|
||||||
|
if (bestDevice) {
|
||||||
|
setSelectedDevice(bestDevice.id); // Update UI state for consistency
|
||||||
|
console.log("Auto-starting with device:", bestDevice.name);
|
||||||
|
startRecording(bestDevice.id); // Pass ID directly
|
||||||
|
} else {
|
||||||
|
console.warn("Auto-start: No meeting device found, trying default.");
|
||||||
|
startRecording();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (props.onAutoStartHandled) {
|
||||||
|
props.onAutoStartHandled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [props.autoStart, devices]);
|
||||||
|
|
||||||
|
// Handle Custom Event (Legacy/Fallback)
|
||||||
|
useEffect(() => {
|
||||||
|
const handleStartReq = () => {
|
||||||
|
if (!isRecording) {
|
||||||
|
if (recordingMode !== 'meeting') {
|
||||||
|
setRecordingMode('meeting');
|
||||||
|
}
|
||||||
|
startRecording();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.addEventListener('start-recording-req', handleStartReq);
|
||||||
|
return () => window.removeEventListener('start-recording-req', handleStartReq);
|
||||||
|
}, [isRecording, recordingMode]);
|
||||||
|
|
||||||
const togglePause = async () => {
|
const togglePause = async () => {
|
||||||
try {
|
try {
|
||||||
if (isPaused) {
|
if (isPaused) {
|
||||||
@@ -150,18 +344,87 @@ const Recorder: React.FC<RecorderProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const stopRecording = async () => {
|
const stopRecording = async () => {
|
||||||
|
if (isStopping) return;
|
||||||
|
setIsStopping(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setIsRecording(false);
|
setIsRecording(false);
|
||||||
setIsPaused(false);
|
setIsPaused(false);
|
||||||
setStatus('Processing...');
|
setIsWaiting(false); // Reset waiting state
|
||||||
|
setTranscription('');
|
||||||
|
setSummary('');
|
||||||
|
setHasSpeechDetected(false); // Reset checkiting state
|
||||||
|
setStatus('Saving recording...');
|
||||||
const filePath = await invoke<string>('stop_recording');
|
const filePath = await invoke<string>('stop_recording');
|
||||||
|
|
||||||
setStatus('Transcribing (Infomaniak Whisper)...');
|
// NEW: Check if speech was actually detected during the session
|
||||||
const transText = await invoke<string>('transcribe_audio', {
|
// If we recorded 20s of silence (Auto-Stop), we shouldn't transcribe.
|
||||||
filePath,
|
// IMPORTANT: Check applies to BOTH 'voice' and 'meeting' modes to prevent "Batch Null" errors on false triggers.
|
||||||
|
if (!hasSpeechDetected) {
|
||||||
|
console.log("No speech detected during recording. Skipping transcription.");
|
||||||
|
addToast("Recording discarded (No speech/audio detected)", 'info');
|
||||||
|
setStatus('Ready to record'); // Reset status text
|
||||||
|
|
||||||
|
// If auto-start is on, we just loop back (in finally block).
|
||||||
|
// But we skip the expensive/failing API call.
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Wait a moment for file flush (safety)
|
||||||
|
await new Promise(r => setTimeout(r, 500));
|
||||||
|
|
||||||
|
// Confirm recording saved
|
||||||
|
addToast(`Recording saved locally: ${filePath.split('/').pop()}`, 'success', 3000);
|
||||||
|
setStatus('Converting to MP3...');
|
||||||
|
|
||||||
|
// Small delay to show the "saved" message
|
||||||
|
await new Promise(r => setTimeout(r, 500));
|
||||||
|
|
||||||
|
// Convert WAV to MP3 for smaller size
|
||||||
|
const mp3Path = await invoke<string>('convert_to_mp3', { wavPath: filePath });
|
||||||
|
|
||||||
|
// Get file size to check if chunking needed
|
||||||
|
interface AudioMetadata { duration: number; size: number; format: string; }
|
||||||
|
const metadata = await invoke<AudioMetadata>('get_audio_metadata', { filePath: mp3Path });
|
||||||
|
const sizeMB = metadata.size / (1024 * 1024);
|
||||||
|
|
||||||
|
let transText = '';
|
||||||
|
|
||||||
|
// Check if chunking needed (only for Meeting mode and large files)
|
||||||
|
if (recordingMode === 'meeting' && sizeMB >= 18) {
|
||||||
|
// CHUNKING PATH for large meetings
|
||||||
|
setStatus(`Large file (${sizeMB.toFixed(1)}MB). Splitting into chunks...`);
|
||||||
|
const chunks = await invoke<string[]>('chunk_audio', {
|
||||||
|
filePath: mp3Path,
|
||||||
|
chunkMinutes: 10
|
||||||
|
});
|
||||||
|
|
||||||
|
addToast(`Processing ${chunks.length} chunks...`, 'info', 4000);
|
||||||
|
|
||||||
|
let allTranscriptions: string[] = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < chunks.length; i++) {
|
||||||
|
setStatus(`Transcribing chunk ${i + 1}/${chunks.length}...`);
|
||||||
|
const chunkText = await invoke<string>('transcribe_audio', {
|
||||||
|
filePath: chunks[i],
|
||||||
apiKey,
|
apiKey,
|
||||||
productId
|
productId
|
||||||
});
|
});
|
||||||
|
allTranscriptions.push(chunkText);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge transcriptions
|
||||||
|
transText = allTranscriptions.join('\n\n--- Next Segment ---\n\n');
|
||||||
|
addToast('All chunks transcribed successfully!', 'success', 3000);
|
||||||
|
} else {
|
||||||
|
// NORMAL PATH for small files
|
||||||
|
setStatus('Transcribing (Infomaniak Whisper)...');
|
||||||
|
transText = await invoke<string>('transcribe_audio', {
|
||||||
|
filePath: mp3Path,
|
||||||
|
apiKey,
|
||||||
|
productId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
setTranscription(transText);
|
setTranscription(transText);
|
||||||
|
|
||||||
// Check if transcription is empty or just whitespace
|
// Check if transcription is empty or just whitespace
|
||||||
@@ -169,11 +432,42 @@ const Recorder: React.FC<RecorderProps> = ({
|
|||||||
setStatus('Done (No speech detected)');
|
setStatus('Done (No speech detected)');
|
||||||
setTranscription('(No speech detected. Check your microphone settings.)');
|
setTranscription('(No speech detected. Check your microphone settings.)');
|
||||||
setTimeout(() => setStatus('Ready to record'), 3000);
|
setTimeout(() => setStatus('Ready to record'), 3000);
|
||||||
return;
|
// allow finally block to restart loop
|
||||||
|
} else {
|
||||||
|
// Logic continues...
|
||||||
|
|
||||||
|
// Find selected prompt content - SMART SELECTION
|
||||||
|
let activePrompt = prompts.find(p => p.id === selectedPromptId);
|
||||||
|
|
||||||
|
// Smart Auto-Select based on keywords
|
||||||
|
const lowerText = transText.toLowerCase();
|
||||||
|
let bestMatchId = selectedPromptId;
|
||||||
|
let maxMatches = 0;
|
||||||
|
|
||||||
|
for (const p of prompts) {
|
||||||
|
if (!p.keywords) continue;
|
||||||
|
let matches = 0;
|
||||||
|
for (const kw of p.keywords) {
|
||||||
|
if (lowerText.includes(kw.toLowerCase())) {
|
||||||
|
matches++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (matches > maxMatches) {
|
||||||
|
maxMatches = matches;
|
||||||
|
bestMatchId = p.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bestMatchId !== selectedPromptId) {
|
||||||
|
const newPrompt = prompts.find(p => p.id === bestMatchId);
|
||||||
|
if (newPrompt) {
|
||||||
|
console.log(`Smart Select: Switched to '${newPrompt.name}' with ${maxMatches} matches.`);
|
||||||
|
setStatus(`Smart Select: Using "${newPrompt.name}"...`);
|
||||||
|
addToast(`Smart Select: Switched to "${newPrompt.name}"`, 'success', 4000);
|
||||||
|
activePrompt = newPrompt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find selected prompt content
|
|
||||||
const activePrompt = prompts.find(p => p.id === selectedPromptId);
|
|
||||||
const promptContent = activePrompt ? activePrompt.content : "Summarize this.";
|
const promptContent = activePrompt ? activePrompt.content : "Summarize this.";
|
||||||
|
|
||||||
setStatus(`Summarizing (${selectedModel})...`);
|
setStatus(`Summarizing (${selectedModel})...`);
|
||||||
@@ -190,56 +484,97 @@ const Recorder: React.FC<RecorderProps> = ({
|
|||||||
onSaveToHistory(transText, sumText);
|
onSaveToHistory(transText, sumText);
|
||||||
|
|
||||||
setStatus('Done!');
|
setStatus('Done!');
|
||||||
|
addToast('Transcription & Summary complete!', 'success', 4000);
|
||||||
onRecordingComplete(); // Auto-switch tab
|
onRecordingComplete(); // Auto-switch tab
|
||||||
setTimeout(() => setStatus('Ready to record'), 3000);
|
setTimeout(() => setStatus('Ready to record'), 3000);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
setStatus(`Error: ${e}`);
|
setStatus(`Error: ${e}`);
|
||||||
|
addToast(`Error processing: ${e}`, 'error');
|
||||||
|
} finally {
|
||||||
|
setIsStopping(false);
|
||||||
|
|
||||||
|
// AUTO-RESTART LOGIC
|
||||||
|
// Use REF to get the latest state (fix for "starts again even if I uncheck")
|
||||||
|
if (autoStartEnabledRef.current) {
|
||||||
|
console.log("Auto-Start enabled: Restarting listener loop...");
|
||||||
|
// Short delay to ensure backend cleanup
|
||||||
|
setTimeout(() => {
|
||||||
|
// Double check ref before restarting
|
||||||
|
if (autoStartEnabledRef.current) {
|
||||||
|
startRecording();
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col w-full h-full bg-background relative">
|
<div className="flex flex-col w-full h-full bg-background relative">
|
||||||
{/* Fixed Header */}
|
{/* Fixed Header - Reduced padding */}
|
||||||
<div className="w-full flex justify-center items-center p-6 shrink-0">
|
<div className="w-full flex justify-center items-center p-4 shrink-0">
|
||||||
<img src={logo} alt="Logo" className="h-12 object-contain" />
|
<img src={localStorage.getItem('customLogo') || logo} alt="Logo" className="h-10 object-contain" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Scrollable Content */}
|
{/* Scrollable Content - Reduced spacing */}
|
||||||
<div className="flex-1 overflow-y-auto p-6 flex flex-col items-center pb-20">
|
<div className="flex-1 overflow-y-auto px-6 pb-6 flex flex-col items-center">
|
||||||
<div className="mb-6 relative shrink-0">
|
<div className="mb-4 relative shrink-0">
|
||||||
<div className={`w-32 h-32 rounded-full flex items-center justify-center transition-all duration-300 ${isRecording ? (isPaused ? 'bg-yellow-500/10' : 'bg-red-500/10 animate-pulse') : 'bg-secondary'}`}>
|
<div className={`w-24 h-24 rounded-full flex items-center justify-center transition-all duration-300 ${isRecording ? (isWaiting ? 'bg-blue-500/20' : isPaused ? 'bg-yellow-500/10' : 'bg-red-500/10 animate-pulse') : 'bg-secondary'}`}>
|
||||||
{isRecording ? (
|
{isRecording ? (
|
||||||
<div className={`w-24 h-24 rounded-full flex items-center justify-center shadow-[0_0_20px_rgba(239,68,68,0.5)] ${isPaused ? 'bg-yellow-500' : 'bg-red-500'}`}>
|
<div className={`w-16 h-16 rounded-full flex items-center justify-center shadow-[0_0_20px_rgba(239,68,68,0.5)] ${isWaiting ? 'bg-blue-500 animate-pulse' : isPaused ? 'bg-yellow-500' : 'bg-red-500'}`}>
|
||||||
<Mic size={40} className="text-white animate-bounce" />
|
<Mic size={32} className="text-white animate-bounce" />
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="w-24 h-24 rounded-full bg-primary flex items-center justify-center">
|
<div className="w-16 h-16 rounded-full bg-primary flex items-center justify-center">
|
||||||
<Mic size={40} className="text-primary-foreground" />
|
<Mic size={32} className="text-primary-foreground" />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h1 className="text-2xl font-bold mb-2 text-foreground">
|
<h1 className="text-xl font-bold mb-1 text-foreground">
|
||||||
{isRecording ? (isPaused ? 'Paused' : 'Listening...') : 'Ready to Record'}
|
{isRecording ? (isWaiting ? 'Waiting for Audio...' : isPaused ? 'Paused' : 'Listening...') : 'Ready to Record'}
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<p className="text-muted-foreground mb-6 text-center text-sm h-6">
|
<p className="text-muted-foreground mb-4 text-center text-xs h-5">
|
||||||
{status}
|
{status}
|
||||||
|
{isRecording && !isPaused && !isWaiting && silenceDuration > 10 && (
|
||||||
|
<span className="block text-xs text-yellow-500 mt-0.5 opacity-80">
|
||||||
|
Silence detected: {Math.floor(silenceDuration)}s
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div className="w-full max-w-sm space-y-4 mb-6 shrink-0">
|
<div className="w-full max-w-sm space-y-3 mb-4 shrink-0">
|
||||||
{!isRecording ? (
|
{!isRecording ? (
|
||||||
|
<>
|
||||||
<button
|
<button
|
||||||
onClick={startRecording}
|
onClick={() => startRecording()}
|
||||||
disabled={!apiKey || !productId}
|
disabled={!apiKey || !productId}
|
||||||
className="w-full py-4 text-lg font-semibold bg-primary text-primary-foreground rounded-lg hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-all shadow-md hover:shadow-lg"
|
className="w-full py-3 text-base font-semibold bg-primary text-primary-foreground rounded-lg hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-all shadow-md hover:shadow-lg"
|
||||||
>
|
>
|
||||||
{!apiKey ? 'Configure API Key First' : 'Start Recording'}
|
{!apiKey ? 'Configure API Key First' : (autoStartEnabled ? 'Standby (Auto-Start)' : 'Start Recording')}
|
||||||
</button>
|
</button>
|
||||||
|
<div className="flex items-center justify-center gap-2 mt-2">
|
||||||
|
<label className="flex items-center gap-2 cursor-pointer select-none">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={autoStartEnabled}
|
||||||
|
onChange={(e) => setAutoStartEnabled(e.target.checked)}
|
||||||
|
className="w-4 h-4 accent-primary rounded cursor-pointer"
|
||||||
|
/>
|
||||||
|
<span className="text-xs text-muted-foreground font-medium">Auto-start when audio detected</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex gap-2 w-full">
|
<div className="flex gap-2 w-full">
|
||||||
|
{/* In Waiting mode, we can only Stop (Cancel) */}
|
||||||
|
{!isWaiting && (
|
||||||
<button
|
<button
|
||||||
onClick={togglePause}
|
onClick={togglePause}
|
||||||
className={`flex-1 py-4 text-lg font-semibold rounded-lg transition-all shadow-md hover:shadow-lg flex items-center justify-center gap-2 ${isPaused
|
className={`flex-1 py-4 text-lg font-semibold rounded-lg transition-all shadow-md hover:shadow-lg flex items-center justify-center gap-2 ${isPaused
|
||||||
@@ -249,42 +584,68 @@ const Recorder: React.FC<RecorderProps> = ({
|
|||||||
>
|
>
|
||||||
{isPaused ? 'Resume' : 'Pause'}
|
{isPaused ? 'Resume' : 'Pause'}
|
||||||
</button>
|
</button>
|
||||||
|
)}
|
||||||
<button
|
<button
|
||||||
onClick={stopRecording}
|
onClick={stopRecording}
|
||||||
className="flex-1 py-4 text-lg font-semibold bg-destructive text-destructive-foreground rounded-lg hover:bg-destructive/90 transition-all shadow-md hover:shadow-lg flex items-center justify-center gap-2"
|
className="flex-1 py-4 text-lg font-semibold bg-destructive text-destructive-foreground rounded-lg hover:bg-destructive/90 transition-all shadow-md hover:shadow-lg flex items-center justify-center gap-2"
|
||||||
>
|
>
|
||||||
<Square size={20} fill="currentColor" />
|
<Square size={20} fill="currentColor" />
|
||||||
Stop
|
{isWaiting ? 'Cancel' : 'Stop'}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="grid grid-cols-2 gap-4 pt-2">
|
<div className="grid grid-cols-2 gap-4 pt-2">
|
||||||
<div>
|
</div>
|
||||||
<label className="text-xs font-semibold text-muted-foreground uppercase tracking-wider block mb-1">
|
|
||||||
Input Device
|
{/* INPUT DEVICE SECTION */}
|
||||||
</label>
|
<div className="col-span-2">
|
||||||
|
<div className="flex bg-secondary p-1 rounded-lg mb-2">
|
||||||
|
<button
|
||||||
|
onClick={() => { setRecordingMode('voice'); setSelectedDevice(''); }}
|
||||||
|
className={`flex-1 flex items-center justify-center gap-2 py-1.5 text-xs font-semibold rounded-md transition-all ${recordingMode === 'voice' ? 'bg-background shadow text-foreground' : 'text-muted-foreground hover:text-foreground'}`}
|
||||||
|
>
|
||||||
|
<Headphones size={14} /> Voice Memo
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => { setRecordingMode('meeting'); setSelectedDevice(''); }}
|
||||||
|
className={`flex-1 flex items-center justify-center gap-2 py-1.5 text-xs font-semibold rounded-md transition-all ${recordingMode === 'meeting' ? 'bg-background shadow text-foreground' : 'text-muted-foreground hover:text-foreground'}`}
|
||||||
|
>
|
||||||
|
<Users size={14} /> Meeting
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<select
|
<select
|
||||||
value={selectedDevice}
|
value={selectedDevice}
|
||||||
onChange={(e) => setSelectedDevice(e.target.value)}
|
onChange={(e) => setSelectedDevice(e.target.value)}
|
||||||
className="w-full p-2 text-sm bg-secondary rounded border border-border outline-none focus:ring-2 focus:ring-primary"
|
className="w-full p-2 text-sm bg-secondary rounded border border-border outline-none focus:ring-2 focus:ring-primary"
|
||||||
disabled={isRecording}
|
disabled={isRecording}
|
||||||
>
|
>
|
||||||
{devices.map(d => (
|
{filteredDevices.map(d => (
|
||||||
<option key={d.id} value={d.id}>{d.name}</option>
|
<option key={d.id} value={d.id}>{d.name}</option>
|
||||||
))}
|
))}
|
||||||
{devices.length === 0 && <option value="">Loading devices...</option>}
|
{filteredDevices.length === 0 && (
|
||||||
|
<option value="">
|
||||||
|
{recordingMode === 'meeting' ? 'No Meeting Device (Create in Settings)' : 'No Microphone Found'}
|
||||||
|
</option>
|
||||||
|
)}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="col-span-2 grid grid-cols-2 gap-4">
|
||||||
<div>
|
<div>
|
||||||
<label className="text-xs font-semibold text-muted-foreground uppercase tracking-wider block mb-1">
|
<label className="text-xs font-semibold text-muted-foreground uppercase tracking-wider block mb-1">
|
||||||
LLM Model
|
LLM Model
|
||||||
</label>
|
</label>
|
||||||
<select
|
<select
|
||||||
value={selectedModel}
|
value={selectedModel}
|
||||||
onChange={(e) => setSelectedModel(e.target.value)}
|
onChange={(e) => {
|
||||||
|
onModelChange(e.target.value);
|
||||||
|
// localStorage handled in App.tsx
|
||||||
|
}}
|
||||||
className="w-full p-2 text-sm bg-secondary rounded border border-border outline-none focus:ring-2 focus:ring-primary"
|
className="w-full p-2 text-sm bg-secondary rounded border border-border outline-none focus:ring-2 focus:ring-primary"
|
||||||
disabled={isRecording}
|
// Allow changing model while recording (since it's used for summary after)
|
||||||
|
disabled={false}
|
||||||
>
|
>
|
||||||
{availableModels.map(m => (
|
{availableModels.map(m => (
|
||||||
<option key={m.id} value={m.id}>{m.name}</option>
|
<option key={m.id} value={m.id}>{m.name}</option>
|
||||||
@@ -301,7 +662,8 @@ const Recorder: React.FC<RecorderProps> = ({
|
|||||||
value={selectedPromptId}
|
value={selectedPromptId}
|
||||||
onChange={(e) => setSelectedPromptId(e.target.value)}
|
onChange={(e) => setSelectedPromptId(e.target.value)}
|
||||||
className="w-full p-2 text-sm bg-secondary rounded border border-border outline-none focus:ring-2 focus:ring-primary"
|
className="w-full p-2 text-sm bg-secondary rounded border border-border outline-none focus:ring-2 focus:ring-primary"
|
||||||
disabled={isRecording || prompts.length === 0}
|
// Allow changing template while recording
|
||||||
|
disabled={prompts.length === 0}
|
||||||
>
|
>
|
||||||
{prompts.map(p => (
|
{prompts.map(p => (
|
||||||
<option key={p.id} value={p.id}>{p.name}</option>
|
<option key={p.id} value={p.id}>{p.name}</option>
|
||||||
@@ -311,11 +673,27 @@ const Recorder: React.FC<RecorderProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col gap-2 mt-2 w-full">
|
<div className="flex flex-col gap-2 mt-2 w-full">
|
||||||
|
{recordingMode === 'meeting' && (
|
||||||
|
<button
|
||||||
|
onClick={async () => {
|
||||||
|
const allowed = await invoke<boolean>('check_screen_recording_permission');
|
||||||
|
if (allowed) {
|
||||||
|
addToast('System Audio Permission: GRANTED ✅', 'success');
|
||||||
|
} else {
|
||||||
|
addToast('System Audio Permission: MISSING ❌. Please enable in System Settings -> Privacy -> Screen Recording', 'error', 5000);
|
||||||
|
// Open Settings?
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
className="text-xs bg-primary/10 text-primary hover:bg-primary/20 w-full text-center border border-primary/20 rounded p-2 mb-2 font-semibold"
|
||||||
|
>
|
||||||
|
🔒 Check Audio Permission
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
<button
|
<button
|
||||||
onClick={openAudioSetup}
|
onClick={openAudioSetup}
|
||||||
className="text-xs text-muted-foreground hover:text-foreground w-full text-center border border-dashed border-border/50 rounded p-1"
|
className="text-xs text-muted-foreground hover:text-foreground w-full text-center border border-dashed border-border/50 rounded p-1"
|
||||||
>
|
>
|
||||||
Open Audio MIDI Setup (Configure Multi-Output)
|
Open Audio MIDI Setup
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,30 +1,146 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { Save, FolderOpen, Lock, Upload, Download, Eye, EyeOff } from 'lucide-react';
|
import { Save, FolderOpen, Lock, Upload, Download, Mail, FileText, ScrollText, Headphones } from 'lucide-react';
|
||||||
import { open } from '@tauri-apps/plugin-dialog';
|
import { save, open } from '@tauri-apps/plugin-dialog';
|
||||||
import { encryptData, decryptData } from '../utils/backup';
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
import { PromptTemplate } from '../App';
|
import EmailTemplateEditor from './EmailTemplateEditor';
|
||||||
|
import logo from '../assets/logo.png';
|
||||||
|
|
||||||
|
import { PromptTemplate, EmailTemplate } from '../App';
|
||||||
|
|
||||||
interface SettingsProps {
|
interface SettingsProps {
|
||||||
apiKey: string;
|
apiKey: string;
|
||||||
productId: string;
|
productId: string;
|
||||||
savePath: string;
|
savePath: string;
|
||||||
prompts: PromptTemplate[];
|
prompts: PromptTemplate[];
|
||||||
onSave: (apiKey: string, productId: string, prompts: PromptTemplate[], savePath: string) => void;
|
emailTemplates: EmailTemplate[];
|
||||||
|
smtpConfig: SmtpConfig;
|
||||||
|
azureConfig: AzureConfig;
|
||||||
|
dailyBackupEnabled: boolean;
|
||||||
|
dailyBackupPath: string;
|
||||||
|
lastBackupDate: string;
|
||||||
|
history: any[];
|
||||||
|
onSave: (
|
||||||
|
apiKey: string,
|
||||||
|
productId: string,
|
||||||
|
prompts: PromptTemplate[],
|
||||||
|
savePath: string,
|
||||||
|
smtp: SmtpConfig,
|
||||||
|
azure: AzureConfig,
|
||||||
|
emailTemplates: EmailTemplate[],
|
||||||
|
dailyBackupEnabled: boolean,
|
||||||
|
dailyBackupPath: string,
|
||||||
|
blockedApps: string[]
|
||||||
|
) => void;
|
||||||
|
onHistoryUpdate: (history: any[]) => void;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
|
blockedApps: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const Settings: React.FC<SettingsProps> = ({ apiKey, productId, prompts, savePath, onSave, onClose }) => {
|
export interface SmtpConfig {
|
||||||
|
host: string;
|
||||||
|
port: string;
|
||||||
|
user: string;
|
||||||
|
pass: string;
|
||||||
|
sender: string;
|
||||||
|
senderName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AzureConfig {
|
||||||
|
clientId: string;
|
||||||
|
tenantId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const APP_PRESETS = [
|
||||||
|
{
|
||||||
|
category: 'Browsers',
|
||||||
|
apps: [
|
||||||
|
{ name: 'Safari', id: 'com.apple.Safari' },
|
||||||
|
{ name: 'Chrome', id: 'com.google.Chrome' },
|
||||||
|
{ name: 'Firefox', id: 'org.mozilla.firefox' },
|
||||||
|
{ name: 'Arc', id: 'company.thebrowser.Browser' },
|
||||||
|
{ name: 'Edge', id: 'com.microsoft.edgemac' },
|
||||||
|
{ name: 'Brave', id: 'com.brave.Browser' },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
category: 'Music & Media',
|
||||||
|
apps: [
|
||||||
|
{ name: 'Apple Music', id: 'com.apple.Music' },
|
||||||
|
{ name: 'Spotify', id: 'com.spotify.client' },
|
||||||
|
{ name: 'Tidal', id: 'com.aspiro.Tidal' },
|
||||||
|
{ name: 'VLC', id: 'org.videolan.vlc' },
|
||||||
|
{ name: 'Podcasts', id: 'com.apple.podcasts' },
|
||||||
|
]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const Settings: React.FC<SettingsProps> = ({ apiKey, productId, prompts, savePath, onSave, onClose, ...props }) => {
|
||||||
const [localApiKey, setLocalApiKey] = useState(apiKey);
|
const [localApiKey, setLocalApiKey] = useState(apiKey);
|
||||||
const [localProductId, setLocalProductId] = useState(productId);
|
const [localProductId, setLocalProductId] = useState(productId);
|
||||||
const [localSavePath, setLocalSavePath] = useState(savePath);
|
const [localSavePath, setLocalSavePath] = useState(savePath);
|
||||||
|
|
||||||
const [localPrompts, setLocalPrompts] = useState<PromptTemplate[]>(prompts);
|
const [localPrompts, setLocalPrompts] = useState<PromptTemplate[]>(prompts);
|
||||||
|
const [localEmailTemplates, setLocalEmailTemplates] = useState<EmailTemplate[]>(props.emailTemplates); // New state
|
||||||
|
const [localSmtp, setLocalSmtp] = useState<SmtpConfig>(props.smtpConfig);
|
||||||
|
const [localAzure, setLocalAzure] = useState<AzureConfig>(props.azureConfig);
|
||||||
|
const [localDailyBackupEnabled, setLocalDailyBackupEnabled] = useState(props.dailyBackupEnabled);
|
||||||
|
const [localDailyBackupPath, setLocalDailyBackupPath] = useState(props.dailyBackupPath);
|
||||||
|
const [localBlockedApps, setLocalBlockedApps] = useState<string[]>(props.blockedApps);
|
||||||
|
const [runningApps, setRunningApps] = useState<{ name: string, bundle_id: string }[]>([]);
|
||||||
const [statusIdx, setStatusIdx] = useState<string | null>(null);
|
const [statusIdx, setStatusIdx] = useState<string | null>(null);
|
||||||
|
|
||||||
// Backup & Restore State
|
// Email Template Editor State
|
||||||
const [backupPassword, setBackupPassword] = useState('');
|
const [editingTemplate, setEditingTemplate] = useState<EmailTemplate | null>(null);
|
||||||
const [showPassword, setShowPassword] = useState(false);
|
const [isEmailEditorOpen, setIsEmailEditorOpen] = useState(false);
|
||||||
const [isImportModalOpen, setIsImportModalOpen] = useState(false);
|
|
||||||
const [importFileContent, setImportFileContent] = useState<string | null>(null);
|
const [activeTab, setActiveTab] = useState<'general' | 'prompts' | 'email' | 'backup' | 'logs' | 'apps'>('general');
|
||||||
|
const [logs, setLogs] = useState<string>('Loading logs...');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (activeTab === 'logs') {
|
||||||
|
loadLogs();
|
||||||
|
} else if (activeTab === 'general') {
|
||||||
|
loadRunningApps();
|
||||||
|
}
|
||||||
|
}, [activeTab]);
|
||||||
|
|
||||||
|
const loadRunningApps = async () => {
|
||||||
|
try {
|
||||||
|
const apps = await invoke<{ name: string, bundle_id: string }[]>('get_running_apps');
|
||||||
|
setRunningApps(apps);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to load running apps:", e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const loadLogs = async () => {
|
||||||
|
try {
|
||||||
|
const content = await invoke<string>('read_log_file');
|
||||||
|
setLogs(content);
|
||||||
|
} catch (e) {
|
||||||
|
setLogs(`Failed to load logs: ${e}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSaveLogs = async () => {
|
||||||
|
try {
|
||||||
|
const filePath = await save({
|
||||||
|
defaultPath: `hearbit_logs_${new Date().toISOString().slice(0, 10)}.log`,
|
||||||
|
filters: [{
|
||||||
|
name: 'Log File',
|
||||||
|
extensions: ['log', 'txt']
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
if (filePath) {
|
||||||
|
await invoke('save_text_file', { path: filePath, content: logs });
|
||||||
|
setStatusIdx(`Logs exported to: ${filePath}`);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
setStatusIdx(`Failed to export logs: ${e}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handlePromptChange = (id: string, field: 'name' | 'content', value: string) => {
|
const handlePromptChange = (id: string, field: 'name' | 'content', value: string) => {
|
||||||
setLocalPrompts(localPrompts.map(p => p.id === id ? { ...p, [field]: value } : p));
|
setLocalPrompts(localPrompts.map(p => p.id === id ? { ...p, [field]: value } : p));
|
||||||
@@ -38,8 +154,37 @@ const Settings: React.FC<SettingsProps> = ({ apiKey, productId, prompts, savePat
|
|||||||
setLocalPrompts(localPrompts.filter(p => p.id !== id));
|
setLocalPrompts(localPrompts.filter(p => p.id !== id));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleSaveEmailTemplate = (template: EmailTemplate) => {
|
||||||
|
const exists = localEmailTemplates.find(t => t.id === template.id);
|
||||||
|
if (exists) {
|
||||||
|
setLocalEmailTemplates(localEmailTemplates.map(t => t.id === template.id ? template : t));
|
||||||
|
} else {
|
||||||
|
setLocalEmailTemplates([...localEmailTemplates, template]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const openEmailEditor = (template: EmailTemplate | null) => {
|
||||||
|
setEditingTemplate(template);
|
||||||
|
setIsEmailEditorOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeEmailTemplate = (id: string) => {
|
||||||
|
setLocalEmailTemplates(localEmailTemplates.filter(t => t.id !== id));
|
||||||
|
};
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
onSave(localApiKey, localProductId, localPrompts, localSavePath);
|
onSave(
|
||||||
|
localApiKey,
|
||||||
|
localProductId,
|
||||||
|
localPrompts,
|
||||||
|
localSavePath,
|
||||||
|
localSmtp,
|
||||||
|
localAzure,
|
||||||
|
localEmailTemplates,
|
||||||
|
localDailyBackupEnabled,
|
||||||
|
localDailyBackupPath,
|
||||||
|
localBlockedApps
|
||||||
|
);
|
||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -60,31 +205,40 @@ const Settings: React.FC<SettingsProps> = ({ apiKey, productId, prompts, savePat
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleExport = async () => {
|
const handleExport = async () => {
|
||||||
if (!backupPassword) {
|
|
||||||
setStatusIdx('Error: Password required to encrypt backup.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const data = {
|
const data = {
|
||||||
apiKey: localApiKey,
|
apiKey: localApiKey,
|
||||||
productId: localProductId,
|
productId: localProductId,
|
||||||
prompts: localPrompts,
|
prompts: localPrompts,
|
||||||
savePath: localSavePath
|
savePath: localSavePath,
|
||||||
|
smtp: localSmtp,
|
||||||
|
azure: localAzure,
|
||||||
|
emailTemplates: localEmailTemplates,
|
||||||
|
history: props.history,
|
||||||
|
dailyBackup: {
|
||||||
|
enabled: localDailyBackupEnabled,
|
||||||
|
path: localDailyBackupPath,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const encrypted = await encryptData(data, backupPassword);
|
|
||||||
const blob = new Blob([encrypted], { type: 'text/plain' });
|
// Always save as JSON (no encryption)
|
||||||
const url = URL.createObjectURL(blob);
|
const content = JSON.stringify(data, null, 2);
|
||||||
const a = document.createElement('a');
|
|
||||||
a.href = url;
|
const filePath = await save({
|
||||||
a.download = `hearbit_backup_${new Date().toISOString().slice(0, 10)}.conf`;
|
defaultPath: `hearbit_backup_${new Date().toISOString().slice(0, 10)}.json`,
|
||||||
document.body.appendChild(a);
|
filters: [{
|
||||||
a.click();
|
name: 'Hearbit Config',
|
||||||
document.body.removeChild(a);
|
extensions: ['json']
|
||||||
URL.revokeObjectURL(url);
|
}]
|
||||||
setStatusIdx('Configuration exported successfully!');
|
});
|
||||||
|
|
||||||
|
if (filePath) {
|
||||||
|
await invoke('save_text_file', { path: filePath, content });
|
||||||
|
setStatusIdx(`Configuration exported to: ${filePath}`);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
setStatusIdx('Export failed.');
|
setStatusIdx(`Export failed: ${e}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -99,94 +253,101 @@ const Settings: React.FC<SettingsProps> = ({ apiKey, productId, prompts, savePat
|
|||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = (event) => {
|
reader.onload = (event) => {
|
||||||
if (event.target?.result) {
|
if (event.target?.result) {
|
||||||
setImportFileContent(event.target.result as string);
|
const content = event.target.result as string;
|
||||||
setIsImportModalOpen(true);
|
// Directly import without password modal since we don't use encryption
|
||||||
setBackupPassword('');
|
try {
|
||||||
|
const data = JSON.parse(content);
|
||||||
|
|
||||||
|
if (data.apiKey) setLocalApiKey(data.apiKey);
|
||||||
|
if (data.productId) setLocalProductId(data.productId);
|
||||||
|
if (data.prompts) setLocalPrompts(data.prompts);
|
||||||
|
if (data.emailTemplates) setLocalEmailTemplates(data.emailTemplates);
|
||||||
|
if (data.savePath) setLocalSavePath(data.savePath);
|
||||||
|
if (data.smtp) setLocalSmtp(data.smtp);
|
||||||
|
if (data.azure) setLocalAzure(data.azure);
|
||||||
|
if (data.dailyBackup) {
|
||||||
|
if (data.dailyBackup.enabled !== undefined) setLocalDailyBackupEnabled(data.dailyBackup.enabled);
|
||||||
|
if (data.dailyBackup.path) setLocalDailyBackupPath(data.dailyBackup.path);
|
||||||
|
}
|
||||||
|
if (data.blockedApps) setLocalBlockedApps(data.blockedApps);
|
||||||
|
// Import history!
|
||||||
|
if (data.history && Array.isArray(data.history)) {
|
||||||
|
props.onHistoryUpdate(data.history);
|
||||||
|
}
|
||||||
|
|
||||||
|
setStatusIdx('Configuration imported! Click Save to apply.');
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
setStatusIdx(`Import failed: ${error}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
e.target.value = '';
|
e.target.value = '';
|
||||||
};
|
};
|
||||||
|
|
||||||
const confirmImport = async () => {
|
|
||||||
if (!backupPassword) {
|
|
||||||
setStatusIdx('Error: Password required to decrypt.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!importFileContent) return;
|
|
||||||
|
|
||||||
|
|
||||||
|
const handleCreateDevice = async () => {
|
||||||
try {
|
try {
|
||||||
const data = await decryptData(importFileContent, backupPassword);
|
setStatusIdx('Creating Hearbit Audio device...');
|
||||||
if (data.apiKey) setLocalApiKey(data.apiKey);
|
await invoke('create_hearbit_audio_device');
|
||||||
if (data.productId) setLocalProductId(data.productId);
|
setStatusIdx('Success! "Hearbit Audio" device created.');
|
||||||
if (data.prompts) setLocalPrompts(data.prompts);
|
|
||||||
if (data.savePath) setLocalSavePath(data.savePath);
|
|
||||||
|
|
||||||
setStatusIdx('Configuration imported! Click Save to apply.');
|
|
||||||
setIsImportModalOpen(false);
|
|
||||||
setImportFileContent(null);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
setStatusIdx('Import failed: Wrong password or corrupted file.');
|
setStatusIdx(`Error: ${e}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const tabs = [
|
||||||
|
{ id: 'general', label: 'General', icon: <Save size={14} /> },
|
||||||
|
{ id: 'prompts', label: 'Prompts', icon: <FileText size={14} /> },
|
||||||
|
{ id: 'email', label: 'Email', icon: <Mail size={14} /> },
|
||||||
|
{ id: 'backup', label: 'Backup', icon: <Lock size={14} /> },
|
||||||
|
{ id: 'apps', label: 'Apps', icon: <Headphones size={14} /> },
|
||||||
|
{ id: 'logs', label: 'Logs', icon: <ScrollText size={14} /> },
|
||||||
|
] as const;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col h-full bg-background font-mono text-sm relative">
|
<div className="flex flex-col h-full bg-background font-mono text-sm relative">
|
||||||
{/* Import Password Modal */}
|
{/* Import Password Modal */}
|
||||||
{isImportModalOpen && (
|
{/* Email Template Editor Modal */}
|
||||||
<div className="absolute inset-0 z-50 bg-black/50 flex items-center justify-center p-4">
|
<EmailTemplateEditor
|
||||||
<div className="bg-background border border-border rounded-lg shadow-xl p-6 w-full max-w-sm space-y-4">
|
isOpen={isEmailEditorOpen}
|
||||||
<div className="flex items-center gap-2 text-foreground font-semibold">
|
onClose={() => setIsEmailEditorOpen(false)}
|
||||||
<Lock size={16} /> Import Configuration
|
template={editingTemplate}
|
||||||
</div>
|
onSave={handleSaveEmailTemplate}
|
||||||
<p className="text-muted-foreground text-xs">
|
smtpConfig={localSmtp}
|
||||||
Enter the password used to encrypt this backup file.
|
addToast={(msg, type) => setStatusIdx(`${type === 'error' ? 'Error' : 'Success'}: ${msg}`)}
|
||||||
</p>
|
|
||||||
<div className="relative">
|
|
||||||
<input
|
|
||||||
type={showPassword ? "text" : "password"}
|
|
||||||
value={backupPassword}
|
|
||||||
onChange={(e) => setBackupPassword(e.target.value)}
|
|
||||||
placeholder="Backup Password"
|
|
||||||
className="w-full p-2 pr-8 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none"
|
|
||||||
/>
|
/>
|
||||||
<button
|
|
||||||
onClick={() => setShowPassword(!showPassword)}
|
|
||||||
className="absolute right-2 top-2.5 text-muted-foreground hover:text-foreground"
|
|
||||||
>
|
|
||||||
{showPassword ? <EyeOff size={14} /> : <Eye size={14} />}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div className="flex justify-end gap-2 pt-2">
|
|
||||||
<button
|
|
||||||
onClick={() => setIsImportModalOpen(false)}
|
|
||||||
className="px-3 py-1.5 text-xs font-medium rounded border border-border hover:bg-secondary text-foreground transition-colors"
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
onClick={confirmImport}
|
|
||||||
disabled={!backupPassword}
|
|
||||||
className="px-3 py-1.5 text-xs font-medium rounded bg-primary text-primary-foreground hover:bg-primary/90 transition-colors disabled:opacity-50"
|
|
||||||
>
|
|
||||||
Decrypt & Import
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="p-4 border-b border-border/40 bg-secondary/20 flex justify-between items-center">
|
<div className="flex flex-col border-b border-border/40 bg-secondary/10">
|
||||||
<span className="text-xs uppercase tracking-wider text-muted-foreground font-semibold">Settings</span>
|
<div className="p-4 flex justify-between items-center">
|
||||||
<button onClick={handleSave} className="flex items-center gap-1 text-primary hover:text-primary/80 transition-colors font-semibold">
|
<h2 className="text-lg font-semibold tracking-tight">Settings</h2>
|
||||||
<Save size={16} /> Save
|
<button onClick={handleSave} className="flex items-center gap-2 bg-primary text-primary-foreground px-4 py-2 rounded font-semibold hover:bg-primary/90 transition-all active:scale-95 text-xs">
|
||||||
|
<Save size={16} /> Save Changes
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex-1 overflow-y-auto p-4 space-y-6">
|
{/* Tabs */}
|
||||||
<div className="space-y-4 border rounded p-4 border-border/50">
|
<div className="flex px-4 gap-2">
|
||||||
<h3 className="text-foreground font-semibold flex items-center gap-2">General</h3>
|
{tabs.map(tab => (
|
||||||
|
<button
|
||||||
|
key={tab.id}
|
||||||
|
onClick={() => setActiveTab(tab.id)}
|
||||||
|
className={`px-4 py-2 text-xs font-medium border-b-2 transition-colors flex items-center gap-2 ${activeTab === tab.id ? 'border-primary text-primary' : 'border-transparent text-muted-foreground hover:text-foreground'}`}
|
||||||
|
>
|
||||||
|
{tab.icon} {tab.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex-1 overflow-y-auto p-6">
|
||||||
|
{activeTab === 'general' && (
|
||||||
|
<div className="space-y-6 max-w-2xl">
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h3 className="text-foreground font-semibold border-b border-border pb-2">Application Keys</h3>
|
||||||
<div>
|
<div>
|
||||||
<label htmlFor="apiKey" className="block text-sm font-medium mb-1 text-foreground">API Key</label>
|
<label htmlFor="apiKey" className="block text-sm font-medium mb-1 text-foreground">API Key</label>
|
||||||
<input
|
<input
|
||||||
@@ -207,6 +368,10 @@ const Settings: React.FC<SettingsProps> = ({ apiKey, productId, prompts, savePat
|
|||||||
className="w-full p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
className="w-full p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h3 className="text-foreground font-semibold border-b border-border pb-2">Storage</h3>
|
||||||
<div>
|
<div>
|
||||||
<label htmlFor="savePath" className="block text-sm font-medium mb-1 text-foreground">Custom Recordings Folder</label>
|
<label htmlFor="savePath" className="block text-sm font-medium mb-1 text-foreground">Custom Recordings Folder</label>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
@@ -220,7 +385,7 @@ const Settings: React.FC<SettingsProps> = ({ apiKey, productId, prompts, savePat
|
|||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
onClick={handleSelectFolder}
|
onClick={handleSelectFolder}
|
||||||
className="p-2 aspect-square flex items-center justify-center bg-secondary hover:bg-secondary/80 border border-border rounded text-foreground transition-colors"
|
className="p-2 aspect-square flex items-center justify-center bg-secondary hover:bg-secondary/80 border border-border rounded text-foreground transition-all active:scale-95"
|
||||||
title="Pick Folder"
|
title="Pick Folder"
|
||||||
>
|
>
|
||||||
<FolderOpen size={16} />
|
<FolderOpen size={16} />
|
||||||
@@ -229,67 +394,95 @@ const Settings: React.FC<SettingsProps> = ({ apiKey, productId, prompts, savePat
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-4 border rounded p-4 border-border/50">
|
<div className="space-y-4">
|
||||||
<h3 className="text-foreground font-semibold flex items-center gap-2">
|
<h3 className="text-foreground font-semibold border-b border-border pb-2">📸 Branding</h3>
|
||||||
<Lock size={16} /> Backup & Restore
|
<div className="p-4 bg-secondary/20 rounded border border-border/50">
|
||||||
</h3>
|
<div className="mb-3">
|
||||||
<p className="text-xs text-muted-foreground">
|
<div className="font-medium text-sm mb-2">Custom Logo</div>
|
||||||
Export your settings (keys, prompts, path) to an encrypted file.
|
<div className="text-xs text-muted-foreground mb-3">Upload your company logo to replace the default Livtec branding throughout the app.</div>
|
||||||
</p>
|
|
||||||
|
|
||||||
<div className="relative">
|
|
||||||
<input
|
|
||||||
type={showPassword ? "text" : "password"}
|
|
||||||
value={backupPassword}
|
|
||||||
onChange={(e) => setBackupPassword(e.target.value)}
|
|
||||||
placeholder="Encryption Password"
|
|
||||||
className="w-full p-2 pr-8 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none text-sm"
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
onClick={() => setShowPassword(!showPassword)}
|
|
||||||
className="absolute right-2 top-2.5 text-muted-foreground hover:text-foreground"
|
|
||||||
>
|
|
||||||
{showPassword ? <EyeOff size={14} /> : <Eye size={14} />}
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex gap-2 pt-2">
|
{/* Logo Preview */}
|
||||||
<button
|
<div className="flex items-center gap-4 mb-3">
|
||||||
onClick={handleExport}
|
<div className="w-20 h-20 bg-background border border-border rounded flex items-center justify-center overflow-hidden">
|
||||||
className="flex-1 flex items-center justify-center gap-2 py-2 px-4 rounded bg-secondary hover:bg-secondary/80 border border-border text-foreground transition-all text-xs font-semibold"
|
<img
|
||||||
>
|
src={localStorage.getItem('customLogo') || logo}
|
||||||
<Download size={14} /> Export Config
|
alt="Logo Preview"
|
||||||
</button>
|
className="max-w-full max-h-full object-contain"
|
||||||
<button
|
|
||||||
onClick={triggerImport}
|
|
||||||
className="flex-1 flex items-center justify-center gap-2 py-2 px-4 rounded bg-secondary hover:bg-secondary/80 border border-border text-foreground transition-all text-xs font-semibold"
|
|
||||||
>
|
|
||||||
<Upload size={14} /> Import Config
|
|
||||||
</button>
|
|
||||||
<input
|
|
||||||
type="file"
|
|
||||||
id="import-file-input"
|
|
||||||
accept=".conf"
|
|
||||||
className="hidden"
|
|
||||||
onChange={handleFileSelect}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex-1">
|
||||||
|
<button
|
||||||
|
onClick={async () => {
|
||||||
|
try {
|
||||||
|
const selected = await open({
|
||||||
|
filters: [{ name: 'Images', extensions: ['png', 'jpg', 'jpeg', 'svg'] }]
|
||||||
|
});
|
||||||
|
if (selected && typeof selected === 'string') {
|
||||||
|
const dataUrl = await invoke<string>('read_image_as_base64', { filePath: selected });
|
||||||
|
localStorage.setItem('customLogo', dataUrl);
|
||||||
|
setStatusIdx('Logo uploaded! Save settings to apply.');
|
||||||
|
// Force re-render
|
||||||
|
window.dispatchEvent(new Event('storage'));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setStatusIdx(`Logo upload failed: ${e}`);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
className="bg-secondary hover:bg-secondary/80 text-xs px-3 py-2 rounded border border-border transition-all flex items-center gap-2"
|
||||||
|
>
|
||||||
|
<Upload size={14} /> Upload Logo
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
localStorage.removeItem('customLogo');
|
||||||
|
setStatusIdx('Logo reset to default. Save to apply.');
|
||||||
|
window.dispatchEvent(new Event('storage'));
|
||||||
|
}}
|
||||||
|
className="mt-2 bg-secondary hover:bg-secondary/80 text-xs px-3 py-2 rounded border border-border transition-all text-muted-foreground"
|
||||||
|
>
|
||||||
|
Reset to Default
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p className="text-[10px] text-muted-foreground">Supported: PNG, JPG, SVG. Recommended: Square format, transparent background.</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-4 border rounded p-4 border-border/50">
|
<div className="space-y-4">
|
||||||
<div className="flex justify-between items-center">
|
<h3 className="text-foreground font-semibold border-b border-border pb-2">System Intergration</h3>
|
||||||
<h3 className="text-foreground font-semibold">Prompts</h3>
|
<div className="flex items-center justify-between p-4 bg-secondary/20 rounded border border-border/50">
|
||||||
<button onClick={addPrompt} className="text-xs bg-primary text-primary-foreground px-2 py-1 rounded hover:bg-primary/90">
|
<div>
|
||||||
|
<div className="font-medium text-sm">Hearbit Audio Device</div>
|
||||||
|
<div className="text-xs text-muted-foreground">Required for recording system audio (Teams, Zoom, etc.)</div>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onClick={handleCreateDevice}
|
||||||
|
className="bg-secondary hover:bg-secondary/80 text-xs px-3 py-2 rounded border border-border transition-all active:scale-95 flex items-center gap-2"
|
||||||
|
>
|
||||||
|
<span>🪄</span> Create / Repair
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{activeTab === 'prompts' && (
|
||||||
|
<div className="space-y-4 max-w-3xl">
|
||||||
|
<div className="flex justify-between items-center border-b border-border pb-2">
|
||||||
|
<h3 className="text-foreground font-semibold">AI Prompts</h3>
|
||||||
|
<button onClick={addPrompt} className="text-xs bg-primary text-primary-foreground px-3 py-1.5 rounded hover:bg-primary/90 transition-all active:scale-95">
|
||||||
+ Add Prompt
|
+ Add Prompt
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="grid gap-4">
|
||||||
{localPrompts.map((prompt) => (
|
{localPrompts.map((prompt) => (
|
||||||
<div key={prompt.id} className="space-y-2 p-3 bg-secondary/30 rounded border border-border/50 relative group">
|
<div key={prompt.id} className="space-y-2 p-4 bg-secondary/10 rounded border border-border/50 relative group">
|
||||||
<button
|
<button
|
||||||
onClick={() => removePrompt(prompt.id)}
|
onClick={() => removePrompt(prompt.id)}
|
||||||
className="absolute top-2 right-2 text-muted-foreground hover:text-destructive opacity-0 group-hover:opacity-100 transition-opacity text-xs"
|
className="absolute top-2 right-2 text-muted-foreground hover:text-destructive opacity-0 group-hover:opacity-100 transition-opacity text-xs flex items-center gap-1"
|
||||||
>
|
>
|
||||||
<EyeOff size={12} className="inline mr-1" /> Remove
|
Remove
|
||||||
</button>
|
</button>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
@@ -301,20 +494,344 @@ const Settings: React.FC<SettingsProps> = ({ apiKey, productId, prompts, savePat
|
|||||||
<textarea
|
<textarea
|
||||||
value={prompt.content}
|
value={prompt.content}
|
||||||
onChange={(e) => handlePromptChange(prompt.id, 'content', e.target.value)}
|
onChange={(e) => handlePromptChange(prompt.id, 'content', e.target.value)}
|
||||||
className="w-full p-2 bg-secondary/50 rounded border border-border/30 focus:border-primary outline-none text-xs resize-y min-h-[60px]"
|
className="w-full p-2 bg-secondary/50 rounded border border-border/30 focus:border-primary outline-none text-xs resize-y min-h-[100px] font-mono"
|
||||||
placeholder="Prompt Content"
|
placeholder="Prompt Content"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{statusIdx && (
|
{activeTab === 'email' && (
|
||||||
<div className={`p-2 text-xs rounded border ${statusIdx.includes('Error') || statusIdx.includes('failed') ? 'bg-destructive/10 border-destructive text-destructive' : 'bg-green-500/10 border-green-500 text-green-500'}`}>
|
<div className="space-y-8 max-w-2xl">
|
||||||
{statusIdx}
|
<div className="space-y-4">
|
||||||
|
<div className="flex justify-between items-center border-b border-border pb-2">
|
||||||
|
<h3 className="text-foreground font-semibold">Email Templates</h3>
|
||||||
|
<button
|
||||||
|
onClick={() => openEmailEditor(null)}
|
||||||
|
className="text-xs bg-primary text-primary-foreground px-3 py-1.5 rounded hover:bg-primary/90 transition-all active:scale-95"
|
||||||
|
>
|
||||||
|
+ Add Template
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
{localEmailTemplates.map((template) => (
|
||||||
|
<div key={template.id} className="flex justify-between items-center p-4 bg-secondary/10 rounded border border-border/50 group hover:border-border/80 transition-colors">
|
||||||
|
<div className="flex-1 min-w-0 pr-4">
|
||||||
|
<div className="font-semibold text-sm truncate">{template.name}</div>
|
||||||
|
<div className="text-xs text-muted-foreground truncate">{template.subject}</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2 shrink-0">
|
||||||
|
<button
|
||||||
|
onClick={() => openEmailEditor(template)}
|
||||||
|
className="px-2 py-1 text-xs font-medium text-primary hover:bg-primary/10 rounded transition-colors"
|
||||||
|
>
|
||||||
|
Edit
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => removeEmailTemplate(template.id)}
|
||||||
|
className="px-2 py-1 text-xs font-medium text-muted-foreground hover:text-destructive hover:bg-destructive/10 rounded transition-colors"
|
||||||
|
>
|
||||||
|
Remove
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
{localEmailTemplates.length === 0 && (
|
||||||
|
<div className="text-center p-8 text-muted-foreground text-xs italic border border-dashed border-border rounded">
|
||||||
|
No templates created yet.
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h3 className="text-foreground font-semibold border-b border-border pb-2">SMTP Configuration</h3>
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-1 text-foreground">SMTP Host</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={localSmtp.host}
|
||||||
|
onChange={(e) => setLocalSmtp({ ...localSmtp, host: e.target.value })}
|
||||||
|
className="w-full p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
||||||
|
placeholder="smtp.office365.com"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-1 text-foreground">Port</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={localSmtp.port}
|
||||||
|
onChange={(e) => setLocalSmtp({ ...localSmtp, port: e.target.value })}
|
||||||
|
className="w-full p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
||||||
|
placeholder="587"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="col-span-2">
|
||||||
|
<label className="block text-sm font-medium mb-1 text-foreground">Sender Email</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={localSmtp.sender}
|
||||||
|
onChange={(e) => setLocalSmtp({ ...localSmtp, sender: e.target.value })}
|
||||||
|
className="w-full p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
||||||
|
placeholder="you@company.com"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="col-span-2">
|
||||||
|
<label className="block text-sm font-medium mb-1 text-foreground">Sender Name (Optional)</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={localSmtp.senderName}
|
||||||
|
onChange={(e) => setLocalSmtp({ ...localSmtp, senderName: e.target.value })}
|
||||||
|
className="w-full p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
||||||
|
placeholder="Hearbit Assistant"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-1 text-foreground">Username</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={localSmtp.user}
|
||||||
|
onChange={(e) => setLocalSmtp({ ...localSmtp, user: e.target.value })}
|
||||||
|
className="w-full p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-1 text-foreground">Password</label>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
value={localSmtp.pass}
|
||||||
|
onChange={(e) => setLocalSmtp({ ...localSmtp, pass: e.target.value })}
|
||||||
|
className="w-full p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h3 className="text-foreground font-semibold border-b border-border pb-2">Microsoft 365 (Azure AD)</h3>
|
||||||
|
<p className="text-xs text-muted-foreground">Optional configuration for advanced MS Graph integrations.</p>
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-1 text-foreground">Client ID</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={localAzure.clientId}
|
||||||
|
onChange={(e) => setLocalAzure({ ...localAzure, clientId: e.target.value })}
|
||||||
|
className="w-full p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
||||||
|
placeholder="Application (client) ID"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{activeTab === 'backup' && (
|
||||||
|
<div className="space-y-6 max-w-xl">
|
||||||
|
{/* Manual Configuration Backup */}
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h3 className="text-foreground font-semibold border-b border-border pb-2">Manual Configuration Backup</h3>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Export all your settings, including API keys, prompts, email templates, and history as JSON files.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="flex gap-4 pt-2">
|
||||||
|
<button
|
||||||
|
onClick={handleExport}
|
||||||
|
className="flex-1 flex items-center justify-center gap-2 py-3 px-4 rounded-lg bg-secondary hover:bg-secondary/80 border border-border text-foreground transition-all font-semibold active:scale-95"
|
||||||
|
>
|
||||||
|
<Download size={18} /> Export Config
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={triggerImport}
|
||||||
|
className="flex-1 flex items-center justify-center gap-2 py-3 px-4 rounded-lg bg-secondary hover:bg-secondary/80 border border-border text-foreground transition-all font-semibold active:scale-95"
|
||||||
|
>
|
||||||
|
<Upload size={18} /> Import Config
|
||||||
|
</button>
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
id="import-file-input"
|
||||||
|
accept=".json"
|
||||||
|
className="hidden"
|
||||||
|
onChange={handleFileSelect}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Daily Automated Backup */}
|
||||||
|
<div className="space-y-4 border-t border-border pt-6">
|
||||||
|
<h3 className="text-foreground font-semibold border-b border-border pb-2">Daily Automated Backup</h3>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Automatically backup your configuration once per day to prevent data loss. Backups are saved as JSON files.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id="enable-daily-backup"
|
||||||
|
checked={localDailyBackupEnabled}
|
||||||
|
onChange={(e) => setLocalDailyBackupEnabled(e.target.checked)}
|
||||||
|
className="w-4 h-4"
|
||||||
|
/>
|
||||||
|
<label htmlFor="enable-daily-backup" className="text-sm text-foreground cursor-pointer">
|
||||||
|
Enable daily automated backup
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{localDailyBackupEnabled && (
|
||||||
|
<div>
|
||||||
|
<label className="block text-xs font-semibold text-muted-foreground mb-1 uppercase tracking-wide">
|
||||||
|
Backup Location
|
||||||
|
</label>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={localDailyBackupPath}
|
||||||
|
onChange={(e) => setLocalDailyBackupPath(e.target.value)}
|
||||||
|
placeholder="Leave empty to use recordings folder"
|
||||||
|
className="flex-1 p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none text-sm"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
onClick={async () => {
|
||||||
|
try {
|
||||||
|
const selected = await open({ directory: true, multiple: false });
|
||||||
|
if (selected && typeof selected === 'string') {
|
||||||
|
setLocalDailyBackupPath(selected);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
className="p-2 aspect-square flex items-center justify-center bg-secondary hover:bg-secondary/80 border border-border rounded text-foreground transition-all active:scale-95"
|
||||||
|
>
|
||||||
|
<FolderOpen size={16} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p className="text-[10px] text-muted-foreground mt-1">
|
||||||
|
Last backup: {props.lastBackupDate || 'Never'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{activeTab === 'apps' && (
|
||||||
|
<div className="space-y-6 max-w-2xl h-full flex flex-col overflow-hidden">
|
||||||
|
<div className="space-y-4 flex-none">
|
||||||
|
<h3 className="text-foreground font-semibold border-b border-border pb-2 flex items-center gap-2">
|
||||||
|
<Lock size={16} /> Recording Filters
|
||||||
|
</h3>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Block specific apps to keep their audio out of your recordings (e.g., music or browser sounds).
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex-1 overflow-y-auto pr-2 space-y-6 custom-scrollbar">
|
||||||
|
{/* App Presets */}
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h4 className="text-[10px] font-bold text-muted-foreground uppercase tracking-wider">Quick Select (Classic Apps)</h4>
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
{APP_PRESETS.map(group => (
|
||||||
|
<div key={group.category} className="space-y-2">
|
||||||
|
<h5 className="text-[11px] font-medium text-foreground/80">{group.category}</h5>
|
||||||
|
<div className="flex flex-wrap gap-1.5">
|
||||||
|
{group.apps.map(app => (
|
||||||
|
<button
|
||||||
|
key={app.id}
|
||||||
|
onClick={() => {
|
||||||
|
if (localBlockedApps.includes(app.id)) {
|
||||||
|
setLocalBlockedApps(localBlockedApps.filter(id => id !== app.id));
|
||||||
|
} else {
|
||||||
|
setLocalBlockedApps([...localBlockedApps, app.id]);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
className={`text-[10px] px-2 py-1 rounded border transition-all active:scale-95 ${localBlockedApps.includes(app.id)
|
||||||
|
? 'bg-primary/20 border-primary text-primary font-medium'
|
||||||
|
: 'bg-secondary/50 border-border/50 text-muted-foreground hover:border-border hover:text-foreground'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{app.name}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Running Apps */}
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h4 className="text-[10px] font-bold text-muted-foreground uppercase tracking-wider">Currently Running</h4>
|
||||||
|
<div className="grid gap-2">
|
||||||
|
{runningApps.length > 0 ? (
|
||||||
|
runningApps.map(app => (
|
||||||
|
<label key={app.bundle_id} className="flex items-center justify-between p-3 bg-secondary/10 rounded border border-border/50 hover:bg-secondary/20 transition-colors cursor-pointer capitalize">
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<span className="font-medium text-sm">{app.name}</span>
|
||||||
|
<span className="text-[10px] text-muted-foreground font-mono">{app.bundle_id}</span>
|
||||||
|
</div>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={localBlockedApps.includes(app.bundle_id)}
|
||||||
|
onChange={(e) => {
|
||||||
|
if (e.target.checked) {
|
||||||
|
setLocalBlockedApps([...localBlockedApps, app.bundle_id]);
|
||||||
|
} else {
|
||||||
|
setLocalBlockedApps(localBlockedApps.filter(id => id !== app.bundle_id));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
className="w-4 h-4 rounded border-border bg-secondary text-primary focus:ring-primary"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<div className="text-center py-8 text-muted-foreground text-xs italic border border-dashed border-border rounded">
|
||||||
|
No running applications detected.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{activeTab === 'logs' && (
|
||||||
|
<div className="space-y-4 max-w-4xl h-full flex flex-col">
|
||||||
|
<div className="flex justify-between items-center border-b border-border pb-2">
|
||||||
|
<h3 className="text-foreground font-semibold">Application Logs</h3>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<button
|
||||||
|
onClick={handleSaveLogs}
|
||||||
|
className="text-xs bg-secondary hover:bg-secondary/80 px-2 py-1 rounded border border-border transition-all active:scale-95 flex items-center gap-1"
|
||||||
|
>
|
||||||
|
<Download size={12} /> Export Logs
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={loadLogs}
|
||||||
|
className="text-xs bg-secondary hover:bg-secondary/80 px-2 py-1 rounded border border-border transition-all active:scale-95"
|
||||||
|
>
|
||||||
|
Refresh Logs
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex-1 bg-black text-white p-4 rounded font-mono text-xs overflow-auto whitespace-pre-wrap leading-relaxed shadow-inner">
|
||||||
|
{logs}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{
|
||||||
|
statusIdx && (
|
||||||
|
<div className={`p-2 text-xs text-center border-t ${statusIdx.includes('Error') || statusIdx.includes('failed') ? 'bg-destructive/10 border-destructive text-destructive' : 'bg-green-500/10 border-green-500 text-green-500'}`}>
|
||||||
|
{statusIdx}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</div >
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
716
src/components/Settings.tsx.bak
Normal file
716
src/components/Settings.tsx.bak
Normal file
@@ -0,0 +1,716 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import { Save, FolderOpen, Lock, Upload, Download, Mail, FileText, ScrollText } from 'lucide-react';
|
||||||
|
import { save, open } from '@tauri-apps/plugin-dialog';
|
||||||
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
|
import EmailTemplateEditor from './EmailTemplateEditor';
|
||||||
|
import logo from '../assets/logo.png';
|
||||||
|
|
||||||
|
import { PromptTemplate, EmailTemplate } from '../App';
|
||||||
|
|
||||||
|
interface SettingsProps {
|
||||||
|
apiKey: string;
|
||||||
|
productId: string;
|
||||||
|
savePath: string;
|
||||||
|
prompts: PromptTemplate[];
|
||||||
|
emailTemplates: EmailTemplate[];
|
||||||
|
smtpConfig: SmtpConfig;
|
||||||
|
azureConfig: AzureConfig;
|
||||||
|
dailyBackupEnabled: boolean;
|
||||||
|
dailyBackupPath: string;
|
||||||
|
lastBackupDate: string;
|
||||||
|
history: any[];
|
||||||
|
onSave: (
|
||||||
|
apiKey: string,
|
||||||
|
productId: string,
|
||||||
|
prompts: PromptTemplate[],
|
||||||
|
savePath: string,
|
||||||
|
smtp: SmtpConfig,
|
||||||
|
azure: AzureConfig,
|
||||||
|
emailTemplates: EmailTemplate[],
|
||||||
|
dailyBackupEnabled: boolean,
|
||||||
|
dailyBackupPath: string
|
||||||
|
) => void;
|
||||||
|
onHistoryUpdate: (history: any[]) => void;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SmtpConfig {
|
||||||
|
host: string;
|
||||||
|
port: string;
|
||||||
|
user: string;
|
||||||
|
pass: string;
|
||||||
|
sender: string;
|
||||||
|
senderName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AzureConfig {
|
||||||
|
clientId: string;
|
||||||
|
tenantId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Settings: React.FC<SettingsProps> = ({ apiKey, productId, prompts, savePath, onSave, onClose, ...props }) => {
|
||||||
|
const [localApiKey, setLocalApiKey] = useState(apiKey);
|
||||||
|
const [localProductId, setLocalProductId] = useState(productId);
|
||||||
|
const [localSavePath, setLocalSavePath] = useState(savePath);
|
||||||
|
|
||||||
|
const [localPrompts, setLocalPrompts] = useState<PromptTemplate[]>(prompts);
|
||||||
|
const [localEmailTemplates, setLocalEmailTemplates] = useState<EmailTemplate[]>(props.emailTemplates); // New state
|
||||||
|
const [localSmtp, setLocalSmtp] = useState<SmtpConfig>(props.smtpConfig);
|
||||||
|
const [localAzure, setLocalAzure] = useState<AzureConfig>(props.azureConfig);
|
||||||
|
const [localDailyBackupEnabled, setLocalDailyBackupEnabled] = useState(props.dailyBackupEnabled);
|
||||||
|
const [localDailyBackupPath, setLocalDailyBackupPath] = useState(props.dailyBackupPath);
|
||||||
|
const [statusIdx, setStatusIdx] = useState<string | null>(null);
|
||||||
|
|
||||||
|
// Email Template Editor State
|
||||||
|
const [editingTemplate, setEditingTemplate] = useState<EmailTemplate | null>(null);
|
||||||
|
const [isEmailEditorOpen, setIsEmailEditorOpen] = useState(false);
|
||||||
|
|
||||||
|
const [activeTab, setActiveTab] = useState<'general' | 'prompts' | 'email' | 'backup' | 'logs'>('general');
|
||||||
|
const [logs, setLogs] = useState<string>('Loading logs...');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (activeTab === 'logs') {
|
||||||
|
loadLogs();
|
||||||
|
}
|
||||||
|
}, [activeTab]);
|
||||||
|
|
||||||
|
const loadLogs = async () => {
|
||||||
|
try {
|
||||||
|
const content = await invoke<string>('read_log_file');
|
||||||
|
setLogs(content);
|
||||||
|
} catch (e) {
|
||||||
|
setLogs(`Failed to load logs: ${e}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSaveLogs = async () => {
|
||||||
|
try {
|
||||||
|
const filePath = await save({
|
||||||
|
defaultPath: `hearbit_logs_${new Date().toISOString().slice(0, 10)}.log`,
|
||||||
|
filters: [{
|
||||||
|
name: 'Log File',
|
||||||
|
extensions: ['log', 'txt']
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
if (filePath) {
|
||||||
|
await invoke('save_text_file', { path: filePath, content: logs });
|
||||||
|
setStatusIdx(`Logs exported to: ${filePath}`);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
setStatusIdx(`Failed to export logs: ${e}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePromptChange = (id: string, field: 'name' | 'content', value: string) => {
|
||||||
|
setLocalPrompts(localPrompts.map(p => p.id === id ? { ...p, [field]: value } : p));
|
||||||
|
};
|
||||||
|
|
||||||
|
const addPrompt = () => {
|
||||||
|
setLocalPrompts([...localPrompts, { id: Date.now().toString(), name: 'New Prompt', content: '' }]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const removePrompt = (id: string) => {
|
||||||
|
setLocalPrompts(localPrompts.filter(p => p.id !== id));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSaveEmailTemplate = (template: EmailTemplate) => {
|
||||||
|
const exists = localEmailTemplates.find(t => t.id === template.id);
|
||||||
|
if (exists) {
|
||||||
|
setLocalEmailTemplates(localEmailTemplates.map(t => t.id === template.id ? template : t));
|
||||||
|
} else {
|
||||||
|
setLocalEmailTemplates([...localEmailTemplates, template]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const openEmailEditor = (template: EmailTemplate | null) => {
|
||||||
|
setEditingTemplate(template);
|
||||||
|
setIsEmailEditorOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeEmailTemplate = (id: string) => {
|
||||||
|
setLocalEmailTemplates(localEmailTemplates.filter(t => t.id !== id));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSave = () => {
|
||||||
|
onSave(
|
||||||
|
localApiKey,
|
||||||
|
localProductId,
|
||||||
|
localPrompts,
|
||||||
|
localSavePath,
|
||||||
|
localSmtp,
|
||||||
|
localAzure,
|
||||||
|
localEmailTemplates,
|
||||||
|
localDailyBackupEnabled,
|
||||||
|
localDailyBackupPath
|
||||||
|
);
|
||||||
|
onClose();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSelectFolder = async () => {
|
||||||
|
try {
|
||||||
|
const selected = await open({
|
||||||
|
directory: true,
|
||||||
|
multiple: false,
|
||||||
|
defaultPath: localSavePath || undefined,
|
||||||
|
});
|
||||||
|
if (selected && typeof selected === 'string') {
|
||||||
|
setLocalSavePath(selected);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to open directory picker", e);
|
||||||
|
setStatusIdx('Error: Failed to open directory picker.');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleExport = async () => {
|
||||||
|
try {
|
||||||
|
const data = {
|
||||||
|
apiKey: localApiKey,
|
||||||
|
productId: localProductId,
|
||||||
|
prompts: localPrompts,
|
||||||
|
savePath: localSavePath,
|
||||||
|
smtp: localSmtp,
|
||||||
|
azure: localAzure,
|
||||||
|
emailTemplates: localEmailTemplates,
|
||||||
|
history: props.history,
|
||||||
|
dailyBackup: {
|
||||||
|
enabled: localDailyBackupEnabled,
|
||||||
|
path: localDailyBackupPath,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Always save as JSON (no encryption)
|
||||||
|
const content = JSON.stringify(data, null, 2);
|
||||||
|
|
||||||
|
const filePath = await save({
|
||||||
|
defaultPath: `hearbit_backup_${new Date().toISOString().slice(0, 10)}.json`,
|
||||||
|
filters: [{
|
||||||
|
name: 'Hearbit Config',
|
||||||
|
extensions: ['json']
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
if (filePath) {
|
||||||
|
await invoke('save_text_file', { path: filePath, content });
|
||||||
|
setStatusIdx(`Configuration exported to: ${filePath}`);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
setStatusIdx(`Export failed: ${e}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const triggerImport = () => {
|
||||||
|
document.getElementById('import-file-input')?.click();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFileSelect = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const file = e.target.files?.[0];
|
||||||
|
if (!file) return;
|
||||||
|
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = (event) => {
|
||||||
|
if (event.target?.result) {
|
||||||
|
const content = event.target.result as string;
|
||||||
|
// Directly import without password modal since we don't use encryption
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(content);
|
||||||
|
|
||||||
|
if (data.apiKey) setLocalApiKey(data.apiKey);
|
||||||
|
if (data.productId) setLocalProductId(data.productId);
|
||||||
|
if (data.prompts) setLocalPrompts(data.prompts);
|
||||||
|
if (data.emailTemplates) setLocalEmailTemplates(data.emailTemplates);
|
||||||
|
if (data.savePath) setLocalSavePath(data.savePath);
|
||||||
|
if (data.smtp) setLocalSmtp(data.smtp);
|
||||||
|
if (data.azure) setLocalAzure(data.azure);
|
||||||
|
if (data.dailyBackup) {
|
||||||
|
if (data.dailyBackup.enabled !== undefined) setLocalDailyBackupEnabled(data.dailyBackup.enabled);
|
||||||
|
if (data.dailyBackup.path) setLocalDailyBackupPath(data.dailyBackup.path);
|
||||||
|
}
|
||||||
|
// Import history!
|
||||||
|
if (data.history && Array.isArray(data.history)) {
|
||||||
|
props.onHistoryUpdate(data.history);
|
||||||
|
}
|
||||||
|
|
||||||
|
setStatusIdx('Configuration imported! Click Save to apply.');
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
setStatusIdx(`Import failed: ${error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
reader.readAsText(file);
|
||||||
|
e.target.value = '';
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const handleCreateDevice = async () => {
|
||||||
|
try {
|
||||||
|
setStatusIdx('Creating Hearbit Audio device...');
|
||||||
|
await invoke('create_hearbit_audio_device');
|
||||||
|
setStatusIdx('Success! "Hearbit Audio" device created.');
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
setStatusIdx(`Error: ${e}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const tabs = [
|
||||||
|
{ id: 'general', label: 'General', icon: <Save size={14} /> },
|
||||||
|
{ id: 'prompts', label: 'Prompts', icon: <FileText size={14} /> },
|
||||||
|
{ id: 'email', label: 'Email', icon: <Mail size={14} /> },
|
||||||
|
{ id: 'backup', label: 'Backup', icon: <Lock size={14} /> },
|
||||||
|
{ id: 'logs', label: 'Logs', icon: <ScrollText size={14} /> },
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col h-full bg-background font-mono text-sm relative">
|
||||||
|
{/* Import Password Modal */}
|
||||||
|
{/* Email Template Editor Modal */}
|
||||||
|
<EmailTemplateEditor
|
||||||
|
isOpen={isEmailEditorOpen}
|
||||||
|
onClose={() => setIsEmailEditorOpen(false)}
|
||||||
|
template={editingTemplate}
|
||||||
|
onSave={handleSaveEmailTemplate}
|
||||||
|
smtpConfig={localSmtp}
|
||||||
|
addToast={(msg, type) => setStatusIdx(`${type === 'error' ? 'Error' : 'Success'}: ${msg}`)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="flex flex-col border-b border-border/40 bg-secondary/10">
|
||||||
|
<div className="p-4 flex justify-between items-center">
|
||||||
|
<h2 className="text-lg font-semibold tracking-tight">Settings</h2>
|
||||||
|
<button onClick={handleSave} className="flex items-center gap-2 bg-primary text-primary-foreground px-4 py-2 rounded font-semibold hover:bg-primary/90 transition-all active:scale-95 text-xs">
|
||||||
|
<Save size={16} /> Save Changes
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Tabs */}
|
||||||
|
<div className="flex px-4 gap-2">
|
||||||
|
{tabs.map(tab => (
|
||||||
|
<button
|
||||||
|
key={tab.id}
|
||||||
|
onClick={() => setActiveTab(tab.id)}
|
||||||
|
className={`px-4 py-2 text-xs font-medium border-b-2 transition-colors flex items-center gap-2 ${activeTab === tab.id ? 'border-primary text-primary' : 'border-transparent text-muted-foreground hover:text-foreground'}`}
|
||||||
|
>
|
||||||
|
{tab.icon} {tab.label}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex-1 overflow-y-auto p-6">
|
||||||
|
{activeTab === 'general' && (
|
||||||
|
<div className="space-y-6 max-w-2xl">
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h3 className="text-foreground font-semibold border-b border-border pb-2">Application Keys</h3>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="apiKey" className="block text-sm font-medium mb-1 text-foreground">API Key</label>
|
||||||
|
<input
|
||||||
|
id="apiKey"
|
||||||
|
type="password"
|
||||||
|
value={localApiKey}
|
||||||
|
onChange={(e) => setLocalApiKey(e.target.value)}
|
||||||
|
className="w-full p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="productId" className="block text-sm font-medium mb-1 text-foreground">Product ID</label>
|
||||||
|
<input
|
||||||
|
id="productId"
|
||||||
|
type="text"
|
||||||
|
value={localProductId}
|
||||||
|
onChange={(e) => setLocalProductId(e.target.value)}
|
||||||
|
className="w-full p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h3 className="text-foreground font-semibold border-b border-border pb-2">Storage</h3>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="savePath" className="block text-sm font-medium mb-1 text-foreground">Custom Recordings Folder</label>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<input
|
||||||
|
id="savePath"
|
||||||
|
type="text"
|
||||||
|
value={localSavePath}
|
||||||
|
onChange={(e) => setLocalSavePath(e.target.value)}
|
||||||
|
placeholder="/Users/username/Desktop/Recordings"
|
||||||
|
className="flex-1 p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
onClick={handleSelectFolder}
|
||||||
|
className="p-2 aspect-square flex items-center justify-center bg-secondary hover:bg-secondary/80 border border-border rounded text-foreground transition-all active:scale-95"
|
||||||
|
title="Pick Folder"
|
||||||
|
>
|
||||||
|
<FolderOpen size={16} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h3 className="text-foreground font-semibold border-b border-border pb-2">📸 Branding</h3>
|
||||||
|
<div className="p-4 bg-secondary/20 rounded border border-border/50">
|
||||||
|
<div className="mb-3">
|
||||||
|
<div className="font-medium text-sm mb-2">Custom Logo</div>
|
||||||
|
<div className="text-xs text-muted-foreground mb-3">Upload your company logo to replace the default Livtec branding throughout the app.</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Logo Preview */}
|
||||||
|
<div className="flex items-center gap-4 mb-3">
|
||||||
|
<div className="w-20 h-20 bg-background border border-border rounded flex items-center justify-center overflow-hidden">
|
||||||
|
<img
|
||||||
|
src={localStorage.getItem('customLogo') || logo}
|
||||||
|
alt="Logo Preview"
|
||||||
|
className="max-w-full max-h-full object-contain"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex-1">
|
||||||
|
<button
|
||||||
|
onClick={async () => {
|
||||||
|
try {
|
||||||
|
const selected = await open({
|
||||||
|
filters: [{ name: 'Images', extensions: ['png', 'jpg', 'jpeg', 'svg'] }]
|
||||||
|
});
|
||||||
|
if (selected && typeof selected === 'string') {
|
||||||
|
const dataUrl = await invoke<string>('read_image_as_base64', { filePath: selected });
|
||||||
|
localStorage.setItem('customLogo', dataUrl);
|
||||||
|
setStatusIdx('Logo uploaded! Save settings to apply.');
|
||||||
|
// Force re-render
|
||||||
|
window.dispatchEvent(new Event('storage'));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setStatusIdx(`Logo upload failed: ${e}`);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
className="bg-secondary hover:bg-secondary/80 text-xs px-3 py-2 rounded border border-border transition-all flex items-center gap-2"
|
||||||
|
>
|
||||||
|
<Upload size={14} /> Upload Logo
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
localStorage.removeItem('customLogo');
|
||||||
|
setStatusIdx('Logo reset to default. Save to apply.');
|
||||||
|
window.dispatchEvent(new Event('storage'));
|
||||||
|
}}
|
||||||
|
className="mt-2 bg-secondary hover:bg-secondary/80 text-xs px-3 py-2 rounded border border-border transition-all text-muted-foreground"
|
||||||
|
>
|
||||||
|
Reset to Default
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p className="text-[10px] text-muted-foreground">Supported: PNG, JPG, SVG. Recommended: Square format, transparent background.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h3 className="text-foreground font-semibold border-b border-border pb-2">System Intergration</h3>
|
||||||
|
<div className="flex items-center justify-between p-4 bg-secondary/20 rounded border border-border/50">
|
||||||
|
<div>
|
||||||
|
<div className="font-medium text-sm">Hearbit Audio Device</div>
|
||||||
|
<div className="text-xs text-muted-foreground">Required for recording system audio (Teams, Zoom, etc.)</div>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onClick={handleCreateDevice}
|
||||||
|
className="bg-secondary hover:bg-secondary/80 text-xs px-3 py-2 rounded border border-border transition-all active:scale-95 flex items-center gap-2"
|
||||||
|
>
|
||||||
|
<span>🪄</span> Create / Repair
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{activeTab === 'prompts' && (
|
||||||
|
<div className="space-y-4 max-w-3xl">
|
||||||
|
<div className="flex justify-between items-center border-b border-border pb-2">
|
||||||
|
<h3 className="text-foreground font-semibold">AI Prompts</h3>
|
||||||
|
<button onClick={addPrompt} className="text-xs bg-primary text-primary-foreground px-3 py-1.5 rounded hover:bg-primary/90 transition-all active:scale-95">
|
||||||
|
+ Add Prompt
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="grid gap-4">
|
||||||
|
{localPrompts.map((prompt) => (
|
||||||
|
<div key={prompt.id} className="space-y-2 p-4 bg-secondary/10 rounded border border-border/50 relative group">
|
||||||
|
<button
|
||||||
|
onClick={() => removePrompt(prompt.id)}
|
||||||
|
className="absolute top-2 right-2 text-muted-foreground hover:text-destructive opacity-0 group-hover:opacity-100 transition-opacity text-xs flex items-center gap-1"
|
||||||
|
>
|
||||||
|
Remove
|
||||||
|
</button>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={prompt.name}
|
||||||
|
onChange={(e) => handlePromptChange(prompt.id, 'name', e.target.value)}
|
||||||
|
className="w-full p-1 bg-transparent border-b border-border/50 focus:border-primary outline-none font-semibold text-sm"
|
||||||
|
placeholder="Prompt Name"
|
||||||
|
/>
|
||||||
|
<textarea
|
||||||
|
value={prompt.content}
|
||||||
|
onChange={(e) => handlePromptChange(prompt.id, 'content', e.target.value)}
|
||||||
|
className="w-full p-2 bg-secondary/50 rounded border border-border/30 focus:border-primary outline-none text-xs resize-y min-h-[100px] font-mono"
|
||||||
|
placeholder="Prompt Content"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{activeTab === 'email' && (
|
||||||
|
<div className="space-y-8 max-w-2xl">
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="flex justify-between items-center border-b border-border pb-2">
|
||||||
|
<h3 className="text-foreground font-semibold">Email Templates</h3>
|
||||||
|
<button
|
||||||
|
onClick={() => openEmailEditor(null)}
|
||||||
|
className="text-xs bg-primary text-primary-foreground px-3 py-1.5 rounded hover:bg-primary/90 transition-all active:scale-95"
|
||||||
|
>
|
||||||
|
+ Add Template
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
{localEmailTemplates.map((template) => (
|
||||||
|
<div key={template.id} className="flex justify-between items-center p-4 bg-secondary/10 rounded border border-border/50 group hover:border-border/80 transition-colors">
|
||||||
|
<div className="flex-1 min-w-0 pr-4">
|
||||||
|
<div className="font-semibold text-sm truncate">{template.name}</div>
|
||||||
|
<div className="text-xs text-muted-foreground truncate">{template.subject}</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2 shrink-0">
|
||||||
|
<button
|
||||||
|
onClick={() => openEmailEditor(template)}
|
||||||
|
className="px-2 py-1 text-xs font-medium text-primary hover:bg-primary/10 rounded transition-colors"
|
||||||
|
>
|
||||||
|
Edit
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => removeEmailTemplate(template.id)}
|
||||||
|
className="px-2 py-1 text-xs font-medium text-muted-foreground hover:text-destructive hover:bg-destructive/10 rounded transition-colors"
|
||||||
|
>
|
||||||
|
Remove
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
{localEmailTemplates.length === 0 && (
|
||||||
|
<div className="text-center p-8 text-muted-foreground text-xs italic border border-dashed border-border rounded">
|
||||||
|
No templates created yet.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h3 className="text-foreground font-semibold border-b border-border pb-2">SMTP Configuration</h3>
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-1 text-foreground">SMTP Host</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={localSmtp.host}
|
||||||
|
onChange={(e) => setLocalSmtp({ ...localSmtp, host: e.target.value })}
|
||||||
|
className="w-full p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
||||||
|
placeholder="smtp.office365.com"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-1 text-foreground">Port</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={localSmtp.port}
|
||||||
|
onChange={(e) => setLocalSmtp({ ...localSmtp, port: e.target.value })}
|
||||||
|
className="w-full p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
||||||
|
placeholder="587"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="col-span-2">
|
||||||
|
<label className="block text-sm font-medium mb-1 text-foreground">Sender Email</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={localSmtp.sender}
|
||||||
|
onChange={(e) => setLocalSmtp({ ...localSmtp, sender: e.target.value })}
|
||||||
|
className="w-full p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
||||||
|
placeholder="you@company.com"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="col-span-2">
|
||||||
|
<label className="block text-sm font-medium mb-1 text-foreground">Sender Name (Optional)</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={localSmtp.senderName}
|
||||||
|
onChange={(e) => setLocalSmtp({ ...localSmtp, senderName: e.target.value })}
|
||||||
|
className="w-full p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
||||||
|
placeholder="Hearbit Assistant"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-1 text-foreground">Username</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={localSmtp.user}
|
||||||
|
onChange={(e) => setLocalSmtp({ ...localSmtp, user: e.target.value })}
|
||||||
|
className="w-full p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-1 text-foreground">Password</label>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
value={localSmtp.pass}
|
||||||
|
onChange={(e) => setLocalSmtp({ ...localSmtp, pass: e.target.value })}
|
||||||
|
className="w-full p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h3 className="text-foreground font-semibold border-b border-border pb-2">Microsoft 365 (Azure AD)</h3>
|
||||||
|
<p className="text-xs text-muted-foreground">Optional configuration for advanced MS Graph integrations.</p>
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium mb-1 text-foreground">Client ID</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={localAzure.clientId}
|
||||||
|
onChange={(e) => setLocalAzure({ ...localAzure, clientId: e.target.value })}
|
||||||
|
className="w-full p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none font-mono text-sm"
|
||||||
|
placeholder="Application (client) ID"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{activeTab === 'backup' && (
|
||||||
|
<div className="space-y-6 max-w-xl">
|
||||||
|
{/* Manual Configuration Backup */}
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h3 className="text-foreground font-semibold border-b border-border pb-2">Manual Configuration Backup</h3>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Export all your settings, including API keys, prompts, email templates, and history as JSON files.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="flex gap-4 pt-2">
|
||||||
|
<button
|
||||||
|
onClick={handleExport}
|
||||||
|
className="flex-1 flex items-center justify-center gap-2 py-3 px-4 rounded-lg bg-secondary hover:bg-secondary/80 border border-border text-foreground transition-all font-semibold active:scale-95"
|
||||||
|
>
|
||||||
|
<Download size={18} /> Export Config
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={triggerImport}
|
||||||
|
className="flex-1 flex items-center justify-center gap-2 py-3 px-4 rounded-lg bg-secondary hover:bg-secondary/80 border border-border text-foreground transition-all font-semibold active:scale-95"
|
||||||
|
>
|
||||||
|
<Upload size={18} /> Import Config
|
||||||
|
</button>
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
id="import-file-input"
|
||||||
|
accept=".json"
|
||||||
|
className="hidden"
|
||||||
|
onChange={handleFileSelect}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Daily Automated Backup */}
|
||||||
|
<div className="space-y-4 border-t border-border pt-6">
|
||||||
|
<h3 className="text-foreground font-semibold border-b border-border pb-2">Daily Automated Backup</h3>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Automatically backup your configuration once per day to prevent data loss. Backups are saved as JSON files.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id="enable-daily-backup"
|
||||||
|
checked={localDailyBackupEnabled}
|
||||||
|
onChange={(e) => setLocalDailyBackupEnabled(e.target.checked)}
|
||||||
|
className="w-4 h-4"
|
||||||
|
/>
|
||||||
|
<label htmlFor="enable-daily-backup" className="text-sm text-foreground cursor-pointer">
|
||||||
|
Enable daily automated backup
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{localDailyBackupEnabled && (
|
||||||
|
<div>
|
||||||
|
<label className="block text-xs font-semibold text-muted-foreground mb-1 uppercase tracking-wide">
|
||||||
|
Backup Location
|
||||||
|
</label>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={localDailyBackupPath}
|
||||||
|
onChange={(e) => setLocalDailyBackupPath(e.target.value)}
|
||||||
|
placeholder="Leave empty to use recordings folder"
|
||||||
|
className="flex-1 p-2 rounded border border-border bg-secondary text-foreground focus:ring-2 focus:ring-primary outline-none text-sm"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
onClick={async () => {
|
||||||
|
try {
|
||||||
|
const selected = await open({ directory: true, multiple: false });
|
||||||
|
if (selected && typeof selected === 'string') {
|
||||||
|
setLocalDailyBackupPath(selected);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
className="p-2 aspect-square flex items-center justify-center bg-secondary hover:bg-secondary/80 border border-border rounded text-foreground transition-all active:scale-95"
|
||||||
|
>
|
||||||
|
<FolderOpen size={16} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p className="text-[10px] text-muted-foreground mt-1">
|
||||||
|
Last backup: {props.lastBackupDate || 'Never'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{activeTab === 'logs' && (
|
||||||
|
<div className="space-y-4 max-w-4xl h-full flex flex-col">
|
||||||
|
<div className="flex justify-between items-center border-b border-border pb-2">
|
||||||
|
<h3 className="text-foreground font-semibold">Application Logs</h3>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<button
|
||||||
|
onClick={handleSaveLogs}
|
||||||
|
className="text-xs bg-secondary hover:bg-secondary/80 px-2 py-1 rounded border border-border transition-all active:scale-95 flex items-center gap-1"
|
||||||
|
>
|
||||||
|
<Download size={12} /> Export Logs
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={loadLogs}
|
||||||
|
className="text-xs bg-secondary hover:bg-secondary/80 px-2 py-1 rounded border border-border transition-all active:scale-95"
|
||||||
|
>
|
||||||
|
Refresh Logs
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex-1 bg-black text-white p-4 rounded font-mono text-xs overflow-auto whitespace-pre-wrap leading-relaxed shadow-inner">
|
||||||
|
{logs}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{
|
||||||
|
statusIdx && (
|
||||||
|
<div className={`p-2 text-xs text-center border-t ${statusIdx.includes('Error') || statusIdx.includes('failed') ? 'bg-destructive/10 border-destructive text-destructive' : 'bg-green-500/10 border-green-500 text-green-500'}`}>
|
||||||
|
{statusIdx}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</div >
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Settings;
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Mic, Terminal, FileText } from 'lucide-react';
|
import { Mic, FileText, Calendar, Upload } from 'lucide-react';
|
||||||
|
|
||||||
interface TabsProps {
|
interface TabsProps {
|
||||||
currentTab: 'recorder' | 'logs' | 'transcription' | 'settings';
|
currentTab: 'recorder' | 'transcription' | 'settings' | 'meetings' | 'history' | 'import';
|
||||||
onTabChange: (tab: 'recorder' | 'logs' | 'transcription' | 'settings') => void;
|
onTabChange: (tab: 'recorder' | 'transcription' | 'settings' | 'meetings' | 'history' | 'import') => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Tabs: React.FC<TabsProps> = ({ currentTab, onTabChange }) => {
|
const Tabs: React.FC<TabsProps> = ({ currentTab, onTabChange }) => {
|
||||||
@@ -15,6 +16,13 @@ const Tabs: React.FC<TabsProps> = ({ currentTab, onTabChange }) => {
|
|||||||
<Mic size={16} />
|
<Mic size={16} />
|
||||||
Recording
|
Recording
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => onTabChange('import')}
|
||||||
|
className={`flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-colors ${currentTab === 'import' ? 'bg-secondary text-foreground' : 'text-muted-foreground hover:text-foreground hover:bg-secondary/50'}`}
|
||||||
|
>
|
||||||
|
<Upload size={16} />
|
||||||
|
Import
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => onTabChange('transcription')}
|
onClick={() => onTabChange('transcription')}
|
||||||
className={`flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-colors ${currentTab === 'transcription' ? 'bg-secondary text-foreground' : 'text-muted-foreground hover:text-foreground hover:bg-secondary/50'}`}
|
className={`flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-colors ${currentTab === 'transcription' ? 'bg-secondary text-foreground' : 'text-muted-foreground hover:text-foreground hover:bg-secondary/50'}`}
|
||||||
@@ -23,15 +31,20 @@ const Tabs: React.FC<TabsProps> = ({ currentTab, onTabChange }) => {
|
|||||||
Transcription
|
Transcription
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => onTabChange('logs')}
|
onClick={() => onTabChange('meetings')}
|
||||||
className={`flex items-center gap-2 px-4 py-1.5 rounded-full text-sm font-medium transition-all duration-200 ${currentTab === 'logs'
|
className={`flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-colors ${currentTab === 'meetings' ? 'bg-secondary text-foreground' : 'text-muted-foreground hover:text-foreground hover:bg-secondary/50'}`}
|
||||||
? 'bg-background shadow-sm text-foreground ring-1 ring-border/50'
|
|
||||||
: 'text-muted-foreground hover:text-foreground hover:bg-background/50'
|
|
||||||
}`}
|
|
||||||
>
|
>
|
||||||
<Terminal size={14} />
|
<Calendar size={16} />
|
||||||
Logs
|
Meetings
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => onTabChange('history')}
|
||||||
|
className={`flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-colors ${currentTab === 'history' ? 'bg-secondary text-foreground' : 'text-muted-foreground hover:text-foreground hover:bg-secondary/50'}`}
|
||||||
|
>
|
||||||
|
<FileText size={16} />
|
||||||
|
History
|
||||||
|
</button>
|
||||||
|
|
||||||
{/* Settings could be a tab, but often better as an icon elsewhere, however sticking to the 'tab' request */}
|
{/* Settings could be a tab, but often better as an icon elsewhere, however sticking to the 'tab' request */}
|
||||||
{/* The user didn't explicitly ask for settings tab, but we need a way to get there. Let's keep it here for now or maybe just an icon?
|
{/* The user didn't explicitly ask for settings tab, but we need a way to get there. Let's keep it here for now or maybe just an icon?
|
||||||
The prompt showed "Recording | Summary | Meetings". We are doing "Recording | Logs".
|
The prompt showed "Recording | Summary | Meetings". We are doing "Recording | Logs".
|
||||||
|
|||||||
@@ -1,15 +1,84 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import ReactMarkdown from 'react-markdown';
|
import ReactMarkdown from 'react-markdown';
|
||||||
import { Copy, Check } from 'lucide-react';
|
import { Copy, Check, Mail, RefreshCw, Wand2 } from 'lucide-react';
|
||||||
|
import EmailPreviewModal from './EmailPreviewModal';
|
||||||
|
import { SmtpConfig } from './Settings';
|
||||||
|
import { ToastType } from './ui/Toast';
|
||||||
|
import { PromptTemplate, EmailTemplate } from '../App';
|
||||||
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
|
|
||||||
interface TranscriptionViewProps {
|
interface TranscriptionViewProps {
|
||||||
transcription: string;
|
transcription: string;
|
||||||
summary: string;
|
summary: string;
|
||||||
|
smtpConfig: SmtpConfig;
|
||||||
|
apiKey: string;
|
||||||
|
productId: string;
|
||||||
|
prompts: PromptTemplate[];
|
||||||
|
emailTemplates: EmailTemplate[];
|
||||||
|
onUpdateSummary: (newSummary: string) => void;
|
||||||
|
addToast: (message: string, type: ToastType, duration?: number) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TranscriptionView: React.FC<TranscriptionViewProps> = ({ transcription, summary }) => {
|
const TranscriptionView: React.FC<TranscriptionViewProps> = ({
|
||||||
|
transcription, summary, smtpConfig, apiKey, productId, prompts, emailTemplates, onUpdateSummary, addToast
|
||||||
|
}) => {
|
||||||
const [copiedTrans, setCopiedTrans] = useState(false);
|
const [copiedTrans, setCopiedTrans] = useState(false);
|
||||||
const [copiedSum, setCopiedSum] = useState(false);
|
const [copiedSum, setCopiedSum] = useState(false);
|
||||||
|
const [isEmailModalOpen, setIsEmailModalOpen] = useState(false);
|
||||||
|
|
||||||
|
// Regenerate State
|
||||||
|
const [isRegenerating, setIsRegenerating] = useState(false);
|
||||||
|
const [showRegenOptions, setShowRegenOptions] = useState(false);
|
||||||
|
const [regenModel, setRegenModel] = useState<string>('mixtral');
|
||||||
|
const [regenPromptId, setRegenPromptId] = useState<string>('');
|
||||||
|
const [availableModels, setAvailableModels] = useState<Array<{ id: string, name: string }>>([]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (showRegenOptions && availableModels.length === 0) {
|
||||||
|
loadModels();
|
||||||
|
}
|
||||||
|
if (prompts.length > 0 && !regenPromptId) {
|
||||||
|
setRegenPromptId(prompts[0].id);
|
||||||
|
}
|
||||||
|
}, [showRegenOptions]);
|
||||||
|
|
||||||
|
const loadModels = async () => {
|
||||||
|
try {
|
||||||
|
const models = await invoke<Array<{ id: string, name: string }>>('get_available_models', { apiKey, productId });
|
||||||
|
if (models && models.length > 0) {
|
||||||
|
models.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
|
setAvailableModels(models);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to load models:", e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRegenerate = async () => {
|
||||||
|
if (!transcription || !apiKey || !productId) return;
|
||||||
|
|
||||||
|
setIsRegenerating(true);
|
||||||
|
try {
|
||||||
|
const prompt = prompts.find(p => p.id === regenPromptId)?.content || "Summarize this.";
|
||||||
|
|
||||||
|
const newSummary = await invoke<string>('summarize_text', {
|
||||||
|
text: transcription,
|
||||||
|
apiKey,
|
||||||
|
productId,
|
||||||
|
prompt,
|
||||||
|
model: regenModel
|
||||||
|
});
|
||||||
|
|
||||||
|
onUpdateSummary(newSummary);
|
||||||
|
addToast('Summary regenerated!', 'success');
|
||||||
|
setShowRegenOptions(false);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
addToast(`Regeneration failed: ${e}`, 'error');
|
||||||
|
} finally {
|
||||||
|
setIsRegenerating(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleCopy = async (text: string, isSummary: boolean) => {
|
const handleCopy = async (text: string, isSummary: boolean) => {
|
||||||
if (!text) return;
|
if (!text) return;
|
||||||
@@ -56,6 +125,30 @@ const TranscriptionView: React.FC<TranscriptionViewProps> = ({ transcription, su
|
|||||||
<div className="flex-1 flex flex-col min-h-0">
|
<div className="flex-1 flex flex-col min-h-0">
|
||||||
<div className="p-3 border-b border-border/40 bg-secondary/20 flex justify-between items-center shrink-0">
|
<div className="p-3 border-b border-border/40 bg-secondary/20 flex justify-between items-center shrink-0">
|
||||||
<span className="text-xs uppercase tracking-wider text-muted-foreground font-semibold">AI Summary</span>
|
<span className="text-xs uppercase tracking-wider text-muted-foreground font-semibold">AI Summary</span>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
{/* Regenerate Trigger */}
|
||||||
|
<button
|
||||||
|
onClick={() => setShowRegenOptions(!showRegenOptions)}
|
||||||
|
disabled={!transcription || !apiKey}
|
||||||
|
className={`text-xs flex items-center gap-1 transition-colors px-2 py-1 rounded ${showRegenOptions ? 'bg-primary text-primary-foreground' : 'hover:bg-secondary text-muted-foreground hover:text-foreground'}`}
|
||||||
|
title="Regenerate Summary"
|
||||||
|
>
|
||||||
|
<RefreshCw size={12} className={isRegenerating ? "animate-spin" : ""} />
|
||||||
|
{showRegenOptions ? 'Close' : 'Redo'}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div className="h-4 w-px bg-border/50 mx-1"></div>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<button
|
||||||
|
onClick={() => setIsEmailModalOpen(true)}
|
||||||
|
disabled={!summary}
|
||||||
|
className="text-xs flex items-center gap-1 hover:text-primary transition-colors disabled:opacity-50"
|
||||||
|
title="Send via Email"
|
||||||
|
>
|
||||||
|
<Mail size={14} /> Email
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => handleCopy(summary, true)}
|
onClick={() => handleCopy(summary, true)}
|
||||||
className="text-xs flex items-center gap-1 hover:text-primary transition-colors disabled:opacity-50"
|
className="text-xs flex items-center gap-1 hover:text-primary transition-colors disabled:opacity-50"
|
||||||
@@ -65,6 +158,41 @@ const TranscriptionView: React.FC<TranscriptionViewProps> = ({ transcription, su
|
|||||||
{copiedSum ? 'Copied' : 'Copy'}
|
{copiedSum ? 'Copied' : 'Copy'}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/* Regenerate Panel */}
|
||||||
|
{showRegenOptions && (
|
||||||
|
<div className="p-3 bg-secondary/30 border-b border-border/40 grid grid-cols-1 md:grid-cols-[1fr_1fr_auto] gap-2 items-end animate-in slide-in-from-top-2 duration-200">
|
||||||
|
<div>
|
||||||
|
<label className="text-[10px] uppercase font-bold text-muted-foreground block mb-1">Model</label>
|
||||||
|
<select
|
||||||
|
value={regenModel}
|
||||||
|
onChange={(e) => setRegenModel(e.target.value)}
|
||||||
|
className="w-full text-xs p-1.5 rounded border border-border bg-background"
|
||||||
|
>
|
||||||
|
{availableModels.length === 0 && <option value="mixtral">Loading...</option>}
|
||||||
|
{availableModels.map(m => <option key={m.id} value={m.id}>{m.name}</option>)}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="text-[10px] uppercase font-bold text-muted-foreground block mb-1">Template</label>
|
||||||
|
<select
|
||||||
|
value={regenPromptId}
|
||||||
|
onChange={(e) => setRegenPromptId(e.target.value)}
|
||||||
|
className="w-full text-xs p-1.5 rounded border border-border bg-background"
|
||||||
|
>
|
||||||
|
{prompts.map(p => <option key={p.id} value={p.id}>{p.name}</option>)}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onClick={handleRegenerate}
|
||||||
|
disabled={isRegenerating}
|
||||||
|
className="text-xs bg-primary text-primary-foreground px-3 py-1.5 rounded font-semibold hover:bg-primary/90 disabled:opacity-50 flex items-center gap-2 h-[30px]"
|
||||||
|
>
|
||||||
|
<Wand2 size={12} /> {isRegenerating ? 'Running...' : 'Generate New'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div className="flex-1 overflow-y-auto p-4 bg-secondary/10 prose prose-sm max-w-none prose-p:text-foreground/90 prose-headings:text-foreground prose-strong:text-foreground prose-ul:text-foreground/90">
|
<div className="flex-1 overflow-y-auto p-4 bg-secondary/10 prose prose-sm max-w-none prose-p:text-foreground/90 prose-headings:text-foreground prose-strong:text-foreground prose-ul:text-foreground/90">
|
||||||
{summary ? (
|
{summary ? (
|
||||||
<ReactMarkdown>{summary}</ReactMarkdown>
|
<ReactMarkdown>{summary}</ReactMarkdown>
|
||||||
@@ -74,6 +202,17 @@ const TranscriptionView: React.FC<TranscriptionViewProps> = ({ transcription, su
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<EmailPreviewModal
|
||||||
|
isOpen={isEmailModalOpen}
|
||||||
|
onClose={() => setIsEmailModalOpen(false)}
|
||||||
|
initialRecipients={[]} // TODO: Pass attendees from meeting
|
||||||
|
initialSubject="Meeting Summary" // Default subject
|
||||||
|
initialBody={summary}
|
||||||
|
emailTemplates={emailTemplates} // Pass templates
|
||||||
|
smtpConfig={smtpConfig ? { ...smtpConfig, port: Number(smtpConfig.port) } : null}
|
||||||
|
addToast={addToast}
|
||||||
|
/>
|
||||||
</div >
|
</div >
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
81
src/components/ui/Toast.tsx
Normal file
81
src/components/ui/Toast.tsx
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import { X, CheckCircle, AlertCircle, Info } from 'lucide-react';
|
||||||
|
|
||||||
|
export type ToastType = 'success' | 'error' | 'info';
|
||||||
|
|
||||||
|
export interface ToastMessage {
|
||||||
|
id: string;
|
||||||
|
message: string;
|
||||||
|
type: ToastType;
|
||||||
|
duration?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ToastProps {
|
||||||
|
toast: ToastMessage;
|
||||||
|
onClose: (id: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Toast: React.FC<ToastProps> = ({ toast, onClose }) => {
|
||||||
|
const [isVisible, setIsVisible] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Determine background color based on type
|
||||||
|
// Animate in
|
||||||
|
requestAnimationFrame(() => setIsVisible(true));
|
||||||
|
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
setIsVisible(false);
|
||||||
|
setTimeout(() => onClose(toast.id), 300); // Wait for animation
|
||||||
|
}, toast.duration || 3000);
|
||||||
|
|
||||||
|
return () => clearTimeout(timer);
|
||||||
|
}, [toast, onClose]);
|
||||||
|
|
||||||
|
const bgColors = {
|
||||||
|
success: 'bg-green-600',
|
||||||
|
error: 'bg-destructive',
|
||||||
|
info: 'bg-blue-600'
|
||||||
|
};
|
||||||
|
|
||||||
|
const icon = {
|
||||||
|
success: <CheckCircle size={18} />,
|
||||||
|
error: <AlertCircle size={18} />,
|
||||||
|
info: <Info size={18} />
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`
|
||||||
|
flex items-center gap-3 px-4 py-3 rounded-lg shadow-lg text-white mb-2 transition-all duration-300 transform
|
||||||
|
${bgColors[toast.type]}
|
||||||
|
${isVisible ? 'translate-x-0 opacity-100' : 'translate-x-full opacity-0'}
|
||||||
|
`}
|
||||||
|
style={{ minWidth: '300px', maxWidth: '400px' }}
|
||||||
|
>
|
||||||
|
<div className="shrink-0">
|
||||||
|
{icon[toast.type]}
|
||||||
|
</div>
|
||||||
|
<p className="text-sm font-medium flex-1">{toast.message}</p>
|
||||||
|
<button
|
||||||
|
onClick={() => { setIsVisible(false); setTimeout(() => onClose(toast.id), 300); }}
|
||||||
|
className="text-white/80 hover:text-white"
|
||||||
|
>
|
||||||
|
<X size={16} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ToastContainer: React.FC<{ toasts: ToastMessage[], removeToast: (id: string) => void }> = ({ toasts, removeToast }) => {
|
||||||
|
return (
|
||||||
|
<div className="fixed bottom-4 right-4 z-50 flex flex-col items-end pointer-events-none">
|
||||||
|
<div className="pointer-events-auto">
|
||||||
|
{toasts.map(t => (
|
||||||
|
<Toast key={t.id} toast={t} onClose={removeToast} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ToastContainer;
|
||||||
Reference in New Issue
Block a user