| 
									
										
										
										
											2014-10-31 11:17:05 -07:00
										 |  |  | // Copyright (c) 2013 GitHub, Inc.
 | 
					
						
							| 
									
										
										
										
											2014-04-25 17:49:37 +08:00
										 |  |  | // Use of this source code is governed by the MIT license that can be
 | 
					
						
							| 
									
										
										
										
											2013-08-03 15:58:59 +08:00
										 |  |  | // found in the LICENSE file.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-04 12:19:40 -08:00
										 |  |  | #ifndef SHELL_BROWSER_API_ELECTRON_API_POWER_MONITOR_H_
 | 
					
						
							|  |  |  | #define SHELL_BROWSER_API_ELECTRON_API_POWER_MONITOR_H_
 | 
					
						
							| 
									
										
										
										
											2013-08-03 15:58:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-24 09:03:29 -07:00
										 |  |  | #include "base/power_monitor/power_observer.h"
 | 
					
						
							|  |  |  | #include "gin/wrappable.h"
 | 
					
						
							|  |  |  | #include "shell/browser/event_emitter_mixin.h"
 | 
					
						
							|  |  |  | #include "shell/common/gin_helper/pinnable.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-13 22:42:08 -07:00
										 |  |  | #include "ui/base/idle/idle.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-03 15:58:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-24 09:03:29 -07:00
										 |  |  | #if defined(OS_LINUX)
 | 
					
						
							|  |  |  | #include "shell/browser/lib/power_observer_linux.h"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  | namespace electron { | 
					
						
							| 
									
										
										
										
											2013-08-03 15:58:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace api { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-24 09:03:29 -07:00
										 |  |  | class PowerMonitor : public gin::Wrappable<PowerMonitor>, | 
					
						
							|  |  |  |                      public gin_helper::EventEmitterMixin<PowerMonitor>, | 
					
						
							|  |  |  |                      public gin_helper::Pinnable<PowerMonitor>, | 
					
						
							|  |  |  |                      public base::PowerObserver { | 
					
						
							| 
									
										
										
										
											2013-08-03 15:58:59 +08:00
										 |  |  |  public: | 
					
						
							| 
									
										
										
										
											2015-05-22 19:11:22 +08:00
										 |  |  |   static v8::Local<v8::Value> Create(v8::Isolate* isolate); | 
					
						
							| 
									
										
										
										
											2013-08-03 15:58:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-24 09:03:29 -07:00
										 |  |  |   // gin::Wrappable
 | 
					
						
							|  |  |  |   static gin::WrapperInfo kWrapperInfo; | 
					
						
							|  |  |  |   gin::ObjectTemplateBuilder GetObjectTemplateBuilder( | 
					
						
							|  |  |  |       v8::Isolate* isolate) override; | 
					
						
							|  |  |  |   const char* GetTypeName() override; | 
					
						
							| 
									
										
										
										
											2016-04-25 10:17:54 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-24 09:03:29 -07:00
										 |  |  |  private: | 
					
						
							| 
									
										
										
										
											2016-04-25 10:17:54 +09:00
										 |  |  |   explicit PowerMonitor(v8::Isolate* isolate); | 
					
						
							| 
									
										
										
										
											2015-11-04 18:21:03 +08:00
										 |  |  |   ~PowerMonitor() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-05 15:49:43 +09:00
										 |  |  | #if defined(OS_LINUX)
 | 
					
						
							| 
									
										
										
										
											2020-03-24 09:03:29 -07:00
										 |  |  |   void SetListeningForShutdown(bool); | 
					
						
							| 
									
										
										
										
											2018-02-05 15:49:43 +09:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-24 09:03:29 -07:00
										 |  |  |   // Called by native calles.
 | 
					
						
							|  |  |  |   bool ShouldShutdown(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-12 11:33:58 -07:00
										 |  |  | #if defined(OS_MAC) || defined(OS_WIN)
 | 
					
						
							| 
									
										
										
										
											2018-05-01 02:04:27 +10:00
										 |  |  |   void InitPlatformSpecificMonitors(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 17:13:17 +08:00
										 |  |  |   // base::PowerObserver implementations:
 | 
					
						
							| 
									
										
										
										
											2015-01-09 17:24:36 -08:00
										 |  |  |   void OnPowerStateChange(bool on_battery_power) override; | 
					
						
							|  |  |  |   void OnSuspend() override; | 
					
						
							|  |  |  |   void OnResume() override; | 
					
						
							| 
									
										
										
										
											2013-08-03 15:58:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-01 02:04:27 +10: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
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-24 09:03:29 -07:00
										 |  |  | #if defined(OS_LINUX)
 | 
					
						
							|  |  |  |   PowerObserverLinux power_observer_linux_{this}; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   v8::Global<v8::Value> pinned_; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-03 15:58:59 +08:00
										 |  |  |   DISALLOW_COPY_AND_ASSIGN(PowerMonitor); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace api
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 14:23:04 -07:00
										 |  |  | }  // namespace electron
 | 
					
						
							| 
									
										
										
										
											2013-08-03 15:58:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-04 12:19:40 -08:00
										 |  |  | #endif  // SHELL_BROWSER_API_ELECTRON_API_POWER_MONITOR_H_
 |