mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
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:
committed by
Shelley Vohr
parent
9ef83cd8a0
commit
271531f5ff
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
3
typings/internal-electron.d.ts
vendored
3
typings/internal-electron.d.ts
vendored
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user