From e392e5dfccbba59e693f4f63bd4ed28de64cc037 Mon Sep 17 00:00:00 2001 From: Dave Rael Date: Tue, 24 Nov 2015 09:34:53 -0700 Subject: [PATCH 1/3] :checkered_flag: Make --wait work on Windows including using Atom as the git commit editor --- resources/win/atom.cmd | 34 +++++++++++++++++++++++++++--- resources/win/atom.sh | 33 +++++++++++++++++++++++++---- src/browser/squirrel-update.coffee | 2 +- 3 files changed, 61 insertions(+), 8 deletions(-) diff --git a/resources/win/atom.cmd b/resources/win/atom.cmd index d3188b3ea..0df49dd64 100644 --- a/resources/win/atom.cmd +++ b/resources/win/atom.cmd @@ -1,6 +1,7 @@ @echo off SET EXPECT_OUTPUT= +SET WAIT= FOR %%a IN (%*) DO ( IF /I "%%a"=="-f" SET EXPECT_OUTPUT=YES @@ -11,13 +12,40 @@ FOR %%a IN (%*) DO ( IF /I "%%a"=="--test" SET EXPECT_OUTPUT=YES IF /I "%%a"=="-v" SET EXPECT_OUTPUT=YES IF /I "%%a"=="--version" SET EXPECT_OUTPUT=YES - IF /I "%%a"=="-w" SET EXPECT_OUTPUT=YES - IF /I "%%a"=="--wait" SET EXPECT_OUTPUT=YES + IF /I "%%a"=="-w" ( + SET EXPECT_OUTPUT=YES + SET WAIT=YES + ) + IF /I "%%a"=="--wait" ( + SET EXPECT_OUTPUT=YES + SET WAIT=YES + ) ) +rem Getting the process ID in cmd of the current cmd process: http://superuser.com/questions/881789/identify-and-kill-batch-script-started-before +set T=%TEMP%\sthUnique.tmp +wmic process where (Name="WMIC.exe" AND CommandLine LIKE "%%%TIME%%%") get ParentProcessId /value | find "ParentProcessId" >%T% +set /P A=<%T% +set PID=%A:~16% + IF "%EXPECT_OUTPUT%"=="YES" ( SET ELECTRON_ENABLE_LOGGING=YES - "%~dp0\..\..\atom.exe" %* + IF "%WAIT%"=="YES" ( + "%~dp0\..\..\atom.exe" --pid=%PID% %* + rem If the wait flag is set, don't exit this process until Atom tells it to. + goto waitLoop + ) + ELSE ( + "%~dp0\..\..\atom.exe" %* + ) ) ELSE ( "%~dp0\..\app\apm\bin\node.exe" "%~dp0\atom.js" %* ) + +goto end + +:waitLoop + sleep 1 + goto waitLoop + +:end diff --git a/resources/win/atom.sh b/resources/win/atom.sh index 9e2c6da65..4fd5a3106 100644 --- a/resources/win/atom.sh +++ b/resources/win/atom.sh @@ -4,12 +4,26 @@ while getopts ":fhtvw-:" opt; do case "$opt" in -) case "${OPTARG}" in - foreground|help|test|version|wait) + wait) + WAIT=1 + ;; + help|version) + REDIRECT_STDERR=1 EXPECT_OUTPUT=1 - ;; + ;; + foreground|test) + EXPECT_OUTPUT=1 + ;; esac ;; - f|h|t|v|w) + w) + WAIT=1 + ;; + h|v) + REDIRECT_STDERR=1 + EXPECT_OUTPUT=1 + ;; + f|t) EXPECT_OUTPUT=1 ;; esac @@ -17,9 +31,20 @@ done directory=$(dirname "$0") +WINPS=`ps | grep -i $$` +PID=`echo $WINPS | cut -d' ' -f 4` +echo $PID + if [ $EXPECT_OUTPUT ]; then export ELECTRON_ENABLE_LOGGING=1 - "$directory/../../atom.exe" "$@" + "$directory/../../atom.exe" --executed-from="$(pwd)" --pid=$PID "$@" else "$directory/../app/apm/bin/node.exe" "$directory/atom.js" "$@" fi + +# If the wait flag is set, don't exit this process until Atom tells it to. +if [ $WAIT ]; then + while true; do + sleep 1 + done +fi diff --git a/src/browser/squirrel-update.coffee b/src/browser/squirrel-update.coffee index 0e4743a21..3660158fc 100644 --- a/src/browser/squirrel-update.coffee +++ b/src/browser/squirrel-update.coffee @@ -139,7 +139,7 @@ addCommandsToPath = (callback) -> atomShCommandPath = path.join(binFolder, 'atom') relativeAtomShPath = path.relative(binFolder, path.join(appFolder, 'resources', 'cli', 'atom.sh')) - atomShCommand = "#!/bin/sh\r\n\"$(dirname \"$0\")/#{relativeAtomShPath.replace(/\\/g, '/')}\" \"$@\"" + atomShCommand = "#!/bin/sh\r\n\"$(dirname \"$0\")/#{relativeAtomShPath.replace(/\\/g, '/')}\" \"$@\"\r\necho" apmCommandPath = path.join(binFolder, 'apm.cmd') relativeApmPath = path.relative(binFolder, path.join(process.resourcesPath, 'app', 'apm', 'bin', 'apm.cmd')) From ca629027ff6cb5d258d8bafbd78e09f1e54a1e12 Mon Sep 17 00:00:00 2001 From: Dave Rael Date: Tue, 24 Nov 2015 15:04:53 -0700 Subject: [PATCH 2/3] :checkered-flag: Add race condition protection for getting process id to make sure temp file isn't in conflict with another process and to make sure to get the right process id --- resources/win/atom.cmd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/win/atom.cmd b/resources/win/atom.cmd index 0df49dd64..0463928d8 100644 --- a/resources/win/atom.cmd +++ b/resources/win/atom.cmd @@ -23,10 +23,11 @@ FOR %%a IN (%*) DO ( ) rem Getting the process ID in cmd of the current cmd process: http://superuser.com/questions/881789/identify-and-kill-batch-script-started-before -set T=%TEMP%\sthUnique.tmp +set T=%TEMP%\atomCmdProcessId-%time::=%.tmp wmic process where (Name="WMIC.exe" AND CommandLine LIKE "%%%TIME%%%") get ParentProcessId /value | find "ParentProcessId" >%T% set /P A=<%T% set PID=%A:~16% +del %T% IF "%EXPECT_OUTPUT%"=="YES" ( SET ELECTRON_ENABLE_LOGGING=YES From f1cb69ccdeb09735fff8d9cabecbb8239bdd5c95 Mon Sep 17 00:00:00 2001 From: Dave Rael Date: Mon, 30 Nov 2015 18:20:40 -0600 Subject: [PATCH 3/3] :art: Cleanup tabs vs spaces and debugging line --- resources/win/atom.cmd | 6 +++--- resources/win/atom.sh | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/resources/win/atom.cmd b/resources/win/atom.cmd index 0463928d8..c9bfdd5ba 100644 --- a/resources/win/atom.cmd +++ b/resources/win/atom.cmd @@ -34,7 +34,7 @@ IF "%EXPECT_OUTPUT%"=="YES" ( IF "%WAIT%"=="YES" ( "%~dp0\..\..\atom.exe" --pid=%PID% %* rem If the wait flag is set, don't exit this process until Atom tells it to. - goto waitLoop + goto waitLoop ) ELSE ( "%~dp0\..\..\atom.exe" %* @@ -46,7 +46,7 @@ IF "%EXPECT_OUTPUT%"=="YES" ( goto end :waitLoop - sleep 1 - goto waitLoop + sleep 1 + goto waitLoop :end diff --git a/resources/win/atom.sh b/resources/win/atom.sh index 4fd5a3106..0eaf193c0 100644 --- a/resources/win/atom.sh +++ b/resources/win/atom.sh @@ -33,7 +33,6 @@ directory=$(dirname "$0") WINPS=`ps | grep -i $$` PID=`echo $WINPS | cut -d' ' -f 4` -echo $PID if [ $EXPECT_OUTPUT ]; then export ELECTRON_ENABLE_LOGGING=1