import { invoke } from '@tauri-apps/api/tauri'; /** * Send a desktop notification * @param title Notification title * @param body Notification body text */ export async function sendNotification(title: string, body: string): Promise { try { await invoke('send_notification', { title, body }); } catch (error) { console.error('Failed to send notification:', error); } } /** * Truncate text to specified length with ellipsis */ export function truncateText(text: string, maxLength: number): string { if (text.length <= maxLength) return text; return text.substring(0, maxLength - 3) + '...'; } /** * Format notification body from message content * Strips markdown and limits length */ export function formatNotificationBody(content: string, maxLength: number = 100): string { // Remove markdown formatting let cleaned = content .replace(/```[\s\S]*?```/g, '[code block]') // Remove code blocks .replace(/`([^`]+)`/g, '$1') // Remove inline code .replace(/\*\*([^*]+)\*\*/g, '$1') // Remove bold .replace(/\*([^*]+)\*/g, '$1') // Remove italic .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') // Remove links .replace(/^#+\s+/gm, '') // Remove headers .replace(/^\s*[-*+]\s+/gm, '') // Remove list markers .replace(/^\s*>\s+/gm, '') // Remove blockquotes .replace(/\n+/g, ' ') // Replace newlines with spaces .trim(); return truncateText(cleaned, maxLength); }