From b887f869cd2f2f5a69b30a497758eeedf7d925a8 Mon Sep 17 00:00:00 2001 From: Martin Cavoj Date: Sun, 6 May 2018 12:15:01 +0200 Subject: [PATCH 1/9] version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3bc7472..74a5e41 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ }, "license": "MIT", "description": "Tray App for Hotel Process Manager", - "version": "0.1.0", + "version": "0.1.1", "dependencies": { "is-electron": "^2.1.0", "react": "^16.3.2", From c0c933b9aef105312bea3abd71c3472726586265 Mon Sep 17 00:00:00 2001 From: Martin Cavoj Date: Mon, 7 May 2018 16:34:31 +0200 Subject: [PATCH 2/9] fix issues on windows --- public/electron.js | 23 ++++++++++++++++------- public/preload.js | 2 +- src/App.css | 15 +++------------ src/App.js | 11 ++++++++--- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/public/electron.js b/public/electron.js index 3dba3c4..f0c4df2 100644 --- a/public/electron.js +++ b/public/electron.js @@ -1,11 +1,14 @@ -const { app, BrowserWindow, ipcMain, Tray } = require('electron') -const path = require('path') +const electron = require('electron'); +const { app, BrowserWindow, ipcMain, Tray } = electron; +const path = require('path'); const url = require('url'); const assetsDirectory = path.join(__dirname, './assets') -let tray = undefined -let window = undefined +let tray = undefined; +let window = undefined; +// workaround for Windows, where blur event occured when clicking on a tray icon +let blurredRecently = false; if (process.platform === 'darwin') { app.dock.hide() @@ -23,7 +26,6 @@ app.on('window-all-closed', () => { const createTray = () => { tray = new Tray(path.join(assetsDirectory, 'hotelTemplate.png')) tray.on('right-click', toggleWindow) - tray.on('double-click', toggleWindow) tray.on('click', function (event) { toggleWindow() @@ -36,10 +38,15 @@ const createTray = () => { const getWindowPosition = () => { const windowBounds = window.getBounds() const trayBounds = tray.getBounds() + const { width, height } = electron.screen.getPrimaryDisplay().workAreaSize; const x = Math.round(trayBounds.x + (trayBounds.width / 2) - (windowBounds.width / 2)) - const y = Math.round(trayBounds.y + trayBounds.height + 4) + let y = Math.round(trayBounds.y + trayBounds.height + 4) + + if (height < y) { + y = Math.round(trayBounds.y - windowBounds.height - 4) + } return { x: x, y: y } } @@ -66,6 +73,8 @@ const createWindow = () => { window.loadURL(startUrl); window.on('blur', () => { + blurredRecently = true; + setTimeout(() => blurredRecently = false, 100); if (!window.webContents.isDevToolsOpened()) { window.hide() } @@ -73,7 +82,7 @@ const createWindow = () => { } const toggleWindow = () => { - if (window.isVisible()) { + if (window.isVisible() || blurredRecently) { window.hide() } else { showWindow() diff --git a/public/preload.js b/public/preload.js index 958a9a6..b0b6e18 100644 --- a/public/preload.js +++ b/public/preload.js @@ -1,2 +1,2 @@ -const { shell } = require('electron'); +const { shell, Tray } = require('electron'); window.shell = shell; diff --git a/src/App.css b/src/App.css index 5c3ae4d..40fe4f2 100644 --- a/src/App.css +++ b/src/App.css @@ -1,12 +1,3 @@ -.footer-link { - padding-top: 8px; - padding-left: 10px; - font-size: calc(var(--font-size) - 4px); - float: left; -} - -.footer-link a { - color: var(--text-color); - cursor: pointer; - text-decoration: underline; -} +.window { + border: 1px solid #d2d2d2; +} \ No newline at end of file diff --git a/src/App.js b/src/App.js index 4ed7371..f0f0393 100644 --- a/src/App.js +++ b/src/App.js @@ -13,6 +13,7 @@ class App extends Component { } loadServers = () => { + this.setState({ loading: true }); this.getServers().then(servers => { servers = Object.keys(servers).map(serverId => { const server = servers[serverId]; @@ -29,7 +30,11 @@ class App extends Component { getServers = () => { return window.fetch(`${this.getHotelUrl()}/_/servers`).then(response => { this.setState({ loading: false }); - return response.json(); + if (response.ok) { + return response.json(); + } else { + return []; + } }); }; @@ -153,8 +158,8 @@ class App extends Component {