mirror of
https://gitee.com/dromara/electron-egg.git
synced 2026-06-12 13:51:04 +08:00
tray
This commit is contained in:
BIN
app/public/images/tray_logo.png
Normal file
BIN
app/public/images/tray_logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 435 B |
38
electron/tray.js
Normal file
38
electron/tray.js
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
const {app, Tray, Menu} = require('electron');
|
||||
const path = require('path');
|
||||
const pkg = require('../package.json');
|
||||
|
||||
module.exports = () => {
|
||||
MAIN_WINDOW.on('close', (event) => {
|
||||
if (!CAN_QUIT) {
|
||||
MAIN_WINDOW.hide();
|
||||
MAIN_WINDOW.setSkipTaskbar(true);
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
MAIN_WINDOW.show();
|
||||
let trayMenuTemplate = [{
|
||||
label: '退出',
|
||||
click: function () {
|
||||
MAIN_WINDOW.destroy();
|
||||
app.quit()
|
||||
}
|
||||
}]
|
||||
let iconPath = path.join(app.getAppPath(), '/app/public/images/tray_logo.png');
|
||||
APP_TRAY = new Tray(iconPath);
|
||||
const contextMenu = Menu.buildFromTemplate(trayMenuTemplate);
|
||||
APP_TRAY.setToolTip(pkg.softName);
|
||||
APP_TRAY.setContextMenu(contextMenu);
|
||||
APP_TRAY.on('click', function(){
|
||||
if (MAIN_WINDOW.isVisible()) {
|
||||
MAIN_WINDOW.hide();
|
||||
MAIN_WINDOW.setSkipTaskbar(false);
|
||||
} else {
|
||||
MAIN_WINDOW.show();
|
||||
MAIN_WINDOW.setSkipTaskbar(true);
|
||||
}
|
||||
});
|
||||
return APP_TRAY;
|
||||
}
|
||||
6
main.js
6
main.js
@@ -5,9 +5,12 @@ const setup = require('./electron/setup')
|
||||
const electronConfig = require('./electron/config')
|
||||
const storage = require('./electron/storage')
|
||||
const is = require('electron-is')
|
||||
const setTray = require('./electron/tray')
|
||||
|
||||
// main window
|
||||
global.MAIN_WINDOW = null
|
||||
global.APP_TRAY = null;
|
||||
global.CAN_QUIT = false;
|
||||
|
||||
// Initialize
|
||||
setup()
|
||||
@@ -71,6 +74,9 @@ async function createWindow () {
|
||||
// loding page
|
||||
MAIN_WINDOW.loadURL(path.join('file://', __dirname, '/app/public/loading.html'))
|
||||
|
||||
// tray
|
||||
setTray();
|
||||
|
||||
// egg server
|
||||
await startServer(eggConfig)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"version": "1.7.1",
|
||||
"description": "A fast, desktop software development framework",
|
||||
"main": "main.js",
|
||||
"softName": "electron-egg",
|
||||
"scripts": {
|
||||
"start": "electron .",
|
||||
"dev": "electron . --env=local",
|
||||
|
||||
Reference in New Issue
Block a user