Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

Add platform guards for macOS-specific tauri_nspanel code

Louis Beaumonte42f1a9a0d27
diff --git a/screenpipe-app-tauri/src-tauri/src/main.rs b/screenpipe-app-tauri/src-tauri/src/main.rs
index b7398fb6c..f86e6efc0 100755
--- a/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -5,6 +5,7 @@ use analytics::AnalyticsManager;
use commands::show_main_window;
use serde_json::json;
use serde_json::Value;
+#[cfg(target_os = "macos")]
use tauri_nspanel::ManagerExt;
use std::env;
use std::fs::File;
@@ -175,21 +176,43 @@ async fn apply_shortcuts(app: &AppHandle, config: &ShortcutConfig) -> Result<(),
// Register show shortcut
register_shortcut(app, &config.show, config.is_disabled("show"), |app| {
info!("show shortcut triggered");
- if let Ok(window) = app.get_webview_panel("main") {
- match window.is_visible() {
- true => {
- info!("window is visible, hiding main window");
- hide_main_window(app)
+ #[cfg(target_os = "macos")]
+ {
+ if let Ok(window) = app.get_webview_panel("main") {
+ match window.is_visible() {
+ true => {
+ info!("window is visible, hiding main window");
+ hide_main_window(app)
+ }
+ false => {
+ info!(
+ "window is not visible or error checking visibility, showing main window"
+ );
+ show_main_window(app, false)
+ }
}
- false => {
- info!(
- "window is not visible or error checking visibility, showing main window"
- );
- show_main_window(app, false)
+ } else {
+ debug!("main window not found");
+ }
+ }
+ #[cfg(not(target_os = "macos"))]
+ {
+ if let Some(window) = app.get_webview_window("main") {
+ match window.is_visible() {
+ Ok(true) => {
+ info!("window is visible, hiding main window");
+ hide_main_window(app)
+ }
+ _ => {
+ info!(
+ "window is not visible or error checking visibility, showing main window"
+ );
+ show_main_window(app, false)
+ }
}
+ } else {
+ debug!("main window not found");
}
- } else {
- debug!("main window not found");
}
})
.await?;
@@ -696,9 +719,12 @@ async fn main() {
}))
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
- .plugin(tauri_plugin_sentry::init(&sentry_guard))
- .plugin(tauri_nspanel::init())
- .manage(sidecar_state)
+ .plugin(tauri_plugin_sentry::init(&sentry_guard));
+
+ #[cfg(target_os = "macos")]
+ let app = app.plugin(tauri_nspanel::init());
+
+ let app = app.manage(sidecar_state)
.invoke_handler(tauri::generate_handler![
spawn_screenpipe,
stop_screenpipe,
diff --git a/screenpipe-app-tauri/src-tauri/src/window_api.rs b/screenpipe-app-tauri/src-tauri/src/window_api.rs
index c1fbfbf4e..0070d5cb9 100644
--- a/screenpipe-app-tauri/src-tauri/src/window_api.rs
+++ b/screenpipe-app-tauri/src-tauri/src/window_api.rs
@@ -3,6 +3,7 @@ use std::{path::PathBuf, str::FromStr};
use axum::{extract::State, http::StatusCode, Json};
use serde::{Deserialize, Serialize};
use tauri::{AppHandle, Emitter, LogicalSize, Manager, Size, WebviewUrl, WebviewWindow, WebviewWindowBuilder, Wry};
+#[cfg(target_os = "macos")]
use tauri_nspanel::ManagerExt;
use tracing::{error, info};
#[cfg(target_os = "macos")]
@@ -285,13 +286,19 @@ impl ShowRewindWindow {
if id.label() == RewindWindowId::Main.label() {
info!("showing panel");
- let app_clone = app.clone();
-
- app.run_on_main_thread(move || {
- if let Ok(panel) = app_clone.get_webview_panel(RewindWindowId::Main.label()) {
- panel.show();
- }
- }).ok();
+ #[cfg(target_os = "macos")]
+ {
+ let app_clone = app.clone();
+ app.run_on_main_thread(move || {
+ if let Ok(panel) = app_clone.get_webview_panel(RewindWindowId::Main.label()) {
+ panel.show();
+ }
+ }).ok();
+ }
+ #[cfg(not(target_os = "macos"))]
+ {
+ window.show().ok();
+ }
return Ok(window);
}
@@ -328,8 +335,12 @@ impl ShowRewindWindow {
let monitor = app.primary_monitor().unwrap().unwrap();
let logical_size = monitor.size().to_logical(monitor.scale_factor());
- let builder = self.window_builder(app, "/")
- .hidden_title(true)
+ let mut builder = self.window_builder(app, "/");
+ #[cfg(target_os = "macos")]
+ {
+ builder = builder.hidden_title(true);
+ }
+ let builder = builder
.visible_on_all_workspaces(true)
.always_on_top(true)
.decorations(false)
@@ -419,7 +430,12 @@ impl ShowRewindWindow {
window
}
ShowRewindWindow::Settings { page: _ } => {
- let builder = self.window_builder(app, "/settings").hidden_title(true).focused(true);
+ let mut builder = self.window_builder(app, "/settings");
+ #[cfg(target_os = "macos")]
+ {
+ builder = builder.hidden_title(true);
+ }
+ let builder = builder.focused(true);
let window = builder.build()?;
window
}
@@ -431,7 +447,12 @@ impl ShowRewindWindow {
// let encoded_query = q.replace(' ', "%20").replace('#', "%23").replace('&', "%26");
url.push_str(&format!("{}", q));
}
- let builder = self.window_builder(app, url).hidden_title(true).focused(true);
+ let mut builder = self.window_builder(app, url);
+ #[cfg(target_os = "macos")]
+ {
+ builder = builder.hidden_title(true);
+ }
+ let builder = builder.focused(true);
let window = builder.build()?;
window