From 60127831b82439d0f1265d50f0061c2fd681e47b Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Mon, 1 Nov 2021 07:38:06 +0000 Subject: [PATCH 1/2] Desktop: Fixed crash on certain Linux distributions when importing or exporting a file Ref: https://discourse.joplinapp.org/t/20702/37 --- packages/app-desktop/InteropServiceHelper.ts | 4 ++-- packages/app-desktop/bridge.ts | 8 ++++---- packages/app-desktop/gui/ConfigScreen/ConfigScreen.tsx | 4 ++-- .../gui/ConfigScreen/controls/plugins/PluginsStates.tsx | 2 +- .../app-desktop/gui/KeymapConfig/KeymapConfigScreen.tsx | 4 ++-- packages/app-desktop/gui/MainScreen/commands/exportPdf.ts | 4 ++-- packages/app-desktop/gui/MenuBar.tsx | 4 ++-- packages/app-desktop/gui/NoteEditor/utils/contextMenu.ts | 2 +- .../app-desktop/gui/NoteEditor/utils/resourceHandling.ts | 2 +- packages/app-desktop/gui/StatusScreen/StatusScreen.tsx | 2 +- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/app-desktop/InteropServiceHelper.ts b/packages/app-desktop/InteropServiceHelper.ts index dc06f0d60..02525e08b 100644 --- a/packages/app-desktop/InteropServiceHelper.ts +++ b/packages/app-desktop/InteropServiceHelper.ts @@ -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'], }); } diff --git a/packages/app-desktop/bridge.ts b/packages/app-desktop/bridge.ts index d5ff87e6c..3876f298c 100644 --- a/packages/app-desktop/bridge.ts +++ b/packages/app-desktop/bridge.ts @@ -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]); } diff --git a/packages/app-desktop/gui/ConfigScreen/ConfigScreen.tsx b/packages/app-desktop/gui/ConfigScreen/ConfigScreen.tsx index ec87fee67..a6b6c86ee 100644 --- a/packages/app-desktop/gui/ConfigScreen/ConfigScreen.tsx +++ b/packages/app-desktop/gui/ConfigScreen/ConfigScreen.tsx @@ -481,8 +481,8 @@ class ConfigScreenComponent extends React.Component { 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]; diff --git a/packages/app-desktop/gui/ConfigScreen/controls/plugins/PluginsStates.tsx b/packages/app-desktop/gui/ConfigScreen/controls/plugins/PluginsStates.tsx index 186803762..4e8d13ebb 100644 --- a/packages/app-desktop/gui/ConfigScreen/controls/plugins/PluginsStates.tsx +++ b/packages/app-desktop/gui/ConfigScreen/controls/plugins/PluginsStates.tsx @@ -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'] }], }); diff --git a/packages/app-desktop/gui/KeymapConfig/KeymapConfigScreen.tsx b/packages/app-desktop/gui/KeymapConfig/KeymapConfigScreen.tsx index c7ce869fe..39712dedb 100644 --- a/packages/app-desktop/gui/KeymapConfig/KeymapConfigScreen.tsx +++ b/packages/app-desktop/gui/KeymapConfig/KeymapConfigScreen.tsx @@ -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'] }], }); diff --git a/packages/app-desktop/gui/MainScreen/commands/exportPdf.ts b/packages/app-desktop/gui/MainScreen/commands/exportPdf.ts index 0e20507f1..db6800cca 100644 --- a/packages/app-desktop/gui/MainScreen/commands/exportPdf.ts +++ b/packages/app-desktop/gui/MainScreen/commands/exportPdf.ts @@ -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'], }); } diff --git a/packages/app-desktop/gui/MenuBar.tsx b/packages/app-desktop/gui/MenuBar.tsx index b8162720b..2987afbc9 100644 --- a/packages/app-desktop/gui/MenuBar.tsx +++ b/packages/app-desktop/gui/MenuBar.tsx @@ -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'], }); } diff --git a/packages/app-desktop/gui/NoteEditor/utils/contextMenu.ts b/packages/app-desktop/gui/NoteEditor/utils/contextMenu.ts index 44613b54a..e30f300bb 100644 --- a/packages/app-desktop/gui/NoteEditor/utils/contextMenu.ts +++ b/packages/app-desktop/gui/NoteEditor/utils/contextMenu.ts @@ -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; diff --git a/packages/app-desktop/gui/NoteEditor/utils/resourceHandling.ts b/packages/app-desktop/gui/NoteEditor/utils/resourceHandling.ts index a71dcbe80..de937d5be 100644 --- a/packages/app-desktop/gui/NoteEditor/utils/resourceHandling.ts +++ b/packages/app-desktop/gui/NoteEditor/utils/resourceHandling.ts @@ -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; diff --git a/packages/app-desktop/gui/StatusScreen/StatusScreen.tsx b/packages/app-desktop/gui/StatusScreen/StatusScreen.tsx index 800cad293..47a860fc7 100644 --- a/packages/app-desktop/gui/StatusScreen/StatusScreen.tsx +++ b/packages/app-desktop/gui/StatusScreen/StatusScreen.tsx @@ -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, }); From 1eda835236ef2c4c3f1f348a17652ec852566e20 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Mon, 1 Nov 2021 00:52:32 +0000 Subject: [PATCH 2/2] Desktop release v2.5.9 --- packages/app-desktop/package-lock.json | 4 ++-- packages/app-desktop/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/app-desktop/package-lock.json b/packages/app-desktop/package-lock.json index ab2aaea36..d29a505a3 100644 --- a/packages/app-desktop/package-lock.json +++ b/packages/app-desktop/package-lock.json @@ -1,12 +1,12 @@ { "name": "@joplin/app-desktop", - "version": "2.5.8", + "version": "2.5.9", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@joplin/app-desktop", - "version": "2.5.8", + "version": "2.5.9", "license": "MIT", "dependencies": { "@electron/remote": "^2.0.1", diff --git a/packages/app-desktop/package.json b/packages/app-desktop/package.json index 7c7a3a73a..87f976bb2 100644 --- a/packages/app-desktop/package.json +++ b/packages/app-desktop/package.json @@ -1,6 +1,6 @@ { "name": "@joplin/app-desktop", - "version": "2.5.8", + "version": "2.5.9", "description": "Joplin for Desktop", "main": "main.js", "private": true,