Files
openhuman/src-tauri/src/lib.rs
T
Steven EnamakelandGitHub cd9ebcd927 Feat/skills advanced (#12)
* Update skills submodule and enhance skill management interface

- Updated the skills submodule to the latest commit, ensuring alignment with project dependencies.
- Refactored the SkillSetupModal to conditionally render either the SkillSetupWizard or SkillManagementPanel based on the skill's setup status, improving user experience.
- Introduced the SkillManagementPanel component to manage connected skills, allowing users to view connection status and configurable options.
- Enhanced the package-and-publish workflow by updating the release name for better clarity.

These changes improve the overall functionality and maintainability of the skill management system.

* Remove skills catalog JSON and refactor skills loading mechanism

- Deleted the `skills-catalog.json` file from the public directory, as it is no longer needed.
- Updated the `SkillsGrid` component to load the skills catalog directly from the local skills directory via Rust, improving the skills management process.
- Enhanced the `SkillProvider` to discover skills from the local directory and sync from GitHub if no local skills are found, streamlining the skill lifecycle management.

These changes improve the overall efficiency and maintainability of the skill management system.

* Update skills submodule and enhance skill management features

- Updated the skills submodule to the latest commit, ensuring alignment with project dependencies.
- Modified the `ConnectionIndicator` component's description for clarity.
- Refactored the `SkillsGrid` component to improve type definitions and streamline skill processing, including the addition of a `hasSetup` property for better skill management.
- Enhanced the `SkillManagementPanel` to conditionally render the "Re-run Setup" button based on the presence of setup hooks.
- Updated the `SkillSetupModal` to handle skills without setup hooks more effectively.
- Implemented a background update check in the `SkillProvider` to ensure skills are kept up to date with the latest changes from GitHub.

These changes improve the overall functionality and maintainability of the skill management system.

* Enhance skill management interface and update dependencies

- Added new CSS styles for the skills table, improving layout and user experience.
- Updated the SkillsGrid component to utilize new props and improve type definitions.
- Enhanced the SkillSetupModal to include skill descriptions for better context.
- Updated the Home component to include a call-to-action for upgrading to premium plans.
- Added new entries to .gitignore for mypy and ruff caches to streamline development.

These changes improve the overall functionality and maintainability of the skill management system.
2026-02-01 09:26:32 +05:30

256 lines
7.9 KiB
Rust

//! AlphaHuman Desktop Application
//!
//! This is the Rust backend for the cross-platform crypto community platform.
//! It provides:
//! - System tray with background execution
//! - Deep link authentication
//! - Persistent Socket.io connection
//! - Secure session storage
//! - Native notifications
mod ai;
mod commands;
mod models;
mod services;
mod utils;
use ai::*;
use commands::*;
use services::socket_service::SOCKET_SERVICE;
use tauri::{
menu::{Menu, MenuItem},
tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
AppHandle, Manager, RunEvent,
};
#[cfg(any(windows, target_os = "linux"))]
use tauri_plugin_deep_link::DeepLinkExt;
/// Demo command - can be removed in production
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}
// Helper function to show the window
fn show_main_window(app: &AppHandle) {
if let Some(window) = app.get_webview_window("main") {
let _ = window.show();
let _ = window.unminimize();
let _ = window.set_focus();
}
}
// Helper function to toggle window visibility
fn toggle_main_window_visibility(app: &AppHandle) {
if let Some(window) = app.get_webview_window("main") {
match window.is_visible() {
Ok(true) => {
let _ = window.hide();
}
Ok(false) => {
show_main_window(app);
}
Err(_) => {
// If we can't determine visibility, try to show it
show_main_window(app);
}
}
} else {
eprintln!("Could not find window 'main'");
}
}
// Setup system tray with menu
#[cfg(desktop)]
fn setup_tray(app: &AppHandle) -> Result<(), Box<dyn std::error::Error>> {
let show_hide_item =
MenuItem::with_id(app, "show_hide", "Show/Hide Window", true, None::<&str>)?;
let quit_item = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
let menu = Menu::with_items(app, &[&show_hide_item, &quit_item])?;
let _tray = TrayIconBuilder::with_id("main-tray")
.icon(app.default_window_icon().unwrap().clone())
.menu(&menu)
.tooltip("AlphaHuman")
.on_menu_event(move |app, event| match event.id().as_ref() {
"show_hide" => {
toggle_main_window_visibility(app);
}
"quit" => {
// Cleanup before exit - request frontend to disconnect
let _ = SOCKET_SERVICE.request_disconnect();
app.exit(0);
}
_ => {}
})
.on_tray_icon_event(|tray, event| match event {
TrayIconEvent::Click {
button: MouseButton::Left,
button_state: MouseButtonState::Up,
..
} => {
let app = tray.app_handle();
toggle_main_window_visibility(app);
}
TrayIconEvent::DoubleClick {
button: MouseButton::Left,
..
} => {
let app = tray.app_handle();
show_main_window(app);
}
_ => {}
})
.build(app)?;
Ok(())
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
let mut builder = tauri::Builder::default()
// Plugins
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_deep_link::init())
.plugin(tauri_plugin_autostart::init(
tauri_plugin_autostart::MacosLauncher::LaunchAgent,
Some(vec!["--minimized"]),
));
// Add notification plugin on desktop only
#[cfg(desktop)]
{
builder = builder.plugin(tauri_plugin_notification::init());
}
// Add shell plugin for subprocess skill runtime
builder = builder.plugin(tauri_plugin_shell::init());
builder
// Setup
.setup(|app| {
// Initialize socket service with app handle
SOCKET_SERVICE.set_app_handle(app.handle().clone());
// Register deep link handlers (Windows/Linux)
#[cfg(any(windows, target_os = "linux"))]
{
app.deep_link().register_all()?;
}
// Setup system tray (desktop only)
#[cfg(desktop)]
{
setup_tray(app.handle())?;
}
// macOS-specific: Handle window close event to minimize to tray
#[cfg(target_os = "macos")]
{
if let Some(window) = app.get_webview_window("main") {
let app_handle = app.handle().clone();
window.on_window_event(move |event| {
if let tauri::WindowEvent::CloseRequested { api, .. } = event {
// Prevent the window from closing, hide it instead
api.prevent_close();
if let Some(win) = app_handle.get_webview_window("main") {
let _ = win.hide();
}
}
});
}
}
Ok(())
})
// Register all commands
.invoke_handler(tauri::generate_handler![
// Demo
greet,
// Auth commands
exchange_token,
get_auth_state,
get_session_token,
get_current_user,
is_authenticated,
logout,
store_session,
// Socket commands
socket_connect,
socket_disconnect,
get_socket_state,
is_socket_connected,
report_socket_connected,
report_socket_disconnected,
report_socket_error,
update_socket_status,
// Telegram commands
start_telegram_login,
start_telegram_login_with_url,
// Window commands
show_window,
hide_window,
toggle_window,
is_window_visible,
minimize_window,
maximize_window,
close_window,
set_window_title,
// AI encryption commands
ai_init_encryption,
ai_encrypt,
ai_decrypt,
// AI memory filesystem commands
ai_memory_init,
ai_memory_upsert_file,
ai_memory_get_file,
ai_memory_upsert_chunk,
ai_memory_delete_chunks_by_path,
ai_memory_fts_search,
ai_memory_get_chunks,
ai_memory_get_all_embeddings,
ai_memory_cache_embedding,
ai_memory_get_cached_embedding,
ai_memory_set_meta,
ai_memory_get_meta,
// AI session commands
ai_sessions_init,
ai_sessions_load_index,
ai_sessions_update_index,
ai_sessions_append_transcript,
ai_sessions_read_transcript,
ai_sessions_delete,
ai_sessions_list,
ai_read_memory_file,
ai_write_memory_file,
ai_list_memory_files,
// Skill commands
skill_read_data,
skill_write_data,
skill_data_dir,
skill_list_manifests,
skill_cwd,
skill_venv_site_packages,
skill_read_catalog,
skill_sync_repo,
skill_catalog_exists,
skill_check_for_updates,
skill_read_icon,
])
.build(tauri::generate_context!())
.expect("error while building tauri application")
.run(|app_handle, event| {
// Handle macOS Dock icon click (reopen event)
#[cfg(target_os = "macos")]
if let RunEvent::Reopen { .. } = event {
show_main_window(app_handle);
}
// Suppress unused variable warning on non-macOS
#[cfg(not(target_os = "macos"))]
let _ = (app_handle, event);
});
}