diff --git a/app/src/components/Sidebar/HistoryDrawer.tsx b/app/src/components/Sidebar/HistoryDrawer.tsx index e9090ea3..f86558a8 100644 --- a/app/src/components/Sidebar/HistoryDrawer.tsx +++ b/app/src/components/Sidebar/HistoryDrawer.tsx @@ -20,6 +20,20 @@ interface Props { children?: any } +function dowloadHistoryAsFile(props: Props) { + var filename = "save.txt" + const elementsText = props.items.map((element) => ( + '"' + element.key + '";"' + element.value + '";\r\n' + )) + var element = document.createElement('a') + element.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURIComponent(elementsText.join(''))) + element.setAttribute('download', filename) + element.style.display = 'none' + document.body.appendChild(element) + element.click() + document.body.removeChild(element) +} + function HistoryDrawer(props: Props) { const handleCtrlA = selectTextWithCtrlA({ targetSelector: 'pre' }) const [expanded, setExpanded] = useState(undefined) @@ -40,6 +54,10 @@ function HistoryDrawer(props: Props) { event.stopPropagation() } + const saveHistory = (() => { + dowloadHistoryAsFile(props); + }) + function renderHistory() { const style = (element: HistoryItem) => ({ backgroundColor: element.selected @@ -98,6 +116,24 @@ function HistoryDrawer(props: Props) { {expanded ? props.children : null} {expanded ? elements : null} +
+ + + + Save history + + + +
) } diff --git a/src/MenuTemplate.ts b/src/MenuTemplate.ts index f3c63b6c..906c9c00 100644 --- a/src/MenuTemplate.ts +++ b/src/MenuTemplate.ts @@ -20,6 +20,12 @@ const applicationMenu: MenuItemConstructorOptions = { { type: 'separator' as 'separator', }, + { + label: 'Minimize to tray', + click: () => { + BrowserWindow.getFocusedWindow()?.hide() + } + }, { label: 'Dev Tools', accelerator: 'CmdOrCtrl+Alt+I', diff --git a/src/electron.ts b/src/electron.ts index db66d853..81750c64 100644 --- a/src/electron.ts +++ b/src/electron.ts @@ -1,7 +1,7 @@ import * as log from 'electron-log' import * as path from 'path' import ConfigStorage from '../backend/src/ConfigStorage' -import { app, BrowserWindow, Menu, dialog } from 'electron' +import { app, BrowserWindow, Tray, Menu, dialog } from 'electron' import { autoUpdater } from 'electron-updater' import { ConnectionManager } from '../backend/src/index' import { promises as fsPromise } from 'fs' @@ -54,6 +54,7 @@ configStorage.init() // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. let mainWindow: BrowserWindow | undefined +let tray: Tray | undefined async function createWindow() { if (isDev()) { @@ -104,6 +105,22 @@ async function createWindow() { mainWindow = undefined app.quit() }) + + mainWindow.on('hide', () => { + tray = new Tray(path.join(__dirname, '..', '..', 'icon.png')); + tray.setContextMenu(Menu.buildFromTemplate([ + { + label: 'Show App', click: function () { + mainWindow?.show(); + } + }, + ])); + }) + + mainWindow.on('show', () => { + tray?.removeBalloon() + tray?.destroy() + }) } // This method will be called when Electron has finished