From 6b3ff63358d29067122aad6bb1fed195cddc81ef Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 17 Feb 2014 14:51:22 +0800 Subject: [PATCH 1/7] Close all windows before installing update. --- browser/api/lib/auto-updater.coffee | 11 +++++++++++ renderer/lib/init.coffee | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/browser/api/lib/auto-updater.coffee b/browser/api/lib/auto-updater.coffee index 81c22f16d57b..c18580f46107 100644 --- a/browser/api/lib/auto-updater.coffee +++ b/browser/api/lib/auto-updater.coffee @@ -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 diff --git a/renderer/lib/init.coffee b/renderer/lib/init.coffee index 8c061149cd46..64d9b75af177 100644 --- a/renderer/lib/init.coffee +++ b/renderer/lib/init.coffee @@ -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 = {} From b932461b4506853b39870c22ea16598dd02b7895 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 17 Feb 2014 14:56:23 +0800 Subject: [PATCH 2/7] Fix crash when calling quitAndUpdate without any update. --- browser/api/atom_api_auto_updater.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/api/atom_api_auto_updater.cc b/browser/api/atom_api_auto_updater.cc index 69ed10089128..b1fe2915d331 100644 --- a/browser/api/atom_api_auto_updater.cc +++ b/browser/api/atom_api_auto_updater.cc @@ -80,7 +80,11 @@ void AutoUpdater::CheckForUpdates( void AutoUpdater::QuitAndInstall( const v8::FunctionCallbackInfo& args) { AutoUpdater* self = AutoUpdater::Unwrap(args.This()); - self->quit_and_install_.Run(); + + if (!self->quit_and_install_.is_null()) { + self->quit_and_install_.Run(); + self->quit_and_install_.Reset(); + } } // static From a9efe77ceb8c1e08c42c6299794df890f7feeadf Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 17 Feb 2014 15:05:34 +0800 Subject: [PATCH 3/7] Fix quitAndInstall when there is no window. --- browser/api/lib/auto-updater.coffee | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/browser/api/lib/auto-updater.coffee b/browser/api/lib/auto-updater.coffee index c18580f46107..53d067267777 100644 --- a/browser/api/lib/auto-updater.coffee +++ b/browser/api/lib/auto-updater.coffee @@ -9,6 +9,13 @@ autoUpdater.on 'update-downloaded-raw', (args...) -> @emit 'update-downloaded', args..., => @quitAndInstall() autoUpdater.quitAndInstall = -> + # If we don't have any window then quitAndInstall immediately. + BrowserWindow = require 'browser-window' + windows = BrowserWindow.getAllWindows() + if windows.length is 0 + AutoUpdater::quitAndInstall.call this + return + # Do the restart after all windows have been closed. app = require 'app' app.removeAllListeners 'window-all-closed' @@ -16,7 +23,6 @@ autoUpdater.quitAndInstall = -> # 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() + ipc.sendChannel win.getProcessId(), win.getRoutingId(), 'ATOM_SHELL_SILENT_CLOSE' for win in windows module.exports = autoUpdater From 07fc2b41af1e0f963a7e378f3d2565a1c9390386 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 17 Feb 2014 15:24:42 +0800 Subject: [PATCH 4/7] Fix using BrowserWindow as parameter for ipc.sendChannel. --- browser/api/lib/auto-updater.coffee | 2 +- browser/api/lib/ipc.coffee | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/browser/api/lib/auto-updater.coffee b/browser/api/lib/auto-updater.coffee index 53d067267777..39097314978d 100644 --- a/browser/api/lib/auto-updater.coffee +++ b/browser/api/lib/auto-updater.coffee @@ -23,6 +23,6 @@ autoUpdater.quitAndInstall = -> # Tell all windows to remove beforeunload handler and then close itself. ipc = require 'ipc' - ipc.sendChannel win.getProcessId(), win.getRoutingId(), 'ATOM_SHELL_SILENT_CLOSE' for win in windows + ipc.sendChannel win, 'ATOM_SHELL_SILENT_CLOSE' for win in windows module.exports = autoUpdater diff --git a/browser/api/lib/ipc.coffee b/browser/api/lib/ipc.coffee index 11377ec28300..c93ed4f20576 100644 --- a/browser/api/lib/ipc.coffee +++ b/browser/api/lib/ipc.coffee @@ -5,6 +5,7 @@ sendWrap = (channel, processId, routingId, args...) -> BrowserWindow = require 'browser-window' if processId?.constructor is BrowserWindow window = processId + args = [routingId, args...] processId = window.getProcessId() routingId = window.getRoutingId() From 274c9d04b1e463ec4fe4e517d93b74ac52022a20 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 17 Feb 2014 16:25:00 +0800 Subject: [PATCH 5/7] Enable the quitAndInstall to be cancelled by beforeunload handler. --- browser/api/atom_api_auto_updater.cc | 4 +--- browser/api/lib/auto-updater.coffee | 5 +---- renderer/lib/init.coffee | 10 ---------- 3 files changed, 2 insertions(+), 17 deletions(-) diff --git a/browser/api/atom_api_auto_updater.cc b/browser/api/atom_api_auto_updater.cc index b1fe2915d331..6375e19a9218 100644 --- a/browser/api/atom_api_auto_updater.cc +++ b/browser/api/atom_api_auto_updater.cc @@ -81,10 +81,8 @@ void AutoUpdater::QuitAndInstall( const v8::FunctionCallbackInfo& args) { AutoUpdater* self = AutoUpdater::Unwrap(args.This()); - if (!self->quit_and_install_.is_null()) { + if (!self->quit_and_install_.is_null()) self->quit_and_install_.Run(); - self->quit_and_install_.Reset(); - } } // static diff --git a/browser/api/lib/auto-updater.coffee b/browser/api/lib/auto-updater.coffee index 39097314978d..4cd8dc9cb7e9 100644 --- a/browser/api/lib/auto-updater.coffee +++ b/browser/api/lib/auto-updater.coffee @@ -20,9 +20,6 @@ autoUpdater.quitAndInstall = -> 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' - ipc.sendChannel win, 'ATOM_SHELL_SILENT_CLOSE' for win in windows + win.close() for win in windows module.exports = autoUpdater diff --git a/renderer/lib/init.coffee b/renderer/lib/init.coffee index 64d9b75af177..8c061149cd46 100644 --- a/renderer/lib/init.coffee +++ b/renderer/lib/init.coffee @@ -50,16 +50,6 @@ 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 = {} From fde4c544b8e4ff9e3f4cc72e52ccc842c42f60f2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 17 Feb 2014 16:33:26 +0800 Subject: [PATCH 6/7] :lipstick: --- browser/native_window.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/native_window.h b/browser/native_window.h index 0e802fd110d9..0b82b969c723 100644 --- a/browser/native_window.h +++ b/browser/native_window.h @@ -56,7 +56,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, class DialogScope { public: - DialogScope(NativeWindow* window) + explicit DialogScope(NativeWindow* window) : window_(window) { if (window_ != NULL) window_->set_has_dialog_attached(true); From a76183c1886882ae199b0d5f4edc8b1d36150fdd Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 17 Feb 2014 17:50:25 +0800 Subject: [PATCH 7/7] Do not print download progress in CI. --- script/cibuild | 2 ++ script/lib/util.py | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/script/cibuild b/script/cibuild index d9e8ceb68924..dd2dfc5e99ca 100755 --- a/script/cibuild +++ b/script/cibuild @@ -11,6 +11,8 @@ SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) def main(): + os.environ['CI'] = '1' + rm_rf(os.path.join(SOURCE_ROOT, 'out')) rm_rf(os.path.join(SOURCE_ROOT, 'node_modules')) rm_rf(os.path.join(SOURCE_ROOT, 'frameworks')) diff --git a/script/lib/util.py b/script/lib/util.py index 8eefed3f9fff..ecbe812162cb 100644 --- a/script/lib/util.py +++ b/script/lib/util.py @@ -36,6 +36,8 @@ def download(text, url, path): downloaded_size = 0 block_size = 128 + ci = os.environ.get('CI') == '1' + while True: buf = web_file.read(block_size) if not buf: @@ -44,11 +46,15 @@ def download(text, url, path): downloaded_size += len(buf) local_file.write(buf) - percent = downloaded_size * 100. / file_size - status = "\r%s %10d [%3.1f%%]" % (text, downloaded_size, percent) - print status, + if not ci: + percent = downloaded_size * 100. / file_size + status = "\r%s %10d [%3.1f%%]" % (text, downloaded_size, percent) + print status, - print + if ci: + print "%s done." % (text) + else: + print def extract_tarball(tarball_path, member, destination):