Skip to content

Commit

Permalink
fix: modify new promise object for dialog methods to match old callba…
Browse files Browse the repository at this point in the history
…ck api (#18724)

This was an unexpected and undocumented breaking change, the deprecated
callback method should have the same signature it used to have.
  • Loading branch information
MarshallOfSound authored and codebytere committed Jun 11, 2019
1 parent 9ef83cd commit 271531f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/browser/api/dialog.js
Expand Up @@ -229,7 +229,7 @@ module.exports = {
}
}

module.exports.showMessageBox = deprecate.promisify(module.exports.showMessageBox)
module.exports.showOpenDialog = deprecate.promisify(module.exports.showOpenDialog)
module.exports.showSaveDialog = deprecate.promisify(module.exports.showSaveDialog)
module.exports.showMessageBox = deprecate.promisifyMultiArg(module.exports.showMessageBox, ({ response, checkboxChecked }) => [response, checkboxChecked])
module.exports.showOpenDialog = deprecate.promisifyMultiArg(module.exports.showOpenDialog, ({ filePaths, bookmarks }) => [filePaths, bookmarks])
module.exports.showSaveDialog = deprecate.promisifyMultiArg(module.exports.showSaveDialog, ({ filePath, bookmarks }) => [filePath, bookmarks])
module.exports.showCertificateTrustDialog = deprecate.promisify(module.exports.showCertificateTrustDialog)
4 changes: 2 additions & 2 deletions lib/common/api/deprecate.ts
Expand Up @@ -122,9 +122,8 @@ const deprecate: ElectronInternal.DeprecationUtil = {
} as T
},

// convertPromiseValue: Temporarily disabled until it's used
// deprecate a callback-based function in favor of one returning a Promise
promisifyMultiArg: <T extends (...args: any[]) => any>(fn: T /* convertPromiseValue: (v: any) => any */): T => {
promisifyMultiArg: <T extends (...args: any[]) => any>(fn: T, convertPromiseValue?: (v: any) => any): T => {
const fnName = fn.name || 'function'
const oldName = `${fnName} with callbacks`
const newName = `${fnName} with Promises`
Expand All @@ -140,6 +139,7 @@ const deprecate: ElectronInternal.DeprecationUtil = {
if (process.enablePromiseAPIs) warn()
return promise
.then((res: any) => {
if (convertPromiseValue) { res = convertPromiseValue(res) }
process.nextTick(() => {
// eslint-disable-next-line standard/no-callback-literal
cb!.length > 2 ? cb!(null, ...res) : cb!(...res)
Expand Down
3 changes: 1 addition & 2 deletions typings/internal-electron.d.ts
Expand Up @@ -83,8 +83,7 @@ declare namespace ElectronInternal {

promisify<T extends (...args: any[]) => any>(fn: T): T;

// convertPromiseValue: Temporarily disabled until it's used
promisifyMultiArg<T extends (...args: any[]) => any>(fn: T, /*convertPromiseValue: (v: any) => any*/): T;
promisifyMultiArg<T extends (...args: any[]) => any>(fn: T, convertPromiseValue: (v: any) => any): T;
}

// Internal IPC has _replyInternal and NO reply method
Expand Down

0 comments on commit 271531f

Please sign in to comment.