Add hide to tray
This commit is contained in:
parent
4a7fec4ba3
commit
18c87e1a14
3 changed files with 73 additions and 12 deletions
|
@ -1,11 +1,15 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { app, crashReporter, BrowserWindow, Menu } from 'electron';
|
import { app, crashReporter, BrowserWindow, Menu, Tray } from 'electron';
|
||||||
|
const screenz = require('screenz');
|
||||||
|
|
||||||
const isDevelopment = process.env.NODE_ENV === 'development';
|
const isDevelopment = process.env.NODE_ENV === 'development';
|
||||||
|
|
||||||
let mainWindow = null;
|
let mainWindow = null;
|
||||||
let forceQuit = false;
|
let forceQuit = false;
|
||||||
|
|
||||||
|
const windowSize = { width: 630, height: 350 };
|
||||||
|
const taskBarHeight = 40;
|
||||||
|
|
||||||
const installExtensions = async () => {
|
const installExtensions = async () => {
|
||||||
const installer = require('electron-devtools-installer');
|
const installer = require('electron-devtools-installer');
|
||||||
const extensions = ['REACT_DEVELOPER_TOOLS', 'REDUX_DEVTOOLS'];
|
const extensions = ['REACT_DEVELOPER_TOOLS', 'REDUX_DEVTOOLS'];
|
||||||
|
@ -19,13 +23,6 @@ const installExtensions = async () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
crashReporter.start({
|
|
||||||
productName: 'GHOSCHTS Lamp control',
|
|
||||||
companyName: 'GHOSCHT',
|
|
||||||
submitURL: 'https://your-domain.com/url-to-submit',
|
|
||||||
uploadToServer: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
// On OS X it is common for applications and their menu bar
|
// On OS X it is common for applications and their menu bar
|
||||||
// to stay active until the user quits explicitly with Cmd + Q
|
// to stay active until the user quits explicitly with Cmd + Q
|
||||||
|
@ -40,10 +37,15 @@ app.on('ready', async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: 630,
|
width: windowSize.width,
|
||||||
height: 370,
|
height: windowSize.height,
|
||||||
|
x: screenz.width - windowSize.width,
|
||||||
|
y: screenz.height - windowSize.height - taskBarHeight,
|
||||||
|
movable: false,
|
||||||
resizable: false,
|
resizable: false,
|
||||||
|
frame: false,
|
||||||
show: false,
|
show: false,
|
||||||
|
alwaysOnTop: true,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
},
|
},
|
||||||
|
@ -83,9 +85,51 @@ app.on('ready', async () => {
|
||||||
mainWindow.on('closed', () => {
|
mainWindow.on('closed', () => {
|
||||||
mainWindow = null;
|
mainWindow = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.on('browser-window-blur', () => {
|
||||||
|
if (mainWindow) {
|
||||||
|
mainWindow.hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let tray = null;
|
||||||
|
tray = createTray();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function createTray() {
|
||||||
|
let appIcon = new Tray(path.join(__dirname, '../../dist-assets/icon.png'));
|
||||||
|
const contextMenu = Menu.buildFromTemplate([
|
||||||
|
{
|
||||||
|
label: 'Show',
|
||||||
|
click: () => {
|
||||||
|
mainWindow.show();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Hide',
|
||||||
|
click: () => {
|
||||||
|
mainWindow.hide();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Exit',
|
||||||
|
click: () => {
|
||||||
|
app.isQuiting = true;
|
||||||
|
app.quit();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
appIcon.on('click', (event) => {
|
||||||
|
mainWindow.show();
|
||||||
|
});
|
||||||
|
|
||||||
|
appIcon.setToolTip('Light Control');
|
||||||
|
appIcon.setContextMenu(contextMenu);
|
||||||
|
return appIcon;
|
||||||
|
}
|
||||||
|
|
||||||
if (isDevelopment) {
|
if (isDevelopment) {
|
||||||
// auto-open dev tools
|
// auto-open dev tools
|
||||||
mainWindow.webContents.openDevTools();
|
mainWindow.webContents.openDevTools();
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
"redux-actions": "^2.6.5",
|
"redux-actions": "^2.6.5",
|
||||||
"redux-localstorage": "^0.4.1",
|
"redux-localstorage": "^0.4.1",
|
||||||
"redux-thunk": "^2.2.0",
|
"redux-thunk": "^2.2.0",
|
||||||
|
"screenz": "^1.0.0",
|
||||||
"serialport": "^9.0.0",
|
"serialport": "^9.0.0",
|
||||||
"yarn": "^1.22.4"
|
"yarn": "^1.22.4"
|
||||||
},
|
},
|
||||||
|
|
|
@ -5009,7 +5009,7 @@ mute-stream@0.0.8:
|
||||||
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"
|
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"
|
||||||
integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==
|
integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==
|
||||||
|
|
||||||
nan@^2.12.1, nan@^2.14.1:
|
nan@^2.12.1, nan@^2.14.0, nan@^2.14.1:
|
||||||
version "2.14.1"
|
version "2.14.1"
|
||||||
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.1.tgz#d7be34dfa3105b91494c3147089315eff8874b01"
|
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.1.tgz#d7be34dfa3105b91494c3147089315eff8874b01"
|
||||||
integrity sha512-isWHgVjnFjh2x2yuJ/tj3JbwoHu3UC2dX5G/88Cm24yB6YopVgxvBObDY7n5xW6ExmFhJpSEQqFPvq9zaXc8Jw==
|
integrity sha512-isWHgVjnFjh2x2yuJ/tj3JbwoHu3UC2dX5G/88Cm24yB6YopVgxvBObDY7n5xW6ExmFhJpSEQqFPvq9zaXc8Jw==
|
||||||
|
@ -5061,7 +5061,7 @@ nice-try@^1.0.4:
|
||||||
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
|
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
|
||||||
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==
|
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==
|
||||||
|
|
||||||
node-abi@^2.7.0:
|
node-abi@^2.13.0, node-abi@^2.7.0:
|
||||||
version "2.18.0"
|
version "2.18.0"
|
||||||
resolved "https://registry.yarnpkg.com/node-abi/-/node-abi-2.18.0.tgz#1f5486cfd7d38bd4f5392fa44a4ad4d9a0dffbf4"
|
resolved "https://registry.yarnpkg.com/node-abi/-/node-abi-2.18.0.tgz#1f5486cfd7d38bd4f5392fa44a4ad4d9a0dffbf4"
|
||||||
integrity sha512-yi05ZoiuNNEbyT/xXfSySZE+yVnQW6fxPZuFbLyS1s6b5Kw3HzV2PHOM4XR+nsjzkHxByK+2Wg+yCQbe35l8dw==
|
integrity sha512-yi05ZoiuNNEbyT/xXfSySZE+yVnQW6fxPZuFbLyS1s6b5Kw3HzV2PHOM4XR+nsjzkHxByK+2Wg+yCQbe35l8dw==
|
||||||
|
@ -6146,6 +6146,15 @@ roarr@^2.15.3:
|
||||||
semver-compare "^1.0.0"
|
semver-compare "^1.0.0"
|
||||||
sprintf-js "^1.1.2"
|
sprintf-js "^1.1.2"
|
||||||
|
|
||||||
|
robotjs@~0.6.0:
|
||||||
|
version "0.6.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/robotjs/-/robotjs-0.6.0.tgz#8d1f63221f5b18dc496c7768f75261043891f64a"
|
||||||
|
integrity sha512-6pRWI3d+CBZqCXT/rsJfabbZoELua+jTeXilG27F8Jvix/J2BYZ0O7Tly2WCmXyqw5xYdCvOwvCeLRHEtXkt4w==
|
||||||
|
dependencies:
|
||||||
|
nan "^2.14.0"
|
||||||
|
node-abi "^2.13.0"
|
||||||
|
prebuild-install "^5.3.3"
|
||||||
|
|
||||||
run-async@^2.4.0:
|
run-async@^2.4.0:
|
||||||
version "2.4.1"
|
version "2.4.1"
|
||||||
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455"
|
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455"
|
||||||
|
@ -6212,6 +6221,13 @@ scheduler@^0.19.1:
|
||||||
loose-envify "^1.1.0"
|
loose-envify "^1.1.0"
|
||||||
object-assign "^4.1.1"
|
object-assign "^4.1.1"
|
||||||
|
|
||||||
|
screenz@^1.0.0:
|
||||||
|
version "1.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/screenz/-/screenz-1.0.0.tgz#9e59fe161f1744416036f0171c716faf3d891d2b"
|
||||||
|
integrity sha512-dAEx0aCTL99Kw6MUtJGpgjxNpeG7+vg52Yik09stY9TOKnHr1W8NU7TAF6AoMgV2cr7yiCLyqbNbmQJtGtdcbw==
|
||||||
|
dependencies:
|
||||||
|
robotjs "~0.6.0"
|
||||||
|
|
||||||
semver-compare@^1.0.0:
|
semver-compare@^1.0.0:
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc"
|
resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc"
|
||||||
|
|
Reference in a new issue