Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some new functionality #817

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions app/src/components/Sidebar/HistoryDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean | undefined>(undefined)
Expand All @@ -40,6 +54,10 @@ function HistoryDrawer(props: Props) {
event.stopPropagation()
}

const saveHistory = (() => {
dowloadHistoryAsFile(props);
})

function renderHistory() {
const style = (element: HistoryItem) => ({
backgroundColor: element.selected
Expand Down Expand Up @@ -98,6 +116,24 @@ function HistoryDrawer(props: Props) {
{expanded ? props.children : null}
{expanded ? elements : null}
</div>
<div
style={{
backgroundColor: emphasize(props.theme.palette.background.default, 0.15),
}}
>
<Typography component={'span'} onClick={saveHistory} style={{ cursor: 'pointer', display: 'flex' }}>
<span style={{ flexGrow: 1 }}>
<Badge
classes={{ badge: props.classes.badge }}
invisible={true}
badgeContent={props.items.length}
color="primary"
>
Save history
</Badge>
</span>
</Typography>
</div>
</div>
)
}
Expand Down
6 changes: 6 additions & 0 deletions src/MenuTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
19 changes: 18 additions & 1 deletion src/electron.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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
Expand Down
Loading