Skip to content

listening autodetect #1155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

listening autodetect #1155

wants to merge 12 commits into from

Conversation

plyght
Copy link
Collaborator

@plyght plyght commented Jul 14, 2025

No description provided.

Copy link

coderabbitai bot commented Jul 14, 2025

📝 Walkthrough

Walkthrough

This change introduces a new Tauri plugin, meeting-automation, to the project. It includes Rust backend logic for meeting automation, TypeScript bindings, configuration management, error handling, and plugin registration in the desktop app. The update also expands detection capabilities, adds new dependencies, updates localization metadata, and refactors the desktop settings UI and event handling to integrate the new meeting automation features.

Changes

File(s) Change Summary
Cargo.toml, apps/desktop/src-tauri/Cargo.toml, apps/desktop/package.json Added tauri-plugin-meeting-automation as a workspace dependency and registered it in the desktop app.
apps/desktop/src-tauri/src/lib.rs Initialized the new plugin in the Tauri app builder chain.
apps/desktop/src/locales/en/messages.po, apps/desktop/src/locales/ko/messages.po Updated translation metadata (line numbers, comments); marked some old meeting notification entries obsolete; added new meeting automation messages.
crates/db-user/src/events_ops.rs Added get_events_in_range async function for querying events within a date range.
crates/detect/src/app/macos.rs Expanded monitored app bundle IDs; added detection of app termination events and improved callback logic.
crates/detect/src/lib.rs Reactivated app_detector and browser_detector fields and their usage in Detector.
crates/detect/src/mic/macos.rs Added microphone state tracking to detect start/stop transitions and trigger corresponding callbacks.
plugins/listener/js/bindings.gen.ts Reformatted and restyled code for consistency; no logic changes.
plugins/meeting-automation/Cargo.toml, plugins/meeting-automation/package.json, plugins/meeting-automation/tsconfig.json Added manifests and TypeScript config for the new plugin.
plugins/meeting-automation/build.rs Added build script to trigger rebuilds on source changes.
plugins/meeting-automation/js/bindings.gen.ts, plugins/meeting-automation/js/index.ts Added generated TypeScript bindings and event interface for meeting automation plugin.
plugins/meeting-automation/src/automation.rs Implemented meeting automation logic: detection, notifications, recording, and event emission.
plugins/meeting-automation/src/commands.rs Added Tauri commands for starting/stopping automation, config, and status queries.
plugins/meeting-automation/src/config.rs Defined configuration structures, enums, and helper methods for automation.
plugins/meeting-automation/src/error.rs Defined a comprehensive error enum and result type for plugin operations.
plugins/meeting-automation/src/ext.rs Added extension trait for app handle to manage meeting automation lifecycle and configuration.
plugins/meeting-automation/src/lib.rs Registered the plugin, set up state, commands, and re-exports.
plugins/meeting-automation/src/storage.rs Implemented persistent config storage and management for automation settings.
apps/desktop/src/components/settings/views/notifications.tsx Refactored settings UI to replace old notification toggles with meeting automation configuration and controls.
apps/desktop/src/routes/app.tsx Added a React component subscribing to meeting automation events and showing toast notifications.
plugins/analytics/js/bindings.gen.ts, plugins/auth/js/bindings.gen.ts, plugins/misc/js/bindings.gen.ts, plugins/store2/js/bindings.gen.ts Reformatted TypeScript bindings for style and consistency; no functional changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Frontend
    participant TauriPlugin (meeting-automation)
    participant AutomationLogic
    participant Detector
    participant Database
    participant Notification
    participant Recorder

    User->>Frontend: Triggers "Start Meeting Automation"
    Frontend->>TauriPlugin: invoke startMeetingAutomation()
    TauriPlugin->>AutomationLogic: start()
    AutomationLogic->>Detector: start detection loops
    loop Detection Events
        Detector-->>AutomationLogic: Meeting app launched/terminated or mic activity
        AutomationLogic->>Notification: Show notification (if enabled)
        AutomationLogic->>Recorder: Start/stop recording session (if triggered)
        AutomationLogic->>Frontend: Emit event (e.g., recording_auto_started)
    end
    AutomationLogic->>Database: Query for upcoming scheduled meetings (periodically)
    Database-->>AutomationLogic: Return events in range
    AutomationLogic->>Notification: Show pre-meeting notification (if enabled)
    AutomationLogic->>Recorder: Start recording if meeting imminent
    User->>Frontend: Triggers "Stop Meeting Automation"
    Frontend->>TauriPlugin: invoke stopMeetingAutomation()
    TauriPlugin->>AutomationLogic: stop()
    AutomationLogic->>Detector: stop detection loops
    AutomationLogic->>Recorder: Stop any active recordings
