Ensure windows doesn't strip file ext when saving

This commit is contained in:
Jamie Kyle 2023-06-14 13:55:07 -07:00 committed by GitHub
parent efc237d106
commit 95bdfcf8f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 () => {