[Mac] Add API for dock, fixes #46.
This commit is contained in:
		
					parent
					
						
							
								6e90430df5
							
						
					
				
			
			
				commit
				
					
						b1f88d680b
					
				
			
		
					 5 changed files with 76 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -139,6 +139,38 @@ v8::Handle<v8::Value> App::AppendArgument(const v8::Arguments &args) {
 | 
			
		|||
  return v8::Undefined();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if defined(OS_MACOSX)
 | 
			
		||||
 | 
			
		||||
// static
 | 
			
		||||
v8::Handle<v8::Value> App::DockBounce(const v8::Arguments& args) {
 | 
			
		||||
  std::string type(*v8::String::Utf8Value(args[0]));
 | 
			
		||||
  int request_id = -1;
 | 
			
		||||
 | 
			
		||||
  if (type == "critical")
 | 
			
		||||
    request_id = Browser::Get()->DockBounce(Browser::BOUNCE_CRITICAL);
 | 
			
		||||
  else if (type == "informational")
 | 
			
		||||
    request_id = Browser::Get()->DockBounce(Browser::BOUNCE_INFORMATIONAL);
 | 
			
		||||
  else
 | 
			
		||||
    return node::ThrowTypeError("Invalid bounce type");
 | 
			
		||||
 | 
			
		||||
  return v8::Integer::New(request_id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// static
 | 
			
		||||
v8::Handle<v8::Value> App::DockCancelBounce(const v8::Arguments& args) {
 | 
			
		||||
  Browser::Get()->DockCancelBounce(args[0]->IntegerValue());
 | 
			
		||||
  return v8::Undefined();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// static
 | 
			
		||||
v8::Handle<v8::Value> App::DockSetBadgeText(const v8::Arguments& args) {
 | 
			
		||||
  std::string label(*v8::String::Utf8Value(args[0]));
 | 
			
		||||
  Browser::Get()->DockSetBadgeText(label);
 | 
			
		||||
  return v8::Undefined();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif  // defined(OS_MACOSX)
 | 
			
		||||
 | 
			
		||||
// static
 | 
			
		||||
void App::Initialize(v8::Handle<v8::Object> target) {
 | 
			
		||||
  v8::HandleScope scope;
 | 
			
		||||
| 
						 | 
				
			
			@ -157,6 +189,12 @@ void App::Initialize(v8::Handle<v8::Object> target) {
 | 
			
		|||
 | 
			
		||||
  NODE_SET_METHOD(target, "appendSwitch", AppendSwitch);
 | 
			
		||||
  NODE_SET_METHOD(target, "appendArgument", AppendArgument);
 | 
			
		||||
 | 
			
		||||
#if defined(OS_MACOSX)
 | 
			
		||||
  NODE_SET_METHOD(target, "dockBounce", DockBounce);
 | 
			
		||||
  NODE_SET_METHOD(target, "dockCancelBounce", DockCancelBounce);
 | 
			
		||||
  NODE_SET_METHOD(target, "dockSetBadgeText", DockSetBadgeText);
 | 
			
		||||
#endif  // defined(OS_MACOSX)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}  // namespace api
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -43,6 +43,12 @@ class App : public EventEmitter,
 | 
			
		|||
  static v8::Handle<v8::Value> AppendSwitch(const v8::Arguments &args);
 | 
			
		||||
  static v8::Handle<v8::Value> AppendArgument(const v8::Arguments &args);
 | 
			
		||||
 | 
			
		||||
#if defined(OS_MACOSX)
 | 
			
		||||
  static v8::Handle<v8::Value> DockBounce(const v8::Arguments& args);
 | 
			
		||||
  static v8::Handle<v8::Value> DockCancelBounce(const v8::Arguments& args);
 | 
			
		||||
  static v8::Handle<v8::Value> DockSetBadgeText(const v8::Arguments& args);
 | 
			
		||||
#endif  // defined(OS_MACOSX)
 | 
			
		||||
 | 
			
		||||
  DISALLOW_COPY_AND_ASSIGN(App);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,5 +13,11 @@ app.commandLine =
 | 
			
		|||
  appendSwitch: bindings.appendSwitch,
 | 
			
		||||
  appendArgument: bindings.appendArgument
 | 
			
		||||
 | 
			
		||||
if process.platform is 'darwin'
 | 
			
		||||
  app.dock =
 | 
			
		||||
    bounce: (type = 'informational') -> bindings.dockBounce type
 | 
			
		||||
    cancelBounce: bindings.dockCancelBounce
 | 
			
		||||
    setBadge: bindings.dockSetBadgeText
 | 
			
		||||
 | 
			
		||||
# Only one App object pemitted.
 | 
			
		||||
module.exports = app
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,6 +33,19 @@ class Browser : public WindowListObserver {
 | 
			
		|||
  // Returns the version of the executable (or bundle).
 | 
			
		||||
  std::string GetVersion();
 | 
			
		||||
 | 
			
		||||
#if defined(OS_MACOSX)
 | 
			
		||||
  // Bounce the dock icon.
 | 
			
		||||
  enum BounceType {
 | 
			
		||||
    BOUNCE_CRITICAL = 0,
 | 
			
		||||
    BOUNCE_INFORMATIONAL = 10,
 | 
			
		||||
  };
 | 
			
		||||
  int DockBounce(BounceType type);
 | 
			
		||||
  void DockCancelBounce(int request_id);
 | 
			
		||||
 | 
			
		||||
  // Set dock's badge text.
 | 
			
		||||
  void DockSetBadgeText(const std::string& label);
 | 
			
		||||
#endif  // defined(OS_MACOSX)
 | 
			
		||||
 | 
			
		||||
  // Tell the application to open a file.
 | 
			
		||||
  bool OpenFile(const std::string& file_path);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,4 +29,17 @@ void Browser::CancelQuit() {
 | 
			
		|||
  [[AtomApplication sharedApplication] replyToApplicationShouldTerminate:NO];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Browser::DockBounce(BounceType type) {
 | 
			
		||||
  return [[AtomApplication sharedApplication] requestUserAttention:type];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Browser::DockCancelBounce(int rid) {
 | 
			
		||||
  [[AtomApplication sharedApplication] cancelUserAttentionRequest:rid];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Browser::DockSetBadgeText(const std::string& label) {
 | 
			
		||||
  NSDockTile *tile = [[AtomApplication sharedApplication] dockTile];
 | 
			
		||||
  [tile setBadgeLabel:base::SysUTF8ToNSString(label)];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}  // namespace atom
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue