mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-08 14:29:15 +08:00
fix: handle user cancellation and improve error reporting in file saving process
- Added a check for user cancellation in the file save dialog, rejecting the promise if canceled. - Enhanced error handling to reject the promise with a detailed error message instead of returning null.
This commit is contained in:
parent
f67545d751
commit
b6675853ed
@ -328,7 +328,7 @@ class FileStorage {
|
|||||||
fileName: string,
|
fileName: string,
|
||||||
content: string,
|
content: string,
|
||||||
options?: SaveDialogOptions
|
options?: SaveDialogOptions
|
||||||
): Promise<string | null> => {
|
): Promise<string> => {
|
||||||
try {
|
try {
|
||||||
const result: SaveDialogReturnValue = await dialog.showSaveDialog({
|
const result: SaveDialogReturnValue = await dialog.showSaveDialog({
|
||||||
title: '保存文件',
|
title: '保存文件',
|
||||||
@ -336,14 +336,18 @@ class FileStorage {
|
|||||||
...options
|
...options
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (result.canceled) {
|
||||||
|
return Promise.reject(new Error('User canceled the save dialog'))
|
||||||
|
}
|
||||||
|
|
||||||
if (!result.canceled && result.filePath) {
|
if (!result.canceled && result.filePath) {
|
||||||
await writeFileSync(result.filePath, content, { encoding: 'utf-8' })
|
await writeFileSync(result.filePath, content, { encoding: 'utf-8' })
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.filePath
|
return result.filePath
|
||||||
} catch (err) {
|
} catch (err: any) {
|
||||||
logger.error('[IPC - Error]', 'An error occurred saving the file:', err)
|
logger.error('[IPC - Error]', 'An error occurred saving the file:', err)
|
||||||
return null
|
return Promise.reject('An error occurred saving the file: ' + err?.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user