|
2 | 2 | // Use of this source code is governed by the MIT license that can be
|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
| 5 | +#include "atom/browser/browser.h" |
5 | 6 | #include "atom/common/native_mate_converters/gfx_converter.h"
|
6 | 7 | #include "atom/common/node_includes.h"
|
7 | 8 |
|
8 | 9 | namespace {
|
9 | 10 |
|
| 11 | +const char* kRequireAppReadyMessage = |
| 12 | + "APIs of \"screen\" module can only be used after the \"ready\" event of " |
| 13 | + "\"app\" module gets emitted."; |
| 14 | + |
| 15 | +gfx::Point GetCursorScreenPoint(mate::Arguments* args) { |
| 16 | + if (!atom::Browser::Get()->is_ready()) { |
| 17 | + args->ThrowError(kRequireAppReadyMessage); |
| 18 | + return gfx::Point(); |
| 19 | + } |
| 20 | + |
| 21 | + gfx::Screen* screen = gfx::Screen::GetNativeScreen(); |
| 22 | + return screen->GetCursorScreenPoint(); |
| 23 | +} |
| 24 | + |
| 25 | +gfx::Display GetPrimaryDisplay(mate::Arguments* args) { |
| 26 | + if (!atom::Browser::Get()->is_ready()) { |
| 27 | + args->ThrowError(kRequireAppReadyMessage); |
| 28 | + return gfx::Display(); |
| 29 | + } |
| 30 | + |
| 31 | + gfx::Screen* screen = gfx::Screen::GetNativeScreen(); |
| 32 | + return screen->GetPrimaryDisplay(); |
| 33 | +} |
| 34 | + |
10 | 35 | void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
11 | 36 | v8::Handle<v8::Context> context, void* priv) {
|
12 |
| - gfx::Screen* screen = gfx::Screen::GetNativeScreen(); |
13 | 37 | mate::Dictionary dict(context->GetIsolate(), exports);
|
14 |
| - dict.SetMethod("getCursorScreenPoint", |
15 |
| - base::Bind(&gfx::Screen::GetCursorScreenPoint, |
16 |
| - base::Unretained(screen))); |
17 |
| - dict.SetMethod("getPrimaryDisplay", |
18 |
| - base::Bind(&gfx::Screen::GetPrimaryDisplay, |
19 |
| - base::Unretained(screen))); |
| 38 | + dict.SetMethod("getCursorScreenPoint", &GetCursorScreenPoint); |
| 39 | + dict.SetMethod("getPrimaryDisplay", &GetPrimaryDisplay); |
20 | 40 | }
|
21 | 41 |
|
22 | 42 | } // namespace
|
|
0 commit comments