From e1d32c30f2dae373578d29add4941ba233bb5f97 Mon Sep 17 00:00:00 2001 From: Jocelyn Le Sage Date: Sat, 8 Apr 2023 21:18:35 -0400 Subject: [PATCH] Improved graceful shutdown of Firefox: - By default, disable confirmation when quitting using the ctrl+q shortcut. - Wait for Firefox to quit after sending ctrl+q key presses. --- rootfs/defaults/prefs.js | 3 +++ rootfs/etc/services.d/app/kill | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/rootfs/defaults/prefs.js b/rootfs/defaults/prefs.js index c91c032..5e1d3e9 100644 --- a/rootfs/defaults/prefs.js +++ b/rootfs/defaults/prefs.js @@ -2,3 +2,6 @@ user_pref("toolkit.telemetry.reportingpolicy.firstRun", false); // Prevent closing Firefox when closing the last tab. user_pref("browser.tabs.closeWindowWithLastTab", false); +// Disable confirmation before quitting with Ctrl+Q. Needed to allow Firefox +// to quit cleanly when container is shutted down. +user_pref("browser.warnOnQuitShortcut", false); diff --git a/rootfs/etc/services.d/app/kill b/rootfs/etc/services.d/app/kill index 7a99f23..f26848a 100755 --- a/rootfs/etc/services.d/app/kill +++ b/rootfs/etc/services.d/app/kill @@ -1,14 +1,25 @@ #!/bin/sh # -# When receiving SIGTERM, Firefox doesn't qui immediately and instead ask for -# confirmation. Instead, terminate Firefox by sending the CTRL+q key presses. +# Firefox doesn't gracefully shutdown when receiving SIGTERM. For example, last +# opened tabs may not be saved. Instead, terminate Firefox by sending the +# CTRL+q key presses. # set -e # Exit immediately if a command exits with a non-zero status. set -u # Treat unset variables as an error. xdotool key "Escape" +sleep 0.5 xdotool key "ctrl+q" +for i in $(seq 1 10) +do + if ! ps | grep "/usr/lib/firefox/firefox" | grep -q -v grep + then + break + fi + sleep 0.5 +done + # vim:ft=sh:ts=4:sw=4:et:sts=4