Add session restore to Google Chrome FMA updates (#36662)
- 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.
This commit is contained in:
@@ -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
|
||||
@@ -37,5 +31,32 @@ quit_application() {
|
||||
fi
|
||||
}
|
||||
|
||||
quit_application 'com.google.Chrome'
|
||||
installer -pkg "$INSTALLER_PATH" -target /
|
||||
restart_chrome() {
|
||||
local console_user="$1"
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
# 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
|
||||
|
||||
installer -pkg "$INSTALLER_PATH" -target /
|
||||
|
||||
# Restart Chrome if it was running before installation
|
||||
if [[ "$CHROME_WAS_RUNNING" == "true" ]]; then
|
||||
sleep 2
|
||||
restart_chrome "$CONSOLE_USER" || true
|
||||
fi
|
||||
@@ -6,7 +6,7 @@
|
||||
"exists": "SELECT 1 FROM apps WHERE bundle_identifier = 'com.google.Chrome';"
|
||||
},
|
||||
"installer_url": "https://dl.google.com/dl/chrome/mac/universal/stable/gcem/GoogleChrome.pkg",
|
||||
"install_script_ref": "cb87ad28",
|
||||
"install_script_ref": "0eca52a6",
|
||||
"uninstall_script_ref": "48896621",
|
||||
"sha256": "no_check",
|
||||
"default_categories": [
|
||||
@@ -15,7 +15,7 @@
|
||||
}
|
||||
],
|
||||
"refs": {
|
||||
"48896621": "#!/bin/sh\n\n# variables\nAPPDIR=\"/Applications/\"\nLOGGED_IN_USER=$(scutil <<< \"show State:/Users/ConsoleUser\" | awk '/Name :/ { print $3 }')\n# functions\n\nremove_launchctl_service() {\n local service=\"$1\"\n local booleans=(\"true\" \"false\")\n local plist_status\n local paths\n local should_sudo\n\n echo \"Removing launchctl service ${service}\"\n\n for should_sudo in \"${booleans[@]}\"; do\n plist_status=$(launchctl list \"${service}\" 2>/dev/null)\n\n if [[ $plist_status == \\{* ]]; then\n if [[ $should_sudo == \"true\" ]]; then\n sudo launchctl remove \"${service}\"\n else\n launchctl remove \"${service}\"\n fi\n sleep 1\n fi\n\n paths=(\n \"/Library/LaunchAgents/${service}.plist\"\n \"/Library/LaunchDaemons/${service}.plist\"\n )\n\n # if not using sudo, prepend the home directory to the paths\n if [[ $should_sudo == \"false\" ]]; then\n for i in \"${!paths[@]}\"; do\n paths[i]=\"${HOME}${paths[i]}\"\n done\n fi\n\n for path in \"${paths[@]}\"; do\n if [[ -e \"$path\" ]]; then\n if [[ $should_sudo == \"true\" ]]; then\n sudo rm -f -- \"$path\"\n else\n rm -f -- \"$path\"\n fi\n fi\n done\n done\n}\n\ntrash() {\n local logged_in_user=\"$1\"\n local target_file=\"$2\"\n local timestamp=\"$(date +%Y-%m-%d-%s)\"\n local rand=\"$(jot -r 1 0 99999)\"\n\n # replace ~ with /Users/$logged_in_user\n if [[ \"$target_file\" == ~* ]]; then\n target_file=\"/Users/$logged_in_user${target_file:1}\"\n fi\n\n local trash=\"/Users/$logged_in_user/.Trash\"\n local file_name=\"$(basename \"${target_file}\")\"\n\n if [[ -e \"$target_file\" ]]; then\n echo \"removing $target_file.\"\n mv -f \"$target_file\" \"$trash/${file_name}_${timestamp}_${rand}\"\n else\n echo \"$target_file doesn't exist.\"\n fi\n}\n\nsudo rm -rf \"$APPDIR/Google Chrome.app\"\nremove_launchctl_service 'com.google.keystone.agent'\nremove_launchctl_service 'com.google.keystone.daemon'\nsudo rmdir '/Library/Google'\nsudo rmdir '~/Library/Application Support/Google'\nsudo rmdir '~/Library/Caches/Google'\nsudo rmdir '~/Library/Google'\ntrash $LOGGED_IN_USER '/Library/Caches/com.google.SoftwareUpdate.*'\ntrash $LOGGED_IN_USER '/Library/Google/Google Chrome Brand.plist'\ntrash $LOGGED_IN_USER '/Library/Google/GoogleSoftwareUpdate'\ntrash $LOGGED_IN_USER '~/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments/com.google.chrome.app.*.sfl*'\ntrash $LOGGED_IN_USER '~/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments/com.google.chrome.sfl*'\ntrash $LOGGED_IN_USER '~/Library/Application Support/Google/Chrome'\ntrash $LOGGED_IN_USER '~/Library/Caches/com.google.Chrome'\ntrash $LOGGED_IN_USER '~/Library/Caches/com.google.Chrome.helper.*'\ntrash $LOGGED_IN_USER '~/Library/Caches/com.google.Keystone'\ntrash $LOGGED_IN_USER '~/Library/Caches/com.google.Keystone.Agent'\ntrash $LOGGED_IN_USER '~/Library/Caches/com.google.SoftwareUpdate'\ntrash $LOGGED_IN_USER '~/Library/Caches/Google/Chrome'\ntrash $LOGGED_IN_USER '~/Library/Google/Google Chrome Brand.plist'\ntrash $LOGGED_IN_USER '~/Library/Google/GoogleSoftwareUpdate'\ntrash $LOGGED_IN_USER '~/Library/LaunchAgents/com.google.keystone.agent.plist'\ntrash $LOGGED_IN_USER '~/Library/LaunchAgents/com.google.keystone.xpcservice.plist'\ntrash $LOGGED_IN_USER '~/Library/Logs/GoogleSoftwareUpdateAgent.log'\ntrash $LOGGED_IN_USER '~/Library/Preferences/com.google.Chrome.plist'\ntrash $LOGGED_IN_USER '~/Library/Preferences/com.google.Keystone.Agent.plist'\ntrash $LOGGED_IN_USER '~/Library/Saved Application State/com.google.Chrome.app.*.savedState'\ntrash $LOGGED_IN_USER '~/Library/Saved Application State/com.google.Chrome.savedState'\ntrash $LOGGED_IN_USER '~/Library/WebKit/com.google.Chrome'\n",
|
||||
"cb87ad28": "#!/bin/sh\n\nquit_application() {\n local bundle_id=\"$1\"\n local timeout_duration=10\n\n # check if the application is running\n if ! osascript -e \"application id \\\"$bundle_id\\\" is running\" 2>/dev/null; then\n return\n fi\n\n local console_user\n console_user=$(stat -f \"%Su\" /dev/console)\n if [[ $EUID -eq 0 && \"$console_user\" == \"root\" ]]; then\n echo \"Not logged into a non-root GUI; skipping quitting application ID '$bundle_id'.\"\n return\n fi\n\n echo \"Quitting application '$bundle_id'...\"\n\n # try to quit the application within the timeout period\n local quit_success=false\n SECONDS=0\n while (( SECONDS < timeout_duration )); do\n if osascript -e \"tell application id \\\"$bundle_id\\\" to quit\" >/dev/null 2>&1; then\n if ! pgrep -f \"$bundle_id\" >/dev/null 2>&1; then\n echo \"Application '$bundle_id' quit successfully.\"\n quit_success=true\n break\n fi\n fi\n sleep 1\n done\n\n if [[ \"$quit_success\" = false ]]; then\n echo \"Application '$bundle_id' did not quit.\"\n fi\n}\n\nquit_application 'com.google.Chrome'\ninstaller -pkg \"$INSTALLER_PATH\" -target /"
|
||||
"0eca52a6": "#!/bin/sh\n\nquit_application() {\n local bundle_id=\"$1\"\n local console_user=\"$2\"\n local timeout_duration=10\n\n if [[ $EUID -eq 0 && \"$console_user\" == \"root\" ]]; then\n echo \"Not logged into a non-root GUI; skipping quitting application ID '$bundle_id'.\"\n return\n fi\n\n echo \"Quitting application '$bundle_id'...\"\n\n # try to quit the application within the timeout period\n local quit_success=false\n SECONDS=0\n while (( SECONDS < timeout_duration )); do\n if osascript -e \"tell application id \\\"$bundle_id\\\" to quit\" >/dev/null 2>&1; then\n if ! pgrep -f \"$bundle_id\" >/dev/null 2>&1; then\n echo \"Application '$bundle_id' quit successfully.\"\n quit_success=true\n break\n fi\n fi\n sleep 1\n done\n\n if [[ \"$quit_success\" = false ]]; then\n echo \"Application '$bundle_id' did not quit.\"\n fi\n}\n\nrestart_chrome() {\n local console_user=\"$1\"\n \n if [[ -n \"$console_user\" && \"$console_user\" != \"root\" ]]; then\n echo \"Restarting Chrome for user: $console_user\"\n sudo -u \"$console_user\" open -a \"Google Chrome\" --args --restore-last-session\n else\n echo \"No console user found, attempting direct Chrome start...\"\n open -a \"Google Chrome\" --args --restore-last-session\n fi\n}\n\n# Get console user once (used by both quit and restart)\nCONSOLE_USER=$(stat -f \"%Su\" /dev/console 2>/dev/null || echo \"\")\n\n# Check if Chrome is running (only check once)\nCHROME_WAS_RUNNING=false\nif osascript -e \"application id \\\"com.google.Chrome\\\" is running\" 2>/dev/null; then\n CHROME_WAS_RUNNING=true\n quit_application 'com.google.Chrome' \"$CONSOLE_USER\"\nfi\n\ninstaller -pkg \"$INSTALLER_PATH\" -target /\n\n# Restart Chrome if it was running before installation\nif [[ \"$CHROME_WAS_RUNNING\" == \"true\" ]]; then\n sleep 2\n restart_chrome \"$CONSOLE_USER\" || true\nfi",
|
||||
"48896621": "#!/bin/sh\n\n# variables\nAPPDIR=\"/Applications/\"\nLOGGED_IN_USER=$(scutil <<< \"show State:/Users/ConsoleUser\" | awk '/Name :/ { print $3 }')\n# functions\n\nremove_launchctl_service() {\n local service=\"$1\"\n local booleans=(\"true\" \"false\")\n local plist_status\n local paths\n local should_sudo\n\n echo \"Removing launchctl service ${service}\"\n\n for should_sudo in \"${booleans[@]}\"; do\n plist_status=$(launchctl list \"${service}\" 2>/dev/null)\n\n if [[ $plist_status == \\{* ]]; then\n if [[ $should_sudo == \"true\" ]]; then\n sudo launchctl remove \"${service}\"\n else\n launchctl remove \"${service}\"\n fi\n sleep 1\n fi\n\n paths=(\n \"/Library/LaunchAgents/${service}.plist\"\n \"/Library/LaunchDaemons/${service}.plist\"\n )\n\n # if not using sudo, prepend the home directory to the paths\n if [[ $should_sudo == \"false\" ]]; then\n for i in \"${!paths[@]}\"; do\n paths[i]=\"${HOME}${paths[i]}\"\n done\n fi\n\n for path in \"${paths[@]}\"; do\n if [[ -e \"$path\" ]]; then\n if [[ $should_sudo == \"true\" ]]; then\n sudo rm -f -- \"$path\"\n else\n rm -f -- \"$path\"\n fi\n fi\n done\n done\n}\n\ntrash() {\n local logged_in_user=\"$1\"\n local target_file=\"$2\"\n local timestamp=\"$(date +%Y-%m-%d-%s)\"\n local rand=\"$(jot -r 1 0 99999)\"\n\n # replace ~ with /Users/$logged_in_user\n if [[ \"$target_file\" == ~* ]]; then\n target_file=\"/Users/$logged_in_user${target_file:1}\"\n fi\n\n local trash=\"/Users/$logged_in_user/.Trash\"\n local file_name=\"$(basename \"${target_file}\")\"\n\n if [[ -e \"$target_file\" ]]; then\n echo \"removing $target_file.\"\n mv -f \"$target_file\" \"$trash/${file_name}_${timestamp}_${rand}\"\n else\n echo \"$target_file doesn't exist.\"\n fi\n}\n\nsudo rm -rf \"$APPDIR/Google Chrome.app\"\nremove_launchctl_service 'com.google.keystone.agent'\nremove_launchctl_service 'com.google.keystone.daemon'\nsudo rmdir '/Library/Google'\nsudo rmdir '~/Library/Application Support/Google'\nsudo rmdir '~/Library/Caches/Google'\nsudo rmdir '~/Library/Google'\ntrash $LOGGED_IN_USER '/Library/Caches/com.google.SoftwareUpdate.*'\ntrash $LOGGED_IN_USER '/Library/Google/Google Chrome Brand.plist'\ntrash $LOGGED_IN_USER '/Library/Google/GoogleSoftwareUpdate'\ntrash $LOGGED_IN_USER '~/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments/com.google.chrome.app.*.sfl*'\ntrash $LOGGED_IN_USER '~/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments/com.google.chrome.sfl*'\ntrash $LOGGED_IN_USER '~/Library/Application Support/Google/Chrome'\ntrash $LOGGED_IN_USER '~/Library/Caches/com.google.Chrome'\ntrash $LOGGED_IN_USER '~/Library/Caches/com.google.Chrome.helper.*'\ntrash $LOGGED_IN_USER '~/Library/Caches/com.google.Keystone'\ntrash $LOGGED_IN_USER '~/Library/Caches/com.google.Keystone.Agent'\ntrash $LOGGED_IN_USER '~/Library/Caches/com.google.SoftwareUpdate'\ntrash $LOGGED_IN_USER '~/Library/Caches/Google/Chrome'\ntrash $LOGGED_IN_USER '~/Library/Google/Google Chrome Brand.plist'\ntrash $LOGGED_IN_USER '~/Library/Google/GoogleSoftwareUpdate'\ntrash $LOGGED_IN_USER '~/Library/LaunchAgents/com.google.keystone.agent.plist'\ntrash $LOGGED_IN_USER '~/Library/LaunchAgents/com.google.keystone.xpcservice.plist'\ntrash $LOGGED_IN_USER '~/Library/Logs/GoogleSoftwareUpdateAgent.log'\ntrash $LOGGED_IN_USER '~/Library/Preferences/com.google.Chrome.plist'\ntrash $LOGGED_IN_USER '~/Library/Preferences/com.google.Keystone.Agent.plist'\ntrash $LOGGED_IN_USER '~/Library/Saved Application State/com.google.Chrome.app.*.savedState'\ntrash $LOGGED_IN_USER '~/Library/Saved Application State/com.google.Chrome.savedState'\ntrash $LOGGED_IN_USER '~/Library/WebKit/com.google.Chrome'\n"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user