Skip to content

The agent that grows with you

fix(desktop): the /save dialog asks before overwriting a file on Linux

Teknium3683fc95755b
diff --git a/apps/desktop/electron/save-text-file.test.ts b/apps/desktop/electron/save-text-file.test.ts
index ec7d2c3624b..e859e727531 100644
--- a/apps/desktop/electron/save-text-file.test.ts
+++ b/apps/desktop/electron/save-text-file.test.ts
@@ -50,6 +50,24 @@ describe('saveTextFileAs (Electron-side /save write)', () => {
expect(seen!.filters).toEqual([{ name: 'Markdown', extensions: ['md'] }])
})
+ it('asks before overwriting an existing file and can create a directory (Linux needs both flags)', async () => {
+ let seen: { properties?: string[] } | null = null
+
+ await saveTextFileAs(
+ { content: 'x', defaultPath: 'a.md' },
+ {
+ defaultDir: () => '/home/u',
+ showSaveDialog: async options => {
+ seen = options
+
+ return { canceled: true }
+ }
+ }
+ )
+
+ expect(seen!.properties).toEqual(['createDirectory', 'showOverwriteConfirmation'])
+ })
+
it('writes nothing when the dialog is cancelled', async () => {
const writes: string[] = []
diff --git a/apps/desktop/electron/save-text-file.ts b/apps/desktop/electron/save-text-file.ts
index 583785aba10..384211567e9 100644
--- a/apps/desktop/electron/save-text-file.ts
+++ b/apps/desktop/electron/save-text-file.ts
@@ -23,6 +23,7 @@ export interface SaveTextFileDeps {
showSaveDialog: (options: {
defaultPath?: string
filters?: Array<{ extensions: string[]; name: string }>
+ properties?: Array<'createDirectory' | 'showOverwriteConfirmation'>
title: string
}) => Promise<{ canceled: boolean; filePath?: string }>
writeFile?: (filePath: string, content: string) => Promise<void>
@@ -87,7 +88,9 @@ export async function saveTextFileAs(
const result = await deps.showSaveDialog({
title: typeof request.title === 'string' && request.title ? request.title : 'Save',
defaultPath: name ? path.join(deps.defaultDir(), name) : undefined,
- filters: safeFilters(request.filters)
+ filters: safeFilters(request.filters),
+ // Linux dialogs replace an existing file silently unless asked to confirm.
+ properties: ['createDirectory', 'showOverwriteConfirmation']
})
if (result.canceled || !result.filePath) {