mirror of
https://github.com/sascha-hemi/homeassistant-desktop.git
synced 2026-03-21 04:06:06 +01:00
refactor: Refactor availability checker method
This commit is contained in:
51
app.js
51
app.js
@@ -40,6 +40,7 @@ let forceQuit = false;
|
|||||||
let resizeEvent = false;
|
let resizeEvent = false;
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
let tray;
|
let tray;
|
||||||
|
let availabilityCheckerInterval;
|
||||||
|
|
||||||
function registerKeyboardShortcut() {
|
function registerKeyboardShortcut() {
|
||||||
globalShortcut.register('CommandOrControl+Alt+X', () => {
|
globalShortcut.register('CommandOrControl+Alt+X', () => {
|
||||||
@@ -88,30 +89,34 @@ function checkAutoStart() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function startAvailabilityCheck() {
|
function availabilityCheck() {
|
||||||
let interval;
|
const instance = currentInstance();
|
||||||
|
|
||||||
function availabilityCheck() {
|
if (!instance) {
|
||||||
const request = net.request(`${currentInstance()}/auth/providers`);
|
return;
|
||||||
request.on('response', (response) => {
|
|
||||||
if (response.statusCode !== 200) {
|
|
||||||
logger.error('Error: ' + response);
|
|
||||||
}
|
|
||||||
showError(response.statusCode !== 200);
|
|
||||||
});
|
|
||||||
request.on('error', (error) => {
|
|
||||||
logger.error(error);
|
|
||||||
clearInterval(interval);
|
|
||||||
showError(true);
|
|
||||||
|
|
||||||
if (config.get('automaticSwitching')) {
|
|
||||||
checkForAvailableInstance();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
request.end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interval = setInterval(availabilityCheck, 3000);
|
const request = net.request(`${instance}/auth/providers`);
|
||||||
|
|
||||||
|
request.on('response', (response) => {
|
||||||
|
if (response.statusCode !== 200) {
|
||||||
|
logger.error('Response error: ' + response);
|
||||||
|
showError(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
request.on('error', async (error) => {
|
||||||
|
logger.error(error);
|
||||||
|
clearInterval(availabilityCheckerInterval);
|
||||||
|
availabilityCheckerInterval = null;
|
||||||
|
showError(true);
|
||||||
|
|
||||||
|
if (config.get('automaticSwitching')) {
|
||||||
|
checkForAvailableInstance();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
request.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
function changePosition() {
|
function changePosition() {
|
||||||
@@ -684,7 +689,9 @@ app.whenReady().then(() => {
|
|||||||
tray.setContextMenu(getMenu());
|
tray.setContextMenu(getMenu());
|
||||||
}
|
}
|
||||||
|
|
||||||
startAvailabilityCheck();
|
if (!availabilityCheckerInterval) {
|
||||||
|
availabilityCheckerInterval = setInterval(availabilityCheck, 3000);
|
||||||
|
}
|
||||||
|
|
||||||
// register shortcut
|
// register shortcut
|
||||||
if (config.get('shortcutEnabled')) {
|
if (config.get('shortcutEnabled')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user