@dotrino/vaultd 0.199.0 → 0.199.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/tray.js +43 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/vaultd",
3
- "version": "0.199.0",
3
+ "version": "0.199.1",
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/tray.js CHANGED
@@ -17,6 +17,16 @@
17
17
  *
18
18
  * Solo en el binario (SEA): desde npm no hay ventana al lado, y en desarrollo cada prueba que
19
19
  * arranca un daemon sacaría un icono.
20
+ *
21
+ * Solo una ventana que sabe hacer de icono. Una anterior a la 0.199.0 no conoce `--tray` y abre
22
+ * la interfaz entera; al cerrarla salía con 0 y el daemon la relanzaba a los 30 s: la ventana
23
+ * «se abría sola» cada rato. Pasa cuando la ventana viene de otra instalación que no se
24
+ * actualiza con el daemon (un .deb viejo en /usr/bin y el daemon autoactualizado en
25
+ * ~/.local/share/dotrino/bin). Por eso:
26
+ * - antes de lanzarla se busca en el binario la marca `TRAY_MARKER` (desktop/src/tray.rs);
27
+ * sin ella no se lanza y se dice en el log;
28
+ * - si el icono sale con 0 sin que el daemon lo haya parado, no era un icono (alguien cerró
29
+ * una ventana): no se relanza y se dice en el log.
20
30
  */
21
31
  import fs from 'node:fs'
22
32
  import path from 'node:path'
@@ -25,6 +35,8 @@ import { execFile, spawn } from 'node:child_process'
25
35
  const RETRY_MS = 30_000
26
36
  /** Código con el que sale `--tray` cuando en esta sesión no puede haber icono. */
27
37
  export const NO_TRAY_EXIT = 3
38
+ /** La marca de una ventana que entiende `--tray`. La misma que `TRAY_MARKER` en desktop/src/tray.rs. */
39
+ export const TRAY_MARKER = 'dotrino-vault-desktop:tray:v1'
28
40
 
29
41
  const GUI_NAME = (platform) => platform === 'win32' ? 'dotrino-vault-desktop.exe' : 'dotrino-vault-desktop'
30
42
 
@@ -40,6 +52,11 @@ export function findGui ({ platform = process.platform, execPath = process.execP
40
52
  return null
41
53
  }
42
54
 
55
+ /** ¿Este binario de la ventana entiende `--tray`? Se mira sin ejecutarlo: ejecutarlo es justo lo que abre la ventana. */
56
+ export function guiSupportsTray (gui, { read = fs.readFileSync } = {}) {
57
+ return read(gui).includes(Buffer.from(TRAY_MARKER))
58
+ }
59
+
43
60
  /** Las variables de una sesión gráfica en Linux, sacadas de un entorno. `null` = no hay. */
44
61
  export function graphicalEnv (env) {
45
62
  const out = {}
@@ -77,13 +94,28 @@ async function sessionNow (platform, env) {
77
94
  * Lanza y mantiene el icono mientras viva este proceso. No hace nada si no es el binario, si
78
95
  * no hay ventana instalada o si el sistema no tiene icono todavía.
79
96
  */
80
- export function startTray ({ log = console.log, platform = process.platform, env = process.env, sea = !!globalThis.__DOTRINO_SEA__ } = {}) {
97
+ export function startTray ({ log = console.log, platform = process.platform, env = process.env, sea = !!globalThis.__DOTRINO_SEA__, find = findGui, supports = guiSupportsTray, spawnFn = spawn } = {}) {
81
98
  if (!sea || (platform !== 'linux' && platform !== 'win32')) return null
82
- const gui = findGui({ platform, env })
83
- if (!gui) return null
99
+ const gui = find({ platform, env })
100
+ if (!gui) {
101
+ log('[vault] tray icon: %s not found next to the vault or in PATH; no tray icon', GUI_NAME(platform))
102
+ return null
103
+ }
104
+ let ok
105
+ try {
106
+ ok = supports(gui)
107
+ } catch (e) {
108
+ log('[vault] tray icon: could not read %s (%s); no tray icon', gui, e.message)
109
+ return null
110
+ }
111
+ if (!ok) {
112
+ log('[vault] tray icon: %s is too old for --tray (it would open the full window); update it to 0.199.0 or later', gui)
113
+ return null
114
+ }
84
115
  let stopped = false
85
116
  let timer = null
86
117
  let child = null
118
+ let waitingLogged = false
87
119
 
88
120
  const later = () => { if (!stopped) { timer = setTimeout(tick, RETRY_MS); timer.unref?.() } }
89
121
 
@@ -91,10 +123,13 @@ export function startTray ({ log = console.log, platform = process.platform, env
91
123
  timer = null
92
124
  if (stopped) return
93
125
  const session = await sessionNow(platform, env)
94
- if (!session) return later()
126
+ if (!session) {
127
+ if (!waitingLogged) { waitingLogged = true; log('[vault] tray icon: no graphical session yet (no DISPLAY or WAYLAND_DISPLAY); checking again every %ds', RETRY_MS / 1000) }
128
+ return later()
129
+ }
95
130
  try {
96
131
  // 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 })
132
+ child = spawnFn(gui, ['--tray'], { env: { ...env, ...session }, stdio: ['pipe', 'ignore', 'ignore'], windowsHide: true })
98
133
  } catch (e) {
99
134
  log('[vault] tray icon: could not start %s (%s)', gui, e.message)
100
135
  return later()
@@ -104,6 +139,9 @@ export function startTray ({ log = console.log, platform = process.platform, env
104
139
  child = null
105
140
  if (stopped) return
106
141
  if (code === NO_TRAY_EXIT) { log('[vault] tray icon: this session has no system tray'); return }
142
+ // `--tray` solo sale con 0 al cerrarse su entrada, y eso lo hace el daemon al pararlo.
143
+ if (code === 0) { log('[vault] tray icon: %s exited by itself, so it is not a tray icon; not starting it again', gui); return }
144
+ log('[vault] tray icon: %s exited with code %s; retrying in %ds', gui, code, RETRY_MS / 1000)
107
145
  later()
108
146
  })
109
147
  // El icono no debe retener al daemon: el daemon se va cuando le toca y la tubería se cierra.