From 4af379ae8eb4a5ac3642b430fa50ebabf4a7fe9b Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Thu, 21 Mar 2019 18:15:38 -0400 Subject: [PATCH 1/6] Re-use an existing window if one is available that contains all paths --- src/main-process/atom-application.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main-process/atom-application.js b/src/main-process/atom-application.js index 00fef2d6f..7be947115 100644 --- a/src/main-process/atom-application.js +++ b/src/main-process/atom-application.js @@ -878,13 +878,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 } } From 18847f79d1b458e3d8eae4755baac03cd095420f Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Thu, 21 Mar 2019 19:09:02 -0400 Subject: [PATCH 2/6] Restore the newWindow option to force a path to open in a new window --- src/main-process/atom-application.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main-process/atom-application.js b/src/main-process/atom-application.js index 7be947115..6fe8a0c34 100644 --- a/src/main-process/atom-application.js +++ b/src/main-process/atom-application.js @@ -230,6 +230,7 @@ class AtomApplication extends EventEmitter { pidToKillWhenClosed, devMode, safeMode, + newWindow, logFile, profileStartup, timeout, @@ -267,6 +268,7 @@ class AtomApplication extends EventEmitter { foldersToOpen, executedFrom, pidToKillWhenClosed, + newWindow, devMode, safeMode, profileStartup, @@ -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, @@ -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. @@ -810,6 +814,7 @@ class AtomApplication extends EventEmitter { return this.openPaths({ pathsToOpen: [pathToOpen], pidToKillWhenClosed, + newWindow, devMode, safeMode, profileStartup, @@ -826,6 +831,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. @@ -836,6 +842,7 @@ class AtomApplication extends EventEmitter { foldersToOpen, executedFrom, pidToKillWhenClosed, + newWindow, devMode, safeMode, windowDimensions, From 2546170c0bbade11d46c15ef607a167969e9bd71 Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Thu, 21 Mar 2019 19:09:19 -0400 Subject: [PATCH 3/6] Revert changes to help text --- src/main-process/parse-command-line.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/main-process/parse-command-line.js b/src/main-process/parse-command-line.js index 3aa019565..d57a2fca5 100644 --- a/src/main-process/parse-command-line.js +++ b/src/main-process/parse-command-line.js @@ -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. @@ -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( From 372652915eed851af5bc27bf030fad1029e5dca7 Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Thu, 21 Mar 2019 19:53:06 -0400 Subject: [PATCH 4/6] :shirt: Add missing newWindow parameter --- src/main-process/atom-application.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main-process/atom-application.js b/src/main-process/atom-application.js index 6fe8a0c34..1753a0ac3 100644 --- a/src/main-process/atom-application.js +++ b/src/main-process/atom-application.js @@ -803,6 +803,7 @@ class AtomApplication extends EventEmitter { openPath ({ pathToOpen, pidToKillWhenClosed, + newWindow, devMode, safeMode, profileStartup, From 2526e69e28ee2a1dfca7487637b2db6c789ed7f8 Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Fri, 22 Mar 2019 11:29:21 -0400 Subject: [PATCH 5/6] Exit with 1 and a message when -a and -n are both provided --- atom.sh | 35 +++++++++++++++++++++++--- src/main-process/parse-command-line.js | 10 ++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/atom.sh b/atom.sh index 935204bfc..042084751 100755 --- a/atom.sh +++ b/atom.sh @@ -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 ;; @@ -45,6 +55,12 @@ while getopts ":wtfvh-:" opt; do ;; esac ;; + a) + ATOM_ADD=true + ;; + n) + ATOM_NEW_WINDOW=true + ;; w) WAIT=1 ;; @@ -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 @@ -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 @@ -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 diff --git a/src/main-process/parse-command-line.js b/src/main-process/parse-command-line.js index d57a2fca5..27a2f07f6 100644 --- a/src/main-process/parse-command-line.js +++ b/src/main-process/parse-command-line.js @@ -105,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'] From 04685d13fea0514b484d24fc8223a0b5c5f6adf2 Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Wed, 27 Mar 2019 08:00:52 -0400 Subject: [PATCH 6/6] Port changes to atom.cmd to show conflicting option error on win32 --- resources/win/atom.cmd | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/resources/win/atom.cmd b/resources/win/atom.cmd index 07b9933cb..6fc7fc697 100644 --- a/resources/win/atom.cmd +++ b/resources/win/atom.cmd @@ -4,6 +4,8 @@ SET EXPECT_OUTPUT= SET WAIT= SET PSARGS=%* SET ELECTRON_ENABLE_LOGGING= +SET ATOM_ADD= +SET ATOM_NEW_WINDOW= FOR %%a IN (%*) DO ( IF /I "%%a"=="-f" SET EXPECT_OUTPUT=YES @@ -17,6 +19,10 @@ FOR %%a IN (%*) DO ( IF /I "%%a"=="-v" SET EXPECT_OUTPUT=YES IF /I "%%a"=="--version" SET EXPECT_OUTPUT=YES IF /I "%%a"=="--enable-electron-logging" SET ELECTRON_ENABLE_LOGGING=YES + IF /I "%%a"=="-a" SET ATOM_ADD=YES + IF /I "%%a"=="--add" SET ATOM_ADD=YES + IF /I "%%a"=="-n" SET ATOM_NEW_WINDOW=YES + IF /I "%%a"=="--new-window" SET ATOM_NEW_WINDOW=YES IF /I "%%a"=="-w" ( SET EXPECT_OUTPUT=YES SET WAIT=YES @@ -27,6 +33,12 @@ FOR %%a IN (%*) DO ( ) ) +IF "%ATOM_ADD%"=="YES" ( + IF "%ATOM_NEW_WINDOW%"=="YES" ( + SET EXPECT_OUTPUT=YES + ) +) + IF "%EXPECT_OUTPUT%"=="YES" ( IF "%WAIT%"=="YES" ( powershell -noexit "Start-Process -FilePath \"%~dp0\..\..\atom.exe\" -ArgumentList \"--pid=$pid $env:PSARGS\" ; wait-event"