mirror of
https://github.com/haexhub/haex-hub.git
synced 2025-12-17 22:40:51 +01:00
- Split extensionMessageHandler into separate handler files - Created handlers directory with individual files for database, filesystem, http, permissions, context, and storage - Reduced main handler file from 602 to 342 lines - Improved code organization and maintainability - Add viewport utilities for safe area handling - New viewport.ts utility with helpers for fullscreen dimensions - Proper safe area inset calculations for mobile devices - Fixed window positioning on small screens to start at 0,0 - Create UiDrawer wrapper component - Automatically applies safe area insets - Uses TypeScript DrawerProps interface for code completion - Replaced all UDrawer instances with UiDrawer - Improve window management - Windows on small screens now use full viewport with safe areas - Fixed maximize functionality to respect safe areas - Consolidated safe area logic in reusable utilities
85 lines
2.2 KiB
TypeScript
85 lines
2.2 KiB
TypeScript
import { invoke } from '@tauri-apps/api/core'
|
|
import type { IHaexHubExtension } from '~/types/haexhub'
|
|
import type { ExtensionRequest } from './types'
|
|
|
|
export async function handleDatabaseMethodAsync(
|
|
request: ExtensionRequest,
|
|
extension: IHaexHubExtension,
|
|
) {
|
|
const params = request.params as {
|
|
query?: string
|
|
params?: unknown[]
|
|
}
|
|
|
|
switch (request.method) {
|
|
case 'haextension.db.query': {
|
|
try {
|
|
const rows = await invoke<unknown[]>('extension_sql_select', {
|
|
sql: params.query || '',
|
|
params: params.params || [],
|
|
publicKey: extension.publicKey,
|
|
name: extension.name,
|
|
})
|
|
|
|
return {
|
|
rows,
|
|
rowsAffected: 0,
|
|
lastInsertId: undefined,
|
|
}
|
|
} catch (error) {
|
|
// If error is about non-SELECT statements (INSERT/UPDATE/DELETE with RETURNING),
|
|
// automatically retry with execute
|
|
if (error?.message?.includes('Only SELECT statements are allowed')) {
|
|
const rows = await invoke<unknown[]>('extension_sql_execute', {
|
|
sql: params.query || '',
|
|
params: params.params || [],
|
|
publicKey: extension.publicKey,
|
|
name: extension.name,
|
|
})
|
|
|
|
return {
|
|
rows,
|
|
rowsAffected: rows.length,
|
|
lastInsertId: undefined,
|
|
}
|
|
}
|
|
throw error
|
|
}
|
|
}
|
|
|
|
case 'haextension.db.execute': {
|
|
const rows = await invoke<unknown[]>('extension_sql_execute', {
|
|
sql: params.query || '',
|
|
params: params.params || [],
|
|
publicKey: extension.publicKey,
|
|
name: extension.name,
|
|
})
|
|
|
|
return {
|
|
rows,
|
|
rowsAffected: 1,
|
|
lastInsertId: undefined,
|
|
}
|
|
}
|
|
|
|
case 'haextension.db.transaction': {
|
|
const statements =
|
|
(request.params as { statements?: string[] }).statements || []
|
|
|
|
for (const stmt of statements) {
|
|
await invoke('extension_sql_execute', {
|
|
sql: stmt,
|
|
params: [],
|
|
publicKey: extension.publicKey,
|
|
name: extension.name,
|
|
})
|
|
}
|
|
|
|
return { success: true }
|
|
}
|
|
|
|
default:
|
|
throw new Error(`Unknown database method: ${request.method}`)
|
|
}
|
|
}
|