This commit is contained in:
Cheng Zhao 2013-08-06 16:19:56 +08:00
Родитель 6e90430df5
Коммит b1f88d680b
5 изменённых файлов: 76 добавлений и 0 удалений

Просмотреть файл

@ -139,6 +139,38 @@ v8::Handle<v8::Value> App::AppendArgument(const v8::Arguments &args) {
return v8::Undefined(); 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 // static
void App::Initialize(v8::Handle<v8::Object> target) { void App::Initialize(v8::Handle<v8::Object> target) {
v8::HandleScope scope; 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, "appendSwitch", AppendSwitch);
NODE_SET_METHOD(target, "appendArgument", AppendArgument); 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 } // 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> AppendSwitch(const v8::Arguments &args);
static v8::Handle<v8::Value> AppendArgument(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); DISALLOW_COPY_AND_ASSIGN(App);
}; };

Просмотреть файл

@ -13,5 +13,11 @@ app.commandLine =
appendSwitch: bindings.appendSwitch, appendSwitch: bindings.appendSwitch,
appendArgument: bindings.appendArgument 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. # Only one App object pemitted.
module.exports = app module.exports = app

Просмотреть файл

@ -33,6 +33,19 @@ class Browser : public WindowListObserver {
// Returns the version of the executable (or bundle). // Returns the version of the executable (or bundle).
std::string GetVersion(); 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. // Tell the application to open a file.
bool OpenFile(const std::string& file_path); bool OpenFile(const std::string& file_path);

Просмотреть файл

@ -29,4 +29,17 @@ void Browser::CancelQuit() {
[[AtomApplication sharedApplication] replyToApplicationShouldTerminate:NO]; [[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 } // namespace atom