File size: 1,520 Bytes
7b3289b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
# Copyright Epic Games, Inc. All Rights Reserved.

set -eu

UNAMEOS="$(uname -s)"

SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd)
CHROME_USER_DATA=$(mktemp -d -t GPUDumpViewerUserData-XXXXXX)

APPS=()
APPS+=(google-chrome-stable)
APPS+=(google-chrome)

if [[ "${UNAMEOS}" =~ "Darwin" ]]; then
	APPS+=(open)
fi

CMD=
for val in "${APPS[@]}"; do
	CMD="$(command -v "${val}")" || true
	if [[ -n "${CMD}" ]]; then
		break
	fi
done

if [[ -z "${CMD}" ]]; then
	echo "ERROR: Browser launch command not found"
	exit 1
fi

ARGS=("${CMD}")

if [[ "${CMD}" == *open ]]; then
	ARGS+=(-a "google chrome")
	ARGS+=(--new)
	ARGS+=(-W)
fi

ARGS+=("file://${SCRIPT_DIR}/GPUDumpViewer.html")

if [[ "${CMD}" == *open ]]; then
	ARGS+=(--args)
fi

# --allow-file-access-from-files allow to load a file from a file:// webpage required for GPUDumpViewer.html to work.
# --user-data-dir is required to force chrome to open a new instance so that --allow-file-access-from-files is honored.
ARGS+=(--allow-file-access-from-files)
ARGS+=(--new-window)
ARGS+=(--incognito)
ARGS+=("--user-data-dir=${CHROME_USER_DATA}")

echo "Executing:"
echo

echo "${ARGS[0]} \\"
for ((i=1; i < ${#ARGS[@]}; i++ )); do
	echo "  ${ARGS[$i]} \\";
done
echo

"${ARGS[@]}"

echo
echo "Closing ${CMD}..."

if [[ -n "${CHROME_USER_DATA}" ]]; then
	# Wait for 2s to shut down so that CHROME_USER_DATA can be deleted completely
	sleep 2
	rm -rf "${CHROME_USER_DATA}"
fi