-
Notifications
You must be signed in to change notification settings - Fork 71
/
index.coffee
152 lines (125 loc) · 4.81 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
fs = require('fs-plus')
CompositeDisposable = null
path = null
$ = null
getEventPath = (e)->
$ ?= require('atom-space-pen-views').$
target = $(e.target).closest('.file, .directory, .tab')[0]
target ?= atom.workspace.getActiveTextEditor()
fullPath = target?.getPath?()
return [] unless fullPath
[projectPath, relativePath] = atom.project.relativizePath(fullPath)
return [projectPath, fullPath]
projectDict = null
disposables = null
RemoteSync = null
initProject = (projectPaths)->
disposes = []
for projectPath of projectDict
disposes.push projectPath if projectPaths.indexOf(projectPath) == -1
for projectPath in disposes
projectDict[projectPath].dispose()
delete projectDict[projectPath]
for projectPath in projectPaths
try
projectPath = fs.realpathSync(projectPath)
catch err
continue
continue if projectDict[projectPath]
RemoteSync ?= require "./lib/RemoteSync"
obj = RemoteSync.create(projectPath)
projectDict[projectPath] = obj if obj
handleEvent = (e, cmd)->
[projectPath, fullPath] = getEventPath(e)
return unless projectPath
projectObj = projectDict[fs.realpathSync(projectPath)]
projectObj[cmd]?(fs.realpathSync(fullPath))
reload = (projectPath)->
projectDict[projectPath]?.dispose()
projectDict[projectPath] = RemoteSync.create(projectPath)
configure = (e)->
[projectPath] = getEventPath(e)
return unless projectPath
projectPath = fs.realpathSync(projectPath)
RemoteSync ?= require "./lib/RemoteSync"
RemoteSync.configure projectPath, -> reload(projectPath)
module.exports =
config:
logToConsole:
type: 'boolean'
default: false
title: 'Log to console'
description: 'Log messages to the console instead of the status view at the bottom of the window'
autoHideLogPanel:
type: 'boolean'
default: false
title: 'Hide log panel after transferring'
description: 'Hides the status view at the bottom of the window after the transfer operation is done'
foldLogPanel:
type: 'boolean'
default: false
title: 'Fold log panel by default'
description: 'Shows only one line in the status view'
monitorFileAnimation:
type: 'boolean'
default: true
title: 'Monitor file animation'
description: 'Toggles the pulse animation for a monitored file'
difftoolCommand:
type: 'string'
default: ''
title: 'Diff tool command'
description: 'The command to run for your diff tool'
configFileName:
type: 'string'
default: '.remote-sync.json'
activate: (state) ->
projectDict = {}
try
initProject(atom.project.getPaths())
catch
atom.notifications.addError "RemoteSync Error",
{dismissable: true, detail: "Failed to initalise RemoteSync"}
CompositeDisposable ?= require('atom').CompositeDisposable
disposables = new CompositeDisposable
disposables.add atom.commands.add('atom-workspace', {
'remote-sync:upload-folder': (e)-> handleEvent(e, "uploadFolder")
'remote-sync:upload-file': (e)-> handleEvent(e, "uploadFile")
'remote-sync:delete-file': (e)-> handleEvent(e, "deleteFile")
'remote-sync:delete-folder': (e)-> handleEvent(e, "deleteFile")
'remote-sync:download-file': (e)-> handleEvent(e, "downloadFile")
'remote-sync:download-folder': (e)-> handleEvent(e, "downloadFolder")
'remote-sync:diff-file': (e)-> handleEvent(e, "diffFile")
'remote-sync:diff-folder': (e)-> handleEvent(e, "diffFolder")
'remote-sync:upload-git-change': (e)-> handleEvent(e, "uploadGitChange")
'remote-sync:monitor-file': (e)-> handleEvent(e, "monitorFile")
'remote-sync:monitor-files-list': (e)-> handleEvent(e,"monitorFilesList")
'remote-sync:configure': configure
})
disposables.add atom.project.onDidChangePaths (projectPaths)->
initProject(projectPaths)
disposables.add atom.workspace.observeTextEditors (editor) ->
onDidSave = editor.onDidSave (e) ->
fullPath = e.path
[projectPath, relativePath] = atom.project.relativizePath(fullPath)
return unless projectPath
projectPath = fs.realpathSync(projectPath)
projectObj = projectDict[projectPath]
return unless projectObj
if fs.realpathSync(fullPath) == fs.realpathSync(projectObj.configPath)
projectObj = reload(projectPath)
return unless projectObj.host.uploadOnSave
projectObj.uploadFile(fs.realpathSync(fullPath))
onDidDestroy = editor.onDidDestroy ->
disposables.remove onDidSave
disposables.remove onDidDestroy
onDidDestroy.dispose()
onDidSave.dispose()
disposables.add onDidSave
disposables.add onDidDestroy
deactivate: ->
disposables.dispose()
disposables = null
for projectPath, obj of projectDict
obj.dispose()
projectDict = null