Loading
sequenceDiagram
    participant Frontend
    participant TauriPlugin (meeting-automation)
    participant ConfigManager

    Frontend->>TauriPlugin: invoke configureAutomation(config)
    TauriPlugin->>ConfigManager: save_config(config)
    ConfigManager-->>TauriPlugin: Result
    TauriPlugin-->>Frontend: Success/Error

    Frontend->>TauriPlugin: invoke getAutomationConfig()
    TauriPlugin->>ConfigManager: get_config()
    ConfigManager-->>TauriPlugin: AutomationConfig
    TauriPlugin-->>Frontend: AutomationConfig
Loading
sequenceDiagram
    participant Detector
    participant AutomationLogic
    participant Frontend

    Detector-->>AutomationLogic: App/mic event detected
    AutomationLogic->>Frontend: Emit event (e.g., meeting_notification, recording_auto_started)
Loading

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ecf6107 and 1d30823.

⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • Cargo.toml (1 hunks)
  • apps/desktop/package.json (1 hunks)
  • apps/desktop/src-tauri/Cargo.toml (1 hunks)
  • apps/desktop/src-tauri/src/lib.rs (1 hunks)
  • apps/desktop/src/locales/en/messages.po (9 hunks)
  • apps/desktop/src/locales/ko/messages.po (9 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Cargo.toml
🚧 Files skipped from review as they are similar to previous changes (5)
  • apps/desktop/src-tauri/src/lib.rs
  • apps/desktop/package.json
  • apps/desktop/src-tauri/Cargo.toml
  • apps/desktop/src/locales/en/messages.po
  • apps/desktop/src/locales/ko/messages.po
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@plyght
Copy link
Collaborator Author

plyght commented Jul 14, 2025

@coderabbitai review

Copy link

coderabbitai bot commented Jul 14, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

🧹 Nitpick comments (8)
plugins/listener/js/bindings.gen.ts (1)

1-4: Avoid manual formatting changes to auto-generated files

This file is auto-generated by tauri-specta (as noted in line 3). Manual formatting changes may be lost when the file is regenerated. Consider updating the generator configuration instead to ensure consistent formatting.

crates/detect/src/app/macos.rs (1)

61-65: Consider using an enum for event types instead of string prefixes

While the implementation correctly distinguishes between launch and terminate events, using string prefixes like "app_launched:" and "app_terminated:" could be error-prone. Consider defining an enum or structured event type.

Example approach:

enum AppEvent {
    Launched(String),
    Terminated(String),
}

// Then serialize to a consistent format when calling the callback
plugins/meeting-automation/src/lib.rs (2)

33-45: Consider making the runtime type generic.

The function hardcodes tauri::Wry as the runtime type in the command collection. This could limit flexibility if the plugin needs to support different runtime implementations.

-fn make_specta_builder<R: tauri::Runtime>() -> tauri_specta::Builder<R> {
+fn make_specta_builder<R: tauri::Runtime>() -> tauri_specta::Builder<R> 
+where
+    R: tauri::Runtime + 'static,
+{
     tauri_specta::Builder::<R>::new()
         .plugin_name(PLUGIN_NAME)
         .commands(tauri_specta::collect_commands![
-            commands::start_meeting_automation::<tauri::Wry>,
-            commands::stop_meeting_automation::<tauri::Wry>,
-            commands::get_automation_status::<tauri::Wry>,
-            commands::configure_automation::<tauri::Wry>,
-            commands::get_automation_config::<tauri::Wry>,
-            commands::test_meeting_detection::<tauri::Wry>,
+            commands::start_meeting_automation::<R>,
+            commands::stop_meeting_automation::<R>,
+            commands::get_automation_status::<R>,
+            commands::configure_automation::<R>,
+            commands::get_automation_config::<R>,
+            commands::test_meeting_detection::<R>,
         ])
         .error_handling(tauri_specta::ErrorHandlingMode::Throw)
 }

69-80: Add assertion to verify export success.

The test generates TypeScript bindings but doesn't verify the operation succeeded.

 #[test]
 fn export_types() {
-    make_specta_builder::<tauri::Wry>()
+    let result = make_specta_builder::<tauri::Wry>()
         .export(
             specta_typescript::Typescript::default()
                 .header("// @ts-nocheck\n\n")
                 .formatter(specta_typescript::formatter::prettier)
                 .bigint(specta_typescript::BigIntExportBehavior::Number),
             "./js/bindings.gen.ts",
-        )
-        .unwrap()
+        );
+    assert!(result.is_ok(), "Failed to export TypeScript types");
 }
plugins/meeting-automation/src/automation.rs (1)

382-409: Document platform-specific behavior.

Window focus detection is only implemented for macOS. Consider documenting this limitation in the plugin documentation and configuration.

Add a comment at the function level:

+    /// Gets the bundle identifier of the currently focused application.
+    /// 
+    /// # Platform Support
+    /// - macOS: Fully supported using AppleScript
+    /// - Windows/Linux: Not implemented, returns an error
     async fn get_focused_app() -> Result<String> {
plugins/meeting-automation/src/ext.rs (1)

90-107: Release mutex before blocking operation.

Similar to start_meeting_automation, this holds a mutex while blocking.

 fn get_automation_config(&self) -> Result<AutomationConfig> {
     let config_manager = {
         let state = self.state::<ManagedState<R>>();
         let state = state.lock().unwrap();

         state
             .config_manager
             .as_ref()
             .ok_or_else(|| {
                 crate::Error::ConfigurationError("Config manager not initialized".to_string())
             })?
             .clone()
-    };
+    }?;

     tokio::task::block_in_place(|| {
         tokio::runtime::Handle::current().block_on(async { config_manager.get_config().await })
     })
 }
plugins/meeting-automation/src/storage.rs (2)

31-33: Verify directory path before creation.

The code creates directories without checking if the path already exists as a file.

-std::fs::create_dir_all(&app_data_dir).map_err(|e| {
-    crate::Error::ConfigurationError(format!("Failed to create config directory: {}", e))
-})?;
+if app_data_dir.exists() && !app_data_dir.is_dir() {
+    return Err(crate::Error::ConfigurationError(
+        format!("Config path exists but is not a directory: {}", app_data_dir.display())
+    ));
+}
+std::fs::create_dir_all(&app_data_dir).map_err(|e| {
+    crate::Error::ConfigurationError(format!("Failed to create config directory: {}", e))
+})?;

113-128: Potential race condition when loading configuration.

Dropping the read lock before acquiring the write lock could allow multiple threads to simultaneously load the configuration from disk.

Consider using a double-checked locking pattern or accepting the race condition with a comment:

 pub async fn get_config(&self) -> Result<AutomationConfig> {
     let cached = self.cached_config.read().await;

     if let Some(config) = cached.as_ref() {
         debug!("Returning cached config");
         return Ok(config.clone());
     }

     drop(cached);

+    // Note: Multiple tasks might load config simultaneously here.
+    // This is acceptable as they'll all load the same data.
     let config = self.storage.load_config()?;
     let mut cached = self.cached_config.write().await;
     *cached = Some(config.clone());

     Ok(config)
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b712996 and 2e8e172.

⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (24)
  • Cargo.toml (1 hunks)
  • apps/desktop/package.json (1 hunks)
  • apps/desktop/src-tauri/Cargo.toml (1 hunks)
  • apps/desktop/src-tauri/src/lib.rs (1 hunks)
  • apps/desktop/src/locales/en/messages.po (18 hunks)
  • apps/desktop/src/locales/ko/messages.po (18 hunks)
  • crates/db-user/src/events_ops.rs (1 hunks)
  • crates/detect/src/app/macos.rs (2 hunks)
  • crates/detect/src/lib.rs (2 hunks)
  • crates/detect/src/mic/macos.rs (5 hunks)
  • plugins/listener/js/bindings.gen.ts (1 hunks)
  • plugins/meeting-automation/Cargo.toml (1 hunks)
  • plugins/meeting-automation/build.rs (1 hunks)
  • plugins/meeting-automation/js/bindings.gen.ts (1 hunks)
  • plugins/meeting-automation/js/index.ts (1 hunks)
  • plugins/meeting-automation/package.json (1 hunks)
  • plugins/meeting-automation/src/automation.rs (1 hunks)
  • plugins/meeting-automation/src/commands.rs (1 hunks)
  • plugins/meeting-automation/src/config.rs (1 hunks)
  • plugins/meeting-automation/src/error.rs (1 hunks)
  • plugins/meeting-automation/src/ext.rs (1 hunks)
  • plugins/meeting-automation/src/lib.rs (1 hunks)
  • plugins/meeting-automation/src/storage.rs (1 hunks)
  • plugins/meeting-automation/tsconfig.json (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,ts,tsx,rs}

Instructions used from:

Sources:
⚙️ CodeRabbit Configuration File

🧬 Code Graph Analysis (2)
plugins/listener/js/bindings.gen.ts (2)
plugins/local-stt/js/bindings.gen.ts (1)
  • events (54-58)
plugins/windows/js/bindings.gen.ts (1)
  • events (57-65)
plugins/meeting-automation/src/commands.rs (2)
plugins/meeting-automation/js/bindings.gen.ts (1)
  • AutomationConfig (47-57)
plugins/meeting-automation/src/ext.rs (12)
  • start_meeting_automation (7-7)
  • start_meeting_automation (16-45)
  • stop_meeting_automation (8-8)
  • stop_meeting_automation (47-58)
  • get_automation_status (9-9)
  • get_automation_status (60-65)
  • configure_automation (10-10)
  • configure_automation (67-88)
  • get_automation_config (11-11)
  • get_automation_config (90-107)
  • test_meeting_detection (12-12)
  • test_meeting_detection (109-140)
🔇 Additional comments (19)
apps/desktop/src/locales/ko/messages.po (1)

254-262: LGTM: Localization metadata updates reflect code reorganization.

The line number updates are expected when source code is reorganized during plugin integration. The added comment at line 254 provides helpful context for the placeholder condition.

apps/desktop/package.json (1)

38-38: LGTM: Workspace dependency addition follows established pattern.

The meeting automation plugin dependency is correctly added and follows the same workspace pattern as other plugins in the project.

plugins/meeting-automation/package.json (1)

1-6: LGTM: Standard package.json structure for TypeScript plugin.

The minimal package.json follows standard conventions. Having both main and types point to the same TypeScript file is appropriate for this plugin structure.

apps/desktop/src-tauri/src/lib.rs (1)

98-98: LGTM: Plugin registration follows Tauri best practices.

The meeting automation plugin is correctly integrated into the Tauri plugin builder chain using the standard initialization pattern.

plugins/meeting-automation/build.rs (1)

1-3: LGTM: Standard build script pattern.

The build script correctly instructs Cargo to rerun when source files change, which is essential for plugin development and follows standard Rust practices.

Cargo.toml (1)

95-95: LGTM! Plugin dependency addition follows established patterns.

The workspace dependency is correctly added and follows the same pattern as other plugin dependencies in the file.

apps/desktop/src-tauri/Cargo.toml (1)

40-40: LGTM! Plugin dependency correctly added.

The dependency addition follows the established pattern and properly references the workspace dependency.

plugins/meeting-automation/tsconfig.json (1)

1-9: LGTM! Standard TypeScript configuration.

The TypeScript configuration is well-structured and follows standard conventions for a plugin with TypeScript bindings.

apps/desktop/src/locales/en/messages.po (1)

254-262: LGTM! Localization metadata updates are correctly maintained.

The line number updates and added placeholder comments properly maintain translation references after code changes.

crates/detect/src/lib.rs (1)

28-31: LGTM! Detector fields reactivated correctly

The app_detector and browser_detector fields and their corresponding lifecycle methods follow the same pattern as mic_detector. The implementation is consistent and properly integrated.

Also applies to: 66-68, 72-74

plugins/meeting-automation/js/index.ts (1)

1-17: LGTM! Clean event interface definition

The module properly re-exports generated bindings and defines a clear event interface for meeting automation events. The event types and their properties are well-structured.

crates/detect/src/app/macos.rs (1)

7-28: Comprehensive app coverage for meeting detection

Good expansion of the meeting app list to cover popular communication and meeting platforms. The additions include major platforms like Chrome, Safari, Discord, Slack, and various meeting-specific applications.

crates/detect/src/mic/macos.rs (2)

31-31: Excellent implementation of microphone state tracking

The state tracking mechanism is well-designed:

  • Thread-safe state management using Arc<Mutex<bool>>
  • Clean state transition detection logic
  • Proper emission of both start and stop events
  • Guards against race conditions with mutex locks

This enhancement enables accurate microphone lifecycle tracking for the meeting automation feature.

Also applies to: 35-35, 48-48, 52-52, 65-82


141-145: Consistent tuple type updates for the new state field

The tuple types in Box allocations and unsafe casts have been correctly updated to include the new mic_state field, maintaining type safety throughout the callback system.

Also applies to: 209-213

plugins/meeting-automation/src/error.rs (1)

1-35: Well-structured error handling module!

The error types comprehensively cover the various failure scenarios in the meeting automation plugin. Good use of the thiserror crate for automatic error trait implementation.

plugins/meeting-automation/Cargo.toml (1)

1-27: LGTM!

The Cargo manifest is properly configured with appropriate dependencies for the meeting automation plugin.

plugins/meeting-automation/js/bindings.gen.ts (1)

1-126: Auto-generated bindings look correct.

The TypeScript bindings properly reflect the Rust command interface. Since this is generated code, any issues should be addressed in the source Rust files.

plugins/meeting-automation/src/ext.rs (1)

47-58: LGTM!

The stop method correctly takes ownership of the automation before stopping it, preventing any race conditions.

plugins/meeting-automation/src/config.rs (1)

1-189: Well-structured configuration module!

The configuration types are properly organized with sensible defaults, comprehensive app support, and efficient helper methods.

@plyght plyght changed the title listening autodetect listening autodetect (backend only Jul 14, 2025
@plyght plyght changed the title listening autodetect (backend only listening autodetect (backend only) Jul 14, 2025
@plyght plyght changed the title listening autodetect (backend only) listening autodetect Jul 15, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9d91ea1 and 0bae1be.

📒 Files selected for processing (4)
  • apps/desktop/src/components/settings/views/notifications.tsx (2 hunks)
  • apps/desktop/src/locales/en/messages.po (23 hunks)
  • apps/desktop/src/locales/ko/messages.po (23 hunks)
  • apps/desktop/src/routes/app.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/desktop/src/locales/ko/messages.po
  • apps/desktop/src/locales/en/messages.po
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,ts,tsx,rs}

Instructions used from:

Sources:
⚙️ CodeRabbit Configuration File

🧬 Code Graph Analysis (1)
apps/desktop/src/routes/app.tsx (1)
packages/ui/src/components/ui/toast.tsx (1)
  • sonnerToast (6-6)

@plyght
Copy link
Collaborator Author

plyght commented Jul 19, 2025

@coderabbitai review

Copy link

coderabbitai bot commented Jul 19, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant