Skip to content

Commit

Permalink
Fix when hidden electron
Browse files Browse the repository at this point in the history
  • Loading branch information
Chi-EEE committed Apr 19, 2024
1 parent f34d174 commit e6d3ebc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/admin_panel/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function isDev() {

function createWindow() {
// Create the browser window.
global.mainWindow = new BrowserWindow({
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
Expand All @@ -24,6 +24,8 @@ function createWindow() {
show: false
});

global.mainWindow = mainWindow;

// This block of code is intended for development purpose only.
// Delete this entire block of code when you are ready to package the application.
if (isDev()) {
Expand All @@ -47,6 +49,14 @@ function createWindow() {
global.mainWindow = null
});

global.mainWindow.on('hide', () => {
global.hidden = true;
});

global.mainWindow.on('show', () => {
global.hidden = false;
});

// Emitted when the window is ready to be shown
// This helps in showing the window gracefully.
global.mainWindow.once('ready-to-show', () => {
Expand Down
3 changes: 3 additions & 0 deletions app/admin_panel/js/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ class WebSocketServer {
if (uuid !== this.getSelectedRaspberryPi()?.uuid) {
return;
}
if (global.hidden) {
return;
}
global.mainWindow.webContents.send('onMessage', message.toString());
});
});
Expand Down

0 comments on commit e6d3ebc

Please sign in to comment.