electron#powerMonitor TypeScript 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: main.ts From SpaceEye with MIT License | 6 votes |
/**
* Heartbeat function which runs every `HEARTBEAT_INTERVAL` seconds to perform
* any necessary tasks.
*/
async function heartbeat() {
log.debug('Heartbeat triggered')
if (powerMonitor.getSystemIdleState(100) === 'locked') {
log.debug('Not updating from heartbeat because screen locked')
return
}
await WallpaperManager.update(Initiator.heartbeatFunction)
}
Example #2
Source File: main.ts From TidGi-Desktop with Mozilla Public License 2.0 | 6 votes |
app.on('ready', async () => {
whenCommonInitFinished()
// eslint-disable-next-line promise/always-return
.then(async () => {
buildLanguageMenu();
if (await preferenceService.get('syncBeforeShutdown')) {
wikiGitWorkspaceService.registerSyncBeforeShutdown();
}
await updaterService.checkForUpdates();
})
.catch((error) => console.error(error));
powerMonitor.on('shutdown', () => {
app.quit();
});
await initRendererI18NHandler();
await commonInit();
});
Example #3
Source File: index.ts From TidGi-Desktop with Mozilla Public License 2.0 | 6 votes |
public registerSyncBeforeShutdown(): void {
const listener = async (event: Event): Promise<void> => {
event.preventDefault();
try {
if (await this.contextService.isOnline()) {
const workspaces = await this.workspaceService.getWorkspacesAsList();
const workspacesToSync = workspaces.filter((workspace) => workspace.storageService !== SupportedStorageServices.local && !workspace.hibernated);
await Promise.allSettled([
this.notificationService.show({ title: i18n.t('Preference.SyncBeforeShutdown') }),
...workspacesToSync.map(async (workspace) => {
const userInfo = await this.authService.getStorageServiceUserInfo(workspace.storageService);
if (userInfo !== undefined && workspace.gitUrl !== null) {
await this.gitService.commitAndSync(workspace, { remoteUrl: workspace.gitUrl, userInfo });
}
}),
]);
}
} catch (error) {
logger.error(`SyncBeforeShutdown failed`, { error });
} finally {
app.quit();
}
};
powerMonitor.addListener('shutdown', listener);
}
Example #4
Source File: main.ts From SpaceEye with MIT License | 5 votes |
// mb.on('ready', () => {})
mb.on('ready', () => {
log.info('Menubar ready')
// createWindow()
heartbeatHandle = setInterval(heartbeat, HEARTBEAT_INTERVAL)
// Check if toolbar icon should be updated (Windows only)
updateToolbarIcon()
// Display config change triggers update
screen.on('display-added', async () => {
log.debug('Display added')
await WallpaperManager.update(Initiator.displayChangeWatcher)
})
screen.on('display-removed', async () => {
log.debug('Display removed')
await WallpaperManager.update(Initiator.displayChangeWatcher)
})
screen.on('display-metrics-changed', async () => {
log.debug('Display metrics changed')
await WallpaperManager.update(Initiator.displayChangeWatcher)
})
// Update when machine is unlocked/resumed
// TODO: Need a new initiator
if (process.platform === 'darwin' || process.platform === 'win32') {
powerMonitor.on('unlock-screen', async () => {
log.debug('Screen unlocked')
await WallpaperManager.update(Initiator.displayChangeWatcher)
})
}
if (process.platform === 'linux' || process.platform === 'win32') {
powerMonitor.on('resume', async () => {
log.debug('System resumed')
await WallpaperManager.update(Initiator.displayChangeWatcher)
})
}
// If first run, show user the window
if (AppConfigStore.firstRun) {
mb.showWindow()
// If macOS, no onboarding, so first run must be reset here
if (process.platform === 'darwin') {
AppConfigStore.firstRun = false
}
}
// Run an update on start
WallpaperManager.update(Initiator.user)
})
Example #5
Source File: main.ts From WowUp with GNU General Public License v3.0 | 5 votes |
powerMonitor.on("resume", () => {
log.info("powerMonitor resume");
win?.webContents?.send(IPC_POWER_MONITOR_RESUME);
});
Example #6
Source File: main.ts From WowUp with GNU General Public License v3.0 | 5 votes |
powerMonitor.on("suspend", () => {
log.info("powerMonitor suspend");
win?.webContents?.send(IPC_POWER_MONITOR_SUSPEND);
});
Example #7
Source File: main.ts From WowUp with GNU General Public License v3.0 | 5 votes |
powerMonitor.on("lock-screen", () => {
log.info("powerMonitor lock-screen");
win?.webContents?.send(IPC_POWER_MONITOR_LOCK);
});
Example #8
Source File: main.ts From WowUp with GNU General Public License v3.0 | 5 votes |
powerMonitor.on("unlock-screen", () => {
log.info("powerMonitor unlock-screen");
win?.webContents?.send(IPC_POWER_MONITOR_UNLOCK);
});