Skip to content
Snippets Groups Projects
Commit f1d409b1 authored by Daniel Bayley's avatar Daniel Bayley
Browse files

Improve project handling


Keep track of GitKraken instances; either spawn one per project or limit to a single instance.

Signed-off-by: default avatarDaniel Bayley <daniel.bayley@me.com>
parent 6277d1b5
No related branches found
No related tags found
No related merge requests found
[Atom] + [GitKraken] [Atom] + [GitKraken]
==================== ====================
Open the current Atom project in [GitKraken](http://gitkraken.com). This can be activated from the Packages menu, command palette, tree view or the git branch indicator in the status bar. Open the current [Atom] project in _[GitKraken]_.
This can be activated from the _Packages_ menu, _command palette_, from the context menu on the root project folder in _tree view_, or the git _branch_ indicator in the _status bar_.
An instance of _GitKraken_ will be spawned for each project by default, but can be configured in the package settings to only ever run a single instance of the application.
Install Install
------- -------
`apm install gitkraken` or search "gitkraken" under packages within Atom. `apm install gitkraken` or search "kraken" under packages within Atom.
License License
------- -------
......
{exec} = require 'child_process' {execSync, exec} = require 'child_process'
{writeFile, unlink} = require 'fs'
tmp = '/tmp/GitKraken.json'
id = 'com.axosoft.GitKraken'
selector = '[class^="status-bar"] .git-branch'
#-------------------------------------------------------------------------------
module.exports = module.exports =
#os: process.platform #os: process.platform
#timeout: #timeout:
#timeout: 10000 #timeout: 10000
#killSignal: 'SIGKILL' #killSignal: 'SIGKILL'
selector: '[class^="status-bar"] .git-branch'
subs: null subs: null
activate: -> activate: ->
SubAtom = require 'sub-atom' # {CompositeDisposable} = require 'atom' SubAtom = require 'sub-atom'
@subs = new SubAtom #CompositeDisposable @subs = new SubAtom
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
@subs.add atom.commands.add 'atom-workspace', @subs.add atom.commands.add 'atom-workspace',
'gitkraken:release': => @open() 'gitkraken:release': => @open()
atom.packages.onDidActivateInitialPackages => atom.packages.onDidActivateInitialPackages =>
@subs.add 'status-bar','click', @selector, @open @subs.add 'status-bar','click', selector, @open
#-------------------------------------------------------------------------------
open: -> open: ->
{path} = atom.project.getDirectories()[0] {path} = atom.project.getDirectories()[0]
exec "open -b com.axosoft.GitKraken --args -p '#{path}'" #, @timeout
if atom.config.get 'gitkraken.singleInstance'
exec "pkill GitKraken; sleep .1 && open -Fb #{id} --args -p '#{path}'" #, @timeout
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
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
deactivate: -> @subs.dispose() deactivate: ->
@subs.dispose()
unlink tmp
...@@ -22,10 +22,17 @@ ...@@ -22,10 +22,17 @@
"os": [ "os": [
"darwin" "darwin"
], ],
"dependencies": {
"sub-atom": "^1.1.0"
},
"engines": { "engines": {
"atom": "*" "atom": "*"
}, },
"dependencies": { "configSchema": {
"sub-atom": "^1.1.0" "singleInstance": {
"description": "Limit to a single instance of the application, else spawn one per project.",
"type": "boolean",
"default": false
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment