aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--package.json2
-rw-r--r--pnpm-lock.yaml10
-rw-r--r--src/electron/ipc-api/download.ts6
-rw-r--r--src/webview/contextMenuBuilder.ts45
4 files changed, 31 insertions, 32 deletions
diff --git a/package.json b/package.json
index 676a4336c..a928442cb 100644
--- a/package.json
+++ b/package.json
@@ -86,7 +86,6 @@
86 "lodash": "4.17.21", 86 "lodash": "4.17.21",
87 "macos-version": "5.2.1", 87 "macos-version": "5.2.1",
88 "markdown-to-jsx": "7.2.0", 88 "markdown-to-jsx": "7.2.0",
89 "mime-types": "2.1.35",
90 "minimist": "1.2.8", 89 "minimist": "1.2.8",
91 "mobx": "6.9.0", 90 "mobx": "6.9.0",
92 "mobx-localstorage": "1.2.0", 91 "mobx-localstorage": "1.2.0",
@@ -135,7 +134,6 @@
135 "@types/fs-extra": "11.0.1", 134 "@types/fs-extra": "11.0.1",
136 "@types/jest": "29.5.1", 135 "@types/jest": "29.5.1",
137 "@types/lodash": "4.14.195", 136 "@types/lodash": "4.14.195",
138 "@types/mime-types": "2.1.1",
139 "@types/ms": "0.7.31", 137 "@types/ms": "0.7.31",
140 "@types/node": "18.15.3", 138 "@types/node": "18.15.3",
141 "@types/react": "18.2.7", 139 "@types/react": "18.2.7",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 6ef24e438..3727d8b98 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -133,9 +133,6 @@ dependencies:
133 markdown-to-jsx: 133 markdown-to-jsx:
134 specifier: 7.2.0 134 specifier: 7.2.0
135 version: 7.2.0(react@18.2.0) 135 version: 7.2.0(react@18.2.0)
136 mime-types:
137 specifier: 2.1.35
138 version: 2.1.35
139 minimist: 136 minimist:
140 specifier: 1.2.8 137 specifier: 1.2.8
141 version: 1.2.8 138 version: 1.2.8
@@ -284,9 +281,6 @@ devDependencies:
284 '@types/lodash': 281 '@types/lodash':
285 specifier: 4.14.195 282 specifier: 4.14.195
286 version: 4.14.195 283 version: 4.14.195
287 '@types/mime-types':
288 specifier: 2.1.1
289 version: 2.1.1
290 '@types/ms': 284 '@types/ms':
291 specifier: 0.7.31 285 specifier: 0.7.31
292 version: 0.7.31 286 version: 0.7.31
@@ -2463,10 +2457,6 @@ packages:
2463 resolution: {integrity: sha512-Hwx9EUgdwf2GLarOjQp5ZH8ZmblzcbTBC2wtQWNKARBSxM9ezRIAUpeDTgoQRAFB0+8CNWXVA9+MaSOzOF3nPg==} 2457 resolution: {integrity: sha512-Hwx9EUgdwf2GLarOjQp5ZH8ZmblzcbTBC2wtQWNKARBSxM9ezRIAUpeDTgoQRAFB0+8CNWXVA9+MaSOzOF3nPg==}
2464 dev: true 2458 dev: true
2465 2459
2466 /@types/mime-types@2.1.1:
2467 resolution: {integrity: sha512-vXOTGVSLR2jMw440moWTC7H19iUyLtP3Z1YTj7cSsubOICinjMxFeb/V57v9QdyyPGbbWolUFSSmSiRSn94tFw==}
2468 dev: true
2469
2470 /@types/minimist@1.2.2: 2460 /@types/minimist@1.2.2:
2471 resolution: {integrity: sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==} 2461 resolution: {integrity: sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==}
2472 dev: true 2462 dev: true
diff --git a/src/electron/ipc-api/download.ts b/src/electron/ipc-api/download.ts
index 518a7091c..851bff4c3 100644
--- a/src/electron/ipc-api/download.ts
+++ b/src/electron/ipc-api/download.ts
@@ -1,6 +1,5 @@
1import { ipcMain, dialog, BrowserWindow } from 'electron'; 1import { ipcMain, dialog, BrowserWindow } from 'electron';
2import { download } from 'electron-dl'; 2import { download } from 'electron-dl';
3import mime from 'mime-types';
4import { writeFileSync } from 'fs-extra'; 3import { writeFileSync } from 'fs-extra';
5import { PathLike } from 'fs'; 4import { PathLike } from 'fs';
6 5
@@ -24,12 +23,9 @@ export default (params: { mainWindow: BrowserWindow }) => {
24 23
25 try { 24 try {
26 if (content) { 25 if (content) {
27 const extension = mime.extension(fileOptions.mime);
28 const filename = `${fileOptions.name}.${extension}`;
29
30 try { 26 try {
31 const saveDialog = await dialog.showSaveDialog(params.mainWindow, { 27 const saveDialog = await dialog.showSaveDialog(params.mainWindow, {
32 defaultPath: filename, 28 defaultPath: fileOptions.name,
33 }); 29 });
34 30
35 if (saveDialog.canceled) return; 31 if (saveDialog.canceled) return;
diff --git a/src/webview/contextMenuBuilder.ts b/src/webview/contextMenuBuilder.ts
index 2e64977c1..6d904eee3 100644
--- a/src/webview/contextMenuBuilder.ts
+++ b/src/webview/contextMenuBuilder.ts
@@ -633,27 +633,42 @@ export class ContextMenuBuilder {
633 menu.append(copyImageUrl); 633 menu.append(copyImageUrl);
634 634
635 // TODO: This doesn't seem to work on linux, so, limiting to Mac for now 635 // TODO: This doesn't seem to work on linux, so, limiting to Mac for now
636 if (isMac && menuInfo.srcURL.startsWith('blob:')) { 636 if (isMac) {
637 const downloadImage = new MenuItem({ 637 const clickHandler = menuInfo.srcURL.startsWith('blob:')
638 label: this.stringTable.downloadImage(), 638 ? () => {
639 click: () => { 639 const urlWithoutBlob = menuInfo.srcURL.slice(5);
640 const urlWithoutBlob = menuInfo.srcURL.slice(5); 640 this.convertImageToBase64(menuInfo.srcURL, (dataURL: any) => {
641 this.convertImageToBase64(menuInfo.srcURL, (dataURL: any) => { 641 const url = new window.URL(urlWithoutBlob);
642 const url = new window.URL(urlWithoutBlob); 642 const fileName = url.pathname.slice(1);
643 ipcRenderer.send('download-file', {
644 content: dataURL,
645 fileOptions: {
646 name: `${fileName}.png`,
647 },
648 });
649 });
650 this._sendNotificationOnClipboardEvent(
651 menuInfo.clipboardNotifications,
652 () => `Image downloaded: ${urlWithoutBlob}`,
653 );
654 }
655 : () => {
656 const url = new window.URL(menuInfo.srcURL);
643 const fileName = url.pathname.slice(1); 657 const fileName = url.pathname.slice(1);
644 ipcRenderer.send('download-file', { 658 ipcRenderer.send('download-file', {
645 content: dataURL, 659 url: menuInfo.srcURL,
646 fileOptions: { 660 fileOptions: {
647 name: fileName, 661 name: fileName,
648 mime: 'image/png',
649 }, 662 },
650 }); 663 });
651 }); 664 this._sendNotificationOnClipboardEvent(
652 this._sendNotificationOnClipboardEvent( 665 menuInfo.clipboardNotifications,
653 menuInfo.clipboardNotifications, 666 () => `Image downloaded: ${menuInfo.srcURL}`,
654 () => `Image downloaded: ${urlWithoutBlob}`, 667 );
655 ); 668 };
656 }, 669 const downloadImage = new MenuItem({
670 label: this.stringTable.downloadImage(),
671 click: clickHandler,
657 }); 672 });
658 673
659 menu.append(downloadImage); 674 menu.append(downloadImage);