From b6aaa4d82b8455035e6dc7dd7ae09a3d6f030801 Mon Sep 17 00:00:00 2001 From: Ken Date: Tue, 11 Aug 2020 09:14:11 +1200 Subject: [PATCH] Copy info to clipboard (#2480) Co-authored-by: Opender Singh Co-authored-by: John --- .../insomnia-app/app/main/window-utils.js | 68 ++++++++++++++----- 1 file changed, 50 insertions(+), 18 deletions(-) diff --git a/packages/insomnia-app/app/main/window-utils.js b/packages/insomnia-app/app/main/window-utils.js index 5ee9c835aa..124a04a715 100644 --- a/packages/insomnia-app/app/main/window-utils.js +++ b/packages/insomnia-app/app/main/window-utils.js @@ -13,9 +13,10 @@ import { MNEMONIC_SYM, } from '../common/constants'; import * as misc from '../common/misc'; +import * as os from 'os'; import { docsBase } from '../common/documentation'; -const { app, Menu, BrowserWindow, shell, dialog } = electron; +const { app, Menu, BrowserWindow, shell, dialog, clipboard } = electron; // So we can use native modules in renderer // NOTE: This will be deprecated in Electron 10 and impossible in 11 @@ -121,9 +122,6 @@ export function createWindow() { const applicationMenu = { label: `${MNEMONIC_SYM}Application`, submenu: [ - ...(isMac() - ? [{ label: `A${MNEMONIC_SYM}bout ${getAppName()}`, role: 'about' }, { type: 'separator' }] - : []), { label: `${MNEMONIC_SYM}Preferences`, click: function(menuItem, window, e) { @@ -294,24 +292,58 @@ export function createWindow() { ], }; - if (!isMac()) { + const aboutDetail = [ + `OS ${os.type()} ${os.arch()} ${os.release()}`, + `Version ${getAppLongName()} ${getAppVersion()}`, + `Shell ${process.versions.electron}`, + `Node ${process.versions.node}`, + `V8 ${process.versions.v8}`, + `Architecture ${process.arch}`, + Curl.getVersion(), + ].join('\n'); + + const aboutMsgOptions = { + type: 'info', + title: getAppName(), + message: getAppLongName(), + detail: aboutDetail, + noLink: true, + }; + + if (isMac()) { + applicationMenu.submenu.unshift( + { + label: `A${MNEMONIC_SYM}bout ${getAppName()}`, + click: async () => { + const buttons = ['OK', 'Copy']; + const msgBox = await dialog.showMessageBox({ + ...aboutMsgOptions, + buttons: buttons, + defaultId: buttons.indexOf('OK'), + cancelId: buttons.indexOf('OK'), + }); + + if (msgBox.response === buttons.indexOf('Copy')) { + clipboard.writeText(aboutDetail); + } + }, + }, + { type: 'separator' }, + ); + } else { helpMenu.submenu.unshift({ label: `${MNEMONIC_SYM}About`, click: async () => { - await dialog.showMessageBox({ - type: 'info', - title: getAppName(), - message: getAppLongName(), - detail: [ - 'Version ' + getAppVersion(), - 'Shell ' + process.versions.electron, - 'Node ' + process.versions.node, - 'V8 ' + process.versions.v8, - 'Architecture ' + process.arch, - '', // Blank line before libcurl - Curl.getVersion(), - ].join('\n'), + const buttons = ['Copy', 'OK']; + const msgBox = await dialog.showMessageBox({ + ...aboutMsgOptions, + buttons: buttons, + defaultId: buttons.indexOf('OK'), + cancelId: buttons.indexOf('OK'), }); + if (msgBox.response === buttons.indexOf('Copy')) { + clipboard.writeText(aboutDetail); + } }, }); }