| 
									
										
										
										
											2013-04-29 21:57:05 +08:00
										 |  |  | // Copyright (c) 2013 GitHub, Inc. All rights reserved.
 | 
					
						
							|  |  |  | // Use of this source code is governed by a BSD-style license that can be
 | 
					
						
							|  |  |  | // found in the LICENSE file.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-16 08:30:26 +08:00
										 |  |  | #include "atom/common/api/atom_api_shell.h"
 | 
					
						
							| 
									
										
										
										
											2013-04-29 21:57:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-16 08:30:26 +08:00
										 |  |  | #include "atom/common/platform_util.h"
 | 
					
						
							|  |  |  | #include "atom/common/v8/native_type_conversions.h"
 | 
					
						
							| 
									
										
										
										
											2014-03-16 09:37:04 +08:00
										 |  |  | #include "base/files/file_path.h"
 | 
					
						
							| 
									
										
										
										
											2013-12-11 15:48:19 +08:00
										 |  |  | #include "url/gurl.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-16 08:30:26 +08:00
										 |  |  | #include "atom/common/v8/node_common.h"
 | 
					
						
							| 
									
										
										
										
											2013-04-29 21:57:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace atom { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace api { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // static
 | 
					
						
							| 
									
										
										
										
											2013-12-11 15:48:19 +08:00
										 |  |  | void Shell::ShowItemInFolder(const v8::FunctionCallbackInfo<v8::Value>& args) { | 
					
						
							| 
									
										
										
										
											2013-04-29 21:57:05 +08:00
										 |  |  |   base::FilePath file_path; | 
					
						
							| 
									
										
										
										
											2013-12-11 15:48:19 +08:00
										 |  |  |   if (!FromV8Arguments(args, &file_path)) | 
					
						
							| 
									
										
										
										
											2013-04-29 21:57:05 +08:00
										 |  |  |     return node::ThrowTypeError("Bad argument"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   platform_util::ShowItemInFolder(file_path); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // static
 | 
					
						
							| 
									
										
										
										
											2013-12-11 15:48:19 +08:00
										 |  |  | void Shell::OpenItem(const v8::FunctionCallbackInfo<v8::Value>& args) { | 
					
						
							| 
									
										
										
										
											2013-04-29 21:57:05 +08:00
										 |  |  |   base::FilePath file_path; | 
					
						
							| 
									
										
										
										
											2013-12-11 15:48:19 +08:00
										 |  |  |   if (!FromV8Arguments(args, &file_path)) | 
					
						
							| 
									
										
										
										
											2013-04-29 21:57:05 +08:00
										 |  |  |     return node::ThrowTypeError("Bad argument"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   platform_util::OpenItem(file_path); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // static
 | 
					
						
							| 
									
										
										
										
											2013-12-11 15:48:19 +08:00
										 |  |  | void Shell::OpenExternal(const v8::FunctionCallbackInfo<v8::Value>& args) { | 
					
						
							|  |  |  |   GURL url; | 
					
						
							|  |  |  |   if (!FromV8Arguments(args, &url)) | 
					
						
							| 
									
										
										
										
											2013-04-29 21:57:05 +08:00
										 |  |  |     return node::ThrowTypeError("Bad argument"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-11 15:48:19 +08:00
										 |  |  |   platform_util::OpenExternal(url); | 
					
						
							| 
									
										
										
										
											2013-04-29 21:57:05 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // static
 | 
					
						
							| 
									
										
										
										
											2013-12-11 15:48:19 +08:00
										 |  |  | void Shell::MoveItemToTrash(const v8::FunctionCallbackInfo<v8::Value>& args) { | 
					
						
							| 
									
										
										
										
											2013-04-29 21:57:05 +08:00
										 |  |  |   base::FilePath file_path; | 
					
						
							| 
									
										
										
										
											2013-12-11 15:48:19 +08:00
										 |  |  |   if (!FromV8Arguments(args, &file_path)) | 
					
						
							| 
									
										
										
										
											2013-04-29 21:57:05 +08:00
										 |  |  |     return node::ThrowTypeError("Bad argument"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   platform_util::MoveItemToTrash(file_path); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-29 22:10:03 +08:00
										 |  |  | // static
 | 
					
						
							| 
									
										
										
										
											2013-12-11 15:48:19 +08:00
										 |  |  | void Shell::Beep(const v8::FunctionCallbackInfo<v8::Value>& args) { | 
					
						
							| 
									
										
										
										
											2013-04-29 22:10:03 +08:00
										 |  |  |   platform_util::Beep(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-29 21:57:05 +08:00
										 |  |  | // static
 | 
					
						
							|  |  |  | void Shell::Initialize(v8::Handle<v8::Object> target) { | 
					
						
							| 
									
										
										
										
											2013-12-11 15:48:19 +08:00
										 |  |  |   NODE_SET_METHOD(target, "showItemInFolder", ShowItemInFolder); | 
					
						
							|  |  |  |   NODE_SET_METHOD(target, "openItem", OpenItem); | 
					
						
							|  |  |  |   NODE_SET_METHOD(target, "openExternal", OpenExternal); | 
					
						
							|  |  |  |   NODE_SET_METHOD(target, "moveItemToTrash", MoveItemToTrash); | 
					
						
							|  |  |  |   NODE_SET_METHOD(target, "beep", Beep); | 
					
						
							| 
									
										
										
										
											2013-04-29 21:57:05 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace api
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace atom
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NODE_MODULE(atom_common_shell, atom::api::Shell::Initialize) |