]> khamidou — GitHub mirrors - electron.git/commitdiff
Forbid using dialog module before app is ready
authorCheng Zhao <zcbenz@gmail.com>
Wed, 5 Nov 2014 11:50:24 +0000 (19:50 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 5 Nov 2014 11:50:24 +0000 (19:50 +0800)
atom/browser/api/lib/dialog.coffee

index 0cdd3c38380979272fcbc04baeae0733172f1702..49b1c0ef00361cae091988ffd439c0651c85dbcf 100644 (file)
@@ -1,5 +1,6 @@
 binding = process.atomBinding 'dialog'
 v8Util = process.atomBinding 'v8_util'
+app = require 'app'
 BrowserWindow = require 'browser-window'
 
 fileDialogProperties =
@@ -22,8 +23,12 @@ parseArgs = (window, options, callback) ->
     options = null
   [window, options, callback]
 
+checkAppInitialized = ->
+  throw new Error('dialog module can only be used after app is ready') unless app.isReady()
+
 module.exports =
   showOpenDialog: (args...) ->
+    checkAppInitialized()
     [window, options, callback] = parseArgs args...
 
     options ?= title: 'Open', properties: ['openFile']
@@ -52,6 +57,7 @@ module.exports =
                            wrappedCallback
 
   showSaveDialog: (args...) ->
+    checkAppInitialized()
     [window, options, callback] = parseArgs args...
 
     options ?= title: 'Save'
@@ -72,6 +78,7 @@ module.exports =
                            wrappedCallback
 
   showMessageBox: (args...) ->
+    checkAppInitialized()
     [window, options, callback] = parseArgs args...
 
     options ?= type: 'none'