Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
40 changes: 30 additions & 10 deletions index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,9 @@ module.exports =
#-------------------------------------------------------------------------------
open: ({path}) ->
if atom.config.get 'gitkraken.singleInstance'
exec "pkill GitKraken; sleep .1 && open -Fb #{@id} --args -p '#{path}'" #, @timeout
@execGitKrakenSingle path
else
projects = {}
try
projects = require @tmp
execSync "ps #{projects[path]} | grep -q GitKraken &&
open -b #{@id} --args -p '#{path}'"
catch
pid = execSync "open -nb #{@id} --args -p '#{path}' & echo $!"
projects[path] = (parseInt pid) + 1
writeFile @tmp, JSON.stringify projects
projects = @execGitKrakenMulti path

window.addEventListener 'beforeunload', ->
exec "kill #{projects[path]}"
Expand All @@ -48,3 +40,31 @@ module.exports =
@subs.dispose()
window.removeEventListener 'beforeunload'
unlink @tmp

#-------------------------------------------------------------------------------
execGitKrakenSingle: (path) ->
if process.platform == 'darwin'
exec "pkill GitKraken; sleep .1 && open -Fb #{@id} --args -p '#{path}'" #, @timeout
else if process.platform == 'linux'
exec "killall gitkraken; sleep .1 && gitkraken --args -p '#{path}' &> /dev/null &"

#-------------------------------------------------------------------------------
execGitKrakenMulti: (path) ->
projects = {}
try
projects = require @tmp
if process.platform == 'darwin'
execSync "ps #{projects[path]} | grep -q GitKraken && open -b #{@id} --args -p '#{path}'"
else if process.platform == 'linux'
execSync "ps #{projects[path]} | grep -q gitkraken"
catch
if process.platform == 'darwin'
pid = execSync "open -nb #{@id} --args -p '#{path}' & echo $!"
else if process.platform == 'linux'
proc = exec "nohup gitkraken --args -p '#{path}' &>/dev/null &"
pid = proc.pid

projects[path] = (parseInt pid) + 1
writeFile @tmp, JSON.stringify projects

projects
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"private": true,
"license": "MIT",
"os": [
"darwin"
"darwin",
"linux"
],
"dependencies": {
"sub-atom": "^1.1.0"
Expand Down