Browse Source

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.
Samuel Attard 5 years ago
parent
commit
271531f5ff
3 changed files with 6 additions and 7 deletions
  1. 3 3
      lib/browser/api/dialog.js
  2. 2 2
      lib/common/api/deprecate.ts
  3. 1 2
      typings/internal-electron.d.ts

+ 3 - 3
lib/browser/api/dialog.js

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

+ 2 - 2
lib/common/api/deprecate.ts

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

+ 1 - 2
typings/internal-electron.d.ts

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