-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.coffee
78 lines (64 loc) · 2.5 KB
/
index.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{execSync, exec} = require 'child_process'
{writeFile, unlink} = require 'fs'
SubAtom = require 'sub-atom'
meta = #Key
define: 'https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/metaKey'
key:
switch process.platform
when 'darwin' then "⌘"
when 'linux' then "◆" # Super
when 'win32' then "❖"
#-------------------------------------------------------------------------------
module.exports =
#os: process.platform
#timeout:
#timeout: 10000
#killSignal: 'SIGKILL'
config:
get: (config) -> atom.config.get "gitkraken.#{config}"
singleInstance:
description: "Limit to a single instance of the application,
else spawn a new instance for each project."
type: 'boolean'
default: false
statusBar:
description: "Enable a modifier key while clicking the
status bar branch to release GitKraken?
Note that _[`meta`](#{meta.define})_ is <kbd>#{meta.key}</kbd>."
type: 'string'
default: 'shift'
enum: ["alt","shift","meta","ctrl","none"]
#-------------------------------------------------------------------------------
project: atom.project.getDirectories()[0] ? path: process.cwd()
tmp: '/tmp/GitKraken.json'
id: 'com.axosoft.GitKraken'
selector: '[class^=status-bar] .git-branch'
subs: new SubAtom
#-------------------------------------------------------------------------------
activate: ->
@subs.add atom.commands.add 'atom-workspace',
'gitkraken:release': => @open @project
@subs.add atom.packages.onDidActivateInitialPackages =>
@subs.add 'status-bar','click', @selector, (key) =>
@open @project if key["#{ @config.get 'statusBar'}Key"]
#-------------------------------------------------------------------------------
open: ({path}) ->
if @config.get '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
window.addEventListener 'beforeunload', ->
exec "kill #{projects[path]}"
#-------------------------------------------------------------------------------
deactivate: ->
@subs.dispose()
window.removeEventListener 'beforeunload'
unlink @tmp