Ensure windows doesn't strip file ext when saving
This commit is contained in:
parent
efc237d106
commit
95bdfcf8f3
1 changed files with 18 additions and 4 deletions
22
app/main.ts
22
app/main.ts
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2017 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { join, normalize } from 'path';
|
||||
import { join, normalize, extname, dirname, basename } from 'path';
|
||||
import { pathToFileURL } from 'url';
|
||||
import * as os from 'os';
|
||||
import { chmod, realpath, writeFile } from 'fs-extra';
|
||||
|
@ -2488,9 +2488,23 @@ ipc.handle('show-save-dialog', async (_event, { defaultPath }) => {
|
|||
return { canceled: true };
|
||||
}
|
||||
|
||||
return dialog.showSaveDialog(mainWindow, {
|
||||
defaultPath,
|
||||
});
|
||||
const { canceled, filePath: selectedFilePath } = await dialog.showSaveDialog(
|
||||
mainWindow,
|
||||
{ defaultPath }
|
||||
);
|
||||
|
||||
if (canceled || selectedFilePath == null) {
|
||||
return { canceled: true };
|
||||
}
|
||||
|
||||
// On Windows, if you change the path from the default, the extension is
|
||||
// removed. We want to make sure the extension is always there.
|
||||
const defaultExt = extname(defaultPath);
|
||||
const finalDirname = dirname(selectedFilePath);
|
||||
const finalBasename = basename(selectedFilePath, defaultExt);
|
||||
const finalFilePath = join(finalDirname, `${finalBasename}${defaultExt}`);
|
||||
|
||||
return { canceled: false, filePath: finalFilePath };
|
||||
});
|
||||
|
||||
ipc.handle('getScreenCaptureSources', async () => {
|
||||
|
|
Loading…
Add table
Reference in a new issue