2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-08-03 07:58:59 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#ifndef SHELL_BROWSER_API_ATOM_API_POWER_MONITOR_H_
|
|
|
|
#define SHELL_BROWSER_API_ATOM_API_POWER_MONITOR_H_
|
2013-08-03 07:58:59 +00:00
|
|
|
|
|
|
|
#include "base/compiler_specific.h"
|
2014-04-17 09:13:17 +00:00
|
|
|
#include "native_mate/handle.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/api/trackable_object.h"
|
|
|
|
#include "shell/browser/lib/power_observer.h"
|
2018-03-14 05:42:08 +00:00
|
|
|
#include "ui/base/idle/idle.h"
|
2013-08-03 07:58:59 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2013-08-03 07:58:59 +00:00
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2015-11-04 10:21:03 +00:00
|
|
|
class PowerMonitor : public mate::TrackableObject<PowerMonitor>,
|
2017-12-01 11:44:45 +00:00
|
|
|
public PowerObserver {
|
2013-08-03 07:58:59 +00:00
|
|
|
public:
|
2015-05-22 11:11:22 +00:00
|
|
|
static v8::Local<v8::Value> Create(v8::Isolate* isolate);
|
2013-08-03 07:58:59 +00:00
|
|
|
|
2016-04-25 01:17:54 +00:00
|
|
|
static void BuildPrototype(v8::Isolate* isolate,
|
2016-08-02 09:08:12 +00:00
|
|
|
v8::Local<v8::FunctionTemplate> prototype);
|
2016-04-25 01:17:54 +00:00
|
|
|
|
2013-08-03 07:58:59 +00:00
|
|
|
protected:
|
2016-04-25 01:17:54 +00:00
|
|
|
explicit PowerMonitor(v8::Isolate* isolate);
|
2015-11-04 10:21:03 +00:00
|
|
|
~PowerMonitor() override;
|
|
|
|
|
2018-02-05 06:49:43 +00:00
|
|
|
// Called by native calles.
|
|
|
|
bool ShouldShutdown();
|
|
|
|
|
|
|
|
#if defined(OS_LINUX)
|
|
|
|
// Private JS APIs.
|
|
|
|
void BlockShutdown();
|
|
|
|
void UnblockShutdown();
|
|
|
|
#endif
|
|
|
|
|
2018-04-30 16:04:27 +00:00
|
|
|
#if defined(OS_MACOSX) || defined(OS_WIN)
|
|
|
|
void InitPlatformSpecificMonitors();
|
|
|
|
#endif
|
|
|
|
|
2014-04-17 09:13:17 +00:00
|
|
|
// base::PowerObserver implementations:
|
2015-01-10 01:24:36 +00:00
|
|
|
void OnPowerStateChange(bool on_battery_power) override;
|
|
|
|
void OnSuspend() override;
|
|
|
|
void OnResume() override;
|
2013-08-03 07:58:59 +00:00
|
|
|
|
2014-04-18 09:28:05 +00:00
|
|
|
private:
|
2019-02-27 20:54:01 +00:00
|
|
|
ui::IdleState GetSystemIdleState(v8::Isolate* isolate, int idle_threshold);
|
|
|
|
int GetSystemIdleTime();
|
2018-03-14 05:42:08 +00:00
|
|
|
|
2018-04-30 16:04:27 +00:00
|
|
|
#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
|
|
|
|
|
2013-08-03 07:58:59 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(PowerMonitor);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2013-08-03 07:58:59 +00:00
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#endif // SHELL_BROWSER_API_ATOM_API_POWER_MONITOR_H_
|