1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: Fixed crash on certain Linux distributions when importing or exporting a file

Ref: https://discourse.joplinapp.org/t/20702/37
This commit is contained in:
Laurent Cozic 2021-11-01 07:38:06 +00:00
parent c5569ef06d
commit 60127831b8
10 changed files with 18 additions and 18 deletions

View File

@ -153,12 +153,12 @@ export default class InteropServiceHelper {
if (module.target === 'file') {
const noteId = options.sourceNoteIds && options.sourceNoteIds.length ? options.sourceNoteIds[0] : null;
path = bridge().showSaveDialog({
path = await bridge().showSaveDialog({
filters: [{ name: module.description, extensions: module.fileExtensions }],
defaultPath: await this.defaultFilename(noteId, module.fileExtensions[0]),
});
} else {
path = bridge().showOpenDialog({
path = await bridge().showOpenDialog({
properties: ['openDirectory', 'createDirectory'],
});
}

View File

@ -125,25 +125,25 @@ export class Bridge {
return this.window().webContents.closeDevTools();
}
showSaveDialog(options: any) {
async showSaveDialog(options: any) {
const { dialog } = require('electron');
if (!options) options = {};
if (!('defaultPath' in options) && this.lastSelectedPaths_.file) options.defaultPath = this.lastSelectedPaths_.file;
const filePath = dialog.showSaveDialogSync(this.window(), options);
const { filePath } = await dialog.showSaveDialog(this.window(), options);
if (filePath) {
this.lastSelectedPaths_.file = filePath;
}
return filePath;
}
showOpenDialog(options: any = null) {
async showOpenDialog(options: any = null) {
const { dialog } = require('electron');
if (!options) options = {};
let fileType = 'file';
if (options.properties && options.properties.includes('openDirectory')) fileType = 'directory';
if (!('defaultPath' in options) && this.lastSelectedPaths_[fileType]) options.defaultPath = this.lastSelectedPaths_[fileType];
if (!('createDirectory' in options)) options.createDirectory = true;
const filePaths = dialog.showOpenDialogSync(this.window(), options);
const { filePaths } = await dialog.showOpenDialog(this.window(), options);
if (filePaths && filePaths.length) {
this.lastSelectedPaths_[fileType] = dirname(filePaths[0]);
}

View File

@ -481,8 +481,8 @@ class ConfigScreenComponent extends React.Component<any, any> {
updateSettingValue(key, joinCmd(cmd));
};
const browseButtonClick = () => {
const paths = bridge().showOpenDialog();
const browseButtonClick = async () => {
const paths = await bridge().showOpenDialog();
if (!paths || !paths.length) return;
const cmd = splitCmd(this.state.settings[key]);
cmd[0] = paths[0];

View File

@ -181,7 +181,7 @@ export default function(props: Props) {
}, [pluginSettings, props.onChange]);
const onInstall = useCallback(async () => {
const result = bridge().showOpenDialog({
const result = await bridge().showOpenDialog({
filters: [{ name: 'Joplin Plugin Archive', extensions: ['jpl'] }],
});

View File

@ -50,7 +50,7 @@ export const KeymapConfigScreen = ({ themeId }: KeymapConfigScreenProps) => {
};
const handleImport = async () => {
const filePath = bridge().showOpenDialog({
const filePath = await bridge().showOpenDialog({
properties: ['openFile'],
defaultPath: 'keymap-desktop',
filters: [{ name: 'Joplin Keymaps (keymap-desktop.json)', extensions: ['json'] }],
@ -68,7 +68,7 @@ export const KeymapConfigScreen = ({ themeId }: KeymapConfigScreenProps) => {
};
const handleExport = async () => {
const filePath = bridge().showSaveDialog({
const filePath = await bridge().showSaveDialog({
defaultPath: 'keymap-desktop',
filters: [{ name: 'Joplin Keymaps (keymap-desktop.json)', extensions: ['json'] }],
});

View File

@ -20,12 +20,12 @@ export const runtime = (comp: any): CommandRuntime => {
let path = null;
if (noteIds.length === 1) {
path = bridge().showSaveDialog({
path = await bridge().showSaveDialog({
filters: [{ name: _('PDF File'), extensions: ['pdf'] }],
defaultPath: await InteropServiceHelper.defaultFilename(noteIds[0], 'pdf'),
});
} else {
path = bridge().showOpenDialog({
path = await bridge().showOpenDialog({
properties: ['openDirectory', 'createDirectory'],
});
}

View File

@ -180,11 +180,11 @@ function useMenu(props: Props) {
let path = null;
if (moduleSource === 'file') {
path = bridge().showOpenDialog({
path = await bridge().showOpenDialog({
filters: [{ name: module.description, extensions: module.fileExtensions }],
});
} else {
path = bridge().showOpenDialog({
path = await bridge().showOpenDialog({
properties: ['openDirectory', 'createDirectory'],
});
}

View File

@ -107,7 +107,7 @@ export function menuItems(dispatch: Function): ContextMenuItems {
label: _('Save as...'),
onAction: async (options: ContextMenuOptions) => {
const { resourcePath, resource } = await resourceInfo(options);
const filePath = bridge().showSaveDialog({
const filePath = await bridge().showSaveDialog({
defaultPath: resource.filename ? resource.filename : resource.title,
});
if (!filePath) return;

View File

@ -65,7 +65,7 @@ export async function commandAttachFileToBody(body: string, filePaths: string[]
};
if (!filePaths) {
filePaths = bridge().showOpenDialog({
filePaths = await bridge().showOpenDialog({
properties: ['openFile', 'createDirectory', 'multiSelections'],
});
if (!filePaths || !filePaths.length) return null;

View File

@ -25,7 +25,7 @@ const StyledAdvancedToolItem = styled.div`
async function exportDebugReportClick() {
const filename = `syncReport-${new Date().getTime()}.csv`;
const filePath = bridge().showSaveDialog({
const filePath = await bridge().showSaveDialog({
title: _('Please select where the sync status should be exported to'),
defaultPath: filename,
});