@justanarthur/modo-ui-notch 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/blocks/activities/agenda/examples.mdx +29 -5
- package/blocks/activities/agenda/index.tsx +438 -181
- package/blocks/activities/clock/examples.mdx +89 -0
- package/blocks/activities/clock/index.tsx +917 -0
- package/blocks/activities/now-playing/examples.mdx +40 -13
- package/blocks/activities/now-playing/index.tsx +399 -120
- package/blocks/activities/weather/examples.mdx +123 -0
- package/blocks/activities/weather/index.tsx +863 -0
- package/blocks/app/expanded-island/examples.mdx +8 -7
- package/blocks/app/expanded-island/index.tsx +22 -4
- package/blocks/app/settings-window/examples.mdx +14 -2
- package/blocks/app/settings-window/index.tsx +33 -10
- package/blocks/system/clipboard/examples.mdx +91 -0
- package/blocks/system/clipboard/index.tsx +773 -0
- package/blocks/system/recent-files/examples.mdx +80 -0
- package/blocks/system/recent-files/index.tsx +627 -0
- package/blocks/system/system-stats/examples.mdx +46 -9
- package/blocks/system/system-stats/index.tsx +445 -104
- package/components/indicators/media-scrubber/examples.mdx +8 -0
- package/components/indicators/media-scrubber/index.tsx +37 -13
- package/components/island/island/examples.mdx +4 -4
- package/components/island/island/index.tsx +2 -2
- package/components/island/island-flash/examples.mdx +15 -18
- package/components/island/island-flash/index.tsx +4 -4
- package/components/island/island-tabs/examples.mdx +5 -5
- package/components/island/widget/examples.mdx +76 -0
- package/components/island/widget/index.tsx +465 -0
- package/dist/blocks/activities/agenda/index.d.ts +2 -1
- package/dist/blocks/activities/agenda/index.js +3 -3
- package/dist/blocks/activities/clock/index.d.ts +3 -0
- package/dist/blocks/activities/clock/index.js +25 -0
- package/dist/blocks/activities/now-playing/index.d.ts +4 -2
- package/dist/blocks/activities/now-playing/index.js +5 -3
- package/dist/blocks/activities/weather/index.d.ts +3 -0
- package/dist/blocks/activities/weather/index.js +21 -0
- package/dist/blocks/app/expanded-island/index.d.ts +1 -1
- package/dist/blocks/app/expanded-island/index.js +4 -3
- package/dist/blocks/app/settings-window/index.d.ts +1 -1
- package/dist/blocks/app/settings-window/index.js +1 -1
- package/dist/blocks/system/clipboard/index.d.ts +3 -0
- package/dist/blocks/system/clipboard/index.js +17 -0
- package/dist/blocks/system/recent-files/index.d.ts +3 -0
- package/dist/blocks/system/recent-files/index.js +19 -0
- package/dist/blocks/system/system-stats/index.d.ts +3 -2
- package/dist/blocks/system/system-stats/index.js +4 -1
- package/dist/components/indicators/media-scrubber/index.d.ts +1 -1
- package/dist/components/indicators/media-scrubber/index.js +1 -1
- package/dist/components/island/island/index.d.ts +1 -1
- package/dist/components/island/island/index.js +2 -2
- package/dist/components/island/island-flash/index.d.ts +1 -1
- package/dist/components/island/island-flash/index.js +1 -1
- package/dist/components/island/island-tabs/index.js +2 -2
- package/dist/components/island/widget/index.d.ts +2 -0
- package/dist/components/island/widget/index.js +32 -0
- package/dist/index.d.ts +15 -15
- package/dist/index.js +104 -58
- package/dist/lib/artwork.d.ts +2 -0
- package/dist/lib/artwork.js +8 -0
- package/dist/lib/geometry.js +1 -1
- package/dist/shared/{chunk-yngkkxz2.d.ts → chunk-0ym9mcqc.d.ts} +10 -6
- package/dist/shared/chunk-2b6gpn8k.js +444 -0
- package/dist/shared/chunk-3hcnf4yx.js +481 -0
- package/dist/shared/chunk-42wab62s.d.ts +197 -0
- package/dist/shared/{chunk-zvh0d3qb.js → chunk-61t2dfte.js} +1 -1
- package/dist/shared/{chunk-9nhpg9t8.d.ts → chunk-6tnq6p89.d.ts} +9 -1
- package/dist/shared/{chunk-hpsabfsd.d.ts → chunk-81fpptwp.d.ts} +1 -1
- package/dist/shared/chunk-93dtpjz7.js +789 -0
- package/dist/shared/{chunk-wwjxs75m.js → chunk-9xtcv3sy.js} +26 -12
- package/dist/shared/chunk-a6njb8db.d.ts +129 -0
- package/dist/shared/chunk-ab8mdg0n.d.ts +149 -0
- package/dist/shared/chunk-evqpf92s.d.ts +168 -0
- package/dist/shared/{chunk-6c1jbefs.d.ts → chunk-fexwzycv.d.ts} +3 -3
- package/dist/shared/chunk-gcyspvgr.js +582 -0
- package/dist/shared/chunk-gejenfap.d.ts +25 -0
- package/dist/shared/chunk-gkj0hjrn.d.ts +136 -0
- package/dist/shared/{chunk-rr5e0g15.d.ts → chunk-j755a1a5.d.ts} +7 -1
- package/dist/shared/chunk-n739am8j.d.ts +112 -0
- package/dist/shared/{chunk-78w7qwp0.js → chunk-ndf79pv5.js} +1 -1
- package/dist/shared/chunk-nwzpekvy.js +774 -0
- package/dist/shared/{chunk-rpfwv3pz.js → chunk-r471sknr.js} +1 -1
- package/dist/shared/chunk-sbrtesdg.d.ts +138 -0
- package/dist/shared/chunk-swc7dqpw.d.ts +115 -0
- package/dist/shared/chunk-t9wqhgzt.js +765 -0
- package/dist/shared/chunk-w5h6ay93.js +72 -0
- package/dist/shared/{chunk-mp1nx0ez.js → chunk-wayv5rhr.js} +15 -4
- package/dist/shared/chunk-wf0jtzhs.js +295 -0
- package/dist/shared/{chunk-sbnrhy5m.js → chunk-y0188bbn.js} +2 -2
- package/dist/shared/chunk-yq5svpk7.js +524 -0
- package/dist/shared/{chunk-s33y1pcq.js → chunk-z3tj1ydg.js} +23 -10
- package/dist/styles.css +151 -49
- package/index.ts +7 -6
- package/lib/artwork.ts +112 -0
- package/lib/geometry.ts +1 -1
- package/mock/activities.tsx +9 -32
- package/mock/artwork.tsx +13 -1
- package/mock/clipboard.tsx +113 -0
- package/mock/clock.tsx +77 -0
- package/mock/data.ts +78 -44
- package/mock/files.tsx +83 -0
- package/mock/island-content.tsx +79 -122
- package/mock/screen.tsx +76 -0
- package/mock/settings.tsx +370 -91
- package/mock/system.ts +49 -0
- package/mock/weather.tsx +135 -0
- package/package.json +7 -2
- package/blocks/activities/shelf/examples.mdx +0 -33
- package/blocks/activities/shelf/index.tsx +0 -289
- package/blocks/activities/timer/examples.mdx +0 -52
- package/blocks/activities/timer/index.tsx +0 -292
- package/blocks/system/controls/examples.mdx +0 -34
- package/blocks/system/controls/index.tsx +0 -167
- package/blocks/system/devices/examples.mdx +0 -25
- package/blocks/system/devices/index.tsx +0 -172
- package/blocks/system/power-alert/examples.mdx +0 -32
- package/blocks/system/power-alert/index.tsx +0 -89
- package/components/indicators/battery-glyph/examples.mdx +0 -22
- package/components/indicators/battery-glyph/index.tsx +0 -91
- package/dist/blocks/activities/shelf/index.d.ts +0 -2
- package/dist/blocks/activities/shelf/index.js +0 -14
- package/dist/blocks/activities/timer/index.d.ts +0 -2
- package/dist/blocks/activities/timer/index.js +0 -19
- package/dist/blocks/system/controls/index.d.ts +0 -2
- package/dist/blocks/system/controls/index.js +0 -10
- package/dist/blocks/system/devices/index.d.ts +0 -2
- package/dist/blocks/system/devices/index.js +0 -12
- package/dist/blocks/system/power-alert/index.d.ts +0 -2
- package/dist/blocks/system/power-alert/index.js +0 -9
- package/dist/components/indicators/battery-glyph/index.d.ts +0 -2
- package/dist/components/indicators/battery-glyph/index.js +0 -9
- package/dist/shared/chunk-2qpcsv5h.d.ts +0 -45
- package/dist/shared/chunk-45gytfr1.d.ts +0 -84
- package/dist/shared/chunk-50ffk4r7.d.ts +0 -69
- package/dist/shared/chunk-5w0yck07.d.ts +0 -32
- package/dist/shared/chunk-7hr53mby.js +0 -116
- package/dist/shared/chunk-b8jb1w72.js +0 -145
- package/dist/shared/chunk-cpewy6yg.js +0 -178
- package/dist/shared/chunk-e3e4s4ds.d.ts +0 -77
- package/dist/shared/chunk-enm6td0p.js +0 -280
- package/dist/shared/chunk-fvedaas2.d.ts +0 -33
- package/dist/shared/chunk-gex38j8x.d.ts +0 -82
- package/dist/shared/chunk-hwtxpzg0.js +0 -69
- package/dist/shared/chunk-phb53x1f.js +0 -252
- package/dist/shared/chunk-r8esmjfs.d.ts +0 -42
- package/dist/shared/chunk-rcp1g9ca.js +0 -70
- package/dist/shared/chunk-rx9sphz2.js +0 -266
- package/dist/shared/chunk-xdeek16r.d.ts +0 -58
- package/dist/shared/chunk-xkzjk1tq.js +0 -206
|
@@ -1,16 +1,34 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Local addition: a notch app's system load,
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Local addition: a notch app's system load, the busiest figure as the hero
|
|
3
|
+
* with its trend, the rest as facts and the busiest processes beside it.
|
|
4
|
+
* Rebuilt from Just Notch's stats plugin (`System`, `Tile`, `Measuring`,
|
|
5
|
+
* `CpuLoad`) on the kit's Widget frame and modo-ui's Sparkline and Meter:
|
|
6
|
+
* the readings come in as props.
|
|
6
7
|
*/
|
|
7
8
|
|
|
8
9
|
'use client'
|
|
9
10
|
|
|
10
|
-
import Sparkline from '@justanarthur/modo-ui/components/data-display/sparkline'
|
|
11
|
+
import Sparkline, { type SparklineTone } from '@justanarthur/modo-ui/components/data-display/sparkline'
|
|
12
|
+
import Table from '@justanarthur/modo-ui/components/data-display/table'
|
|
13
|
+
import Meter, { type MeterTone } from '@justanarthur/modo-ui/components/feedback/meter'
|
|
14
|
+
import type { SizeVariant } from '@justanarthur/modo-ui/lib/size-context'
|
|
11
15
|
import { cn } from '@justanarthur/modo-ui/lib/utils'
|
|
12
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
Activity,
|
|
18
|
+
ArrowDown,
|
|
19
|
+
ArrowUp,
|
|
20
|
+
BatteryCharging,
|
|
21
|
+
BatteryFull,
|
|
22
|
+
BatteryLow,
|
|
23
|
+
BatteryMedium,
|
|
24
|
+
Cpu,
|
|
25
|
+
HardDrive,
|
|
26
|
+
type LucideIcon,
|
|
27
|
+
MemoryStick,
|
|
28
|
+
Network,
|
|
29
|
+
} from 'lucide-react'
|
|
13
30
|
import type { ReactNode } from 'react'
|
|
31
|
+
import Widget, { type WidgetLayout } from '../../../components/island/widget'
|
|
14
32
|
|
|
15
33
|
/** One reading of the system. */
|
|
16
34
|
interface StatsSample {
|
|
@@ -20,21 +38,78 @@ interface StatsSample {
|
|
|
20
38
|
memoryUsed: number
|
|
21
39
|
/** All the memory, in bytes. */
|
|
22
40
|
memoryTotal: number
|
|
41
|
+
/** Memory pressure, from 0 to 1, as the system judges it; without it the share in use stands in. */
|
|
42
|
+
memoryPressure?: number
|
|
23
43
|
/** Network in, in bytes per second. */
|
|
24
44
|
netIn: number
|
|
25
45
|
/** Network out, in bytes per second. */
|
|
26
46
|
netOut: number
|
|
27
47
|
}
|
|
28
48
|
|
|
49
|
+
interface StatsBattery {
|
|
50
|
+
/** The charge, in percent (0 to 100). */
|
|
51
|
+
level: number
|
|
52
|
+
/** A charger is connected. */
|
|
53
|
+
charging?: boolean
|
|
54
|
+
/** Minutes until full while charging, else until empty. */
|
|
55
|
+
minutesLeft?: number
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface StatsDisk {
|
|
59
|
+
/** Free space on the startup disk, in bytes. */
|
|
60
|
+
free: number
|
|
61
|
+
/** The disk's size, in bytes. */
|
|
62
|
+
total: number
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface StatsProcess {
|
|
66
|
+
/** What tells it apart: its pid. */
|
|
67
|
+
id: string
|
|
68
|
+
/** The app or process name. */
|
|
69
|
+
name: string
|
|
70
|
+
/** Its share of the CPU, from 0 to 1. */
|
|
71
|
+
cpu: number
|
|
72
|
+
/** The memory it holds, in bytes. */
|
|
73
|
+
memory?: number
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
type StatsHero = 'cpu' | 'memory'
|
|
77
|
+
|
|
29
78
|
interface SystemStatsProps {
|
|
30
79
|
/** The readings so far, oldest first; the latest is the figure, all of them the trend. Without any, it is still measuring. */
|
|
31
80
|
samples: StatsSample[]
|
|
81
|
+
/** Which figure is the hero: the CPU load, or memory pressure when memory is what's tight. Defaults to `'cpu'`. */
|
|
82
|
+
hero?: StatsHero
|
|
83
|
+
/** The battery, on a laptop. */
|
|
84
|
+
battery?: StatsBattery
|
|
85
|
+
/** The startup disk's free space. */
|
|
86
|
+
disk?: StatsDisk
|
|
87
|
+
/** Seconds since the last boot. */
|
|
88
|
+
uptime?: number
|
|
89
|
+
/** The busiest processes, in any order: the top three list beside the hero, by CPU; the top eight at the tall snap. */
|
|
90
|
+
processes?: StatsProcess[]
|
|
91
|
+
/** Step on the size ladder. Omitted, it follows the surrounding SizeProvider. */
|
|
92
|
+
size?: SizeVariant
|
|
93
|
+
/** `tall` is the open island's tall snap: CPU and memory side by side, each with its trend; the network's in and out as one graph beside the battery and the disk as gauges; and the top eight processes as a table. Defaults to `'fit'`. */
|
|
94
|
+
layout?: WidgetLayout
|
|
32
95
|
/** Classes for the root, which fills its container. */
|
|
33
96
|
className?: string
|
|
34
97
|
}
|
|
35
98
|
|
|
99
|
+
/** Processes listed before the count of the rest. */
|
|
100
|
+
const ROWS = 3
|
|
101
|
+
/** Processes in the tall snap's table. */
|
|
102
|
+
const SHEET_ROWS = 8
|
|
103
|
+
|
|
36
104
|
const percent = (v: number) => `${Math.round(v * 100)}%`
|
|
37
|
-
const
|
|
105
|
+
const share = (v: number) => (v < 0.1 ? `${(v * 100).toFixed(1)}%` : percent(v))
|
|
106
|
+
|
|
107
|
+
/** Bytes as `11.4 GB`, `640 MB` or `212 GB`. */
|
|
108
|
+
function bytes(n: number) {
|
|
109
|
+
if (n >= 100e9) return `${Math.round(n / 1e9)} GB`
|
|
110
|
+
if (n >= 1e9) return `${(n / 1e9).toFixed(1)} GB`
|
|
111
|
+
return `${Math.round(n / 1e6)} MB`
|
|
112
|
+
}
|
|
38
113
|
|
|
39
114
|
/** Bytes per second as `2.4 MB/s`, `512 KB/s` or `80 B/s`. */
|
|
40
115
|
function rate(bps: number) {
|
|
@@ -43,46 +118,273 @@ function rate(bps: number) {
|
|
|
43
118
|
return `${Math.round(bps)} B/s`
|
|
44
119
|
}
|
|
45
120
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
121
|
+
/** Seconds as `3 d 4 h`, `5 h 12 min` or `12 min`. */
|
|
122
|
+
function span(seconds: number) {
|
|
123
|
+
const minutes = Math.floor(seconds / 60)
|
|
124
|
+
const hours = Math.floor(minutes / 60)
|
|
125
|
+
const days = Math.floor(hours / 24)
|
|
126
|
+
if (days) return `${days} d ${hours % 24} h`
|
|
127
|
+
if (hours) return `${hours} h ${minutes % 60} min`
|
|
128
|
+
return `${minutes} min`
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Minutes as `3:40`. */
|
|
132
|
+
const clock = (minutes: number) => `${Math.floor(minutes / 60)}:${String(Math.round(minutes % 60)).padStart(2, '0')}`
|
|
133
|
+
|
|
134
|
+
/** The status a load reads as: calm, then the warning hue, then the error hue. */
|
|
135
|
+
function toneOf(load: number): SparklineTone {
|
|
136
|
+
if (load >= 0.9) return 'error'
|
|
137
|
+
if (load >= 0.75) return 'warning'
|
|
138
|
+
return 'current'
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function verdict(load: number) {
|
|
142
|
+
if (load >= 0.9) return 'Under strain'
|
|
143
|
+
if (load >= 0.6) return 'Busy'
|
|
144
|
+
if (load >= 0.2) return 'Steady'
|
|
145
|
+
return 'Idle'
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const pressureOf = (sample: StatsSample) => sample.memoryPressure ?? sample.memoryUsed / sample.memoryTotal
|
|
149
|
+
|
|
150
|
+
function batteryIcon({ level, charging }: StatsBattery) {
|
|
151
|
+
if (charging) return BatteryCharging
|
|
152
|
+
if (level <= 20) return BatteryLow
|
|
153
|
+
if (level <= 70) return BatteryMedium
|
|
154
|
+
return BatteryFull
|
|
51
155
|
}
|
|
52
156
|
|
|
53
|
-
function
|
|
157
|
+
function BatteryItem({ battery }: { battery: StatsBattery }) {
|
|
158
|
+
const left = battery.minutesLeft === undefined ? undefined : clock(battery.minutesLeft)
|
|
54
159
|
return (
|
|
55
|
-
<
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
160
|
+
<Widget.MetaItem icon={batteryIcon(battery)}>
|
|
161
|
+
{battery.level}%{left && ` · ${left} ${battery.charging ? 'to full' : 'left'}`}
|
|
162
|
+
</Widget.MetaItem>
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
interface FactsProps {
|
|
167
|
+
last?: StatsSample
|
|
168
|
+
hero: StatsHero
|
|
169
|
+
battery?: StatsBattery
|
|
170
|
+
disk?: StatsDisk
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Everything but the hero, as two rows of glyph and words. */
|
|
174
|
+
function Facts({ last, hero, battery, disk }: FactsProps) {
|
|
175
|
+
const dash = '–'
|
|
176
|
+
return (
|
|
177
|
+
<div className="flex min-w-0 flex-col gap-1">
|
|
178
|
+
<Widget.Meta>
|
|
179
|
+
{hero === 'cpu' ? (
|
|
180
|
+
<Widget.MetaItem icon={MemoryStick}>
|
|
181
|
+
{last ? `${bytes(last.memoryUsed)} of ${bytes(last.memoryTotal)}` : dash}
|
|
182
|
+
</Widget.MetaItem>
|
|
183
|
+
) : (
|
|
184
|
+
<Widget.MetaItem icon={Cpu}>{last ? `${percent(last.cpu)} CPU` : dash}</Widget.MetaItem>
|
|
185
|
+
)}
|
|
186
|
+
<Widget.MetaItem icon={ArrowDown}>{last ? rate(last.netIn) : dash}</Widget.MetaItem>
|
|
187
|
+
<Widget.MetaItem icon={ArrowUp}>{last ? rate(last.netOut) : dash}</Widget.MetaItem>
|
|
188
|
+
</Widget.Meta>
|
|
189
|
+
{(battery || disk) && (
|
|
190
|
+
<Widget.Meta>
|
|
191
|
+
{battery && <BatteryItem battery={battery} />}
|
|
192
|
+
{disk && <Widget.MetaItem icon={HardDrive}>{bytes(disk.free)} free</Widget.MetaItem>}
|
|
193
|
+
</Widget.Meta>
|
|
194
|
+
)}
|
|
64
195
|
</div>
|
|
65
196
|
)
|
|
66
197
|
}
|
|
67
198
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
{ icon: Cpu, label: 'CPU' },
|
|
72
|
-
{ icon: MemoryStick, label: 'Memory' },
|
|
73
|
-
{ icon: Network, label: 'Network' },
|
|
74
|
-
]
|
|
199
|
+
function Processes({ processes }: { processes: StatsProcess[] }) {
|
|
200
|
+
const top = [...processes].sort((a, b) => b.cpu - a.cpu)
|
|
201
|
+
const more = top.length - ROWS
|
|
75
202
|
return (
|
|
76
|
-
<
|
|
77
|
-
{
|
|
78
|
-
<
|
|
79
|
-
|
|
80
|
-
|
|
203
|
+
<Widget.Section label="Top processes" trailing={<span>CPU · memory</span>}>
|
|
204
|
+
{top.slice(0, ROWS).map(process => (
|
|
205
|
+
<Widget.Row
|
|
206
|
+
key={process.id}
|
|
207
|
+
leading={share(process.cpu)}
|
|
208
|
+
trailing={process.memory !== undefined && bytes(process.memory)}
|
|
209
|
+
>
|
|
210
|
+
{process.name}
|
|
211
|
+
</Widget.Row>
|
|
81
212
|
))}
|
|
213
|
+
{more > 0 && (
|
|
214
|
+
<span className="flex h-6 items-center pl-17.5 text-caption text-muted-foreground">{more} more</span>
|
|
215
|
+
)}
|
|
216
|
+
</Widget.Section>
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
interface TrendProps {
|
|
221
|
+
label: string
|
|
222
|
+
icon: LucideIcon
|
|
223
|
+
/** The latest share, from 0 to 1; left out while measuring. */
|
|
224
|
+
value?: number
|
|
225
|
+
unit?: string
|
|
226
|
+
series: number[]
|
|
227
|
+
/** The line under the trend. */
|
|
228
|
+
caption: ReactNode
|
|
229
|
+
className?: string
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** One figure at the tall snap: its share large, every reading as a trend under it, one line on what it means. */
|
|
233
|
+
function Trend({ label, icon: Icon, value, unit, series, caption, className }: TrendProps) {
|
|
234
|
+
return (
|
|
235
|
+
<div className={cn('flex min-w-0 flex-col gap-1', className)} aria-busy={value === undefined}>
|
|
236
|
+
<Widget.Header icon={Icon}>{label}</Widget.Header>
|
|
237
|
+
<Widget.Figure value={value === undefined ? '–' : percent(value)} unit={unit} />
|
|
238
|
+
<Sparkline
|
|
239
|
+
values={series}
|
|
240
|
+
max={1}
|
|
241
|
+
area
|
|
242
|
+
tone={toneOf(value ?? 0)}
|
|
243
|
+
label={value === undefined ? `${label}, measuring` : `${label}, ${percent(value)}`}
|
|
244
|
+
className={cn('my-1 h-14 w-full', value === undefined && 'text-muted-foreground')}
|
|
245
|
+
/>
|
|
246
|
+
<Widget.Subtitle>{caption}</Widget.Subtitle>
|
|
82
247
|
</div>
|
|
83
248
|
)
|
|
84
249
|
}
|
|
85
250
|
|
|
251
|
+
/** A battery's tone: the warning hue from 20% left, the error hue from 10%, unless it charges. */
|
|
252
|
+
function batteryTone({ level, charging }: StatsBattery): MeterTone {
|
|
253
|
+
if (charging) return 'default'
|
|
254
|
+
if (level <= 10) return 'error'
|
|
255
|
+
if (level <= 20) return 'warning'
|
|
256
|
+
return 'default'
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function ProcessTable({ processes }: { processes: StatsProcess[] }) {
|
|
260
|
+
const top = [...processes].sort((a, b) => b.cpu - a.cpu).slice(0, SHEET_ROWS)
|
|
261
|
+
const head = 'text-caption weight-normal text-muted-foreground'
|
|
262
|
+
return (
|
|
263
|
+
<Widget.Section label="Top processes" trailing={<span>by CPU</span>}>
|
|
264
|
+
<Table>
|
|
265
|
+
<Table.Header>
|
|
266
|
+
<Table.Row>
|
|
267
|
+
<Table.Head className={head}>Name</Table.Head>
|
|
268
|
+
<Table.Head className={cn(head, 'text-right')}>CPU</Table.Head>
|
|
269
|
+
<Table.Head className={cn(head, 'w-24 text-right')}>Memory</Table.Head>
|
|
270
|
+
</Table.Row>
|
|
271
|
+
</Table.Header>
|
|
272
|
+
<Table.Body>
|
|
273
|
+
{top.map(process => (
|
|
274
|
+
<Table.Row key={process.id}>
|
|
275
|
+
<Table.Cell className="text-foreground">{process.name}</Table.Cell>
|
|
276
|
+
<Table.Cell>
|
|
277
|
+
<span className="flex items-center justify-end gap-3">
|
|
278
|
+
<Meter variant="line" value={process.cpu} label={`${process.name}, CPU`} className="w-24" />
|
|
279
|
+
<span className="w-12 text-right tabular-nums">{share(process.cpu)}</span>
|
|
280
|
+
</span>
|
|
281
|
+
</Table.Cell>
|
|
282
|
+
<Table.Cell className="text-right tabular-nums">
|
|
283
|
+
{process.memory === undefined ? '–' : bytes(process.memory)}
|
|
284
|
+
</Table.Cell>
|
|
285
|
+
</Table.Row>
|
|
286
|
+
))}
|
|
287
|
+
</Table.Body>
|
|
288
|
+
</Table>
|
|
289
|
+
</Widget.Section>
|
|
290
|
+
)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
interface SheetProps extends Omit<SystemStatsProps, 'samples' | 'hero' | 'layout'> {
|
|
294
|
+
samples: StatsSample[]
|
|
295
|
+
hero: StatsHero
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** The tall snap's sheet. */
|
|
299
|
+
function Sheet({ samples, hero, battery, disk, uptime, processes, size, className }: SheetProps) {
|
|
300
|
+
const last = samples.at(-1)
|
|
301
|
+
const busiest = processes?.length ? processes.reduce((a, b) => (b.cpu > a.cpu ? b : a)).name : undefined
|
|
302
|
+
const cpu = (
|
|
303
|
+
<Trend
|
|
304
|
+
key="cpu"
|
|
305
|
+
label="CPU"
|
|
306
|
+
icon={Cpu}
|
|
307
|
+
value={last?.cpu}
|
|
308
|
+
unit="load"
|
|
309
|
+
series={samples.map(s => s.cpu)}
|
|
310
|
+
caption={
|
|
311
|
+
last ? [verdict(last.cpu), busiest && `${busiest} is busiest`].filter(Boolean).join(' · ') : 'Measuring…'
|
|
312
|
+
}
|
|
313
|
+
/>
|
|
314
|
+
)
|
|
315
|
+
const memory = (
|
|
316
|
+
<Trend
|
|
317
|
+
key="memory"
|
|
318
|
+
label="Memory"
|
|
319
|
+
icon={MemoryStick}
|
|
320
|
+
value={last && pressureOf(last)}
|
|
321
|
+
unit="pressure"
|
|
322
|
+
series={samples.map(pressureOf)}
|
|
323
|
+
caption={last ? `${bytes(last.memoryUsed)} of ${bytes(last.memoryTotal)} in use` : 'Measuring…'}
|
|
324
|
+
/>
|
|
325
|
+
)
|
|
326
|
+
const [first, second] = hero === 'cpu' ? [cpu, memory] : [memory, cpu]
|
|
327
|
+
const left = battery?.minutesLeft === undefined ? undefined : clock(battery.minutesLeft)
|
|
328
|
+
|
|
329
|
+
return (
|
|
330
|
+
<Widget.Sheet size={size} className={className}>
|
|
331
|
+
<div className="flex min-w-0 flex-col gap-2">
|
|
332
|
+
<Widget.Header icon={Activity}>{uptime === undefined ? 'System' : `System · up ${span(uptime)}`}</Widget.Header>
|
|
333
|
+
<div className="grid grid-cols-2 divide-x divide-border [&>*]:px-6 [&>*:first-child]:pl-0 [&>*:last-child]:pr-0">
|
|
334
|
+
{first}
|
|
335
|
+
{second}
|
|
336
|
+
</div>
|
|
337
|
+
</div>
|
|
338
|
+
|
|
339
|
+
<div className="grid auto-cols-fr grid-flow-col divide-x divide-border [&>*]:px-6 [&>*:first-child]:pl-0 [&>*:last-child]:pr-0">
|
|
340
|
+
<div className="flex min-w-0 flex-col gap-1" aria-busy={!last}>
|
|
341
|
+
<Widget.Header icon={Network}>Network</Widget.Header>
|
|
342
|
+
<div className="flex min-w-0 items-baseline gap-5">
|
|
343
|
+
<span className="flex items-center gap-1.5 whitespace-nowrap text-title weight-semibold tabular-nums text-foreground">
|
|
344
|
+
<ArrowDown size={16} strokeWidth={1.5} aria-label="In" className="text-muted-foreground" />
|
|
345
|
+
{last ? rate(last.netIn) : '–'}
|
|
346
|
+
</span>
|
|
347
|
+
<span className="flex items-center gap-1.5 whitespace-nowrap text-title weight-semibold tabular-nums text-muted-foreground">
|
|
348
|
+
<ArrowUp size={16} strokeWidth={1.5} aria-label="Out" />
|
|
349
|
+
{last ? rate(last.netOut) : '–'}
|
|
350
|
+
</span>
|
|
351
|
+
</div>
|
|
352
|
+
<Sparkline
|
|
353
|
+
values={samples.map(s => s.netIn)}
|
|
354
|
+
secondary={samples.map(s => s.netOut)}
|
|
355
|
+
area
|
|
356
|
+
label={last ? `Network, ${rate(last.netIn)} in, ${rate(last.netOut)} out` : 'Network, measuring'}
|
|
357
|
+
className={cn('my-1 h-12 w-full', !last && 'text-muted-foreground')}
|
|
358
|
+
/>
|
|
359
|
+
</div>
|
|
360
|
+
{(battery || disk) && (
|
|
361
|
+
<div className="flex min-w-0 flex-col justify-center gap-4">
|
|
362
|
+
{battery && (
|
|
363
|
+
<Meter
|
|
364
|
+
label={battery.charging ? 'Battery, charging' : 'Battery'}
|
|
365
|
+
value={battery.level}
|
|
366
|
+
max={100}
|
|
367
|
+
tone={batteryTone(battery)}
|
|
368
|
+
detail={`${battery.level}%${left ? ` · ${left} ${battery.charging ? 'to full' : 'left'}` : ''}`}
|
|
369
|
+
/>
|
|
370
|
+
)}
|
|
371
|
+
{disk && (
|
|
372
|
+
<Meter
|
|
373
|
+
label="Startup disk"
|
|
374
|
+
value={disk.total - disk.free}
|
|
375
|
+
max={disk.total}
|
|
376
|
+
detail={`${bytes(disk.free)} free of ${bytes(disk.total)}`}
|
|
377
|
+
/>
|
|
378
|
+
)}
|
|
379
|
+
</div>
|
|
380
|
+
)}
|
|
381
|
+
</div>
|
|
382
|
+
|
|
383
|
+
{processes?.length ? <ProcessTable processes={processes} /> : null}
|
|
384
|
+
</Widget.Sheet>
|
|
385
|
+
)
|
|
386
|
+
}
|
|
387
|
+
|
|
86
388
|
/** The compact island's left wing: the CPU glyph. */
|
|
87
389
|
function SystemStatsLeading() {
|
|
88
390
|
return <Cpu size={16} strokeWidth={1.5} className="text-muted-foreground" />
|
|
@@ -94,85 +396,124 @@ function SystemStatsTrailing({ sample }: { sample?: StatsSample }) {
|
|
|
94
396
|
return <span className="text-caption weight-semibold tabular-nums text-foreground">{percent(sample.cpu)}</span>
|
|
95
397
|
}
|
|
96
398
|
|
|
399
|
+
/** The split island's bubble: the CPU load as a ring, in the warning hue from 75% and the error hue from 90%. */
|
|
400
|
+
function SystemStatsMinimal({ sample }: { sample?: StatsSample }) {
|
|
401
|
+
const load = sample?.cpu ?? 0
|
|
402
|
+
return (
|
|
403
|
+
<Meter
|
|
404
|
+
variant="ring"
|
|
405
|
+
className="size-5.5"
|
|
406
|
+
size="compact"
|
|
407
|
+
value={load}
|
|
408
|
+
label={sample ? `CPU, ${percent(load)}` : 'CPU, measuring'}
|
|
409
|
+
/>
|
|
410
|
+
)
|
|
411
|
+
}
|
|
412
|
+
|
|
97
413
|
/**
|
|
98
|
-
* A notch app's system load:
|
|
99
|
-
*
|
|
414
|
+
* A notch app's system load: the busiest figure as the hero with its trend,
|
|
415
|
+
* the rest as facts, and the processes behind it.
|
|
416
|
+
*
|
|
417
|
+
* The hero is the CPU load, set large, with every reading so far as a
|
|
418
|
+
* modo-ui Sparkline beside it (it spans the width however many readings
|
|
419
|
+
* there are: the island stays open for seconds, too short to fill a fixed
|
|
420
|
+
* window). The line turns to the warning hue from 75% and the error hue
|
|
421
|
+
* from 90%, so the color comes from the load. When memory is what's tight,
|
|
422
|
+
* `hero="memory"` makes memory pressure the figure and its trend instead.
|
|
423
|
+
* Under it one word for how the machine is doing and who's busiest, then
|
|
424
|
+
* the facts: memory in use of all of it (or the CPU), the network's in and
|
|
425
|
+
* out rates, and, when given, the battery with its time left and the
|
|
426
|
+
* startup disk's free space. The uptime sits on the context line.
|
|
427
|
+
*
|
|
428
|
+
* Beside it, past a hairline, the busiest processes by CPU with the memory
|
|
429
|
+
* they hold, three at most and a count of the rest.
|
|
100
430
|
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
431
|
+
* CPU and network are rates between two readings, so before the first one
|
|
432
|
+
* lands (about a second after opening) the figures are dashes over the
|
|
433
|
+
* Sparkline's baseline.
|
|
434
|
+
*
|
|
435
|
+
* At the open island's tall snap (`layout="tall"`) it becomes a sheet: CPU
|
|
436
|
+
* and memory pressure side by side, each its figure large over its trend
|
|
437
|
+
* and a line on what it means (the hero's column first); then the
|
|
438
|
+
* network's in and out as one graph, its rates over it, beside the battery
|
|
439
|
+
* and the startup disk as Meter bars; then the top eight processes as a
|
|
440
|
+
* table, each with its share of the CPU as a line and the memory it holds.
|
|
107
441
|
*
|
|
108
442
|
* `SystemStats.Leading` and `SystemStats.Trailing` show the CPU load in the
|
|
109
|
-
* compact island's wings.
|
|
443
|
+
* compact island's wings, `SystemStats.Minimal` as a ring in the split
|
|
444
|
+
* island's bubble.
|
|
110
445
|
*
|
|
111
446
|
* @example {@include ./examples.mdx}
|
|
112
447
|
*/
|
|
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
|
-
<Sparkline
|
|
139
|
-
values={memory}
|
|
140
|
-
max={last.memoryTotal}
|
|
141
|
-
label={`Memory, ${gigabytes(last.memoryUsed)}`}
|
|
142
|
-
className="h-10"
|
|
143
|
-
/>
|
|
144
|
-
</Tile>
|
|
145
|
-
<Tile
|
|
146
|
-
icon={Network}
|
|
147
|
-
label="Network"
|
|
148
|
-
value={
|
|
149
|
-
<>
|
|
150
|
-
<span className="flex items-center gap-0.5">
|
|
151
|
-
<ArrowDown size={12} strokeWidth={2} aria-label="In" />
|
|
152
|
-
{rate(last.netIn)}
|
|
153
|
-
</span>
|
|
154
|
-
<span className="flex min-w-0 items-center gap-0.5 truncate text-caption weight-normal text-muted-foreground">
|
|
155
|
-
<ArrowUp size={12} strokeWidth={2} aria-label="Out" />
|
|
156
|
-
{rate(last.netOut)}
|
|
157
|
-
</span>
|
|
158
|
-
</>
|
|
159
|
-
}
|
|
160
|
-
>
|
|
161
|
-
<Sparkline
|
|
162
|
-
values={netIn}
|
|
163
|
-
secondary={netOut}
|
|
164
|
-
label={`Network, ${rate(last.netIn)} in, ${rate(last.netOut)} out`}
|
|
165
|
-
className="h-10"
|
|
448
|
+
const SystemStats = Object.assign(
|
|
449
|
+
function SystemStats({
|
|
450
|
+
samples,
|
|
451
|
+
hero = 'cpu',
|
|
452
|
+
battery,
|
|
453
|
+
disk,
|
|
454
|
+
uptime,
|
|
455
|
+
processes,
|
|
456
|
+
size,
|
|
457
|
+
layout = 'fit',
|
|
458
|
+
className,
|
|
459
|
+
}: SystemStatsProps) {
|
|
460
|
+
if (layout === 'tall')
|
|
461
|
+
return (
|
|
462
|
+
<Sheet
|
|
463
|
+
size={size}
|
|
464
|
+
samples={samples}
|
|
465
|
+
hero={hero}
|
|
466
|
+
battery={battery}
|
|
467
|
+
disk={disk}
|
|
468
|
+
uptime={uptime}
|
|
469
|
+
processes={processes}
|
|
470
|
+
className={className}
|
|
166
471
|
/>
|
|
167
|
-
|
|
168
|
-
</div>
|
|
169
|
-
)
|
|
170
|
-
}
|
|
472
|
+
)
|
|
171
473
|
|
|
172
|
-
|
|
173
|
-
|
|
474
|
+
const last = samples.at(-1)
|
|
475
|
+
const series = hero === 'cpu' ? samples.map(s => s.cpu) : samples.map(pressureOf)
|
|
476
|
+
const load = last ? (hero === 'cpu' ? last.cpu : pressureOf(last)) : 0
|
|
477
|
+
const name = hero === 'cpu' ? 'CPU' : 'Memory pressure'
|
|
478
|
+
const busiest = processes?.length ? processes.reduce((a, b) => (b.cpu > a.cpu ? b : a)).name : undefined
|
|
479
|
+
|
|
480
|
+
return (
|
|
481
|
+
<Widget
|
|
482
|
+
size={size}
|
|
483
|
+
className={cn('h-full', className)}
|
|
484
|
+
aside={processes?.length ? <Processes processes={processes} /> : undefined}
|
|
485
|
+
>
|
|
486
|
+
<Widget.Header icon={Activity}>{uptime === undefined ? 'System' : `System · up ${span(uptime)}`}</Widget.Header>
|
|
487
|
+
<div className="flex min-w-0 items-end gap-4" aria-busy={!last}>
|
|
488
|
+
<Widget.Figure
|
|
489
|
+
value={last ? percent(load) : '–'}
|
|
490
|
+
unit={hero === 'cpu' ? 'CPU' : 'pressure'}
|
|
491
|
+
className="shrink-0"
|
|
492
|
+
/>
|
|
493
|
+
<Sparkline
|
|
494
|
+
values={series}
|
|
495
|
+
max={1}
|
|
496
|
+
area
|
|
497
|
+
tone={toneOf(load)}
|
|
498
|
+
label={last ? `${name}, ${percent(load)}` : `${name}, measuring`}
|
|
499
|
+
className={cn('mb-1.5 h-9 min-w-0 flex-1', !last && 'text-muted-foreground')}
|
|
500
|
+
/>
|
|
501
|
+
</div>
|
|
502
|
+
<Widget.Subtitle className="mb-1">
|
|
503
|
+
{last ? [verdict(load), busiest && `${busiest} is busiest`].filter(Boolean).join(' · ') : 'Measuring…'}
|
|
504
|
+
</Widget.Subtitle>
|
|
505
|
+
<Facts last={last} hero={hero} battery={battery} disk={disk} />
|
|
506
|
+
</Widget>
|
|
507
|
+
)
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
Leading: SystemStatsLeading,
|
|
511
|
+
Trailing: SystemStatsTrailing,
|
|
512
|
+
Minimal: SystemStatsMinimal,
|
|
513
|
+
},
|
|
514
|
+
)
|
|
174
515
|
|
|
175
516
|
export default SystemStats
|
|
176
517
|
|
|
177
|
-
export type { StatsSample, SystemStatsProps }
|
|
178
|
-
export { SystemStats, SystemStatsLeading, SystemStatsTrailing }
|
|
518
|
+
export type { StatsBattery, StatsDisk, StatsHero, StatsProcess, StatsSample, SystemStatsProps }
|
|
519
|
+
export { SystemStats, SystemStatsLeading, SystemStatsMinimal, SystemStatsTrailing }
|
|
@@ -19,3 +19,11 @@ Elapsed, the scrubber and the time remaining, running on a second at a time. Dra
|
|
|
19
19
|
<div className="w-full max-w-md">
|
|
20
20
|
<MediaScrubber position={12} duration={330} size="default" />
|
|
21
21
|
</div>
|
|
22
|
+
|
|
23
|
+
# Quiet
|
|
24
|
+
|
|
25
|
+
`quiet` shows a thin line of progress at rest; hover or focus it and the scrubber fades in to seek. Touch always gets the scrubber.
|
|
26
|
+
|
|
27
|
+
<div className="dark w-full max-w-md rounded-box bg-ink px-5 py-4 text-foreground">
|
|
28
|
+
<MediaScrubber position={71} duration={243} playing quiet />
|
|
29
|
+
</div>
|