-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathiconProvider.js
More file actions
84 lines (79 loc) · 2.02 KB
/
iconProvider.js
File metadata and controls
84 lines (79 loc) · 2.02 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
"use strict";
import Gio from "gi://Gio";
import { Status } from "./status.js";
/**
* Provides gicons and their statuses.
*/
export class IconProvider {
/**
* Constructor.
*
* @param {String} assetPath path to image resources
*/
constructor(assetPath) {
this.serverIcon = Gio.icon_new_for_string(assetPath + "/server.svg");
this.serverUpIcon = Gio.icon_new_for_string(
assetPath + "/server-up.svg",
);
this.serverDownIcon = Gio.icon_new_for_string(
assetPath + "/server-down.svg",
);
this.serverBadIcon = Gio.icon_new_for_string(
assetPath + "/server-bad.svg",
);
}
/**
* Get a gicon for the provided status.
*
* @param {Status} status
* @returns {Gio.icon}
*/
getIcon(status) {
let icon;
switch (status) {
case Status.Up:
icon = this.serverUpIcon;
break;
case Status.Down:
icon = this.serverDownIcon;
break;
case Status.Bad:
icon = this.serverBadIcon;
break;
default:
icon = this.serverIcon;
}
return icon;
}
/**
* Get a status for the provided gicon.
*
* @param {Gio.icon} icon
*/
getStatus(icon) {
let status;
switch (icon) {
case this.serverUpIcon:
status = Status.Up;
break;
case this.serverDownIcon:
status = Status.Down;
break;
case this.serverBadIcon:
status = Status.Bad;
break;
default:
status = Status.Init;
}
return status;
}
/**
* Sets all status-related gicons to null for garbage collection.
*/
destroy() {
this.serverIcon = null;
this.serverUpIcon = null;
this.serverDownIcon = null;
this.serverBadIcon = null;
}
}