Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions app/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ semver = "1"
log = "0.4"
env_logger = "0.11"

[target.'cfg(target_os = "macos")'.dependencies]
objc2-app-kit = "0.3.2"

[features]
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
Expand Down
19 changes: 9 additions & 10 deletions app/src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window (desktop only)",
"platforms": [
"linux",
"macOS",
"windows"
],
"windows": [
"main"
],
"description": "Capability for the main and overlay windows (desktop only)",
"platforms": ["linux", "macOS", "windows"],
"windows": ["main", "overlay"],
"permissions": [
"core:default",
"core:window:default",
"core:window:allow-hide",
"core:window:allow-show",
"core:window:allow-set-focus",
"core:window:allow-unminimize",
"core:window:allow-start-dragging",
"core:window:allow-set-always-on-top",
"core:event:default",
"deep-link:default",
"opener:default",
"allow-core-process"
]
}
}
82 changes: 81 additions & 1 deletion app/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ use std::sync::Mutex;
use tauri::{
menu::{Menu, MenuItem},
tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
AppHandle, Emitter, Manager, RunEvent,
AppHandle, Emitter, Manager, PhysicalPosition, RunEvent, WebviewWindow,
};
use tauri_plugin_global_shortcut::{GlobalShortcutExt, ShortcutState};

#[cfg(any(windows, target_os = "linux"))]
use tauri_plugin_deep_link::DeepLinkExt;

#[cfg(target_os = "macos")]
use objc2_app_kit::{NSStatusWindowLevel, NSWindow, NSWindowCollectionBehavior};

/// Tracks the currently registered dictation hotkey string so we can unregister it later.
struct DictationHotkeyState(Mutex<Vec<String>>);

Expand Down Expand Up @@ -53,6 +56,64 @@ fn core_rpc_url() -> String {
.unwrap_or_else(|_| "http://127.0.0.1:7788/rpc".to_string())
}

#[tauri::command]
fn overlay_parent_rpc_url() -> Option<String> {
let url = std::env::var("OPENHUMAN_CORE_RPC_URL").ok()?;
let trimmed = url.trim();
if trimmed.is_empty() {
return None;
}
Some(trimmed.to_string())
}

fn pin_overlay_bottom_right(window: &WebviewWindow) {
let Ok(Some(monitor)) = window.current_monitor() else {
log::warn!("[overlay] could not resolve current monitor for positioning");
return;
};
let Ok(size) = window.outer_size() else {
log::warn!("[overlay] could not resolve overlay size for positioning");
return;
};

let margin = 20i32;
let x = monitor.position().x + monitor.size().width as i32 - size.width as i32 - margin;
let y = monitor.position().y + monitor.size().height as i32 - size.height as i32 - margin;

if let Err(err) = window.set_position(PhysicalPosition::new(x, y)) {
log::warn!("[overlay] failed to pin overlay bottom-right: {err}");
} else {
log::info!("[overlay] pinned overlay bottom-right at {},{}", x, y);
}
}

#[cfg(target_os = "macos")]
fn configure_overlay_window_macos(window: &WebviewWindow) {
if let Err(err) = window.set_always_on_top(true) {
log::warn!("[overlay] failed to set always-on-top: {err}");
}
if let Err(err) = window.set_visible_on_all_workspaces(true) {
log::warn!("[overlay] failed to set visible-on-all-workspaces: {err}");
}

match window.ns_window() {
Ok(ns_window) => unsafe {
let window: &NSWindow = &*ns_window.cast();
let mut behavior = window.collectionBehavior();
behavior.insert(NSWindowCollectionBehavior::FullScreenAuxiliary);
behavior.insert(NSWindowCollectionBehavior::CanJoinAllSpaces);
window.setCollectionBehavior(behavior);
window.setLevel(NSStatusWindowLevel);
log::info!(
"[overlay] macOS overlay configured for all spaces/fullscreen auxiliary at status level"
);
},
Err(err) => {
log::warn!("[overlay] failed to access native NSWindow handle: {err}");
}
}
}

/// Resolve the core binary, preferring the staged sidecar.
fn resolve_core_bin() -> Result<std::path::PathBuf, String> {
if let Some(bin) = core_process::default_core_bin() {
Expand Down Expand Up @@ -410,6 +471,24 @@ pub fn run() {
}
}

#[cfg(target_os = "macos")]
{
if let Some(window) = app.get_webview_window("overlay") {
configure_overlay_window_macos(&window);
} else {
log::warn!("[overlay] overlay window not found during setup");
}
}

if let Some(window) = app.get_webview_window("overlay") {
pin_overlay_bottom_right(&window);
if let Err(err) = window.show() {
log::warn!("[overlay] failed to show overlay on startup: {err}");
} else {
log::info!("[overlay] overlay shown on startup");
}
}

if let Err(err) = setup_tray(app.handle()) {
log::error!("[tray] failed to setup tray icon: {err}");
}
Expand All @@ -418,6 +497,7 @@ pub fn run() {
})
.invoke_handler(tauri::generate_handler![
core_rpc_url,
overlay_parent_rpc_url,
check_core_update,
apply_core_update,
restart_core_process,
Expand Down
48 changes: 21 additions & 27 deletions app/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,43 @@
"decorations": true,
"resizable": true,
"center": true
},
{
"label": "overlay",
"title": "OpenHuman Overlay",
"width": 248,
"height": 228,
"minWidth": 248,
"minHeight": 228,
"transparent": true,
"decorations": false,
"alwaysOnTop": true,
"skipTaskbar": true,
"resizable": false,
"visible": true,
"center": false
}
],
"security": {
"csp": null
},
"security": { "csp": null },
"macOSPrivateApi": true
},
"bundle": {
"active": true,
"targets": [
"app",
"dmg",
"deb",
"nsis",
"msi",
"appimage"
],
"targets": ["app", "dmg", "deb", "nsis", "msi", "appimage"],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"resources": [
"../../src/openhuman/agent/prompts"
],
"externalBin": [
"binaries/openhuman-core"
],
"resources": ["../../src/openhuman/agent/prompts"],
"externalBin": ["binaries/openhuman-core"],
"createUpdaterArtifacts": false,
"macOS": {
"minimumSystemVersion": "10.15",
"entitlements": "entitlements.sidecar.plist",
"dmg": {
"background": "./images/background-dmg.png"
}
"dmg": { "background": "./images/background-dmg.png" }
}
},
"plugins": {
Expand All @@ -67,12 +67,6 @@
"https://github.com/tinyhumansai/openhuman/releases/latest/download/latest.json"
]
},
"deep-link": {
"desktop": {
"schemes": [
"openhuman"
]
}
}
"deep-link": { "desktop": { "schemes": ["openhuman"] } }
}
}
Loading
Loading