Skip to content

Commit

Permalink
Use an absolute filename for the file save dialog on Linux
Browse files Browse the repository at this point in the history
This fixes #6912.
On Gnome the save dialog works with any filename, on KDE Plasma
the save dialog opens with an empty filename input field,
unless the application uses an absolute file path instead of only the filename.
The default save location is the Downloads directory in the user's home directory.
  • Loading branch information
pelya committed Dec 13, 2024
1 parent 5f611b7 commit ad3e940
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion app/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2017 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only

import { join, normalize, extname, dirname, basename } from 'path';
import { join, normalize, extname, dirname, basename, isAbsolute } from 'path';
import { pathToFileURL } from 'url';
import * as os from 'os';
import { chmod, realpath, writeFile } from 'fs-extra';
Expand Down Expand Up @@ -3021,6 +3021,30 @@ ipc.handle('show-save-dialog', async (_event, { defaultPath }) => {
return { canceled: true };
}

if (
process.platform === 'linux' &&
defaultPath &&
!isAbsolute(defaultPath)
) {
// On Linux the defaultPath should be an absolute path, otherwise the save dialog will have an empty filename on KDE/Plasma
let downloadsPath = '';
try {
downloadsPath = app.getPath('downloads');
getLogger().info(
'show-save-dialog: saving to user downloads directory: ' + downloadsPath
);
} catch (e) {
// If we cannot get Downloads path, fall back to the user's home directory
downloadsPath = app.getPath('home');
getLogger().info(
'show-save-dialog: saving to user home directory: ' + downloadsPath
);
}
if (downloadsPath) {
defaultPath = join(downloadsPath, defaultPath)
}
}

const { canceled, filePath: selectedFilePath } = await dialog.showSaveDialog(
mainWindow,
{
Expand Down

0 comments on commit ad3e940

Please sign in to comment.