{action &&
{action}
}
diff --git a/frontend/src/hooks/useSSE.ts b/frontend/src/hooks/useSSE.ts
index 98477205..37c76262 100644
--- a/frontend/src/hooks/useSSE.ts
+++ b/frontend/src/hooks/useSSE.ts
@@ -3,10 +3,73 @@ import { useQueryClient } from '@tanstack/react-query'
import { useOpenCodeClient } from './useOpenCode'
import type { SSEEvent, MessageListResponse } from '@/api/types'
import { permissionEvents } from './usePermissionRequests'
+import { showToast } from '@/lib/toast'
+import { settingsApi } from '@/api/settings'
const MAX_RECONNECT_DELAY = 30000
const INITIAL_RECONNECT_DELAY = 1000
+const handleRestartServer = async () => {
+ showToast.loading('Restarting OpenCode server...', {
+ id: 'restart-server',
+ })
+
+ try {
+ const result = await settingsApi.restartOpenCodeServer()
+ if (result.success) {
+ showToast.success(result.message || 'OpenCode server restarted successfully', {
+ id: 'restart-server',
+ duration: 3000,
+ })
+ setTimeout(() => {
+ window.location.reload()
+ }, 2000)
+ } else {
+ showToast.error(result.message || 'Failed to restart OpenCode server', {
+ id: 'restart-server',
+ duration: 5000,
+ })
+ }
+ } catch (error) {
+ showToast.error(error instanceof Error ? error.message : 'Failed to restart OpenCode server', {
+ id: 'restart-server',
+ duration: 5000,
+ })
+ }
+}
+
+// Debug function to emulate toasts - remove in production
+if (typeof window !== 'undefined') {
+ (window as any).testToasts = {
+ updateAvailable: () => {
+ showToast.info(`OpenCode v1.2.3 is available`, {
+ description: 'A new version is ready to install.',
+ action: {
+ label: 'Restart to Update',
+ onClick: handleRestartServer
+ },
+ duration: 10000,
+ })
+ },
+ updated: () => {
+ showToast.success(`OpenCode updated to v1.2.3`, {
+ description: 'The server has been successfully upgraded.',
+ duration: 5000,
+ })
+ },
+ restartTest: () => {
+ handleRestartServer()
+ },
+ basic: () => {
+ showToast.info('This is a basic info toast')
+ showToast.success('This is a success toast')
+ showToast.warning('This is a warning toast')
+ showToast.error('This is an error toast')
+ }
+ }
+ console.log('🍞 Toast test functions available: window.testToasts.updateAvailable(), window.testToasts.updated(), window.testToasts.restartTest(), window.testToasts.basic()')
+}
+
export const useSSE = (opcodeUrl: string | null | undefined, directory?: string) => {
const client = useOpenCodeClient(opcodeUrl, directory)
const queryClient = useQueryClient()
@@ -228,6 +291,28 @@ export const useSSE = (opcodeUrl: string | null | undefined, directory?: string)
}
break
+ case 'installation.updated':
+ if ('version' in event.properties) {
+ showToast.success(`OpenCode updated to v${event.properties.version}`, {
+ description: 'The server has been successfully upgraded.',
+ duration: 5000,
+ })
+ }
+ break
+
+ case 'installation.update-available':
+ if ('version' in event.properties) {
+ showToast.info(`OpenCode v${event.properties.version} is available`, {
+ description: 'A new version is ready to install.',
+ action: {
+ label: 'Restart to Update',
+ onClick: handleRestartServer
+ },
+ duration: 10000,
+ })
+ }
+ break
+
default:
break
}
diff --git a/frontend/src/hooks/useTheme.ts b/frontend/src/hooks/useTheme.ts
index 1f7128c0..f152d73a 100644
--- a/frontend/src/hooks/useTheme.ts
+++ b/frontend/src/hooks/useTheme.ts
@@ -1,8 +1,9 @@
-import { useEffect } from 'react'
+import { useEffect, useState } from 'react'
import { useSettings } from './useSettings'
export function useTheme() {
const { preferences } = useSettings()
+ const [currentTheme, setCurrentTheme] = useState<'light' | 'dark'>('dark')
useEffect(() => {
const theme = preferences?.theme || 'dark'
@@ -11,8 +12,10 @@ export function useTheme() {
const applyTheme = (isDark: boolean) => {
if (isDark) {
root.classList.add('dark')
+ setCurrentTheme('dark')
} else {
root.classList.remove('dark')
+ setCurrentTheme('light')
}
}
@@ -27,4 +30,6 @@ export function useTheme() {
applyTheme(theme === 'dark')
}
}, [preferences?.theme])
+
+ return currentTheme
}
diff --git a/frontend/src/lib/toast.ts b/frontend/src/lib/toast.ts
new file mode 100644
index 00000000..4ffb5ca3
--- /dev/null
+++ b/frontend/src/lib/toast.ts
@@ -0,0 +1,39 @@
+import { toast } from 'sonner'
+
+interface ToastOptions {
+ duration?: number
+ description?: string
+ action?: {
+ label: string
+ onClick: () => void
+ }
+ id?: string | number
+}
+
+export const showToast = {
+ success: (message: string, options?: ToastOptions) => {
+ return toast.success(message, options)
+ },
+
+ error: (message: string, options?: ToastOptions) => {
+ return toast.error(message, options)
+ },
+
+ info: (message: string, options?: ToastOptions) => {
+ return toast.info(message, options)
+ },
+
+ warning: (message: string, options?: ToastOptions) => {
+ return toast.warning(message, options)
+ },
+
+ loading: (message: string, options?: ToastOptions) => {
+ return toast.loading(message, options)
+ },
+
+ dismiss: (id?: string | number) => {
+ toast.dismiss(id)
+ }
+}
+
+export type ShowToast = typeof showToast
\ No newline at end of file