Skip to content

Add session restore to Google Chrome FMA updates - #36662

Merged
allenhouchins merged 3 commits into
mainfrom
allenhouchins-chrome-updates
Dec 4, 2025
Merged

Add session restore to Google Chrome FMA updates#36662
allenhouchins merged 3 commits into
mainfrom
allenhouchins-chrome-updates

Conversation

@allenhouchins

@allenhouchins allenhouchins commented Dec 4, 2025

Copy link
Copy Markdown
Member
  • Added logic to automatically re-open Google Chrome with the last session restored when end users run Update to replicate Google's update behavior and improve the user experience.

fleet-release
fleet-release previously approved these changes Dec 4, 2025
@github-actions

github-actions Bot commented Dec 4, 2025

Copy link
Copy Markdown
Contributor

Script Diff Results

ee/maintained-apps/outputs/google-chrome/darwin.json

=== Install // cb87ad28 -> d0438638 ===

--- /tmp/old.tMCQS8	2025-12-04 04:18:32.375503137 +0000
+++ /tmp/new.spqPaG	2025-12-04 04:18:32.375503137 +0000
@@ -37,5 +37,32 @@
   fi
 }
 
+restart_chrome() {
+  local console_user
+  console_user=$(stat -f "%Su" /dev/console 2>/dev/null || echo "")
+  
+  if [[ -n "$console_user" && "$console_user" != "root" ]]; then
+    echo "Restarting Chrome for user: $console_user"
+    sudo -u "$console_user" open -a "Google Chrome" --args --restore-last-session
+  else
+    echo "No console user found, attempting direct Chrome start..."
+    open -a "Google Chrome" --args --restore-last-session
+  fi
+}
+
+# Check if Chrome was running before we quit it
+CHROME_WAS_RUNNING=false
+if osascript -e "application id \"com.google.Chrome\" is running" 2>/dev/null; then
+  CHROME_WAS_RUNNING=true
+fi
+
 quit_application 'com.google.Chrome'
-installer -pkg "$INSTALLER_PATH" -target /
+installer -pkg "$INSTALLER_PATH" -target / || true
+
+# Restart Chrome if it was running before installation
+if [[ "$CHROME_WAS_RUNNING" == "true" ]]; then
+  sleep 2
+  restart_chrome || true
+fi
+
+exit 0

=== Uninstall Script (no changes) ===

@github-actions

github-actions Bot commented Dec 4, 2025

Copy link
Copy Markdown
Contributor

Script Diff Results

ee/maintained-apps/outputs/google-chrome/darwin.json

=== Install // cb87ad28 -> d0438638 ===

--- /tmp/old.i3OxZp	2025-12-04 05:02:33.363724644 +0000
+++ /tmp/new.RKqjDX	2025-12-04 05:02:33.363724644 +0000
@@ -37,5 +37,32 @@
   fi
 }
 
+restart_chrome() {
+  local console_user
+  console_user=$(stat -f "%Su" /dev/console 2>/dev/null || echo "")
+  
+  if [[ -n "$console_user" && "$console_user" != "root" ]]; then
+    echo "Restarting Chrome for user: $console_user"
+    sudo -u "$console_user" open -a "Google Chrome" --args --restore-last-session
+  else
+    echo "No console user found, attempting direct Chrome start..."
+    open -a "Google Chrome" --args --restore-last-session
+  fi
+}
+
+# Check if Chrome was running before we quit it
+CHROME_WAS_RUNNING=false
+if osascript -e "application id \"com.google.Chrome\" is running" 2>/dev/null; then
+  CHROME_WAS_RUNNING=true
+fi
+
 quit_application 'com.google.Chrome'
-installer -pkg "$INSTALLER_PATH" -target /
+installer -pkg "$INSTALLER_PATH" -target / || true
+
+# Restart Chrome if it was running before installation
+if [[ "$CHROME_WAS_RUNNING" == "true" ]]; then
+  sleep 2
+  restart_chrome || true
+fi
+
+exit 0

=== Uninstall Script (no changes) ===

@allenhouchins
allenhouchins marked this pull request as ready for review December 4, 2025 15:41
fleet-release
fleet-release previously approved these changes Dec 4, 2025
@github-actions

github-actions Bot commented Dec 4, 2025

Copy link
Copy Markdown
Contributor

Script Diff Results

ee/maintained-apps/outputs/google-chrome/darwin.json

=== Install // d0438638 -> 0eca52a6 ===

--- /tmp/old.HUg7Ul	2025-12-04 15:44:09.540698969 +0000
+++ /tmp/new.8xXVlH	2025-12-04 15:44:09.540698969 +0000
@@ -2,15 +2,9 @@
 
 quit_application() {
   local bundle_id="$1"
+  local console_user="$2"
   local timeout_duration=10
 
-  # check if the application is running
-  if ! osascript -e "application id \"$bundle_id\" is running" 2>/dev/null; then
-    return
-  fi
-
-  local console_user
-  console_user=$(stat -f "%Su" /dev/console)
   if [[ $EUID -eq 0 && "$console_user" == "root" ]]; then
     echo "Not logged into a non-root GUI; skipping quitting application ID '$bundle_id'."
     return
@@ -38,8 +32,7 @@
 }
 
 restart_chrome() {
-  local console_user
-  console_user=$(stat -f "%Su" /dev/console 2>/dev/null || echo "")
+  local console_user="$1"
   
   if [[ -n "$console_user" && "$console_user" != "root" ]]; then
     echo "Restarting Chrome for user: $console_user"
@@ -50,19 +43,20 @@
   fi
 }
 
-# Check if Chrome was running before we quit it
+# Get console user once (used by both quit and restart)
+CONSOLE_USER=$(stat -f "%Su" /dev/console 2>/dev/null || echo "")
+
+# Check if Chrome is running (only check once)
 CHROME_WAS_RUNNING=false
 if osascript -e "application id \"com.google.Chrome\" is running" 2>/dev/null; then
   CHROME_WAS_RUNNING=true
+  quit_application 'com.google.Chrome' "$CONSOLE_USER"
 fi
 
-quit_application 'com.google.Chrome'
-installer -pkg "$INSTALLER_PATH" -target / || true
+installer -pkg "$INSTALLER_PATH" -target /
 
 # Restart Chrome if it was running before installation
 if [[ "$CHROME_WAS_RUNNING" == "true" ]]; then
   sleep 2
-  restart_chrome || true
+  restart_chrome "$CONSOLE_USER" || true
 fi
-
-exit 0

=== Uninstall Script (no changes) ===

@allenhouchins
allenhouchins merged commit 83c88fd into main Dec 4, 2025
7 checks passed
@allenhouchins
allenhouchins deleted the allenhouchins-chrome-updates branch December 4, 2025 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants