electron/shell/browser/api/atom_api_power_monitor.h
Cheng Zhao 0fe6767d6b
chore: remove native_mate (Part 11) (#20719)
* refactor: convert Menu and globalShortcut to gin

* refactor: convert api::Cookies to gin

* refactor: convert View and WebContentsView to gin

* refactor: convert WebContents related classes to gin

* refactor: convert powerMonitor to gin

* refactor: prepare for header change

* refactor: remove last uses of mate::EventEmitter

* refactor: remove mate::EventEmitter

* refactor: move trackable_object to gin_helper

* fix: custom converter should not use Handle

* fix: no more need to check if icon is empty

It was a bug that the Handle<NativeImage> can be non-empty when the
image file does not exist. The bug was caused by the converter code
writing out the image even when the convertion fails.

The bug was work-arounded by adding an additional check, but since the
original bug had been fixed, the additional check is no longer needed.

* fix: should always set frameId even when callback is null

* fix: do not mix gin/mate handles for NativeImage
2019-10-25 22:03:28 +09:00

80 lines
2.2 KiB
C++

// Copyright (c) 2013 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_POWER_MONITOR_H_
#define SHELL_BROWSER_API_ATOM_API_POWER_MONITOR_H_
#include "base/compiler_specific.h"
#include "shell/browser/lib/power_observer.h"
#include "shell/common/gin_helper/trackable_object.h"
#include "ui/base/idle/idle.h"
namespace electron {
namespace api {
class PowerMonitor : public gin_helper::TrackableObject<PowerMonitor>,
public PowerObserver {
public:
static v8::Local<v8::Value> Create(v8::Isolate* isolate);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
protected:
explicit PowerMonitor(v8::Isolate* isolate);
~PowerMonitor() override;
// Called by native calles.
bool ShouldShutdown();
#if defined(OS_LINUX)
// Private JS APIs.
void BlockShutdown();
void UnblockShutdown();
#endif
#if defined(OS_MACOSX) || defined(OS_WIN)
void InitPlatformSpecificMonitors();
#endif
// base::PowerObserver implementations:
void OnPowerStateChange(bool on_battery_power) override;
void OnSuspend() override;
void OnResume() override;
private:
ui::IdleState GetSystemIdleState(v8::Isolate* isolate, int idle_threshold);
int GetSystemIdleTime();
#if defined(OS_WIN)
// Static callback invoked when a message comes in to our messaging window.
static LRESULT CALLBACK WndProcStatic(HWND hwnd,
UINT message,
WPARAM wparam,
LPARAM lparam);
LRESULT CALLBACK WndProc(HWND hwnd,
UINT message,
WPARAM wparam,
LPARAM lparam);
// The window class of |window_|.
ATOM atom_;
// The handle of the module that contains the window procedure of |window_|.
HMODULE instance_;
// The window used for processing events.
HWND window_;
#endif
DISALLOW_COPY_AND_ASSIGN(PowerMonitor);
};
} // namespace api
} // namespace electron
#endif // SHELL_BROWSER_API_ATOM_API_POWER_MONITOR_H_