refactor: ginify globalShortcut (#22755)
This commit is contained in:
		
					parent
					
						
							
								a824e12275
							
						
					
				
			
			
				commit
				
					
						f1a0d5e811
					
				
			
		
					 2 changed files with 20 additions and 14 deletions
				
			
		|  | @ -9,11 +9,11 @@ | ||||||
| 
 | 
 | ||||||
| #include "base/stl_util.h" | #include "base/stl_util.h" | ||||||
| #include "base/strings/utf_string_conversions.h" | #include "base/strings/utf_string_conversions.h" | ||||||
|  | #include "gin/dictionary.h" | ||||||
|  | #include "gin/object_template_builder.h" | ||||||
| #include "shell/browser/api/electron_api_system_preferences.h" | #include "shell/browser/api/electron_api_system_preferences.h" | ||||||
| #include "shell/common/gin_converters/accelerator_converter.h" | #include "shell/common/gin_converters/accelerator_converter.h" | ||||||
| #include "shell/common/gin_converters/callback_converter.h" | #include "shell/common/gin_converters/callback_converter.h" | ||||||
| #include "shell/common/gin_helper/dictionary.h" |  | ||||||
| #include "shell/common/gin_helper/object_template_builder.h" |  | ||||||
| #include "shell/common/node_includes.h" | #include "shell/common/node_includes.h" | ||||||
| 
 | 
 | ||||||
| #if defined(OS_MACOSX) | #if defined(OS_MACOSX) | ||||||
|  | @ -49,9 +49,9 @@ namespace electron { | ||||||
| 
 | 
 | ||||||
| namespace api { | namespace api { | ||||||
| 
 | 
 | ||||||
| GlobalShortcut::GlobalShortcut(v8::Isolate* isolate) { | gin::WrapperInfo GlobalShortcut::kWrapperInfo = {gin::kEmbedderNativeGin}; | ||||||
|   Init(isolate); | 
 | ||||||
| } | GlobalShortcut::GlobalShortcut(v8::Isolate* isolate) {} | ||||||
| 
 | 
 | ||||||
| GlobalShortcut::~GlobalShortcut() { | GlobalShortcut::~GlobalShortcut() { | ||||||
|   UnregisterAll(); |   UnregisterAll(); | ||||||
|  | @ -131,10 +131,9 @@ gin::Handle<GlobalShortcut> GlobalShortcut::Create(v8::Isolate* isolate) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // static
 | // static
 | ||||||
| void GlobalShortcut::BuildPrototype(v8::Isolate* isolate, | gin::ObjectTemplateBuilder GlobalShortcut::GetObjectTemplateBuilder( | ||||||
|                                     v8::Local<v8::FunctionTemplate> prototype) { |     v8::Isolate* isolate) { | ||||||
|   prototype->SetClassName(gin::StringToV8(isolate, "GlobalShortcut")); |   return gin::Wrappable<GlobalShortcut>::GetObjectTemplateBuilder(isolate) | ||||||
|   gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) |  | ||||||
|       .SetMethod("registerAll", &GlobalShortcut::RegisterAll) |       .SetMethod("registerAll", &GlobalShortcut::RegisterAll) | ||||||
|       .SetMethod("register", &GlobalShortcut::Register) |       .SetMethod("register", &GlobalShortcut::Register) | ||||||
|       .SetMethod("isRegistered", &GlobalShortcut::IsRegistered) |       .SetMethod("isRegistered", &GlobalShortcut::IsRegistered) | ||||||
|  | @ -142,6 +141,10 @@ void GlobalShortcut::BuildPrototype(v8::Isolate* isolate, | ||||||
|       .SetMethod("unregisterAll", &GlobalShortcut::UnregisterAll); |       .SetMethod("unregisterAll", &GlobalShortcut::UnregisterAll); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | const char* GlobalShortcut::GetTypeName() { | ||||||
|  |   return "GlobalShortcut"; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| }  // namespace api
 | }  // namespace api
 | ||||||
| 
 | 
 | ||||||
| }  // namespace electron
 | }  // namespace electron
 | ||||||
|  | @ -153,7 +156,7 @@ void Initialize(v8::Local<v8::Object> exports, | ||||||
|                 v8::Local<v8::Context> context, |                 v8::Local<v8::Context> context, | ||||||
|                 void* priv) { |                 void* priv) { | ||||||
|   v8::Isolate* isolate = context->GetIsolate(); |   v8::Isolate* isolate = context->GetIsolate(); | ||||||
|   gin_helper::Dictionary dict(isolate, exports); |   gin::Dictionary dict(isolate, exports); | ||||||
|   dict.Set("globalShortcut", electron::api::GlobalShortcut::Create(isolate)); |   dict.Set("globalShortcut", electron::api::GlobalShortcut::Create(isolate)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -12,7 +12,7 @@ | ||||||
| #include "base/callback.h" | #include "base/callback.h" | ||||||
| #include "chrome/browser/extensions/global_shortcut_listener.h" | #include "chrome/browser/extensions/global_shortcut_listener.h" | ||||||
| #include "gin/handle.h" | #include "gin/handle.h" | ||||||
| #include "shell/common/gin_helper/trackable_object.h" | #include "gin/wrappable.h" | ||||||
| #include "ui/base/accelerators/accelerator.h" | #include "ui/base/accelerators/accelerator.h" | ||||||
| 
 | 
 | ||||||
| namespace electron { | namespace electron { | ||||||
|  | @ -20,12 +20,15 @@ namespace electron { | ||||||
| namespace api { | namespace api { | ||||||
| 
 | 
 | ||||||
| class GlobalShortcut : public extensions::GlobalShortcutListener::Observer, | class GlobalShortcut : public extensions::GlobalShortcutListener::Observer, | ||||||
|                        public gin_helper::TrackableObject<GlobalShortcut> { |                        public gin::Wrappable<GlobalShortcut> { | ||||||
|  public: |  public: | ||||||
|   static gin::Handle<GlobalShortcut> Create(v8::Isolate* isolate); |   static gin::Handle<GlobalShortcut> Create(v8::Isolate* isolate); | ||||||
| 
 | 
 | ||||||
|   static void BuildPrototype(v8::Isolate* isolate, |   // gin::Wrappable
 | ||||||
|                              v8::Local<v8::FunctionTemplate> prototype); |   static gin::WrapperInfo kWrapperInfo; | ||||||
|  |   gin::ObjectTemplateBuilder GetObjectTemplateBuilder( | ||||||
|  |       v8::Isolate* isolate) override; | ||||||
|  |   const char* GetTypeName() override; | ||||||
| 
 | 
 | ||||||
|  protected: |  protected: | ||||||
|   explicit GlobalShortcut(v8::Isolate* isolate); |   explicit GlobalShortcut(v8::Isolate* isolate); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jeremy Apthorp
				Jeremy Apthorp