Skip to content

Commit

Permalink
Add: Minimize to tray
Browse files Browse the repository at this point in the history
  • Loading branch information
LmeSzinc committed Oct 31, 2021
1 parent 5bde0ae commit 72043ab
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 23 deletions.
2 changes: 2 additions & 0 deletions webapp/.yarnclean
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ wercker.yml
# misc
*.md
LICENSE
*.txt
!path.txt
Binary file added webapp/packages/main/public/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 37 additions & 7 deletions webapp/packages/main/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {app, BrowserWindow, ipcMain, globalShortcut} from 'electron';
import {app, Menu, Tray, BrowserWindow, ipcMain, globalShortcut} from 'electron';
import {URL} from 'url';
import {PyShell} from '/@/pyshell';
import {webuiArgs, webuiPath} from '/@/config';
Expand Down Expand Up @@ -69,7 +69,7 @@ const createWindow = async () => {
mainWindow?.webContents.openDevTools();
}
});

mainWindow.on('focus', function () {
// Dev tools
globalShortcut.register('Ctrl+Shift+I', function () {
Expand All @@ -92,20 +92,50 @@ const createWindow = async () => {
});

// Minimize, maximize, close window.
ipcMain.on('window-tray', function () {
mainWindow?.hide();
});
ipcMain.on('window-min', function () {
mainWindow?.minimize();
});
ipcMain.on('window-max', function () {
if (mainWindow?.isMaximized()) {
mainWindow?.restore();
} else {
mainWindow?.maximize();
}
mainWindow?.isMaximized() ? mainWindow?.restore() : mainWindow?.maximize();
});
ipcMain.on('window-close', function () {
alas.kill();
setTimeout(() => mainWindow?.close(), 500); // Wait taskkill to finish
});

// Tray
const tray = new Tray(path.join(__dirname, 'icon.png'));
const contextMenu = Menu.buildFromTemplate([
{
label: 'Show',
click: function () {
mainWindow?.show();
}
},
{
label: 'Hide',
click: function () {
mainWindow?.hide();
}
},
{
label: 'Exit',
click: function () {
app.quit();
}
}
]);
tray.setToolTip('Alas');
tray.setContextMenu(contextMenu);
tray.on('click', () => {
mainWindow?.isVisible() ? mainWindow?.hide() : mainWindow?.show()
});
tray.on('right-click', () => {
tray.popUpContextMenu(contextMenu)
});
};


Expand Down
15 changes: 0 additions & 15 deletions webapp/packages/renderer/assets/logo.svg

This file was deleted.

7 changes: 6 additions & 1 deletion webapp/packages/renderer/src/components/AppHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div class="app-header">
<div class="header-drag"></div>
<div class="header-icon">
<ArrowDownOutlined class="icon" @click="trayWin"></ArrowDownOutlined>
<MinusOutlined class="icon" @click="minimizeWin"></MinusOutlined>
<BorderOutlined class="icon" @click="maximizeWin"></BorderOutlined>
<CloseOutlined class="icon" @click="closeWin"></CloseOutlined>
Expand All @@ -11,18 +12,22 @@

<script lang="ts">
import {defineComponent} from 'vue';
import {BorderOutlined, CloseOutlined, MinusOutlined} from '@ant-design/icons-vue';
import {BorderOutlined, CloseOutlined, MinusOutlined, ArrowDownOutlined} from '@ant-design/icons-vue';
const ipcRenderer = require('electron').ipcRenderer;
export default defineComponent({
name: 'AppHeader',
components: {
ArrowDownOutlined,
MinusOutlined,
BorderOutlined,
CloseOutlined,
},
methods: {
trayWin() {
ipcRenderer.send('window-tray');
},
minimizeWin() {
ipcRenderer.send('window-min');
},
Expand Down

0 comments on commit 72043ab

Please sign in to comment.