Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | import { invoke } from '@tauri-apps/api/core'; export interface LocalGatewayStatus { supported: boolean; cliAvailable: boolean; runtimeSource: string | null; runtimePath: string | null; serviceLabel: string | null; serviceLoaded: boolean; serviceStatus: string | null; configOk: boolean; port: number | null; portStatus: string | null; probeUrl: string | null; listenerPids: number[]; error: string | null; raw: Record<string, unknown>; } export interface LocalGatewayAuth { configPath: string | null; gatewayToken: string | null; } export interface LocalGatewayPrepareResult { configPath: string | null; originsUpdated: boolean; gatewayRestarted: boolean; } export interface LocalGatewayPairingApprovalResult { approved: boolean; requestId: string | null; deviceId: string | null; } function buildFallbackStatus(supported: boolean, error: string | null = null): LocalGatewayStatus { return { supported, cliAvailable: false, runtimeSource: null, runtimePath: null, serviceLabel: null, serviceLoaded: false, serviceStatus: null, configOk: false, port: null, portStatus: null, probeUrl: null, listenerPids: [], error, raw: {}, }; } export function isTauriRuntime(): boolean { return typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window; } async function callLocalGateway(command: string): Promise<LocalGatewayStatus> { if (!isTauriRuntime()) { return buildFallbackStatus(false); } return invoke<LocalGatewayStatus>(command); } export function getUnsupportedLocalGatewayStatus(): LocalGatewayStatus { return buildFallbackStatus(false); } export async function getLocalGatewayStatus(): Promise<LocalGatewayStatus> { return callLocalGateway('gateway_status'); } export async function startLocalGateway(): Promise<LocalGatewayStatus> { return callLocalGateway('gateway_start'); } export async function stopLocalGateway(): Promise<LocalGatewayStatus> { return callLocalGateway('gateway_stop'); } export async function restartLocalGateway(): Promise<LocalGatewayStatus> { return callLocalGateway('gateway_restart'); } export async function getLocalGatewayAuth(): Promise<LocalGatewayAuth> { if (!isTauriRuntime()) { return { configPath: null, gatewayToken: null, }; } return invoke<LocalGatewayAuth>('gateway_local_auth'); } export async function prepareLocalGatewayForTauri(): Promise<LocalGatewayPrepareResult> { if (!isTauriRuntime()) { return { configPath: null, originsUpdated: false, gatewayRestarted: false, }; } return invoke<LocalGatewayPrepareResult>('gateway_prepare_for_tauri'); } export async function approveLocalGatewayDevicePairing(deviceId: string, publicKeyBase64: string, url?: string): Promise<LocalGatewayPairingApprovalResult> { if (!isTauriRuntime()) { return { approved: false, requestId: null, deviceId: null, }; } return invoke<LocalGatewayPairingApprovalResult>('gateway_approve_device_pairing', { deviceId, publicKeyBase64, url, }); } // ============================================================================ // Process Monitoring Types and Functions // ============================================================================ export interface ProcessInfo { pid: number; name: string; status: string; cpuPercent: number | null; memoryMb: number | null; uptimeSeconds: number | null; } export interface ProcessListResponse { processes: ProcessInfo[]; totalCount: number; runtimeSource: string | null; } export interface ProcessLogsResponse { pid: number | null; logs: string; lines: number; runtimeSource: string | null; } export interface VersionResponse { version: string; commit: string | null; buildDate: string | null; runtimeSource: string | null; raw: Record<string, unknown>; } /** * List OpenFang processes * @returns List of running OpenFang processes with their status */ export async function getOpenFangProcessList(): Promise<ProcessListResponse> { if (!isTauriRuntime()) { return { processes: [], totalCount: 0, runtimeSource: null, }; } return invoke<ProcessListResponse>('openfang_process_list'); } /** * Get OpenFang process logs * @param pid - Optional process ID to get logs for. If not specified, gets main process logs. * @param lines - Number of log lines to retrieve (default: 100) * @returns Process logs */ export async function getOpenFangProcessLogs( pid?: number, lines?: number ): Promise<ProcessLogsResponse> { if (!isTauriRuntime()) { return { pid: pid ?? null, logs: '', lines: 0, runtimeSource: null, }; } return invoke<ProcessLogsResponse>('openfang_process_logs', { pid, lines, }); } /** * Get OpenFang version information * @returns Version information including version string, commit hash, and build date */ export async function getOpenFangVersion(): Promise<VersionResponse> { if (!isTauriRuntime()) { return { version: 'unknown', commit: null, buildDate: null, runtimeSource: null, raw: {}, }; } return invoke<VersionResponse>('openfang_version'); } |