Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Revert launch scenario changes #19028

Merged
merged 6 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions atom.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,20 @@ esac

export ATOM_DISABLE_SHELLING_OUT_FOR_ENVIRONMENT=true

while getopts ":wtfvh-:" opt; do
ATOM_ADD=false
ATOM_NEW_WINDOW=false
EXIT_CODE_OVERRIDE=

while getopts ":anwtfvh-:" opt; do
case "$opt" in
-)
case "${OPTARG}" in
add)
ATOM_ADD=true
;;
new-window)
ATOM_NEW_WINDOW=true
;;
wait)
WAIT=1
;;
Expand All @@ -45,6 +55,12 @@ while getopts ":wtfvh-:" opt; do
;;
esac
;;
a)
ATOM_ADD=true
;;
n)
ATOM_NEW_WINDOW=true
;;
w)
WAIT=1
;;
Expand All @@ -58,6 +74,11 @@ while getopts ":wtfvh-:" opt; do
esac
done

if [ "${ATOM_ADD}" = "true" ] && [ "${ATOM_NEW_WINDOW}" = "true" ]; then
EXPECT_OUTPUT=1
EXIT_CODE_OVERRIDE=1
fi

if [ $REDIRECT_STDERR ]; then
exec 2> /dev/null
fi
Expand Down Expand Up @@ -115,7 +136,11 @@ if [ $OS == 'Mac' ]; then

if [ $EXPECT_OUTPUT ]; then
"$ATOM_PATH/$ATOM_APP_NAME/Contents/MacOS/$ATOM_EXECUTABLE_NAME" --executed-from="$(pwd)" --pid=$$ "$@"
exit $?
if [ $? -eq 0 ] && [ -n "${EXIT_CODE_OVERRIDE}" ]; then
exit "${EXIT_CODE_OVERRIDE}"
else
exit $?
fi
else
open -a "$ATOM_PATH/$ATOM_APP_NAME" -n --args --executed-from="$(pwd)" --pid=$$ --path-environment="$PATH" "$@"
fi
Expand Down Expand Up @@ -144,7 +169,11 @@ elif [ $OS == 'Linux' ]; then

