Skip to content

Commit ad3e940

Browse files
committed
Use an absolute filename for the file save dialog on Linux
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.
1 parent 5f611b7 commit ad3e940

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Diff for: app/main.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2017 Signal Messenger, LLC
22
// SPDX-License-Identifier: AGPL-3.0-only
33

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

3024+
if (
3025+
process.platform === 'linux' &&
3026+
defaultPath &&
3027+
!isAbsolute(defaultPath)
3028+
) {
3029+
// On Linux the defaultPath should be an absolute path, otherwise the save dialog will have an empty filename on KDE/Plasma
3030+
let downloadsPath = '';
3031+
try {
3032+
downloadsPath = app.getPath('downloads');
3033+
getLogger().info(
3034+
'show-save-dialog: saving to user downloads directory: ' + downloadsPath
3035+
);
3036+
} catch (e) {
3037+
// If we cannot get Downloads path, fall back to the user's home directory
3038+
downloadsPath = app.getPath('home');
3039+
getLogger().info(
3040+
'show-save-dialog: saving to user home directory: ' + downloadsPath
3041+
);
3042+
}
3043+
if (downloadsPath) {
3044+
defaultPath = join(downloadsPath, defaultPath)
3045+
}
3046+
}
3047+
30243048
const { canceled, filePath: selectedFilePath } = await dialog.showSaveDialog(
30253049
mainWindow,
30263050
{

0 commit comments

Comments
 (0)