fix: quit after Chromium is fully started (#21488)

* fix: quit when chromium is fully started

* test: remove hacks on app.quit

* chore: RunUntilIdle is unnecessary
This commit is contained in:
Cheng Zhao 2019-12-13 18:57:02 +09:00 committed by GitHub
parent b9a250a623
commit f9a1dc10fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 17 deletions

View file

@ -26,6 +26,21 @@
namespace electron {
namespace {
// Call |quit| after Chromium is fully started.
//
// This is important for quitting immediately in the "ready" event, when
// certain initialization task may still be pending, and quitting at that time
// could end up with crash on exit.
void RunQuitClosure(base::OnceClosure quit) {
// On Linux/Windows the "ready" event is emitted in "PreMainMessageLoopRun",
// make sure we quit after message loop has run for once.
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, std::move(quit));
}
} // namespace
Browser::LoginItemSettings::LoginItemSettings() = default;
Browser::LoginItemSettings::~LoginItemSettings() = default;
Browser::LoginItemSettings::LoginItemSettings(const LoginItemSettings& other) =
@ -94,7 +109,7 @@ void Browser::Shutdown() {
observer.OnQuit();
if (quit_main_message_loop_) {
std::move(quit_main_message_loop_).Run();
RunQuitClosure(std::move(quit_main_message_loop_));
} else {
// There is no message loop available so we are in early stage, wait until
// the quit_main_message_loop_ is available.
@ -189,7 +204,7 @@ void Browser::PreMainMessageLoopRun() {
void Browser::SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure) {
if (is_shutdown_)
std::move(quit_closure).Run();
RunQuitClosure(std::move(quit_closure));
else
quit_main_message_loop_ = std::move(quit_closure);
}

View file

@ -3,5 +3,5 @@ app.on('ready', function () {
const web = webContents.create({})
new WebContentsView(web) // eslint-disable-line
process.nextTick(() => app.quit())
app.quit()
})

View file

@ -9,7 +9,5 @@ app.on('ready', () => {
process.stdout.write(JSON.stringify(payload))
process.stdout.end()
setImmediate(() => {
app.quit()
})
})

View file

@ -42,8 +42,6 @@ app.on('ready', async function () {
} finally {
process.stdout.end()
setImmediate(() => {
app.quit()
})
}
})

View file

@ -4,7 +4,5 @@ app.on('ready', () => {
process.stdout.write(JSON.stringify(ipcMain.eventNames()))
process.stdout.end()
setImmediate(() => {
app.quit()
})
})

View file

@ -2,5 +2,5 @@ const { BrowserView, app } = require('electron')
app.on('ready', function () {
new BrowserView({}) // eslint-disable-line
process.nextTick(() => app.quit())
app.quit()
})

View file

@ -2,5 +2,5 @@ const { app, webContents } = require('electron')
app.on('ready', function () {
webContents.create({})
process.nextTick(() => app.quit())
app.quit()
})

View file

@ -4,7 +4,5 @@ app.on('ready', () => {
process.stdout.write(app.getLocale())
process.stdout.end()
setImmediate(() => {
app.quit()
})
})