Skip to content

Commit

Permalink
Add minimize to system tray.
Browse files Browse the repository at this point in the history
  • Loading branch information
BigIskander committed Jun 27, 2024
1 parent 73458c4 commit cc96fc0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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

0 comments on commit cc96fc0

Please sign in to comment.