|
| 1 | +'use babel' |
| 2 | +import { CompositeDisposable } from 'atom'; |
| 3 | +import client from '../connection/client'; |
| 4 | +import { formatTimePeriod } from '../misc'; |
| 5 | + |
| 6 | +export default { |
| 7 | + progs: {}, |
| 8 | + |
| 9 | + activate(ink) { |
| 10 | + this.subs = new CompositeDisposable; |
| 11 | + this.ink = ink; |
| 12 | + client.handle({'progress': (t, id, m) => this[t](id, m)}); |
| 13 | + let status = []; |
| 14 | + this.subs.add( |
| 15 | + client.onWorking(() => { |
| 16 | + return status = this.ink.progress.add(null, {description: 'Julia'}); |
| 17 | + }), |
| 18 | + client.onDone(() => (status != null ? status.destroy() : undefined)), // status?.destroy() |
| 19 | + client.onAttached(() => this.ink.progress.show()), |
| 20 | + client.onDetached(() => this.clear()) |
| 21 | + ); |
| 22 | + }, |
| 23 | + |
| 24 | + deactivate() { |
| 25 | + this.clear(); |
| 26 | + this.subs.dispose(); |
| 27 | + }, |
| 28 | + |
| 29 | + add(id) { |
| 30 | + const pr = this.ink.progress.add(); |
| 31 | + pr.t0 = Date.now(); |
| 32 | + pr.showTime = true; |
| 33 | + this.progs[id] = pr; |
| 34 | + }, |
| 35 | + |
| 36 | + progress(id, prog) { |
| 37 | + const pr = this.progs[id]; |
| 38 | + if (pr == null) { return; } |
| 39 | + pr.level = prog; |
| 40 | + if (pr.showTime) { return this.rightText(id, null); } |
| 41 | + }, |
| 42 | + |
| 43 | + message(id, m) { return (this.progs[id] != null ? this.progs[id].message = m : undefined); }, // this.progs[id]?.message = m |
| 44 | + |
| 45 | + leftText(id, m) { return (this.progs[id] != null ? this.progs[id].description = m : undefined); }, // this.progs[id]?.description = m |
| 46 | + |
| 47 | + rightText(id, m) { |
| 48 | + const pr = this.progs[id]; |
| 49 | + if (pr == null) { return; } |
| 50 | + if (m != null ? m.length : undefined) { |
| 51 | + pr.rightText = m; |
| 52 | + return pr.showTime = false; |
| 53 | + } else { |
| 54 | + const dt = ((Date.now() - pr.t0)*((1/pr.level) - 1))/1000; |
| 55 | + pr.showTime = true; |
| 56 | + return pr.rightText = formatTimePeriod(dt); |
| 57 | + } |
| 58 | + }, |
| 59 | + |
| 60 | + delete(id) { |
| 61 | + const pr = this.progs[id]; |
| 62 | + if (pr == null) { return; } |
| 63 | + pr.destroy(); |
| 64 | + delete this.progs[id]; |
| 65 | + }, |
| 66 | + |
| 67 | + clear() { |
| 68 | + for (let _ in this.progs) { |
| 69 | + const p = this.progs[_]; |
| 70 | + if (p != null) { |
| 71 | + p.destroy(); |
| 72 | + } |
| 73 | + } |
| 74 | + this.progs = {}; |
| 75 | + this.ink.progress.hide(); |
| 76 | + } |
| 77 | +}; |
0 commit comments