Lightcord/modules/discord_desktop_core/core/app/discord_native/browser/powerSaveBlocker.js

28 lines
876 B
JavaScript
Raw Normal View History

2020-12-12 11:56:28 +01:00
"use strict";
2020-06-06 12:51:51 +02:00
const electron = require('electron');
const {
POWER_SAVE_BLOCKER_BLOCK_DISPLAY_SLEEP,
POWER_SAVE_BLOCKER_UNBLOCK_DISPLAY_SLEEP,
POWER_SAVE_BLOCKER_CLEANUP_DISPLAY_SLEEP
} = require('../common/constants').IPCEvents;
const powerSaveBlockerIds = new Set();
2020-12-12 11:56:28 +01:00
electron.ipcMain.handle(POWER_SAVE_BLOCKER_BLOCK_DISPLAY_SLEEP, async _ => {
const newId = electron.powerSaveBlocker.start('prevent-display-sleep');
powerSaveBlockerIds.add(newId);
return newId;
});
electron.ipcMain.handle(POWER_SAVE_BLOCKER_UNBLOCK_DISPLAY_SLEEP, async (_, id) => {
electron.powerSaveBlocker.stop(id);
powerSaveBlockerIds.delete(id);
});
electron.ipcMain.handle(POWER_SAVE_BLOCKER_CLEANUP_DISPLAY_SLEEP, async _ => {
// cleanup all previous sleeps
for (const id of powerSaveBlockerIds) {
2020-06-06 12:51:51 +02:00
electron.powerSaveBlocker.stop(id);
2020-12-12 11:56:28 +01:00
}
2020-06-06 12:51:51 +02:00
2020-12-12 11:56:28 +01:00
powerSaveBlockerIds.clear();
});