Skip to content

Commit

Permalink
feat: confirm before exit
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Nov 15, 2024
1 parent b07302a commit 02a796f
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions desktop/src-tauri/locales/en-US/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"check-error": "Check failed",
"check-loading": "Checking",
"check-success": "Tested successfully",
"confirm-exit": "Do you want to exit? Unsaved changes will be lost.",
"confirm-relaunch": "Relaunch Now",
"confirm-update": "Update Now",
"copied": "Copied!",
Expand Down
1 change: 1 addition & 0 deletions desktop/src-tauri/locales/es-MX/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"check-error": "La verificación falló",
"check-loading": "Verificando",
"check-success": "Probado con éxito",
"confirm-exit": "¿Quieres salir? \nLos cambios no guardados se perderán.",
"confirm-relaunch": "Relanzar Ahora",
"confirm-update": "Actualizar Ahora",
"copied": "¡Copiado!",
Expand Down
1 change: 1 addition & 0 deletions desktop/src-tauri/locales/fr-FR/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"check-error": "La vérification a échoué",
"check-loading": "Vérification",
"check-success": "Testé avec succès",
"confirm-exit": "Voulez-vous sortir ? \nLes modifications non enregistrées seront perdues.",
"confirm-relaunch": "Relancer maintenant",
"confirm-update": "Mettre à jour maintenant",
"copied": "Copié !",
Expand Down
1 change: 1 addition & 0 deletions desktop/src-tauri/locales/he-IL/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"check-error": "הבדיקה נכשלה",
"check-loading": "בודק",
"check-success": "נבדק בהצלחה",
"confirm-exit": "האם אתה רוצה לצאת? \nשינויים שלא נשמרו יאבדו.",
"confirm-relaunch": "הפעל מחדש עכשיו",
"confirm-update": "עדכן עכשיו",
"copied": "הועתק!",
Expand Down
1 change: 1 addition & 0 deletions desktop/src-tauri/locales/hi-IN/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"check-error": "जाँच विफल रही",
"check-loading": "चेकिंग",
"check-success": "सफलतापूर्वक परीक्षण किया गया",
"confirm-exit": "क्या आपको बाहर निकलना है? \nसहेजे न गए परिवर्तन खो जाएंगे.",
"confirm-relaunch": "अब फिर से चालू करें",
"confirm-update": "अब अपडेट करें",
"copied": "कॉपी किया गया!",
Expand Down
1 change: 1 addition & 0 deletions desktop/src-tauri/locales/it-IT/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"check-error": "Controllo fallito",
"check-loading": "Controllo",
"check-success": "Testato con successo",
"confirm-exit": "Vuoi uscire? \nLe modifiche non salvate andranno perse.",
"confirm-relaunch": "Rilancia ora",
"confirm-update": "Aggiorna ora",
"copied": "Copiato!",
Expand Down
1 change: 1 addition & 0 deletions desktop/src-tauri/locales/pl-PL/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"check-error": "Kontrola nie powiodła się",
"check-loading": "Kontrola",
"check-success": "Przetestowano pomyślnie",
"confirm-exit": "Czy chcesz wyjść? \nNiezapisane zmiany zostaną utracone.",
"confirm-relaunch": "Ponownie uruchom teraz",
"confirm-update": "Zaaktualizuj teraz",
"copied": "Skopiowano!",
Expand Down
1 change: 1 addition & 0 deletions desktop/src-tauri/locales/pt-BR/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"check-error": "Falha na verificação",
"check-loading": "Verificando",
"check-success": "Testado com sucesso",
"confirm-exit": "Você quer sair? \nAs alterações não salvas serão perdidas.",
"confirm-relaunch": "Reiniciar agora",
"confirm-update": "Atualizar agora",
"copied": "Copiado!",
Expand Down
1 change: 1 addition & 0 deletions desktop/src-tauri/locales/sv-SE/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"check-error": "Kontrollen misslyckades",
"check-loading": "Kontroll",
"check-success": "Testade framgångsrikt",
"confirm-exit": "Vill du avsluta? \nOsparade ändringar kommer att gå förlorade.",
"confirm-relaunch": "Starta om",
"confirm-update": "Updatera Nu",
"copied": "Kopierade!",
Expand Down
1 change: 1 addition & 0 deletions desktop/src-tauri/locales/zh-CN/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"check-error": "检查失败",
"check-loading": "检查",
"check-success": "测试成功",
"confirm-exit": "你想退出吗?\n未保存的更改将会丢失。",
"confirm-relaunch": "立即重启",
"confirm-update": "立即更新",
"copied": "已复制!",
Expand Down
25 changes: 25 additions & 0 deletions desktop/src/lib/useConfirmExit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useEffect } from 'react'
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow'
import { useTranslation } from 'react-i18next'
import { UnlistenFn } from '@tauri-apps/api/event'

export function useConfirmExit(shouldConfirm: boolean) {
const { t } = useTranslation()
useEffect(() => {
let unlistenFn: UnlistenFn | null = null
getCurrentWebviewWindow()
.listen('tauri://close-requested', async () => {
if (shouldConfirm) {
if (await confirm(t('common.confirm-exit'))) {
getCurrentWebviewWindow().destroy()
}
} else {
getCurrentWebviewWindow().destroy()
}
})
.then((unlisten) => {
unlistenFn = unlisten
})
return () => unlistenFn?.()
}, [shouldConfirm])
}
2 changes: 2 additions & 0 deletions desktop/src/pages/home/viewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { basename } from '@tauri-apps/api/path'
import { Claude, Llm, Ollama } from '~/lib/llm'
import { toast as hotToast } from 'react-hot-toast'
import { useLocalStorage } from 'usehooks-ts'
import { useConfirmExit } from '~/lib/useConfirmExit'

export interface BatchOptions {
files: NamedPath[]
Expand All @@ -49,6 +50,7 @@ export function viewModel() {
const toast = useToastProvider()
const [llm, setLlm] = useState<Llm | null>(null)
const [transcriptTab, setTranscriptTab] = useLocalStorage<'transcript' | 'summary'>('prefs_transcript_tab', 'transcript')
useConfirmExit((segments?.length ?? 0) > 0 || loading)

const { files, setFiles } = useFilesContext()
const preference = usePreferenceProvider()
Expand Down

0 comments on commit 02a796f

Please sign in to comment.