dsh-device-badge 1.0.0 → 1.0.1
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/client.js +15 -0
- package/index.js +93 -6
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -700,8 +700,23 @@ window.__ModuleLoader__.load({
|
|
|
700
700
|
const rawId = state?.modelId ?? null
|
|
701
701
|
const showRawId =
|
|
702
702
|
rawId !== null && friendlyName !== null && rawId !== friendlyName
|
|
703
|
+
// OS line: "macOS 15.7.4 (24G517)" / "Windows 11 专业版 (26100)".
|
|
704
|
+
// macOS puts the build in osBuild; Windows reports it as osVersion with
|
|
705
|
+
// no separate build, so the two collapse into one readable field.
|
|
706
|
+
const osVersionText = state?.osVersion ?? null
|
|
707
|
+
const osBuildText = state?.osBuild ?? null
|
|
708
|
+
const osLine = (() => {
|
|
709
|
+
if (!state?.osName && !osVersionText) return null
|
|
710
|
+
const head = [state?.osName, osVersionText].filter(Boolean).join(' ')
|
|
711
|
+
// Only append parens when the build is a genuinely separate value.
|
|
712
|
+
const tail =
|
|
713
|
+
osBuildText && osBuildText !== osVersionText ? `(${osBuildText})` : null
|
|
714
|
+
return [head, tail].filter(Boolean).join(' ')
|
|
715
|
+
})()
|
|
716
|
+
|
|
703
717
|
const tooltip = [
|
|
704
718
|
friendlyName ?? text.unknown,
|
|
719
|
+
osLine,
|
|
705
720
|
isLaptop && percent !== null ? `${percent}%` : null,
|
|
706
721
|
isLaptop ? status : null,
|
|
707
722
|
showRawId ? rawId : null,
|
package/index.js
CHANGED
|
@@ -208,6 +208,32 @@ async function readMacModel() {
|
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
+
/**
|
|
212
|
+
* macOS marketing version and build, e.g. "macOS 15.7.4" + "24G517".
|
|
213
|
+
*
|
|
214
|
+
* `sw_vers` is the cheapest source (7 ms measured) and needs no privileges, so
|
|
215
|
+
* it runs alongside the battery read rather than being a separate round trip.
|
|
216
|
+
*/
|
|
217
|
+
async function readMacOsVersion() {
|
|
218
|
+
try {
|
|
219
|
+
const { stdout } = await execFileAsync('/usr/bin/sw_vers', [], {
|
|
220
|
+
timeout: COMMAND_TIMEOUT_MS,
|
|
221
|
+
})
|
|
222
|
+
const lines = String(stdout)
|
|
223
|
+
const pick = (key) => {
|
|
224
|
+
const m = new RegExp(`^${key}:\\s*(.+)$`, 'm').exec(lines)
|
|
225
|
+
return m === null ? null : m[1].trim()
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
name: pick('ProductName'),
|
|
229
|
+
version: pick('ProductVersion'),
|
|
230
|
+
build: pick('BuildVersion'),
|
|
231
|
+
}
|
|
232
|
+
} catch {
|
|
233
|
+
return { name: null, version: null, build: null }
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
211
237
|
async function readMacBattery() {
|
|
212
238
|
try {
|
|
213
239
|
const { stdout } = await execFileAsync('/usr/bin/pmset', ['-g', 'batt'], {
|
|
@@ -280,13 +306,46 @@ async function readWindowsInfo() {
|
|
|
280
306
|
{ timeout: COMMAND_TIMEOUT_MS },
|
|
281
307
|
).then((r) => String(r.stdout).trim())
|
|
282
308
|
|
|
309
|
+
// What to call this PC.
|
|
310
|
+
//
|
|
311
|
+
// `Win32_ComputerSystem.Model` is useless on a self-built desktop: it holds
|
|
312
|
+
// the *motherboard* string (e.g. "JGINYUE"), not a machine name — there is no
|
|
313
|
+
// brand to report for a hand-assembled box. The computer name the owner chose
|
|
314
|
+
// is far more identifying, so Windows always reports that as the label.
|
|
315
|
+
//
|
|
316
|
+
// Windows version is captured alongside it for the tooltip: "Windows 11 专业版
|
|
317
|
+
// 24H2 (26100)" tells you which box you're on better than "Windows" does.
|
|
283
318
|
let model = null
|
|
319
|
+
let osName = null
|
|
320
|
+
let osVersion = null
|
|
321
|
+
let osBuild = null
|
|
284
322
|
let battery = null
|
|
285
323
|
try {
|
|
286
|
-
model =
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
324
|
+
model = (await ps('$env:COMPUTERNAME')) || null
|
|
325
|
+
} catch {
|
|
326
|
+
/* ignore */
|
|
327
|
+
}
|
|
328
|
+
try {
|
|
329
|
+
// Caption is localised ("Microsoft Windows 11 专业版"); DisplayVersion is
|
|
330
|
+
// the marketing version ("24H2"); CurrentBuild is the build number.
|
|
331
|
+
const raw = await ps(
|
|
332
|
+
'Get-CimInstance Win32_OperatingSystem | Select-Object Caption,Version,BuildNumber | ConvertTo-Json -Compress',
|
|
333
|
+
)
|
|
334
|
+
if (raw) {
|
|
335
|
+
const json = JSON.parse(raw)
|
|
336
|
+
// ConvertTo-Json returns an object for one item, an array for several.
|
|
337
|
+
const parsed = Array.isArray(json) ? (json[0] ?? {}) : json
|
|
338
|
+
const caption = String(parsed.Caption ?? '')
|
|
339
|
+
.replace(/^Microsoft\s+/i, '')
|
|
340
|
+
.trim()
|
|
341
|
+
// Caption already carries the edition ("Windows 11 专业版"), so osName is
|
|
342
|
+
// the whole readable name and osVersion stays empty — putting the build
|
|
343
|
+
// number there would render "Windows 11 专业版 26100" without brackets.
|
|
344
|
+
// The build goes in osBuild, which the client wraps in parentheses.
|
|
345
|
+
osName = caption || null
|
|
346
|
+
osVersion = null
|
|
347
|
+
osBuild = String(parsed.BuildNumber ?? '').trim() || String(parsed.Version ?? '').trim() || null
|
|
348
|
+
}
|
|
290
349
|
} catch {
|
|
291
350
|
/* ignore */
|
|
292
351
|
}
|
|
@@ -315,7 +374,7 @@ async function readWindowsInfo() {
|
|
|
315
374
|
} catch {
|
|
316
375
|
/* no battery */
|
|
317
376
|
}
|
|
318
|
-
return { model, battery }
|
|
377
|
+
return { model, osName, osVersion, osBuild, battery }
|
|
319
378
|
}
|
|
320
379
|
|
|
321
380
|
async function snapshot({ fresh = false } = {}) {
|
|
@@ -327,16 +386,28 @@ async function snapshot({ fresh = false } = {}) {
|
|
|
327
386
|
let modelLabel = null
|
|
328
387
|
let battery = null
|
|
329
388
|
let brand = null
|
|
389
|
+
let osName = null
|
|
390
|
+
let osVersion = null
|
|
330
391
|
|
|
331
392
|
if (platform === 'darwin') {
|
|
332
|
-
const [id, batt] = await Promise.all([
|
|
393
|
+
const [id, batt, os] = await Promise.all([
|
|
394
|
+
readMacModel(),
|
|
395
|
+
readMacBattery(),
|
|
396
|
+
readMacOsVersion(),
|
|
397
|
+
])
|
|
333
398
|
modelId = id
|
|
334
399
|
battery = batt
|
|
335
400
|
modelLabel = id === null ? null : MODEL_NAMES[id] ?? null
|
|
401
|
+
osName = os.name
|
|
402
|
+
osVersion = os.version
|
|
403
|
+
osBuild = os.build
|
|
336
404
|
} else if (platform === 'win32') {
|
|
337
405
|
const info = await readWindowsInfo()
|
|
338
406
|
modelLabel = info.model
|
|
339
407
|
modelId = info.model
|
|
408
|
+
osName = info.osName
|
|
409
|
+
osVersion = info.osVersion
|
|
410
|
+
osBuild = info.osBuild
|
|
340
411
|
battery = info.battery
|
|
341
412
|
} else {
|
|
342
413
|
const [vendor, product, osRelease, batt] = await Promise.all([
|
|
@@ -349,6 +420,18 @@ async function snapshot({ fresh = false } = {}) {
|
|
|
349
420
|
brand = detectNasBrand(vendor, product, osRelease)
|
|
350
421
|
modelLabel = product ?? vendor ?? null
|
|
351
422
|
modelId = modelLabel
|
|
423
|
+
// /etc/os-release gives PRETTY_NAME ("Ubuntu 24.04.1 LTS") and
|
|
424
|
+
// VERSION_ID for the tooltip, same fields the other platforms fill.
|
|
425
|
+
const osVars = Object.fromEntries(
|
|
426
|
+
String(osRelease)
|
|
427
|
+
.split('\n')
|
|
428
|
+
.map((line) => line.split('='))
|
|
429
|
+
.filter((pair) => pair.length === 2)
|
|
430
|
+
.map(([k, v]) => [k.trim(), v.trim().replace(/^"|"$/g, '')]),
|
|
431
|
+
)
|
|
432
|
+
osName = osVars.PRETTY_NAME ?? osVars.NAME ?? null
|
|
433
|
+
osVersion = osVars.VERSION_ID ?? null
|
|
434
|
+
osBuild = osVars.BUILD_ID ?? null
|
|
352
435
|
}
|
|
353
436
|
|
|
354
437
|
const kind = deviceKindFor(modelId, platform, battery !== null)
|
|
@@ -367,6 +450,10 @@ async function snapshot({ fresh = false } = {}) {
|
|
|
367
450
|
modelLabel,
|
|
368
451
|
modelShort: shortModelLabel(modelId, modelLabel),
|
|
369
452
|
modelBrief: briefModelLabel(modelId, modelLabel, kind, brand),
|
|
453
|
+
// OS name + version/build, shown in the tooltip. Set on every platform.
|
|
454
|
+
osName,
|
|
455
|
+
osVersion,
|
|
456
|
+
osBuild,
|
|
370
457
|
hostname,
|
|
371
458
|
...(battery === null
|
|
372
459
|
? {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-device-badge",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Shows the machine DSH runs on in the sidebar account row: laptops get the model, battery percentage and a macOS-style charging glyph; iMac, Mac mini, Windows desktops and NAS boxes get their own outlined device icon.",
|