diff --git a/src/components/settings/SettingsHome.tsx b/src/components/settings/SettingsHome.tsx index 5ee053717..1aac74ad2 100644 --- a/src/components/settings/SettingsHome.tsx +++ b/src/components/settings/SettingsHome.tsx @@ -1,18 +1,49 @@ -import { clearToken } from '../../store/authSlice'; -import { useAppDispatch } from '../../store/hooks'; +import { useState } from 'react'; import SettingsHeader from './components/SettingsHeader'; import SettingsMenuItem from './components/SettingsMenuItem'; import { useSettingsNavigation } from './hooks/useSettingsNavigation'; +import { persistor } from '../../store'; +import { skillManager } from '../../lib/skills/manager'; const SettingsHome = () => { - const dispatch = useAppDispatch(); - const { navigateToSettings, closeSettings } = useSettingsNavigation(); + const { navigateToSettings } = useSettingsNavigation(); + const [showLogoutAndClearModal, setShowLogoutAndClearModal] = useState(false); + const [isLoading, setIsLoading] = useState(false); + const [error, setError] = useState(null); const handleLogout = async () => { - await dispatch(clearToken()); - closeSettings(); + // Simple logout without clearing data - redirect to login + window.location.href = '/login'; }; + const clearAllAppData = async () => { + await persistor.purge(); + window.localStorage.clear(); + window.sessionStorage.clear(); + + // NEW: Clear skills databases (emails, chats, cached files) + try { + await skillManager.clearAllSkillsData(); + } catch (error) { + console.warn('Failed to clear skills data:', error); + // Continue with logout even if skills clearing fails + } + + // Complete reset - redirect to login for fresh start + window.location.href = '/login'; + } + + const handleLogoutAndClearData = async () => { + try { + setIsLoading(true); + setError(null); + await clearAllAppData(); // This will redirect to login + } catch (_error) { + setError('Failed to clear data and logout. Please try again.'); + setIsLoading(false); + } + } + // const handleViewEncryptionKey = () => { // // TODO: Show encryption key in a secure modal // console.log('View encryption key'); @@ -244,6 +275,18 @@ const SettingsHome = () => { onClick: handleDeleteAllData, dangerous: true, }, + { + id: 'logout-and-clear', + title: 'Log Out & Clear App Data', + description: 'Sign out and permanently clear all local data', + icon: ( + + + + ), + onClick: () => setShowLogoutAndClearModal(true), + dangerous: true + }, { id: 'logout', title: 'Log out', @@ -302,6 +345,69 @@ const SettingsHome = () => { + + {/* Log Out & Clear Data Confirmation Modal */} + {showLogoutAndClearModal && ( +
+
+
+
+ + + +
+
+

Log Out & Clear App Data

+
+
+ +
+

+ This will sign you out and permanently delete ALL data including: + • App settings and conversations + • Email data from Gmail + • Chat history from Telegram + • Cached files from Notion + • All other skills data +

+ This action cannot be undone and may take a few moments to complete. +

+ + {error && ( +
+

{error}

+
+ )} +
+ +
+ + +
+
+
+ )} ); }; diff --git a/src/lib/skills/manager.ts b/src/lib/skills/manager.ts index 898b3e8ac..4a05d2154 100644 --- a/src/lib/skills/manager.ts +++ b/src/lib/skills/manager.ts @@ -527,6 +527,44 @@ class SkillManager { throw new Error(`Unknown reverse RPC method: ${method}`); } } + + /** + * Clear all skills databases and cached data. + * Used for nuclear reset functionality. + */ + async clearAllSkillsData(): Promise { + try { + // Stop all running skills first + await this.stopAll(); + + // Get all skill IDs from Redux state + const state = store.getState(); + const skillIds = Object.keys(state.skills.skills); + + // Clear data for each skill + const clearPromises = skillIds.map(async (skillId) => { + try { + // Get skill data directory path + const dataDir = await invoke("runtime_skill_data_dir", { skillId }); + + // Note: We don't directly delete directories here since there's no exposed + // Tauri command for that. Instead, we rely on the backend to handle + // clearing when skills are disabled/reset via Redux state clearing. + + console.log(`[SkillManager] Skill ${skillId} data directory: ${dataDir}`); + } catch (err) { + console.warn(`[SkillManager] Failed to get data directory for skill ${skillId}:`, err); + } + }); + + await Promise.all(clearPromises); + + console.log("[SkillManager] Skills data clearing initiated"); + } catch (error) { + console.error("[SkillManager] Failed to clear skills data:", error); + throw new Error("Failed to clear skills databases"); + } + } } // Export singleton