mirror of
https://github.com/sascha-hemi/homeassistant-desktop.git
synced 2026-03-21 00:04:12 +01:00
feat: Added reconnect button on error page
This commit is contained in:
21
app.js
21
app.js
@@ -17,6 +17,7 @@ const Bonjour = require('bonjour-service');
|
||||
const bonjour = new Bonjour.Bonjour();
|
||||
const logger = require('electron-log');
|
||||
const config = require('./config');
|
||||
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
autoUpdater.logger = logger;
|
||||
logger.catchErrors();
|
||||
@@ -114,6 +115,10 @@ function availabilityCheck() {
|
||||
if (config.get('automaticSwitching')) {
|
||||
checkForAvailableInstance();
|
||||
}
|
||||
|
||||
await delay(60 * 1000);
|
||||
|
||||
reinitMainWindow();
|
||||
});
|
||||
|
||||
request.end();
|
||||
@@ -531,6 +536,18 @@ function createMainWindow(show = false) {
|
||||
toggleFullScreen(!!config.get('fullScreen'));
|
||||
}
|
||||
|
||||
function reinitMainWindow() {
|
||||
logger.info('Re-initialized main window');
|
||||
mainWindow.destroy();
|
||||
mainWindow = null;
|
||||
createMainWindow(!config.has('currentInstance'));
|
||||
|
||||
if (!availabilityCheckerInterval) {
|
||||
logger.info('Re-initialized availability check');
|
||||
availabilityCheckerInterval = setInterval(availabilityCheck, 3000);
|
||||
}
|
||||
}
|
||||
|
||||
function showWindow() {
|
||||
if (!config.get('detachedMode')) {
|
||||
changePosition();
|
||||
@@ -736,3 +753,7 @@ ipcMain.on('ha-instance', (event, url) => {
|
||||
event.reply('ha-instance', currentInstance());
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on('reconnect', () => {
|
||||
reinitMainWindow();
|
||||
});
|
||||
|
||||
@@ -6,6 +6,13 @@
|
||||
<meta name="viewport" content="width=device-width,user-scalable=no"/>
|
||||
<link href="assets/style.css" rel="stylesheet"/>
|
||||
<link href="assets/error.css" rel="stylesheet"/>
|
||||
<script>
|
||||
const { ipcRenderer } = require('electron');
|
||||
|
||||
function reconnect() {
|
||||
ipcRenderer.send('reconnect');
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -25,6 +32,9 @@
|
||||
Home Assistant instance is not available, please check your connection.
|
||||
</p>
|
||||
</div>
|
||||
<div class="center">
|
||||
<button class="pure-material-button-contained" onclick="reconnect()">Reconnect</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user