Skip to content
Permalink
Browse files

properly deprecate win.capturePage

  • Loading branch information...
codebytere committed Nov 19, 2018
1 parent 8aff249 commit 5c5286b216efbd2d7a0f690ea973c2e24d5294ff
Showing with 12 additions and 7 deletions.
  1. +2 −4 atom/browser/api/atom_api_web_contents.cc
  2. +8 −1 lib/browser/api/web-contents.js
  3. +2 −2 lib/common/api/deprecate.js
@@ -1758,10 +1758,8 @@ v8::Local<v8::Promise> WebContents::CapturePage(mate::Arguments* args) {
gfx::Rect rect; gfx::Rect rect;
scoped_refptr<util::Promise> promise = new util::Promise(isolate()); scoped_refptr<util::Promise> promise = new util::Promise(isolate());


if (args->Length() == 1 && !args->GetNext(&rect)) { // get rect arguments if they exist
promise->RejectWithErrorMessage("Rect argument is required."); args->GetNext(&rect);
return promise->GetHandle();
}


auto* const view = web_contents()->GetRenderWidgetHostView(); auto* const view = web_contents()->GetRenderWidgetHostView();
if (!view) { if (!view) {
@@ -318,13 +318,19 @@ WebContents.prototype._init = function () {
NavigationController.call(this, this) NavigationController.call(this, this)


// Every remote callback from renderer process would add a listenter to the // Every remote callback from renderer process would add a listenter to the
// render-view-deleted event, so ignore the listenters warning. // render-view-deleted event, so ignore the listeners warning.
this.setMaxListeners(0) this.setMaxListeners(0)


const nativeCapturePage = this.capturePage
this.capturePage = function (rect, cb) {
return deprecate.promisify(nativeCapturePage.call(this, rect), cb)
}

// Dispatch IPC messages to the ipc module. // Dispatch IPC messages to the ipc module.
this.on('ipc-message', function (event, [channel, ...args]) { this.on('ipc-message', function (event, [channel, ...args]) {
ipcMain.emit(channel, event, ...args) ipcMain.emit(channel, event, ...args)
}) })

this.on('ipc-message-sync', function (event, [channel, ...args]) { this.on('ipc-message-sync', function (event, [channel, ...args]) {
Object.defineProperty(event, 'returnValue', { Object.defineProperty(event, 'returnValue', {
set: function (value) { set: function (value) {
@@ -338,6 +344,7 @@ WebContents.prototype._init = function () {
this.on('ipc-internal-message', function (event, [channel, ...args]) { this.on('ipc-internal-message', function (event, [channel, ...args]) {
ipcMainInternal.emit(channel, event, ...args) ipcMainInternal.emit(channel, event, ...args)
}) })

this.on('ipc-internal-message-sync', function (event, [channel, ...args]) { this.on('ipc-internal-message-sync', function (event, [channel, ...args]) {
Object.defineProperty(event, 'returnValue', { Object.defineProperty(event, 'returnValue', {
set: function (value) { set: function (value) {
@@ -68,8 +68,8 @@ const deprecate = {
}, },


promisify: (promise, cb) => { promisify: (promise, cb) => {
const oldName = `${promise.name} with callbacks` const oldName = `function with callbacks`
const newName = `${promise.name} with Promises` const newName = `function with Promises`
const warn = warnOnce(oldName, newName) const warn = warnOnce(oldName, newName)


if (typeof cb !== 'function') return promise if (typeof cb !== 'function') return promise

0 comments on commit 5c5286b

Please sign in to comment.
You can’t perform that action at this time.