Skip to content

Commit 7d5c845

Browse files
committed
Fixed mishandling of monitor info during refresh
Fixes #390
1 parent 87b2e0d commit 7d5c845

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/electron.js

+25-17
Original file line numberDiff line numberDiff line change
@@ -666,13 +666,13 @@ function applyProfile(profile = {}, useTransition = false, transitionSpeed = 1)
666666
}
667667

668668

669-
function applyHotkeys() {
669+
function applyHotkeys(monitorList = monitors) {
670670
if (settings.hotkeys !== undefined) {
671671
globalShortcut.unregisterAll()
672672
for (let hotkey of Object.values(settings.hotkeys)) {
673673
try {
674674
// Only apply if found
675-
if (hotkey.monitor == "all" || hotkey.monitor == "turn_off_displays" || Object.values(monitors).find(m => m.id == hotkey.monitor)) {
675+
if (hotkey.monitor == "all" || hotkey.monitor == "turn_off_displays" || Object.values(monitorList).find(m => m.id == hotkey.monitor)) {
676676
hotkey.active = globalShortcut.register(hotkey.accelerator, () => {
677677
doHotkey(hotkey)
678678
})
@@ -1254,29 +1254,38 @@ refreshMonitors = async (fullRefresh = false, bypassRateLimit = false) => {
12541254
let oldMonitors = Object.assign({}, monitors)
12551255
let newMonitors
12561256

1257+
let failed = false
12571258
try {
12581259
newMonitors = await refreshMonitorsJob(fullRefresh)
1259-
if(!newMonitors) throw "No monitors!";
1260+
if(!newMonitors) {
1261+
failed = true;
1262+
throw "No monitors recieved!";
1263+
}
12601264
lastEagerUpdate = Date.now()
12611265
} catch (e) {
12621266
console.log('Couldn\'t refresh monitors', e)
12631267
}
12641268

12651269
isRefreshing = false
1266-
applyOrder()
1267-
applyRemaps()
1268-
applyHotkeys()
1269-
1270-
for(let id in newMonitors) {
1271-
newMonitors[id].brightness = normalizeBrightness(newMonitors[id].brightness, true, newMonitors[id].min, newMonitors[id].max)
1272-
}
12731270

1274-
// Only send update if something changed
1275-
if (JSON.stringify(newMonitors) !== JSON.stringify(oldMonitors)) {
1276-
setTrayPercent()
1277-
sendToAllWindows('monitors-updated', monitors)
1278-
} else {
1279-
console.log("===--- NO CHANGE ---===")
1271+
if(!failed) {
1272+
applyOrder(newMonitors)
1273+
applyRemaps(newMonitors)
1274+
applyHotkeys(newMonitors)
1275+
1276+
for(let id in newMonitors) {
1277+
newMonitors[id].brightness = normalizeBrightness(newMonitors[id].brightness, true, newMonitors[id].min, newMonitors[id].max)
1278+
}
1279+
1280+
monitors = newMonitors;
1281+
1282+
// Only send update if something changed
1283+
if (JSON.stringify(newMonitors) !== JSON.stringify(oldMonitors)) {
1284+
setTrayPercent()
1285+
sendToAllWindows('monitors-updated', monitors)
1286+
} else {
1287+
console.log("===--- NO CHANGE ---===")
1288+
}
12801289
}
12811290

12821291
if (shouldShowPanel) {
@@ -1285,7 +1294,6 @@ refreshMonitors = async (fullRefresh = false, bypassRateLimit = false) => {
12851294
}
12861295

12871296
console.log("\x1b[34m---------------------------------------------- \x1b[0m")
1288-
monitors = newMonitors;
12891297
return monitors;
12901298
}
12911299

0 commit comments

Comments
 (0)