-
Notifications
You must be signed in to change notification settings - Fork 4
/
status.jsx
167 lines (150 loc) · 5.23 KB
/
status.jsx
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
import styles from "./lib/styles.jsx";
import settings from "./lib/settings.jsx";
import parse from "./lib/parse.jsx";
import { run } from "uebersicht";
import Error from "./lib/Error.jsx";
import Clock from "./lib/Clock.jsx";
import Power from "./lib/Power.jsx";
import CPU from "./lib/CPU.jsx";
import WiFi from "./lib/WiFi.jsx";
import VPN from "./lib/VPN.jsx";
import Ethernet from "./lib/Ethernet.jsx";
import TimeMachine from "./lib/TimeMachine.jsx";
import SecureInput from "./lib/SecureInput.jsx";
import {applyBarHeight} from "./lib/autoBarHeight.jsx";
const defaultStyle = {
display: "grid",
gridAutoFlow: "column",
gridGap: "16px",
position: "fixed",
overflow: "hidden",
padding: styles.padding + "px" + " " + settings.bar.paddingHorizontal + "px",
height: styles.heightWithoutPadding + "px",
lineHeight: styles.heightWithoutPadding + "px",
width: "auto",
...(settings.bar.alignBottom ? {bottom: "0px"} : {top: "0px"}),
right: "0px",
fontFamily: styles.fontFamily,
fontSize: styles.fontSize,
color: styles.colors.minimalFg,
fontWeight: styles.fontWeight,
WebkitUserSelect: "none",
transition: "all 100ms ease-out",
cursor: "default",
zIndex: 102,
};
const dimmedStyle = {
color: styles.colors.dim,
};
const showDesktopHitboxStyle = {
width: "20px",
height: "20px",
position: "fixed",
bottom: "0px",
right: "0px",
zIndex: 110
}
const renderShowDesktopButton = () => {
return (
<div style={showDesktopHitboxStyle} onClick={() => {
run("PATH=/usr/local/bin/:/opt/homebrew/bin/:$PATH yabai -m space mouse --toggle show-desktop")
}}></div>
)
}
const refresh = (dispatch) => {
let disabled = true;
for (let key in settings.bar.status) {
if (settings.bar.status[key]) {
disabled = false;
break;
}
}
if (disabled) {
dispatch({type: 'DATA_UPDATE', output: {}});
} else {
run("./clarity/scripts/status.sh").then( (output) => {
dispatch({type: 'DATA_UPDATE', output: output});
});
}
}
export const refreshFrequency = 30000;
export const command = (dispatch) => {
// This synchronises the update interval with the system clock starting from :00 seconds.
const scheduleUpdate = (action, updateInterval) => {
let dd = new Date();
let nextTimeout = updateInterval - ((dd.getSeconds()*1000 + dd.getMilliseconds()) % updateInterval);
if (isNaN(nextTimeout) || updateInterval == 0) {
action()
return
}
nextTimeout = Math.min(Math.max(500, nextTimeout), 30000);
setTimeout(() => {
action()
}, nextTimeout);
}
scheduleUpdate(() => dispatch({type: 'TIME_UPDATE'}), 30000);
// Do standard refreshes normally
refresh(dispatch);
}
export const updateState = (event, previousState) => {
switch(event.type) {
case 'DATA_UPDATE':
return {output: event.output};
case 'TIME_UPDATE':
default:
return previousState;
}
}
export const render = ({ output }) => {
if (settings.bar.fontSize > settings.bar.height || !settings.bar.status) {
return (
<div style={defaultStyle}/>
);
}
if (typeof output === "undefined" || !output) {
return (
<div style={defaultStyle}>
{settings.bar.status.clock && <Clock/>}
</div>
);
}
const data = parse(output);
let style = {...defaultStyle};
const displayId = Number(window.location.pathname.split("/")[1]);
const displayData = data?.displays.find(d => d.id === displayId) || data?.displays[0];
if (data && displayData && displayData["has-focus"] == false) {
style = {...style, ...dimmedStyle};
}
const [dw, dh, duuid] = [displayData?.frame?.w || 0, displayData?.frame?.h || 0, displayData?.uuid];
applyBarHeight(dw, dh, duuid)(style, -settings.bar.paddingVertical*2);
if (typeof data === "undefined") {
return (
<div style={style}>
<Error msg="Can't parse status output!"/>
{settings.bar.status.clock && <Clock/>}
</div>
);
}
if (typeof data.error !== "undefined") {
return (
<div style={style}>
<Error msg={data.error}/>
{settings.bar.status.clock && <Clock/>}
</div>
);
}
return (
<div style={style}>
{settings.bar.status.secureInput && <SecureInput secureInputData={data.secureInput}/>}
{settings.bar.status.wifi && <WiFi wifiData={data.wifi} ethernetData={data.ethernet}/>}
{settings.bar.status.ethernet && <Ethernet wifiData={data.wifi} ethernetData={data.ethernet}/>}
{settings.bar.status.vpn && <VPN vpnData={data.vpn}/>}
{settings.bar.status.cpu && <CPU cpuData={data.cpu} powerData={data.power}/>}
{settings.bar.status.timeMachine && <TimeMachine tmData={data.timeMachine}/>}
{settings.bar.status.power && <Power powerData={data.power}/>}
{settings.bar.status.clock && <Clock/>}
{settings.bottomRightClickToShowDesktop && renderShowDesktopButton()}
</div>
);
};
export default null;