if [ $EXPECT_OUTPUT ]; then
"$ATOM_PATH" --executed-from="$(pwd)" --pid=$$ "$@"
exit $?
if [ $? -eq 0 ] && [ -n "${EXIT_CODE_OVERRIDE}" ]; then
exit "${EXIT_CODE_OVERRIDE}"
else
exit $?
fi
else
(
nohup "$ATOM_PATH" --executed-from="$(pwd)" --pid=$$ "$@" > "$ATOM_HOME/nohup.out" 2>&1
Expand Down
21 changes: 15 additions & 6 deletions src/main-process/atom-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ class AtomApplication extends EventEmitter {
pidToKillWhenClosed,
devMode,
safeMode,
newWindow,
logFile,
profileStartup,
timeout,
Expand Down Expand Up @@ -267,6 +268,7 @@ class AtomApplication extends EventEmitter {
foldersToOpen,
executedFrom,
pidToKillWhenClosed,
newWindow,
devMode,
safeMode,
profileStartup,
Expand All @@ -280,6 +282,7 @@ class AtomApplication extends EventEmitter {
// Always open a editor window if this is the first instance of Atom.
return this.openPath({
pidToKillWhenClosed,
newWindow,
devMode,
safeMode,
profileStartup,
Expand Down Expand Up @@ -791,6 +794,7 @@ class AtomApplication extends EventEmitter {
// options -
// :pathToOpen - The file path to open
// :pidToKillWhenClosed - The integer of the pid to kill
// :newWindow - Boolean of whether this should be opened in a new window.
// :devMode - Boolean to control the opened window's dev mode.
// :safeMode - Boolean to control the opened window's safe mode.
// :profileStartup - Boolean to control creating a profile of the startup time.
Expand All @@ -799,6 +803,7 @@ class AtomApplication extends EventEmitter {
openPath ({
pathToOpen,
pidToKillWhenClosed,
newWindow,
devMode,
safeMode,
profileStartup,
Expand All @@ -810,6 +815,7 @@ class AtomApplication extends EventEmitter {
return this.openPaths({
pathsToOpen: [pathToOpen],
pidToKillWhenClosed,
newWindow,
devMode,
safeMode,
profileStartup,
Expand All @@ -826,6 +832,7 @@ class AtomApplication extends EventEmitter {
// :pathsToOpen - The array of file paths to open
// :foldersToOpen - An array of additional paths to open that must be existing directories
// :pidToKillWhenClosed - The integer of the pid to kill
// :newWindow - Boolean of whether this should be opened in a new window.
// :devMode - Boolean to control the opened window's dev mode.
// :safeMode - Boolean to control the opened window's safe mode.
// :windowDimensions - Object with height and width keys.
Expand All @@ -836,6 +843,7 @@ class AtomApplication extends EventEmitter {
foldersToOpen,
executedFrom,
pidToKillWhenClosed,
newWindow,
devMode,
safeMode,
windowDimensions,
Expand Down Expand Up @@ -878,13 +886,14 @@ class AtomApplication extends EventEmitter {
const normalizedPathsToOpen = locationsToOpen.map(location => location.pathToOpen).filter(Boolean)

let existingWindow
if (addToLastWindow && normalizedPathsToOpen.length > 0) {
if (!newWindow && normalizedPathsToOpen.length > 0) {
existingWindow = this.windowForPaths(normalizedPathsToOpen, devMode)
if (!existingWindow) {
let lastWindow = window || this.getLastFocusedWindow()
if (lastWindow && lastWindow.devMode === devMode) {
existingWindow = lastWindow
}
}

if (addToLastWindow && !existingWindow) {
let lastWindow = window || this.getLastFocusedWindow()
if (lastWindow && lastWindow.devMode === devMode) {
existingWindow = lastWindow
}
}

Expand Down
27 changes: 17 additions & 10 deletions src/main-process/parse-command-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ module.exports = function parseCommandLine (processArgs) {
atom [options] [path ...]
atom file[:line[:column]]

If no arguments are given and no Atom windows are already open, restore all windows
from the previous editing session. Use "atom --new-window" to open a single empty
Atom window instead.
One or more paths to files or folders may be specified. If there is an
existing Atom window that contains all of the given folders, the paths
will be opened in that window. Otherwise, they will be opened in a new
window.

If no arguments are given and at least one Atom window is open, open a new, empty
Atom window.

One or more paths to files or folders may be specified. All paths will be opened
in a new Atom window. Each file may be opened at the desired line (and optionally
column) by appending the numbers after the file name, e.g. \`atom file:5:8\`.
A file may be opened at the desired line (and optionally column) by
appending the numbers right after the file name, e.g. \`atom file:5:8\`.

Paths that start with \`atom://\` will be interpreted as URLs.

Expand All @@ -43,7 +40,7 @@ module.exports = function parseCommandLine (processArgs) {
options.alias('f', 'foreground').boolean('f').describe('f', 'Keep the main process in the foreground.')
options.alias('h', 'help').boolean('h').describe('h', 'Print this usage message.')
options.alias('l', 'log-file').string('l').describe('l', 'Log all output to file.')
options.alias('n', 'new-window').boolean('n').describe('n', 'Launch an empty Atom window instead of restoring previous session.')
options.alias('n', 'new-window').boolean('n').describe('n', 'Open a new window.')
options.boolean('profile-startup').describe('profile-startup', 'Create a profile of the startup execution time.')
options.alias('r', 'resource-path').string('r').describe('r', 'Set the path to the Atom source directory and enable dev-mode.')
options.boolean('safe').describe(
Expand Down Expand Up @@ -108,6 +105,16 @@ module.exports = function parseCommandLine (processArgs) {
executedFrom = process.cwd()
}

if (newWindow && addToLastWindow) {
process.stderr.write(
`Only one of the --add and --new-window options may be specified at the same time.\n\n${options.help()}`,
)

// Exiting the main process with a nonzero exit code on MacOS causes the app open to fail with the mysterious
// message "LSOpenURLsWithRole() failed for the application /Applications/Atom Dev.app with error -10810."
process.exit(0)
}

let pidToKillWhenClosed = null
if (args['wait']) {
pidToKillWhenClosed = args['pid']
Expand Down