@dotrino/remote-desktop-agent 0.3.0 → 0.3.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/desktop.js +25 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/raise.js +24 -6
package/desktop.js
CHANGED
|
@@ -46,6 +46,8 @@ export function makeDesktop (opts = {}) {
|
|
|
46
46
|
const watchers = new Set()
|
|
47
47
|
/** @type {Map<string, number>} el proceso de cada app, por su nombre en el bus */
|
|
48
48
|
const pids = new Map()
|
|
49
|
+
/** @type {Map<number, number>} el proceso de cada ventana sin accesibilidad (por su id de nodo) */
|
|
50
|
+
const synthPids = new Map()
|
|
49
51
|
/** @type {Set<string>} apps (su nombre en el bus) con algo nuevo */
|
|
50
52
|
const dirtyApps = new Set()
|
|
51
53
|
let fullDue = true
|
|
@@ -112,6 +114,8 @@ export function makeDesktop (opts = {}) {
|
|
|
112
114
|
// Cuál está activa lo dice el gestor de ventanas si se le puede preguntar: la accesibilidad
|
|
113
115
|
// la informa mal (una app de Electron se queda «activa» para siempre).
|
|
114
116
|
const real = await activeWindow()
|
|
117
|
+
/** @type {Node | null} la ventana activa cuando no publica accesibilidad */
|
|
118
|
+
let synth = null
|
|
115
119
|
if (real) {
|
|
116
120
|
for (const w of wins) {
|
|
117
121
|
let pid = pids.get(w.ref[0])
|
|
@@ -119,6 +123,13 @@ export function makeDesktop (opts = {}) {
|
|
|
119
123
|
w.active = pid === real.pid && w.name === real.title
|
|
120
124
|
}
|
|
121
125
|
wins.sort((a, b) => Number(a.active) - Number(b.active))
|
|
126
|
+
// UNA APP SIN ACCESIBILIDAD (la terminal de Dotrino, un juego) no sale en la lista: si es
|
|
127
|
+
// la activa, se enseña igual, como un hueco entero con su sitio y su título. Lleva vídeo.
|
|
128
|
+
if (!wins.some((w) => w.active) && real.w > 0 && real.h > 0) {
|
|
129
|
+
const id = reader.idOf([':x11', `/window/${real.window}`])
|
|
130
|
+
synthPids.set(id, real.pid)
|
|
131
|
+
synth = { id, p: 0, r: 'frame', n: real.title, x: real.x, y: real.y, w: real.w, h: real.h, s: 'a', hole: 1 }
|
|
132
|
+
}
|
|
122
133
|
}
|
|
123
134
|
const full = fullDue
|
|
124
135
|
fullDue = false
|
|
@@ -140,11 +151,13 @@ export function makeDesktop (opts = {}) {
|
|
|
140
151
|
/** @type {Node[]} */
|
|
141
152
|
const nodes = []
|
|
142
153
|
for (const w of wins) { const p = perWin.get(w.id); if (p) nodes.push(...p.nodes) }
|
|
154
|
+
if (synth) nodes.push(synth)
|
|
143
155
|
/** @type {Scene} */
|
|
144
156
|
const next = {
|
|
145
157
|
seq: scene.seq + 1,
|
|
146
158
|
screen: screenOf(wins),
|
|
147
|
-
wins: wins.map((w) => ({ id: w.id, app: w.app, name: w.name, active: w.active })),
|
|
159
|
+
wins: [...wins.map((w) => ({ id: w.id, app: w.app, name: w.name, active: w.active })),
|
|
160
|
+
...(synth ? [{ id: synth.id, app: synth.n || '', name: synth.n || '', active: true }] : [])],
|
|
148
161
|
nodes
|
|
149
162
|
}
|
|
150
163
|
const patch = diff(scene, next)
|
|
@@ -185,6 +198,17 @@ export function makeDesktop (opts = {}) {
|
|
|
185
198
|
get watching () { return watchers.size },
|
|
186
199
|
/** La escena de ahora (la última leída). */
|
|
187
200
|
get scene () { return scene },
|
|
201
|
+
/**
|
|
202
|
+
* El proceso de la app de un nodo: el de una ventana sin accesibilidad lo sabe el gestor de
|
|
203
|
+
* ventanas; el resto, el bus de accesibilidad.
|
|
204
|
+
* @param {number} id
|
|
205
|
+
*/
|
|
206
|
+
async pidOf (id) {
|
|
207
|
+
const p = synthPids.get(id)
|
|
208
|
+
if (p != null) return p
|
|
209
|
+
if (!reader) throw Object.assign(new Error('nobody is watching'), { code: 'not-watching' })
|
|
210
|
+
return reader.pidOf(id)
|
|
211
|
+
},
|
|
188
212
|
/** El lector, para actuar (clic, teclas). `null` si nadie mira. */
|
|
189
213
|
get reader () { return reader },
|
|
190
214
|
stop
|
package/index.js
CHANGED
|
@@ -203,7 +203,7 @@ export function serveSession (session, desktop, { log = () => {}, route = async
|
|
|
203
203
|
if (!int(id)) return fail('bad-input', 'raise needs a window id')
|
|
204
204
|
const win = desktop.scene.wins.find((w) => w.id === id)
|
|
205
205
|
if (!win) return fail('window-not-found', `no window ${id} in the scene`)
|
|
206
|
-
await raiseWindow({ pid: await
|
|
206
|
+
await raiseWindow({ pid: await desktop.pidOf(id), title: win.name })
|
|
207
207
|
return
|
|
208
208
|
}
|
|
209
209
|
case 'key':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/remote-desktop-agent",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Dotrino Remote Desktop: usa el escritorio de esta máquina desde los otros aparatos de tu cuenta. Lo dibuja a partir de su árbol de accesibilidad (ligero y nítido), cifrado punto a punto.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/raise.js
CHANGED
|
@@ -50,19 +50,37 @@ export async function raiseWindow ({ pid, title, session = process.env.XDG_SESSI
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
* La ventana activa DE VERDAD, según el gestor de ventanas: `{ pid, title
|
|
54
|
-
* puede saber (Wayland, sin xdotool). La accesibilidad la informa mal: una app
|
|
55
|
-
* queda «activa» para siempre (visto el 2026-11-16 con dos ventanas activas a la
|
|
53
|
+
* La ventana activa DE VERDAD, según el gestor de ventanas: `{ pid, title, window, x, y, w, h }`,
|
|
54
|
+
* o `null` si no se puede saber (Wayland, sin xdotool). La accesibilidad la informa mal: una app
|
|
55
|
+
* de Electron se queda «activa» para siempre (visto el 2026-11-16 con dos ventanas activas a la
|
|
56
|
+
* vez), y una app sin accesibilidad (la terminal de Dotrino, hecha con iced) ni siquiera sale.
|
|
57
|
+
* Con la posición, el agente puede enseñar esa ventana como un hueco con vídeo.
|
|
56
58
|
* @param {{ session?: string, exec?: typeof run }} [o]
|
|
57
|
-
* @returns {Promise<{ pid: number, title: string } | null>}
|
|
59
|
+
* @returns {Promise<{ pid: number, title: string, window: string, x: number, y: number, w: number, h: number } | null>}
|
|
58
60
|
*/
|
|
59
61
|
export async function activeWindow ({ session = process.env.XDG_SESSION_TYPE || '', exec = run } = {}) {
|
|
60
62
|
if (session === 'wayland') return null
|
|
63
|
+
let out
|
|
61
64
|
try {
|
|
62
|
-
|
|
63
|
-
return pid.trim() ? { pid: Number(pid.trim()), title: title.trim() } : null
|
|
65
|
+
out = await exec('xdotool', ['getactivewindow', 'getwindowname', 'getwindowpid', 'getwindowgeometry', '--shell'])
|
|
64
66
|
} catch (_) {
|
|
65
67
|
// Sin xdotool, o sin ventana activa (el escritorio): no se sabe, y se usa la accesibilidad.
|
|
66
68
|
return null
|
|
67
69
|
}
|
|
70
|
+
return parseActive(out)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Lee lo que contesta `xdotool getactivewindow getwindowname getwindowpid getwindowgeometry --shell`.
|
|
75
|
+
* @param {string} out
|
|
76
|
+
*/
|
|
77
|
+
export function parseActive (out) {
|
|
78
|
+
const lines = out.split('\n')
|
|
79
|
+
const title = (lines[0] || '').trim()
|
|
80
|
+
const pid = Number((lines[1] || '').trim())
|
|
81
|
+
/** @type {Record<string, string>} */
|
|
82
|
+
const kv = {}
|
|
83
|
+
for (const l of lines.slice(2)) { const m = /^([A-Z]+)=(.*)$/.exec(l.trim()); if (m) kv[m[1]] = m[2] }
|
|
84
|
+
if (!pid || !kv.WINDOW) return null
|
|
85
|
+
return { pid, title, window: kv.WINDOW, x: Number(kv.X), y: Number(kv.Y), w: Number(kv.WIDTH), h: Number(kv.HEIGHT) }
|
|
68
86
|
}
|