This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathupdates-panel.js
More file actions
254 lines (215 loc) · 8.26 KB
/
Copy pathupdates-panel.js
File metadata and controls
254 lines (215 loc) · 8.26 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/** @babel */
/** @jsx etch.dom */
import {CompositeDisposable} from 'atom'
import etch from 'etch'
import ErrorView from './error-view'
import PackageCard from './package-card'
export default class UpdatesPanel {
constructor (settingsView, packageManager) {
this.settingsView = settingsView
this.packageManager = packageManager
this.disposables = new CompositeDisposable()
this.updatingPackages = []
this.packageCards = []
etch.initialize(this)
this.refs.updateAllButton.style.display = 'none'
this.checkForUpdates()
this.disposables.add(atom.commands.add(this.element, {
'core:move-up': () => { this.scrollUp() },
'core:move-down': () => { this.scrollDown() },
'core:page-up': () => { this.pageUp() },
'core:page-down': () => { this.pageDown() },
'core:move-to-top': () => { this.scrollToTop() },
'core:move-to-bottom': () => { this.scrollToBottom() }
}))
this.disposables.add(this.packageManager.on('package-updating theme-updating', ({pack, error}) => {
this.refs.checkButton.disabled = true
this.updatingPackages.push(pack)
}))
this.disposables.add(
this.packageManager.on('package-updated theme-updated package-update-failed theme-update-failed', ({pack, error}) => {
if (error != null) {
this.refs.updateErrors.appendChild(new ErrorView(this.packageManager, error).element)
}
for (let i = 0; i < this.updatingPackages.length; i++) {
const update = this.updatingPackages[i]
if (update.name === pack.name) {
this.updatingPackages.splice(i, 1)
}
}
if (!this.updatingPackages.length) {
this.refs.checkButton.disabled = false
}
})
)
}
destroy () {
this.clearPackageCards()
this.disposables.dispose()
return etch.destroy(this)
}
update () {}
render () {
return (
<div tabIndex='0' className='panels-item'>
<section className='section packages'>
<div className='section-container updates-container'>
<div className='updates-heading-container'>
<h1 className='section-heading icon icon-cloud-download'>Available Updates</h1>
<div className='section-heading updates-btn-group'>
<button
ref='checkButton'
className='update-all-button btn'
onclick={() => { this.checkForUpdates(true) }}>Check for Updates</button>
<button
ref='updateAllButton'
className='update-all-button btn btn-primary'
onclick={() => { this.updateAll() }}>Update All</button>
</div>
</div>
<div ref='versionPinnedPackagesMessage' className='alert alert-warning icon icon-alert'>The following packages are pinned to their current version and are not being checked for updates: <strong>{ this.packageManager.getVersionPinnedPackages().join(', ') }</strong></div>
<div ref='automaticallyUpdateDisabledMessage' className='alert alert-warning icon icon-alert'>
Automatically checking for updates is disabled. To enable, check the <em>Automatically Update</em> option
in <a class='link' onclick={() => { atom.workspace.open('atom://config/core') }}>Core settings</a>.
</div>
<div ref='updateErrors'></div>
<div ref='checkingMessage' className='alert alert-info icon icon-hourglass'>{`Checking for updates\u2026`}</div>
<div ref='noUpdatesMessage' className='alert alert-info icon icon-heart'>All of your installed packages are up to date!</div>
<div ref='updatesContainer' className='container package-container'></div>
</div>
</section>
</div>
)
}
focus () {
this.element.focus()
}
show () {
this.element.style.display = ''
}
beforeShow (opts) {
if (opts && opts.back) {
this.refs.breadcrumb.textContent = opts.back
this.refs.breadcrumb.onclick = () => { this.settingsView.showPanel(opts.back) }
}
if (opts && opts.updates) {
this.availableUpdates = opts.updates
this.addUpdateViews()
} else {
this.availableUpdates = []
this.clearPackageCards()
this.checkForUpdates()
}
if (this.packageManager.getVersionPinnedPackages().length === 0) {
this.refs.versionPinnedPackagesMessage.style.display = 'none'
}
if (atom.config.get('core.automaticallyUpdate')) {
this.refs.automaticallyUpdateDisabledMessage.style.display = 'none'
} else {
this.refs.automaticallyUpdateDisabledMessage.style.display = ''
}
}
// Check for updates and display them
async checkForUpdates (clearCache) {
this.refs.noUpdatesMessage.style.display = 'none'
this.refs.updateAllButton.disabled = true
this.refs.checkButton.disabled = true
this.refs.checkingMessage.style.display = ''
try {
this.availableUpdates = await this.packageManager.getOutdated(clearCache)
this.refs.checkButton.disabled = false
this.addUpdateViews(clearCache)
} catch (error) {
this.refs.checkButton.disabled = false
this.refs.checkingMessage.style.display = 'none'
this.refs.updateErrors.appendChild(new ErrorView(this.packageManager, error).element)
}
}
addUpdateViews (forcedUpdate) {
if (this.availableUpdates.length > 0) {
this.refs.updateAllButton.style.display = ''
this.refs.updateAllButton.disabled = false
}
this.refs.checkingMessage.style.display = 'none'
this.clearPackageCards()
if (this.availableUpdates.length === 0 && (forcedUpdate || atom.config.get('core.automaticallyUpdate'))) {
this.refs.noUpdatesMessage.style.display = ''
}
for (const pack of this.availableUpdates) {
const packageCard = new PackageCard(pack, this.settingsView, this.packageManager, {back: 'Updates'})
this.refs.updatesContainer.appendChild(packageCard.element)
this.packageCards.push(packageCard)
}
}
updateAll () {
this.refs.checkButton.disabled = true
this.refs.updateAllButton.disabled = true
let successfulUpdatesCount = 0
let remainingPackagesCount = this.packageCards.length
let totalUpdatesCount = this.packageCards.length // This value doesn't change unlike remainingPackagesCount
const notifyIfDone = () => {
if (remainingPackagesCount === 0) {
if (successfulUpdatesCount > 0) {
let pluralizedPackages = 'package'
if (successfulUpdatesCount > 1) {
pluralizedPackages += 's'
}
const message = `Restart Atom to complete the update of ${successfulUpdatesCount} ${pluralizedPackages}.`
const buttons = [{
text: 'Restart',
onDidClick() { return atom.restartApplication() }
}]
atom.notifications.addSuccess(message, {dismissable: true, buttons})
}
if (successfulUpdatesCount === totalUpdatesCount) {
this.refs.checkButton.disabled = false
this.refs.updateAllButton.style.display = 'none'
} else { // Some updates failed
this.refs.checkButton.disabled = false
this.refs.updateAllButton.disabled = false
}
}
}
const onUpdateResolved = function() {
remainingPackagesCount--
successfulUpdatesCount++
notifyIfDone()
}
const onUpdateRejected = function() {
remainingPackagesCount--
notifyIfDone()
}
for (const packageCard of this.packageCards) {
if (!this.updatingPackages.includes(packageCard.pack)) {
packageCard.update().then(onUpdateResolved, onUpdateRejected)
} else {
remainingPackagesCount--
totalUpdatesCount--
}
}
}
clearPackageCards () {
let packageCard = null
while (packageCard = this.packageCards.pop()) {
packageCard.destroy()
}
}
scrollUp () {
this.element.scrollTop -= document.body.offsetHeight / 20
}
scrollDown () {
this.element.scrollTop += document.body.offsetHeight / 20
}
pageUp () {
this.element.scrollTop -= this.element.offsetHeight
}
pageDown () {
this.element.scrollTop += this.element.offsetHeight
}
scrollToTop () {
this.element.scrollTop = 0
}
scrollToBottom () {
this.element.scrollTop = this.element.scrollHeight
}
}