Skip to content
Closed
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
42 changes: 31 additions & 11 deletions index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,10 @@ module.exports =

#-------------------------------------------------------------------------------
open: ({path}) ->
if @config.get 'singleInstance'
exec "pkill GitKraken; sleep .1 && open -Fb #{@id} --args -p '#{path}'" #, @timeout
if atom.config.get 'gitkraken.singleInstance'
@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 @@ -76,3 +68,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 @@ -19,7 +19,8 @@
"private": true,
"license": "MIT",
"os": [
"darwin"
"darwin",
"linux"
],
"dependencies": {
"sub-atom": "^1.1.0"
Expand Down