]> khamidou — GitHub mirrors - electron.git/commitdiff
Close all windows before installing update.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 17 Feb 2014 06:51:22 +0000 (14:51 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 17 Feb 2014 06:51:22 +0000 (14:51 +0800)
browser/api/lib/auto-updater.coffee
renderer/lib/init.coffee

index 81c22f16d57b60f7aeb5a92b934c27d586f7eed7..c18580f4610774aeaebb424118c67d4d3be9e0a5 100644 (file)
@@ -8,4 +8,15 @@ autoUpdater.on 'update-downloaded-raw', (args...) ->
   args[3] = new Date(args[3])  # releaseDate
   @emit 'update-downloaded', args..., => @quitAndInstall()
 
+autoUpdater.quitAndInstall = ->
+  # Do the restart after all windows have been closed.
+  app = require 'app'
+  app.removeAllListeners 'window-all-closed'
+  app.once 'window-all-closed', AutoUpdater::quitAndInstall.bind(this)
+
+  # Tell all windows to remove beforeunload handler and then close itself.
+  ipc = require 'ipc'
+  BrowserWindow = require 'browser-window'
+  ipc.sendChannel win.getProcessId(), win.getRoutingId(), 'ATOM_SHELL_SILENT_CLOSE' for win in BrowserWindow.getAllWindows()
+
 module.exports = autoUpdater
index 8c061149cd460ca99f953db4804c7beb189d4ae3..64d9b75af177a813f82290b19c22706312991973 100644 (file)
@@ -50,6 +50,16 @@ window.onerror = (error) ->
   else
     false
 
+# Enable browser to close window silently.
+setTimeout ->
+  require('ipc').once 'ATOM_SHELL_SILENT_CLOSE', ->
+    window.onbeforeunload = null
+    window.close()
+
+# Override default window.close.
+window.close = ->
+  require('remote').getCurrentWindow().close()
+
 # Override default window.open.
 window.open = (url, name, features) ->
   options = {}