electron#powerMonitor JavaScript Examples
The following examples show how to use
electron#powerMonitor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: application.js From razer-macos with GNU General Public License v2.0 | 4 votes |
initListeners() {
this.app.on('ready', () => {
this.createTray();
this.createWindow();
});
this.app.on('quit', () => {
this.razerApplication.destroy();
});
nativeTheme.on('updated', () => {
this.createTray();
});
powerMonitor.on('suspend', () => {
if(this.razerApplication.stateManager.stateOnSuspend == null) {
return;
}
this.razerApplication.refresh(false).then(() => {
return this.razerApplication.stateManager.suspend();
});
});
powerMonitor.on('resume', () => {
if(this.razerApplication.stateManager.stateOnResume == null) {
return;
}
this.razerApplication.refresh(false).then(() => {
return this.razerApplication.stateManager.resume();
});
});
powerMonitor.on('on-ac', () => {
if(this.razerApplication.stateManager.stateOnAc == null) {
return;
}
this.razerApplication.refresh(false).then(() => {
return this.razerApplication.stateManager.onAc();
});
});
powerMonitor.on('on-battery', () => {
if(this.razerApplication.stateManager.stateOnBattery == null) {
return;
}
this.razerApplication.refresh(false).then(() => {
return this.razerApplication.stateManager.onBattery();
});
});
powerMonitor.on('shutdown', () => {
if(this.razerApplication.stateManager.stateOnShutdown == null) {
return;
}
this.razerApplication.refresh(false).then(() => {
return this.razerApplication.stateManager.shutdown();
});
});
powerMonitor.on('lock-screen', () => {
if(this.razerApplication.stateManager.stateOnLockScreen == null) {
return;
}
this.razerApplication.refresh(false).then(() => {
return this.razerApplication.stateManager.lockScreen();
});
});
powerMonitor.on('unlock-screen', () => {
if(this.razerApplication.stateManager.stateOnUnlockScreen == null) {
return;
}
this.razerApplication.refresh(false).then(() => {
return this.razerApplication.stateManager.unlockScreen();
});
});
powerMonitor.on('user-did-become-active', () => {
if(this.razerApplication.stateManager.stateOnUserDidBecomeActive == null) {
return;
}
this.razerApplication.refresh(false).then(() => {
return this.razerApplication.stateManager.userDidBecomeActive();
});
});
powerMonitor.on('user-did-resign-active', () => {
if(this.razerApplication.stateManager.stateOnUserDidResignActive == null) {
return;
}
this.razerApplication.refresh(false).then(() => {
return this.razerApplication.stateManager.userDidResignActive();
});
});
// mouse dpi rpc listener
ipcMain.on('request-set-dpi', (_, arg) => {
const { device, dpi } = arg;
const currentDevice = this.razerApplication.deviceManager.getByInternalId(device.internalId);
currentDevice.setDPI(dpi);
this.refreshTray();
});
// keyboard brightness rpc listener
ipcMain.on('update-brightness', (_, arg) => {
const { device, brightness } = arg;
const currentDevice = this.razerApplication.deviceManager.getByInternalId(device.internalId);
currentDevice.setBrightness(brightness);
this.refreshTray();
});
// custom color rpc listener
ipcMain.on('request-set-custom-color', (_, arg) => {
const { device } = arg;
const currentDevice = this.razerApplication.deviceManager.getByInternalId(device.internalId);
currentDevice.setSettings(device.settings);
this.refreshTray();
});
// custom cycle color rpc listener
ipcMain.on('request-cycle-color', (_, arg) => {
const { index, color } = arg;
this.razerApplication.cycleAnimation.updateColor(index, color.rgb);
this.refreshTray();
});
// mouse brightness
['Matrix','Logo', 'Scroll', 'Left', 'Right'].forEach(brightnessMouseIdentifier => {
ipcMain.on('update-mouse-' + brightnessMouseIdentifier.toLowerCase() + '-brightness', (_, arg) => {
const { device, brightness } = arg;
const currentDevice = this.razerApplication.deviceManager.getByInternalId(device.internalId);
currentDevice['setBrightness' + brightnessMouseIdentifier](brightness);
this.refreshTray();
});
});
// poll rate
ipcMain.on('update-mouse-pollrate', (_, arg) => {
const { device, pollRate } = arg;
const currentDevice = this.razerApplication.deviceManager.getByInternalId(device.internalId);
currentDevice.setPollRate(pollRate);
});
//state manager
ipcMain.on('state-settings-add', async (event, stateName) => {
event.returnValue = await this.razerApplication.stateManager.addState(stateName);
});
ipcMain.on('state-settings-remove', (event, stateName) => {
this.razerApplication.stateManager.removeState(stateName);
});
ipcMain.on('state-settings-activate', (event, stateName) => {
this.razerApplication.stateManager.activateState(stateName);
});
ipcMain.on('state-settings-start', (event, stateValue) => {
this.razerApplication.stateManager.stateOnStart = stateValue;
this.razerApplication.stateManager.save();
});
ipcMain.on('state-settings-suspend', (event, stateValue) => {
this.razerApplication.stateManager.stateOnSuspend = stateValue;
this.razerApplication.stateManager.save();
});
ipcMain.on('state-settings-resume', (event, stateValue) => {
this.razerApplication.stateManager.stateOnResume = stateValue;
this.razerApplication.stateManager.save();
});
ipcMain.on('state-settings-ac', (event, stateValue) => {
this.razerApplication.stateManager.stateOnAc = stateValue;
this.razerApplication.stateManager.save();
});
ipcMain.on('state-settings-battery', (event, stateValue) => {
this.razerApplication.stateManager.stateOnBattery = stateValue;
this.razerApplication.stateManager.save();
});
ipcMain.on('state-settings-shutdown', (event, stateValue) => {
this.razerApplication.stateManager.stateOnShutdown = stateValue;
this.razerApplication.stateManager.save();
});
ipcMain.on('state-settings-lockscreen', (event, stateValue) => {
this.razerApplication.stateManager.stateOnLockScreen = stateValue;
this.razerApplication.stateManager.save();
});
ipcMain.on('state-settings-unlockscreen', (event, stateValue) => {
this.razerApplication.stateManager.stateOnUnlockScreen = stateValue;
this.razerApplication.stateManager.save();
});
ipcMain.on('state-settings-userdidbecomeactive', (event, stateValue) => {
this.razerApplication.stateManager.stateOnUserDidBecomeActive = stateValue;
this.razerApplication.stateManager.save();
});
ipcMain.on('state-settings-userdidresignactive', (event, stateValue) => {
this.razerApplication.stateManager.stateOnUserDidResignActive = stateValue;
this.razerApplication.stateManager.save();
});
}