fix: modify new promise object for dialog methods to match old callback api (#18724)

This was an unexpected and undocumented breaking change, the deprecated
callback method should have the same signature it used to have.
This commit is contained in:
Samuel Attard
2019-06-11 10:24:36 -07:00
committed by Shelley Vohr
parent 9ef83cd8a0
commit 271531f5ff
3 changed files with 6 additions and 7 deletions

View File

@@ -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)

View File

@@ -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`
@@ -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)

View File

@@ -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