0Pricing
Electron Desktop App Development · Aula

Monitoramento de Energia e Hardware

Acesse eventos nativos de energia e hardware com o módulo powerMonitor do Electron para criar aplicativos de desktop responsivos e atentos ao consumo da bateria.

Monitoramento de Energia e Hardware é uma aula grátis de Electron Desktop App Development no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Electron Desktop App Development, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Electron Desktop App Development inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

Apps That Sense Their Environment

Great native apps react to power and hardware state: pausing work on battery, saving before sleep, resuming on wake.

The powerMonitor Module

Electron's powerMonitor in the main process emits system power events and reports battery state.

const { powerMonitor } = require('electron');
app.whenReady().then(() => {
  console.log(powerMonitor.getSystemIdleState(60));
});

Suspend and Resume

Listen for suspend and resume to flush data before sleep and refresh after wake.

powerMonitor.on('suspend', () => saveState());
powerMonitor.on('resume', () => reconnect());

Battery vs AC Power

The on-battery and on-ac events let you throttle background work to save battery.

function syncInterval(onBattery) {
  return onBattery ? 300000 : 60000;
}
console.log(syncInterval(true));

Detecting Idle Time

getSystemIdleTime() returns seconds since the last user input, useful for auto-lock or away status.

function isAway(idleSeconds) {
  return idleSeconds > 300;
}
console.log(isAway(420));

Idle State

getSystemIdleState(threshold) reports 'active', 'idle', 'locked', or 'unknown' in one call.

Screen Lock Events

The lock-screen and unlock-screen events help you secure sensitive UI when the user steps away.

powerMonitor.on('lock-screen', () => blurSensitiveData());

Preventing Sleep

Use powerSaveBlocker to keep the system awake during downloads or media playback, then release it promptly.

const { powerSaveBlocker } = require('electron');
const id = powerSaveBlocker.start('prevent-app-suspension');

Releasing Blockers

Always call powerSaveBlocker.stop(id) when the task ends, or you will drain the user's battery.

Notifying the Renderer

Forward power events to the UI over IPC so the renderer can update its status indicators.

Designing for Power Awareness

Combine these signals to build apps that are respectful of resources: defer heavy work on battery, resume cleanly after sleep.

Quick Check

Test your power monitoring knowledge.

Recap

You learned to use powerMonitor for suspend/resume, battery and AC detection, idle time, and screen lock events, plus powerSaveBlocker to keep the system awake responsibly.

Perguntas Frequentes

A aula “Monitoramento de Energia e Hardware” é grátis?

Sim — o texto completo de “Monitoramento de Energia e Hardware” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Electron Desktop App Development, atualize para CoddyKit PRO. O curso de Electron Desktop App Development inclui 4 aulas no total.

O que vou aprender em “Monitoramento de Energia e Hardware”?

Acesse eventos nativos de energia e hardware com o módulo powerMonitor do Electron para criar aplicativos de desktop responsivos e atentos ao consumo da bateria. Você pratica Electron Desktop App Development com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Electron Desktop App Development?

Nenhuma experiência prévia é necessária. Electron Desktop App Development no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Monitoramento de Energia e Hardware”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Electron Desktop App Development?

Sim. Cada aula de Electron Desktop App Development inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Trabalho com Módulos Nativos
  2. Aplicações na Bandeja e Emblemas
  3. Captura de Tela e Mídia
  4. Monitoramento de Energia e Hardware
← Voltar para Electron Desktop App Development