Get rid of the ugly ATOM_BROWSER_INTERNAL_NEW message.
This commit is contained in:
parent
cfca12d4a5
commit
d3f33152d0
7 changed files with 29 additions and 37 deletions
|
@ -8,23 +8,16 @@
|
||||||
|
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "browser/api/atom_api_event.h"
|
#include "browser/api/atom_api_event.h"
|
||||||
#include "common/v8/node_common.h"
|
|
||||||
#include "common/v8/native_type_conversions.h"
|
#include "common/v8/native_type_conversions.h"
|
||||||
|
|
||||||
|
#include "common/v8/node_common.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
EventEmitter::EventEmitter(v8::Handle<v8::Object> wrapper) {
|
EventEmitter::EventEmitter(v8::Handle<v8::Object> wrapper) {
|
||||||
Wrap(wrapper);
|
Wrap(wrapper);
|
||||||
|
|
||||||
// process.emit('ATOM_BROWSER_INTERNAL_NEW', this).
|
|
||||||
v8::Handle<v8::Value> args[] = {
|
|
||||||
v8::String::New("ATOM_BROWSER_INTERNAL_NEW"),
|
|
||||||
wrapper,
|
|
||||||
};
|
|
||||||
node::Environment* env = node::Environment::GetCurrent(node_isolate);
|
|
||||||
node::MakeCallback(env->process_object(), "emit", 2, args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EventEmitter::~EventEmitter() {
|
EventEmitter::~EventEmitter() {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
bindings = process.atomBinding 'app'
|
BrowserWindow = require 'browser-window'
|
||||||
EventEmitter = require('events').EventEmitter
|
EventEmitter = require('events').EventEmitter
|
||||||
|
|
||||||
|
bindings = process.atomBinding 'app'
|
||||||
|
|
||||||
Application = bindings.Application
|
Application = bindings.Application
|
||||||
Application::__proto__ = EventEmitter.prototype
|
Application::__proto__ = EventEmitter.prototype
|
||||||
|
|
||||||
|
@ -9,9 +11,6 @@ app = new Application
|
||||||
app.getHomeDir = ->
|
app.getHomeDir = ->
|
||||||
process.env[if process.platform is 'win32' then 'USERPROFILE' else 'HOME']
|
process.env[if process.platform is 'win32' then 'USERPROFILE' else 'HOME']
|
||||||
|
|
||||||
app.getBrowserWindows = ->
|
|
||||||
require('../../lib/objects-registry.js').getAllWindows()
|
|
||||||
|
|
||||||
app.setApplicationMenu = (menu) ->
|
app.setApplicationMenu = (menu) ->
|
||||||
require('menu').setApplicationMenu menu
|
require('menu').setApplicationMenu menu
|
||||||
|
|
||||||
|
@ -24,7 +23,7 @@ app.commandLine =
|
||||||
|
|
||||||
if process.platform is 'darwin'
|
if process.platform is 'darwin'
|
||||||
app.dock =
|
app.dock =
|
||||||
bounce: (type = 'informational') -> bindings.dockBounce type
|
bounce: (type='informational') -> bindings.dockBounce type
|
||||||
cancelBounce: bindings.dockCancelBounce
|
cancelBounce: bindings.dockCancelBounce
|
||||||
setBadge: bindings.dockSetBadgeText
|
setBadge: bindings.dockSetBadgeText
|
||||||
getBadge: bindings.dockGetBadgeText
|
getBadge: bindings.dockGetBadgeText
|
||||||
|
|
|
@ -1,16 +1,27 @@
|
||||||
EventEmitter = require('events').EventEmitter
|
EventEmitter = require('events').EventEmitter
|
||||||
|
IDWeakMap = require 'id-weak-map'
|
||||||
app = require 'app'
|
app = require 'app'
|
||||||
v8Util = process.atomBinding 'v8_util'
|
|
||||||
|
|
||||||
BrowserWindow = process.atomBinding('window').BrowserWindow
|
BrowserWindow = process.atomBinding('window').BrowserWindow
|
||||||
BrowserWindow::__proto__ = EventEmitter.prototype
|
BrowserWindow::__proto__ = EventEmitter.prototype
|
||||||
|
|
||||||
|
# Store all created windows in the weak map.
|
||||||
|
BrowserWindow.windows = new IDWeakMap
|
||||||
|
|
||||||
BrowserWindow::_init = ->
|
BrowserWindow::_init = ->
|
||||||
# Simulate the application menu on platforms other than OS X.
|
# Simulate the application menu on platforms other than OS X.
|
||||||
if process.platform isnt 'darwin'
|
if process.platform isnt 'darwin'
|
||||||
menu = app.getApplicationMenu()
|
menu = app.getApplicationMenu()
|
||||||
@setMenu menu if menu?
|
@setMenu menu if menu?
|
||||||
|
|
||||||
|
# Remember the window.
|
||||||
|
id = BrowserWindow.windows.add this
|
||||||
|
|
||||||
|
# Remove the window from weak map immediately when it's destroyed, since we
|
||||||
|
# could be iterating windows before GC happended.
|
||||||
|
@once 'destroyed', ->
|
||||||
|
BrowserWindow.windows.remove id if BrowserWindow.windows.has id
|
||||||
|
|
||||||
# Tell the rpc server that a render view has been deleted and we need to
|
# Tell the rpc server that a render view has been deleted and we need to
|
||||||
# release all objects owned by it.
|
# release all objects owned by it.
|
||||||
@on 'render-view-deleted', (event, processId, routingId) ->
|
@on 'render-view-deleted', (event, processId, routingId) ->
|
||||||
|
@ -30,12 +41,16 @@ BrowserWindow::setMenu = (menu) ->
|
||||||
@menu = menu # Keep a reference of menu in case of GC.
|
@menu = menu # Keep a reference of menu in case of GC.
|
||||||
@menu.attachToWindow this
|
@menu.attachToWindow this
|
||||||
|
|
||||||
|
BrowserWindow.getAllWindows = ->
|
||||||
|
windows = BrowserWindow.windows
|
||||||
|
windows.get key for key in windows.keys()
|
||||||
|
|
||||||
BrowserWindow.getFocusedWindow = ->
|
BrowserWindow.getFocusedWindow = ->
|
||||||
windows = app.getBrowserWindows()
|
windows = BrowserWindow.getAllWindows()
|
||||||
return window for window in windows when window.isFocused()
|
return window for window in windows when window.isFocused()
|
||||||
|
|
||||||
BrowserWindow.fromProcessIdAndRoutingId = (processId, routingId) ->
|
BrowserWindow.fromProcessIdAndRoutingId = (processId, routingId) ->
|
||||||
windows = app.getBrowserWindows()
|
windows = BrowserWindow.getAllWindows()
|
||||||
return window for window in windows when window.getProcessId() == processId and
|
return window for window in windows when window.getProcessId() == processId and
|
||||||
window.getRoutingId() == routingId
|
window.getRoutingId() == routingId
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
BrowserWindow = require 'browser-window'
|
BrowserWindow = require 'browser-window'
|
||||||
EventEmitter = require('events').EventEmitter
|
EventEmitter = require('events').EventEmitter
|
||||||
IDWeakMap = require 'id-weak-map'
|
|
||||||
MenuItem = require 'menu-item'
|
MenuItem = require 'menu-item'
|
||||||
|
|
||||||
app = require 'app'
|
|
||||||
bindings = process.atomBinding 'menu'
|
bindings = process.atomBinding 'menu'
|
||||||
|
|
||||||
Menu = bindings.Menu
|
Menu = bindings.Menu
|
||||||
|
@ -52,7 +50,7 @@ Menu.setApplicationMenu = (menu) ->
|
||||||
if process.platform is 'darwin'
|
if process.platform is 'darwin'
|
||||||
bindings.setApplicationMenu menu
|
bindings.setApplicationMenu menu
|
||||||
else
|
else
|
||||||
windows = app.getBrowserWindows()
|
windows = BrowserWindow.getAllWindows()
|
||||||
w.setMenu menu for w in windows
|
w.setMenu menu for w in windows
|
||||||
|
|
||||||
Menu.getApplicationMenu = -> applicationMenu
|
Menu.getApplicationMenu = -> applicationMenu
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
BrowserWindow = require 'browser-window'
|
|
||||||
EventEmitter = require('events').EventEmitter
|
EventEmitter = require('events').EventEmitter
|
||||||
IDWeakMap = require 'id-weak-map'
|
IDWeakMap = require 'id-weak-map'
|
||||||
v8Util = process.atomBinding 'v8_util'
|
v8Util = process.atomBinding 'v8_util'
|
||||||
|
@ -51,13 +50,6 @@ class ObjectsRegistry extends EventEmitter
|
||||||
v8Util.setHiddenValue obj, 'atomId', id
|
v8Util.setHiddenValue obj, 'atomId', id
|
||||||
id
|
id
|
||||||
|
|
||||||
# Remember all windows in the weak map.
|
|
||||||
@windowsWeakMap = new IDWeakMap
|
|
||||||
process.on 'ATOM_BROWSER_INTERNAL_NEW', (obj) =>
|
|
||||||
if obj.constructor is BrowserWindow
|
|
||||||
id = @windowsWeakMap.add obj
|
|
||||||
obj.on 'destroyed', => @windowsWeakMap.remove id
|
|
||||||
|
|
||||||
# Register a new object, the object would be kept referenced until you release
|
# Register a new object, the object would be kept referenced until you release
|
||||||
# it explicitly.
|
# it explicitly.
|
||||||
add: (processId, routingId, obj) ->
|
add: (processId, routingId, obj) ->
|
||||||
|
@ -89,9 +81,4 @@ class ObjectsRegistry extends EventEmitter
|
||||||
@emit "release-renderer-view-#{processId}-#{routingId}"
|
@emit "release-renderer-view-#{processId}-#{routingId}"
|
||||||
ObjectsStore.releaseForRenderView processId, routingId
|
ObjectsStore.releaseForRenderView processId, routingId
|
||||||
|
|
||||||
# Return an array of all browser windows.
|
|
||||||
getAllWindows: ->
|
|
||||||
keys = @windowsWeakMap.keys()
|
|
||||||
@windowsWeakMap.get key for key in keys
|
|
||||||
|
|
||||||
module.exports = new ObjectsRegistry
|
module.exports = new ObjectsRegistry
|
||||||
|
|
|
@ -91,10 +91,6 @@ to the spec of npm modules. So usually you should also specify a `productName`
|
||||||
field, which is your application's full capitalized name, and it will be
|
field, which is your application's full capitalized name, and it will be
|
||||||
preferred over `name` by atom-shell.
|
preferred over `name` by atom-shell.
|
||||||
|
|
||||||
## app.getBrowserWindows()
|
|
||||||
|
|
||||||
Returns an array of all browser windows.
|
|
||||||
|
|
||||||
## app.commandLine.appendSwitch(switch, [value])
|
## app.commandLine.appendSwitch(switch, [value])
|
||||||
|
|
||||||
Append a switch [with optional value] to Chromium's command line.
|
Append a switch [with optional value] to Chromium's command line.
|
||||||
|
|
|
@ -99,6 +99,10 @@ shouldn't!).
|
||||||
Emitted when the memory taken by the native window is released. Usually you
|
Emitted when the memory taken by the native window is released. Usually you
|
||||||
should dereference the javascript object when received this event.
|
should dereference the javascript object when received this event.
|
||||||
|
|
||||||
|
### Class Method: BrowserWindow.getAllWindows()
|
||||||
|
|
||||||
|
Returns an array of all opened browser windows.
|
||||||
|
|
||||||
### Class Method: BrowserWindow.getFocusedWindow()
|
### Class Method: BrowserWindow.getFocusedWindow()
|
||||||
|
|
||||||
Returns the window that is focused in this application.
|
Returns the window that is focused in this application.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue