/
flowStatus.js
68 lines (61 loc) · 1.55 KB
/
flowStatus.js
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
/* @flow */
/*
Copyright (c) 2015-present, Facebook, Inc.
All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
the root directory of this source tree.
*/
import { window, StatusBarAlignment } from 'vscode';
import { isFlowStatusEnabled } from './utils/util'
import type { StatusBarItem } from 'vscode';
import Spinner from 'elegant-spinner';
export class Status {
statusBarItem:StatusBarItem;
state:?{id:IntervalID}
static spin:() => string = Spinner()
static createStatusBarItem() {
const statusBarItem = window.createStatusBarItem(StatusBarAlignment.Left);
statusBarItem.tooltip = 'Flow is type checking';
statusBarItem.command = 'flow.show-output';
return statusBarItem;
}
static render(status:Status):void {
return status.render();
}
constructor() {
this.statusBarItem = Status.createStatusBarItem();
}
isBusy() {
return this.state != null
}
idle() {
this.update(false);
}
busy() {
this.update(isFlowStatusEnabled());
}
update(busy:boolean) {
const {state} = this
if (state && !busy) {
clearInterval(state.id)
this.state = null
}
if (!state && busy) {
this.state = {id: setInterval(Status.render, 100, this)}
}
if (state != this.state) {
this.render()
}
}
render() {
if (this.isBusy()) {
this.statusBarItem.show();
this.statusBarItem.text = `Flow: ${Status.spin()}`;
} else {
this.statusBarItem.hide();
this.statusBarItem.text = ``
}
}
}
export default Status;