@dotrino/vaultd 0.198.1 → 0.199.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 +6 -0
- package/package.json +1 -1
- package/src/daemon.js +5 -0
- package/src/tray.js +123 -0
package/README.md
CHANGED
|
@@ -180,6 +180,12 @@ Busca la bóveda al lado de su ejecutable (así la ponen los instaladores), lueg
|
|
|
180
180
|
`PATH` (`dotrino-vaultd`, o el `dotrino-vault` de npm). Para desarrollo:
|
|
181
181
|
`DOTRINO_VAULT_BRIDGE="node bin/dotrino-vault.js" cargo run` en `desktop/`.
|
|
182
182
|
|
|
183
|
+
**El icono en la bandeja** (Windows y Linux): mientras la bóveda corre, se ve su escudo junto al
|
|
184
|
+
reloj; un clic abre la ventana. Lo lanza el propio daemon (`dotrino-vault-desktop --tray`, ver
|
|
185
|
+
`src/tray.js`) solo si hay sesión gráfica, y se quita solo cuando la bóveda se para. En Linux va
|
|
186
|
+
por StatusNotifierItem (KDE, XFCE, Ubuntu; en GNOME sin la extensión AppIndicator no hay
|
|
187
|
+
bandeja). En macOS todavía no.
|
|
188
|
+
|
|
183
189
|
**Windows — instalador:** `dotrino-vault-X.Y.Z-windows-x64-setup.exe` desde
|
|
184
190
|
[Releases](https://github.com/imdotrino/dotrino-vault/releases/latest). Se instala para
|
|
185
191
|
tu usuario, sin administrador, en `%LOCALAPPDATA%\Programs\Dotrino Vault`, con su entrada
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/vaultd",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.199.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Certificador personal de Dotrino: daemon headless que custodia la clave maestra y delega capacidades a tus dispositivos por el proxy. Tu CA propia.",
|
|
6
6
|
"bin": {
|
package/src/daemon.js
CHANGED
|
@@ -28,6 +28,7 @@ import { watchBinary } from './selfupdate.js'
|
|
|
28
28
|
import { latestRelease, isNewer, CHECK_EVERY_MS, installKind, installRelease } from './update.js'
|
|
29
29
|
import { VERSION } from './version.js'
|
|
30
30
|
import { readSettings } from './settings.js'
|
|
31
|
+
import { startTray } from './tray.js'
|
|
31
32
|
import { approversOfAll, firstYes, readAsked, writeAsked, clearAsked, shouldAsk, resultOfNo, readRootTold, writeRootTold, shouldTellRoot } from './updateApproval.js'
|
|
32
33
|
import { UPDATE_TTL_MS } from '../lib/src/core/approvals.js'
|
|
33
34
|
import crypto from 'node:crypto'
|
|
@@ -1133,6 +1134,10 @@ export async function runDaemon () {
|
|
|
1133
1134
|
})
|
|
1134
1135
|
if (watchdog) console.log('[vault] watching for updates: a new binary restarts the service on its own')
|
|
1135
1136
|
|
|
1137
|
+
// El icono en la bandeja mientras la bóveda corre (Windows y Linux, con sesión gráfica).
|
|
1138
|
+
// Al irse el daemon se cierra la tubería y el icono se va solo: no hace falta pararlo.
|
|
1139
|
+
startTray({ log: console.log })
|
|
1140
|
+
|
|
1136
1141
|
/**
|
|
1137
1142
|
* ¿SALIÓ UNA VERSIÓN NUEVA? Una lectura al día, y nada más.
|
|
1138
1143
|
*
|
package/src/tray.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tray.js — el icono de la bóveda en la bandeja del sistema (Windows y Linux), mientras corre.
|
|
3
|
+
*
|
|
4
|
+
* El daemon es Node empaquetado (SEA) y no puede dibujar un icono: un `.node` no entra en el
|
|
5
|
+
* binario. Lo dibuja la ventana, `dotrino-vault-desktop --tray`, que el daemon lanza como hijo
|
|
6
|
+
* con la entrada por tubería. Cuando el daemon se va (apagado, reinicio, caída), la tubería se
|
|
7
|
+
* cierra y el icono se va con él: el icono dice la verdad sin tener que preguntar nada.
|
|
8
|
+
*
|
|
9
|
+
* Solo con sesión gráfica:
|
|
10
|
+
* Linux `DISPLAY` o `WAYLAND_DISPLAY`. Bajo systemd se mira también el entorno del
|
|
11
|
+
* gestor (`systemctl --user show-environment`): la unidad arranca al entrar, a
|
|
12
|
+
* veces antes de que el escritorio publique su `DISPLAY`, y por eso se vuelve a
|
|
13
|
+
* mirar cada 30 s hasta que aparece.
|
|
14
|
+
* Windows siempre se intenta; si no hay escritorio (una sesión por SSH) el icono sale con
|
|
15
|
+
* el código 3 y no se reintenta.
|
|
16
|
+
* macOS todavía no (pendiente).
|
|
17
|
+
*
|
|
18
|
+
* Solo en el binario (SEA): desde npm no hay ventana al lado, y en desarrollo cada prueba que
|
|
19
|
+
* arranca un daemon sacaría un icono.
|
|
20
|
+
*/
|
|
21
|
+
import fs from 'node:fs'
|
|
22
|
+
import path from 'node:path'
|
|
23
|
+
import { execFile, spawn } from 'node:child_process'
|
|
24
|
+
|
|
25
|
+
const RETRY_MS = 30_000
|
|
26
|
+
/** Código con el que sale `--tray` cuando en esta sesión no puede haber icono. */
|
|
27
|
+
export const NO_TRAY_EXIT = 3
|
|
28
|
+
|
|
29
|
+
const GUI_NAME = (platform) => platform === 'win32' ? 'dotrino-vault-desktop.exe' : 'dotrino-vault-desktop'
|
|
30
|
+
|
|
31
|
+
/** La ventana: al lado del binario de la bóveda, o en el PATH (el .deb la pone en /usr/bin). */
|
|
32
|
+
export function findGui ({ platform = process.platform, execPath = process.execPath, env = process.env, exists = fs.existsSync } = {}) {
|
|
33
|
+
const name = GUI_NAME(platform)
|
|
34
|
+
const side = path.join(path.dirname(execPath), name)
|
|
35
|
+
if (exists(side)) return side
|
|
36
|
+
for (const dir of String(env.PATH || '').split(path.delimiter).filter(Boolean)) {
|
|
37
|
+
const p = path.join(dir, name)
|
|
38
|
+
if (exists(p)) return p
|
|
39
|
+
}
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Las variables de una sesión gráfica en Linux, sacadas de un entorno. `null` = no hay. */
|
|
44
|
+
export function graphicalEnv (env) {
|
|
45
|
+
const out = {}
|
|
46
|
+
for (const k of ['DISPLAY', 'WAYLAND_DISPLAY', 'XAUTHORITY', 'DBUS_SESSION_BUS_ADDRESS', 'XDG_CURRENT_DESKTOP']) {
|
|
47
|
+
if (env[k]) out[k] = env[k]
|
|
48
|
+
}
|
|
49
|
+
return out.DISPLAY || out.WAYLAND_DISPLAY ? out : null
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** `KEY=valor` por línea (lo que imprime `systemctl --user show-environment`). */
|
|
53
|
+
export function parseEnvLines (text) {
|
|
54
|
+
const env = {}
|
|
55
|
+
for (const line of String(text).split('\n')) {
|
|
56
|
+
const i = line.indexOf('=')
|
|
57
|
+
if (i > 0) env[line.slice(0, i)] = line.slice(i + 1)
|
|
58
|
+
}
|
|
59
|
+
return env
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const managerEnv = () => new Promise((resolve) => {
|
|
63
|
+
execFile('systemctl', ['--user', 'show-environment'], { timeout: 5000 }, (err, out) => resolve(err ? {} : parseEnvLines(out)))
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
/** ¿Hay sesión gráfica ahora? Devuelve las variables que hay que pasarle al icono, o null. */
|
|
67
|
+
async function sessionNow (platform, env) {
|
|
68
|
+
if (platform === 'win32') return {}
|
|
69
|
+
if (platform !== 'linux') return null
|
|
70
|
+
const own = graphicalEnv(env)
|
|
71
|
+
if (own) return own
|
|
72
|
+
if (env.INVOCATION_ID) return graphicalEnv(await managerEnv())
|
|
73
|
+
return null
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Lanza y mantiene el icono mientras viva este proceso. No hace nada si no es el binario, si
|
|
78
|
+
* no hay ventana instalada o si el sistema no tiene icono todavía.
|
|
79
|
+
*/
|
|
80
|
+
export function startTray ({ log = console.log, platform = process.platform, env = process.env, sea = !!globalThis.__DOTRINO_SEA__ } = {}) {
|
|
81
|
+
if (!sea || (platform !== 'linux' && platform !== 'win32')) return null
|
|
82
|
+
const gui = findGui({ platform, env })
|
|
83
|
+
if (!gui) return null
|
|
84
|
+
let stopped = false
|
|
85
|
+
let timer = null
|
|
86
|
+
let child = null
|
|
87
|
+
|
|
88
|
+
const later = () => { if (!stopped) { timer = setTimeout(tick, RETRY_MS); timer.unref?.() } }
|
|
89
|
+
|
|
90
|
+
async function tick () {
|
|
91
|
+
timer = null
|
|
92
|
+
if (stopped) return
|
|
93
|
+
const session = await sessionNow(platform, env)
|
|
94
|
+
if (!session) return later()
|
|
95
|
+
try {
|
|
96
|
+
// La entrada por tubería ES el hilo de vida: el icono termina al leer su fin.
|
|
97
|
+
child = spawn(gui, ['--tray'], { env: { ...env, ...session }, stdio: ['pipe', 'ignore', 'ignore'], windowsHide: true })
|
|
98
|
+
} catch (e) {
|
|
99
|
+
log('[vault] tray icon: could not start %s (%s)', gui, e.message)
|
|
100
|
+
return later()
|
|
101
|
+
}
|
|
102
|
+
child.on('error', (e) => log('[vault] tray icon: %s', e.message))
|
|
103
|
+
child.on('exit', (code) => {
|
|
104
|
+
child = null
|
|
105
|
+
if (stopped) return
|
|
106
|
+
if (code === NO_TRAY_EXIT) { log('[vault] tray icon: this session has no system tray'); return }
|
|
107
|
+
later()
|
|
108
|
+
})
|
|
109
|
+
// El icono no debe retener al daemon: el daemon se va cuando le toca y la tubería se cierra.
|
|
110
|
+
child.unref()
|
|
111
|
+
child.stdin.on('error', () => {})
|
|
112
|
+
child.stdin.unref?.()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
tick()
|
|
116
|
+
return {
|
|
117
|
+
stop () {
|
|
118
|
+
stopped = true
|
|
119
|
+
if (timer) clearTimeout(timer)
|
|
120
|
+
try { child?.stdin.end() } catch (_) {}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|