|
1 | 1 | // Copyright 2017 Signal Messenger, LLC
|
2 | 2 | // SPDX-License-Identifier: AGPL-3.0-only
|
3 | 3 |
|
4 |
| -import { join, normalize, extname, dirname, basename } from 'path'; |
| 4 | +import { join, normalize, extname, dirname, basename, isAbsolute } from 'path'; |
5 | 5 | import { pathToFileURL } from 'url';
|
6 | 6 | import * as os from 'os';
|
7 | 7 | import { chmod, realpath, writeFile } from 'fs-extra';
|
@@ -3021,6 +3021,30 @@ ipc.handle('show-save-dialog', async (_event, { defaultPath }) => {
|
3021 | 3021 | return { canceled: true };
|
3022 | 3022 | }
|
3023 | 3023 |
|
| 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 | + |
3024 | 3048 | const { canceled, filePath: selectedFilePath } = await dialog.showSaveDialog(
|
3025 | 3049 | mainWindow,
|
3026 | 3050 | {
|
|
0 commit comments