mirror of
https://github.com/purocean/yn.git
synced 2026-10-16 15:41:46 +08:00
feat: optimize auto-save logic
This commit is contained in:
@@ -559,37 +559,46 @@ export async function ensureCurrentFileSaved () {
|
||||
try {
|
||||
const autoSave = !isEncrypted(currentFile) && getSetting('auto-save', 2000)
|
||||
if (autoSave) {
|
||||
await saveContent()
|
||||
} else {
|
||||
const confirm = await useModal().confirm({
|
||||
title: t('save-check-dialog.title'),
|
||||
content: t('save-check-dialog.desc'),
|
||||
action: h(Fragment, [
|
||||
h('button', {
|
||||
onClick: async () => {
|
||||
await saveContent()
|
||||
useModal().ok()
|
||||
}
|
||||
}, t('save')),
|
||||
h('button', {
|
||||
onClick: () => useModal().ok()
|
||||
}, t('discard')),
|
||||
h('button', {
|
||||
onClick: () => useModal().cancel()
|
||||
}, t('cancel')),
|
||||
])
|
||||
})
|
||||
|
||||
checkFile()
|
||||
|
||||
if (confirm) {
|
||||
if (!store.getters.isSaved && currentFile.content) {
|
||||
store.state.currentContent = currentFile.content!
|
||||
}
|
||||
} else {
|
||||
throw new Error('Document not saved')
|
||||
try {
|
||||
await saveContent()
|
||||
return
|
||||
} catch (error: any) {
|
||||
useToast().show('warning', error.message)
|
||||
}
|
||||
}
|
||||
|
||||
const confirm = await useModal().confirm({
|
||||
title: t('save-check-dialog.title'),
|
||||
content: t('save-check-dialog.desc'),
|
||||
action: h(Fragment, [
|
||||
h('button', {
|
||||
onClick: async () => {
|
||||
await saveContent().catch(error => {
|
||||
useToast().show('warning', error.message)
|
||||
throw error
|
||||
})
|
||||
|
||||
useModal().ok()
|
||||
}
|
||||
}, t('save')),
|
||||
h('button', {
|
||||
onClick: () => useModal().ok()
|
||||
}, t('discard')),
|
||||
h('button', {
|
||||
onClick: () => useModal().cancel()
|
||||
}, t('cancel')),
|
||||
])
|
||||
})
|
||||
|
||||
checkFile()
|
||||
|
||||
if (confirm) {
|
||||
if (!store.getters.isSaved && currentFile.content) {
|
||||
store.state.currentContent = currentFile.content!
|
||||
}
|
||||
} else {
|
||||
throw new Error('Document not saved')
|
||||
}
|
||||
} catch (error: any) {
|
||||
useToast().show('warning', error.message)
|
||||
throw error
|
||||
|
||||
Reference in New Issue
Block a user