Files
openhuman/docs/src-tauri/02-commands.md
T
M3gA-Mind 632ecc05b7 Add comprehensive documentation for application architecture, state management, services layer, MCP system, pages and routing, components, and providers
- Introduced detailed architecture overview outlining system components and entry points.
- Documented state management using Redux Toolkit and Redux-Persist, including store configuration and slice structures.
- Described services layer architecture, detailing API client, socket service, and MTProto service functionalities.
- Explained the Model Context Protocol (MCP) system, including tool categories and implementation examples.
- Outlined routing structure and page components, emphasizing protected and public routes.
- Organized reusable components by feature, detailing their structure and usage.
- Provided insights into provider management for service lifecycle and shared state.

This documentation enhances understanding of the application's structure and improves onboarding for new developers, ensuring clarity in the system's design and functionality.
2026-01-29 21:21:07 +05:30

5.6 KiB

Tauri Commands Reference

This document lists all Tauri commands available to the frontend.

Authentication Commands

exchange_token

Exchange a login token for a session token.

const result = await invoke('exchange_token', {
  backendUrl: 'https://api.example.com',
  token: 'login-token-from-deep-link'
});
// Returns: { sessionToken: string, user: User }

get_auth_state

Get current authentication state.

const state = await invoke<AuthState>('get_auth_state');
// Returns: { is_authenticated: boolean, user: User | null }

get_session_token

Get the current session token.

const token = await invoke<string | null>('get_session_token');

get_current_user

Get the current authenticated user.

const user = await invoke<User | null>('get_current_user');

is_authenticated

Check if user is authenticated.

const isAuth = await invoke<boolean>('is_authenticated');

logout

Clear session and disconnect socket.

await invoke('logout');

store_session

Manually store a session (usually called automatically by exchange_token).

await invoke('store_session', {
  token: 'session-token',
  user: { id: '123', firstName: 'John' }
});

Socket Commands

socket_connect

Request frontend to connect to socket server.

await invoke('socket_connect', {
  backendUrl: 'https://api.example.com',
  token: 'session-token'
});
// Emits "socket:should_connect" event

socket_disconnect

Request frontend to disconnect from socket server.

await invoke('socket_disconnect');
// Emits "socket:should_disconnect" event

get_socket_state

Get current socket state.

const state = await invoke<SocketState>('get_socket_state');
// Returns: { status: 'connected' | 'disconnected' | ..., socket_id: string | null, error: string | null }

is_socket_connected

Check if socket is connected.

const isConnected = await invoke<boolean>('is_socket_connected');

report_socket_connected

Report that socket connected (called by frontend).

await invoke('report_socket_connected', { socketId: 'socket-id' });

report_socket_disconnected

Report that socket disconnected (called by frontend).

await invoke('report_socket_disconnected');

report_socket_error

Report socket error (called by frontend).

await invoke('report_socket_error', { error: 'Connection failed' });

update_socket_status

Update socket status (called by frontend).

await invoke('update_socket_status', {
  status: 'connected', // 'connected' | 'connecting' | 'disconnected' | 'reconnecting' | 'error'
  socketId: 'socket-id'
});

Telegram Commands

start_telegram_login

Open Telegram login widget in browser.

await invoke('start_telegram_login');
// Opens ${DEFAULT_BACKEND_URL}/auth/telegram-widget?redirect=outsourced://auth

start_telegram_login_with_url

Open Telegram login widget with custom backend URL.

await invoke('start_telegram_login_with_url', {
  backendUrl: 'https://custom-backend.com'
});

Window Commands

show_window

Show and focus the main window.

await invoke('show_window');

hide_window

Hide the main window.

await invoke('hide_window');

toggle_window

Toggle window visibility.

await invoke('toggle_window');

is_window_visible

Check if window is visible.

const isVisible = await invoke<boolean>('is_window_visible');

minimize_window

Minimize the window.

await invoke('minimize_window');

maximize_window

Maximize or unmaximize the window.

await invoke('maximize_window');

close_window

Close the window (minimizes to tray on macOS).

await invoke('close_window');

set_window_title

Set the window title.

await invoke('set_window_title', { title: 'New Title' });

Events (Rust → Frontend)

These events are emitted by Rust and can be listened to in the frontend:

Socket Events

Event Payload Description
socket:connected () Socket connected
socket:disconnected () Socket disconnected
socket:error string Socket error occurred
socket:message { event: string, data: any } Socket message received
socket:state_changed SocketState Socket state changed
socket:should_connect { backendUrl: string, token: string } Request to connect
socket:should_disconnect () Request to disconnect

Listening to Events

import { listen } from '@tauri-apps/api/event';

// Listen for socket connection request
await listen('socket:should_connect', (event) => {
  const { backendUrl, token } = event.payload;
  socketService.connect(backendUrl, token);
});

// Listen for state changes
await listen('socket:state_changed', (event) => {
  const state = event.payload as SocketState;
  dispatch(setSocketStatus(state.status));
});

Type Definitions

interface AuthState {
  is_authenticated: boolean;
  user: User | null;
}

interface User {
  id: string;
  firstName?: string;
  lastName?: string;
  username?: string;
  email?: string;
  telegramId?: string;
}

interface SocketState {
  status: 'connected' | 'connecting' | 'disconnected' | 'reconnecting' | 'error';
  socket_id: string | null;
  error?: string;
}

Previous: Architecture | Next: Services