Comparar commits
2 Commits
v1.20.0
...
ia-del-equ
| Autor | SHA1 | Fecha | |
|---|---|---|---|
|
|
a725900a4a | ||
|
|
6539f6939c |
21
README.md
21
README.md
@@ -20,6 +20,27 @@ NAS. Esto le da al equipo un cliente nativo de verdad en Windows y Mac:
|
|||||||
- **Colores de pestaña** (v1.6.0): clic derecho sobre una pestaña ▸ **Color**, con
|
- **Colores de pestaña** (v1.6.0): clic derecho sobre una pestaña ▸ **Color**, con
|
||||||
la misma paleta de nueve tonos que usa Chrome para sus grupos. Sirve para agrupar
|
la misma paleta de nueve tonos que usa Chrome para sus grupos. Sirve para agrupar
|
||||||
de un vistazo (todo lo de un cliente en verde) y **se guarda con la sesión**.
|
de un vistazo (todo lo de un cliente en verde) y **se guarda con la sesión**.
|
||||||
|
- **Pestaña del color de su página** (v1.21.0): una página puede pedir el color de
|
||||||
|
su pestaña con `<html data-ls-pestana="#rrggbb">` (solo ese formato). El modo
|
||||||
|
edición de un set la pinta del gris del editor: activa se funde con su barra de
|
||||||
|
arriba y detrás se reconoce entre las demás. Esa página no cambia el tema de la
|
||||||
|
barra (su fondo oscuro no es el de la app).
|
||||||
|
- **La IA del equipo** (v1.22.0, Windows con tarjeta NVIDIA): la máscara de «Sujeto» y
|
||||||
|
«Fondo» del editor de revelado la busca la app, no el navegador — ONNX Runtime con
|
||||||
|
DirectML sobre la tarjeta y BiRefNet en media precisión (`src-tauri/src/ia/`): 0,3 s
|
||||||
|
por foto en vez de 2,5–3 s. La primera vez baja ≈700 MB a los datos de la app
|
||||||
|
(`%LOCALAPPDATA%\<identificador>\ia`): ONNX Runtime 1.24.4 DirectML y DirectML 1.15.4
|
||||||
|
de NuGet y el modelo del servidor de la app (`/api/modelos/sujeto-equipo`, con la
|
||||||
|
sesión de la pestaña), todo fijado por huella SHA-256. La página llama a
|
||||||
|
`ia_estado` / `ia_preparar` / `ia_sujeto`, permitidos solo para el origen de la app
|
||||||
|
(`build.rs` + `capabilities/default.json`). El modelo se suelta de la tarjeta a los
|
||||||
|
2 min sin uso. Prueba de punta a punta en la tarjeta del equipo:
|
||||||
|
`LS_IA_DIR=<carpeta> cargo test --lib de_punta_a_punta -- --ignored --nocapture`.
|
||||||
|
- **Pestañas con nombre** (v1.21.0): `window.open(url, "ls-…")` o un enlace con
|
||||||
|
`target="ls-…"` abre la pestaña la primera vez y las siguientes **vuelven a
|
||||||
|
ella** en vez de abrir otra. La página recibe la URL nueva por
|
||||||
|
`window.__lsAbrir(url)` (el modo edición cambia de foto sin recargar); si no lo
|
||||||
|
tiene, navega. Nombre y color se guardan con la sesión.
|
||||||
- **Zoom de interfaz**: ⌘/Ctrl `+` / `−` / `0` y Ctrl+rueda, con indicador en la
|
- **Zoom de interfaz**: ⌘/Ctrl `+` / `−` / `0` y Ctrl+rueda, con indicador en la
|
||||||
barra y **persistencia** entre sesiones (50%–250%).
|
barra y **persistencia** entre sesiones (50%–250%).
|
||||||
- **Documentos dentro de la app**: los visores/editores del propio servidor
|
- **Documentos dentro de la app**: los visores/editores del propio servidor
|
||||||
|
|||||||
27
dist/index.html
vendido
27
dist/index.html
vendido
@@ -7,7 +7,7 @@
|
|||||||
<!--
|
<!--
|
||||||
Barra de pestañas del shell de escritorio (webview "chrome", local).
|
Barra de pestañas del shell de escritorio (webview "chrome", local).
|
||||||
Habla con Rust por eventos (__TAURI__.event):
|
Habla con Rust por eventos (__TAURI__.event):
|
||||||
recibe ls-tabs {tabs:[{label,title,url,loading,active,color}], zoom, version,
|
recibe ls-tabs {tabs:[{label,title,url,loading,active,color,pagina}], zoom, version,
|
||||||
mac, win, maximized, dark}
|
mac, win, maximized, dark}
|
||||||
emite ls-ready, ls-new-tab, ls-activate, ls-close-tab, ls-reload, ls-zoom, ls-cycle,
|
emite ls-ready, ls-new-tab, ls-activate, ls-close-tab, ls-reload, ls-zoom, ls-cycle,
|
||||||
ls-activate-n, ls-nav, ls-menu, ls-check-update, ls-tab-menu, ls-reorder
|
ls-activate-n, ls-nav, ls-menu, ls-check-update, ls-tab-menu, ls-reorder
|
||||||
@@ -208,6 +208,17 @@
|
|||||||
}
|
}
|
||||||
:root.oscuro .tab[data-color]:not(.active) { background: rgba(var(--tc), 0.36); }
|
:root.oscuro .tab[data-color]:not(.active) { background: rgba(var(--tc), 0.36); }
|
||||||
:root.oscuro .tab[data-color]:not(.active):hover { background: rgba(var(--tc), 0.5); }
|
:root.oscuro .tab[data-color]:not(.active):hover { background: rgba(var(--tc), 0.5); }
|
||||||
|
/* ── La pestaña del COLOR DE SU PÁGINA (1.21) ──
|
||||||
|
La página lo pide (`<html data-ls-pestana="#262626">`): el modo edición de un set pinta la
|
||||||
|
suya del gris del editor. Activa, es de ese color y se funde con la barra de arriba de la
|
||||||
|
página, como la de siempre se funde con el blanco de la app. Detrás, el mismo color: entre
|
||||||
|
las demás se reconoce de un vistazo. Con color del menú encima, ese va de franja arriba.
|
||||||
|
(#tabs delante: gana a las reglas de tema y de color del menú sin !important.) */
|
||||||
|
#tabs .tab.pagina { --muted: color-mix(in srgb, var(--tp-fg) 60%, transparent); background: var(--tp); color: var(--tp-fg); }
|
||||||
|
#tabs .tab.pagina:not(.active) { box-shadow: none; }
|
||||||
|
#tabs .tab.pagina:not(.active):hover { background: color-mix(in srgb, var(--tp) 86%, var(--tp-fg)); color: var(--tp-fg); }
|
||||||
|
#tabs .tab.pagina .cerrar:hover { background: color-mix(in srgb, var(--tp-fg) 18%, transparent); color: var(--tp-fg); }
|
||||||
|
#tabs .tab.pagina[data-color] { box-shadow: inset 0 3px 0 rgb(var(--tc)); }
|
||||||
/* Reordenar arrastrando: NO se usa drag&drop de HTML5 (en el webview de la barra en
|
/* Reordenar arrastrando: NO se usa drag&drop de HTML5 (en el webview de la barra en
|
||||||
macOS los eventos no llegan), sino eventos de puntero. Se apaga el arrastre nativo de
|
macOS los eventos no llegan), sino eventos de puntero. Se apaga el arrastre nativo de
|
||||||
WebKit para que no salga la imagen fantasma al mover una pestaña. */
|
WebKit para que no salga la imagen fantasma al mover una pestaña. */
|
||||||
@@ -500,6 +511,14 @@
|
|||||||
$tabs.classList.toggle("compactas", ancho < 112);
|
$tabs.classList.toggle("compactas", ancho < 112);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ¿Un #rrggbb claro? (luminancia relativa): decide si la letra encima va oscura o clara.
|
||||||
|
function esClaro(hex) {
|
||||||
|
const n = parseInt(hex.slice(1), 16);
|
||||||
|
const lin = (c) => { c /= 255; return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4; };
|
||||||
|
const l = 0.2126 * lin((n >> 16) & 255) + 0.7152 * lin((n >> 8) & 255) + 0.0722 * lin(n & 255);
|
||||||
|
return l > 0.35;
|
||||||
|
}
|
||||||
|
|
||||||
function render() {
|
function render() {
|
||||||
$tabs.textContent = "";
|
$tabs.textContent = "";
|
||||||
for (const t of estado.tabs) {
|
for (const t of estado.tabs) {
|
||||||
@@ -508,6 +527,12 @@
|
|||||||
el.className = "tab" + (t.active ? " active" : "");
|
el.className = "tab" + (t.active ? " active" : "");
|
||||||
el.dataset.label = t.label;
|
el.dataset.label = t.label;
|
||||||
if (t.color) el.dataset.color = t.color; // teñido desde el menú de la pestaña
|
if (t.color) el.dataset.color = t.color; // teñido desde el menú de la pestaña
|
||||||
|
// El color que pide la página (ya validado #rrggbb en el shell), con letra que se lea encima.
|
||||||
|
if (t.pagina) {
|
||||||
|
el.classList.add("pagina");
|
||||||
|
el.style.setProperty("--tp", t.pagina);
|
||||||
|
el.style.setProperty("--tp-fg", esClaro(t.pagina) ? "#202124" : "#ececec");
|
||||||
|
}
|
||||||
el.title = texto;
|
el.title = texto;
|
||||||
|
|
||||||
const fav = document.createElement("span");
|
const fav = document.createElement("span");
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "labstream-desktop",
|
"name": "labstream-desktop",
|
||||||
"version": "1.20.0",
|
"version": "1.22.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "App de escritorio (Windows) que envuelve Labstream OS — cliente del servidor del NAS.",
|
"description": "App de escritorio (Windows) que envuelve Labstream OS — cliente del servidor del NAS.",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
119
src-tauri/Cargo.lock
generado
119
src-tauri/Cargo.lock
generado
@@ -1319,6 +1319,7 @@ checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"crc32fast",
|
"crc32fast",
|
||||||
"miniz_oxide",
|
"miniz_oxide",
|
||||||
|
"zlib-rs",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2366,15 +2367,17 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "labstream-desktop"
|
name = "labstream-desktop"
|
||||||
version = "1.20.0"
|
version = "1.22.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"active-win-pos-rs",
|
"active-win-pos-rs",
|
||||||
"device_query",
|
"device_query",
|
||||||
"gethostname 0.5.0",
|
"gethostname 0.5.0",
|
||||||
|
"ort",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"rfd",
|
"rfd",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"sha2",
|
||||||
"tauri",
|
"tauri",
|
||||||
"tauri-build",
|
"tauri-build",
|
||||||
"tauri-plugin-autostart",
|
"tauri-plugin-autostart",
|
||||||
@@ -2386,6 +2389,7 @@ dependencies = [
|
|||||||
"ureq",
|
"ureq",
|
||||||
"webview2-com",
|
"webview2-com",
|
||||||
"windows 0.61.3",
|
"windows 0.61.3",
|
||||||
|
"zip",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2459,6 +2463,16 @@ dependencies = [
|
|||||||
"windows-link 0.2.1",
|
"windows-link 0.2.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libloading"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "754ca22de805bb5744484a5b151a9e1a8e837d5dc232c2d7d8c2e3492edc8b60"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"windows-link 0.2.1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libredox"
|
name = "libredox"
|
||||||
version = "0.1.17"
|
version = "0.1.17"
|
||||||
@@ -2545,6 +2559,16 @@ dependencies = [
|
|||||||
"web_atoms",
|
"web_atoms",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "matrixmultiply"
|
||||||
|
version = "0.3.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3f607c237553f086e7043417a51df26b2eb899d3caff94e6a67592ff992fedc7"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"rawpointer",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.8.2"
|
version = "2.8.2"
|
||||||
@@ -2630,6 +2654,21 @@ dependencies = [
|
|||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ndarray"
|
||||||
|
version = "0.17.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "520080814a7a6b4a6e9070823bb24b4531daac8c4627e08ba5de8c5ef2f2752d"
|
||||||
|
dependencies = [
|
||||||
|
"matrixmultiply",
|
||||||
|
"num-complex",
|
||||||
|
"num-integer",
|
||||||
|
"num-traits",
|
||||||
|
"portable-atomic",
|
||||||
|
"portable-atomic-util",
|
||||||
|
"rawpointer",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ndk"
|
name = "ndk"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
@@ -2693,12 +2732,30 @@ dependencies = [
|
|||||||
"zbus",
|
"zbus",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-complex"
|
||||||
|
version = "0.4.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-conv"
|
name = "num-conv"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441"
|
checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-integer"
|
||||||
|
version = "0.1.47"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7ce2d95d4b3734dc35aa2f45e1aa22cd416814592a4f9d9205e11affd5b8e10b"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-modular"
|
name = "num-modular"
|
||||||
version = "0.6.5"
|
version = "0.6.5"
|
||||||
@@ -3003,6 +3060,25 @@ dependencies = [
|
|||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ort"
|
||||||
|
version = "2.0.0-rc.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "08ca9287c05aace7e95250104a00d54b7da0fc9ac5f25efa424b80827d2e25eb"
|
||||||
|
dependencies = [
|
||||||
|
"libloading 0.9.0",
|
||||||
|
"ndarray",
|
||||||
|
"ort-sys",
|
||||||
|
"smallvec",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ort-sys"
|
||||||
|
version = "2.0.0-rc.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4af4763e553f916650b0bfe4b8d217d61c28607f6117e48b8ab5584d1138f22f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "os_pipe"
|
name = "os_pipe"
|
||||||
version = "1.2.3"
|
version = "1.2.3"
|
||||||
@@ -3287,6 +3363,21 @@ dependencies = [
|
|||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "portable-atomic"
|
||||||
|
version = "1.15.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "portable-atomic-util"
|
||||||
|
version = "0.2.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "10ab3eb7f3becc3a1cbc4f2c6f20267996cfc1a6467a873763411b136a122715"
|
||||||
|
dependencies = [
|
||||||
|
"portable-atomic",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "potential_utf"
|
name = "potential_utf"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
@@ -3475,6 +3566,12 @@ version = "0.6.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "20675572f6f24e9e76ef639bc5552774ed45f1c30e2951e1e99c59888861c539"
|
checksum = "20675572f6f24e9e76ef639bc5552774ed45f1c30e2951e1e99c59888861c539"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rawpointer"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "readkey"
|
name = "readkey"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
@@ -6484,16 +6581,36 @@ checksum = "caa8cd6af31c3b31c6631b8f483848b91589021b28fffe50adada48d4f4d2ed1"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"arbitrary",
|
"arbitrary",
|
||||||
"crc32fast",
|
"crc32fast",
|
||||||
|
"flate2",
|
||||||
"indexmap 2.14.0",
|
"indexmap 2.14.0",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
"zopfli",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zlib-rs"
|
||||||
|
version = "0.6.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zmij"
|
name = "zmij"
|
||||||
version = "1.0.21"
|
version = "1.0.21"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
|
checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zopfli"
|
||||||
|
version = "0.8.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f05cd8797d63865425ff89b5c4a48804f35ba0ce8d125800027ad6017d2b5249"
|
||||||
|
dependencies = [
|
||||||
|
"bumpalo",
|
||||||
|
"crc32fast",
|
||||||
|
"log",
|
||||||
|
"simd-adler32",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zune-core"
|
name = "zune-core"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "labstream-desktop"
|
name = "labstream-desktop"
|
||||||
version = "1.20.0"
|
version = "1.22.0"
|
||||||
description = "Cliente de escritorio de Labstream OS"
|
description = "Cliente de escritorio de Labstream OS"
|
||||||
authors = ["Labstream SAS"]
|
authors = ["Labstream SAS"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
@@ -49,6 +49,10 @@ percent-encoding = "2"
|
|||||||
active-win-pos-rs = "0.11"
|
active-win-pos-rs = "0.11"
|
||||||
ureq = { version = "2", features = ["json"] }
|
ureq = { version = "2", features = ["json"] }
|
||||||
gethostname = "0.5"
|
gethostname = "0.5"
|
||||||
|
# ── La IA del equipo (src/ia, 1.22) ──
|
||||||
|
# sha2: la huella de lo que se baja (modelo y motor); zip: sacar las DLL del paquete del motor.
|
||||||
|
sha2 = "0.10"
|
||||||
|
zip = { version = "4", default-features = false, features = ["deflate"] }
|
||||||
|
|
||||||
# device_query solo en Windows/Linux: la huella de entrada (posición del mouse + cuántas teclas
|
# device_query solo en Windows/Linux: la huella de entrada (posición del mouse + cuántas teclas
|
||||||
# hay presionadas). En macOS NO se usa —leer el teclado global dispara el permiso de
|
# hay presionadas). En macOS NO se usa —leer el teclado global dispara el permiso de
|
||||||
@@ -64,6 +68,10 @@ device_query = "4"
|
|||||||
# Solo Windows: en macOS no hay API pública sencilla de nivel de audio por app (el equipo de
|
# Solo Windows: en macOS no hay API pública sencilla de nivel de audio por app (el equipo de
|
||||||
# edición es Windows). El `windows` crate ya está en la caché por Tauri.
|
# edición es Windows). El `windows` crate ya está en la caché por Tauri.
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
|
# IA del equipo (1.22, src/ia/motor.rs): ONNX Runtime con DirectML sobre la tarjeta. `load-dynamic`:
|
||||||
|
# nada se enlaza al compilar; la DLL (la de DirectML 1.24, de NuGet) se baja la primera vez y se
|
||||||
|
# carga desde la carpeta de la IA. `api-24`: la versión de la API que trae esa DLL.
|
||||||
|
ort = { version = "=2.0.0-rc.14", default-features = false, features = ["std", "load-dynamic", "directml", "api-24"] }
|
||||||
# Pestañas en reposo (1.19): ICoreWebView2_3::TrySuspend. Es la misma versión que ya trae Tauri.
|
# Pestañas en reposo (1.19): ICoreWebView2_3::TrySuspend. Es la misma versión que ya trae Tauri.
|
||||||
webview2-com = "0.38"
|
webview2-com = "0.38"
|
||||||
windows = { version = "0.61", features = [
|
windows = { version = "0.61", features = [
|
||||||
@@ -83,4 +91,8 @@ windows = { version = "0.61", features = [
|
|||||||
# Memoria (1.20): ¿cuánto lleva el equipo sin tocar? (para reciclar el proceso gráfico sin que se note)
|
# Memoria (1.20): ¿cuánto lleva el equipo sin tocar? (para reciclar el proceso gráfico sin que se note)
|
||||||
"Win32_UI_Input_KeyboardAndMouse",
|
"Win32_UI_Input_KeyboardAndMouse",
|
||||||
"Win32_System_SystemInformation",
|
"Win32_System_SystemInformation",
|
||||||
|
# IA del equipo (1.22): ¿hay tarjeta NVIDIA? (los adaptadores de DXGI)
|
||||||
|
"Win32_Graphics_Dxgi",
|
||||||
|
# y cargar DirectML.dll por su ruta antes que ONNX Runtime (src/ia/motor.rs)
|
||||||
|
"Win32_System_LibraryLoader",
|
||||||
] }
|
] }
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
tauri_build::build()
|
// Los comandos de la app (la IA del equipo, src/ia): con su manifiesto, cada uno necesita su
|
||||||
|
// permiso en capabilities/default.json, y es lo que deja que la página remota los llame.
|
||||||
|
tauri_build::try_build(
|
||||||
|
tauri_build::Attributes::new()
|
||||||
|
.app_manifest(tauri_build::AppManifest::new().commands(&["ia_estado", "ia_preparar", "ia_sujeto"])),
|
||||||
|
)
|
||||||
|
.expect("tauri-build");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,9 @@
|
|||||||
"core:default",
|
"core:default",
|
||||||
"opener:default",
|
"opener:default",
|
||||||
"notification:default",
|
"notification:default",
|
||||||
"core:window:allow-start-dragging"
|
"core:window:allow-start-dragging",
|
||||||
|
"allow-ia-estado",
|
||||||
|
"allow-ia-preparar",
|
||||||
|
"allow-ia-sujeto"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
11
src-tauri/permissions/autogenerated/ia_estado.toml
Archivo normal
11
src-tauri/permissions/autogenerated/ia_estado.toml
Archivo normal
@@ -0,0 +1,11 @@
|
|||||||
|
# Automatically generated - DO NOT EDIT!
|
||||||
|
|
||||||
|
[[permission]]
|
||||||
|
identifier = "allow-ia-estado"
|
||||||
|
description = "Enables the ia_estado command without any pre-configured scope."
|
||||||
|
commands.allow = ["ia_estado"]
|
||||||
|
|
||||||
|
[[permission]]
|
||||||
|
identifier = "deny-ia-estado"
|
||||||
|
description = "Denies the ia_estado command without any pre-configured scope."
|
||||||
|
commands.deny = ["ia_estado"]
|
||||||
11
src-tauri/permissions/autogenerated/ia_preparar.toml
Archivo normal
11
src-tauri/permissions/autogenerated/ia_preparar.toml
Archivo normal
@@ -0,0 +1,11 @@
|
|||||||
|
# Automatically generated - DO NOT EDIT!
|
||||||
|
|
||||||
|
[[permission]]
|
||||||
|
identifier = "allow-ia-preparar"
|
||||||
|
description = "Enables the ia_preparar command without any pre-configured scope."
|
||||||
|
commands.allow = ["ia_preparar"]
|
||||||
|
|
||||||
|
[[permission]]
|
||||||
|
identifier = "deny-ia-preparar"
|
||||||
|
description = "Denies the ia_preparar command without any pre-configured scope."
|
||||||
|
commands.deny = ["ia_preparar"]
|
||||||
11
src-tauri/permissions/autogenerated/ia_sujeto.toml
Archivo normal
11
src-tauri/permissions/autogenerated/ia_sujeto.toml
Archivo normal
@@ -0,0 +1,11 @@
|
|||||||
|
# Automatically generated - DO NOT EDIT!
|
||||||
|
|
||||||
|
[[permission]]
|
||||||
|
identifier = "allow-ia-sujeto"
|
||||||
|
description = "Enables the ia_sujeto command without any pre-configured scope."
|
||||||
|
commands.allow = ["ia_sujeto"]
|
||||||
|
|
||||||
|
[[permission]]
|
||||||
|
identifier = "deny-ia-sujeto"
|
||||||
|
description = "Denies the ia_sujeto command without any pre-configured scope."
|
||||||
|
commands.deny = ["ia_sujeto"]
|
||||||
170
src-tauri/src/ia/bajar.rs
Archivo normal
170
src-tauri/src/ia/bajar.rs
Archivo normal
@@ -0,0 +1,170 @@
|
|||||||
|
// ── Bajar las piezas de la IA: comprobadas con su huella y, si vienen en un zip, sacadas de él ──
|
||||||
|
//
|
||||||
|
// Todo va a la carpeta de la IA en los datos de la app del equipo (`ia::carpeta`). Cada pieza se
|
||||||
|
// baja a un `.parte`, se le saca la huella SHA-256 MIENTRAS llega y solo si cuadra con la anotada
|
||||||
|
// en el código pasa a su sitio; al acabar se deja una marca `<nombre>.ok` con la huella, que es lo
|
||||||
|
// que se mira después para saber si está (un archivo a medias nunca tiene marca).
|
||||||
|
|
||||||
|
use sha2::{Digest, Sha256};
|
||||||
|
use std::fs::{self, File};
|
||||||
|
use std::io::{self, BufReader, BufWriter, Read, Write};
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
/// Una pieza que se baja: un archivo tal cual o un zip del que se sacan unos archivos.
|
||||||
|
pub struct Pieza {
|
||||||
|
/// Nombre corto (la marca `.ok` y los avisos).
|
||||||
|
pub nombre: &'static str,
|
||||||
|
pub url: &'static str,
|
||||||
|
/// Huella SHA-256 del archivo bajado, en hexadecimal.
|
||||||
|
pub sha256: &'static str,
|
||||||
|
pub bytes: u64,
|
||||||
|
pub forma: Forma,
|
||||||
|
/// Se pide con la sesión de la pestaña (lo sirve el servidor de la app solo al equipo).
|
||||||
|
pub con_sesion: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Forma {
|
||||||
|
/// El archivo, con este nombre, en la carpeta de la IA.
|
||||||
|
Archivo(&'static str),
|
||||||
|
/// Un zip (un .nupkg lo es): de él, estos archivos —por su ruta EXACTA dentro: un paquete trae
|
||||||
|
/// varias DLL con el mismo nombre (x86, arm64, Xbox…)— a la carpeta de la IA, con su nombre.
|
||||||
|
Zip(&'static [&'static str]),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn marca(dir: &Path, p: &Pieza) -> PathBuf {
|
||||||
|
dir.join(format!("{}.ok", p.nombre))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ¿Está ya en el equipo (con su marca y la huella de ahora)?
|
||||||
|
pub fn esta(dir: &Path, p: &Pieza) -> bool {
|
||||||
|
fs::read_to_string(marca(dir, p)).map(|s| s.trim() == p.sha256).unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Baja la pieza (si no está) avisando de lo que lleva con `avance(bytes_nuevos)`. `sesion`: las
|
||||||
|
/// cookies de la pestaña para el servidor de la app (solo viajan a él: `con_sesion` y su origen).
|
||||||
|
pub fn bajar(dir: &Path, p: &Pieza, sesion: Option<&str>, avance: &mut dyn FnMut(u64)) -> Result<(), String> {
|
||||||
|
if esta(dir, p) {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
fs::create_dir_all(dir).map_err(|e| format!("No se pudo crear la carpeta de la IA: {e}"))?;
|
||||||
|
let parte = dir.join(format!("{}.parte", p.nombre));
|
||||||
|
let mut pedido = ureq::AgentBuilder::new()
|
||||||
|
.timeout_connect(Duration::from_secs(20))
|
||||||
|
.timeout_read(Duration::from_secs(60))
|
||||||
|
.build()
|
||||||
|
.get(p.url);
|
||||||
|
if p.con_sesion && p.url.starts_with(&format!("{}/", crate::SERVER_URL)) {
|
||||||
|
if let Some(c) = sesion.filter(|c| !c.is_empty()) {
|
||||||
|
pedido = pedido.set("Cookie", c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let resp = pedido.call().map_err(|e| match e {
|
||||||
|
ureq::Error::Status(401, _) => format!("No se pudo bajar {}: la sesión de la app caducó (vuelve a entrar).", p.nombre),
|
||||||
|
e => format!("No se pudo bajar {}: {e}", p.nombre),
|
||||||
|
})?;
|
||||||
|
let mut leer = resp.into_reader();
|
||||||
|
let mut escribir = BufWriter::new(File::create(&parte).map_err(|e| format!("No se pudo escribir {}: {e}", p.nombre))?);
|
||||||
|
let mut huella = Sha256::new();
|
||||||
|
let mut buf = vec![0u8; 1 << 20];
|
||||||
|
let mut total: u64 = 0;
|
||||||
|
loop {
|
||||||
|
let n = leer.read(&mut buf).map_err(|e| format!("La descarga de {} se cortó: {e}", p.nombre))?;
|
||||||
|
if n == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
huella.update(&buf[..n]);
|
||||||
|
escribir.write_all(&buf[..n]).map_err(|e| format!("No se pudo escribir {}: {e}", p.nombre))?;
|
||||||
|
total += n as u64;
|
||||||
|
avance(n as u64);
|
||||||
|
}
|
||||||
|
escribir.flush().map_err(|e| format!("No se pudo escribir {}: {e}", p.nombre))?;
|
||||||
|
drop(escribir);
|
||||||
|
let hex = huella.finalize().iter().map(|b| format!("{b:02x}")).collect::<String>();
|
||||||
|
if hex != p.sha256 {
|
||||||
|
let _ = fs::remove_file(&parte);
|
||||||
|
return Err(format!("{} llegó distinto de lo esperado ({total} bytes). Vuelve a intentarlo.", p.nombre));
|
||||||
|
}
|
||||||
|
match p.forma {
|
||||||
|
Forma::Archivo(destino) => {
|
||||||
|
let d = dir.join(destino);
|
||||||
|
let _ = fs::remove_file(&d);
|
||||||
|
fs::rename(&parte, &d).map_err(|e| format!("No se pudo guardar {}: {e}", p.nombre))?;
|
||||||
|
}
|
||||||
|
Forma::Zip(quiero) => {
|
||||||
|
let r = extraer(&parte, dir, quiero);
|
||||||
|
let _ = fs::remove_file(&parte);
|
||||||
|
r?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fs::write(marca(dir, p), p.sha256).map_err(|e| format!("No se pudo guardar {}: {e}", p.nombre))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Saca del zip los archivos de `quiero` (rutas exactas dentro del zip) a `dir`, con su nombre.
|
||||||
|
fn extraer(zip: &Path, dir: &Path, quiero: &[&str]) -> Result<(), String> {
|
||||||
|
let f = File::open(zip).map_err(|e| format!("No se pudo abrir lo bajado: {e}"))?;
|
||||||
|
let mut z = zip::ZipArchive::new(BufReader::new(f)).map_err(|e| format!("Lo bajado no es un zip válido: {e}"))?;
|
||||||
|
let mut faltan: Vec<&str> = quiero.to_vec();
|
||||||
|
for i in 0..z.len() {
|
||||||
|
let mut e = z.by_index(i).map_err(|e| format!("El zip está dañado: {e}"))?;
|
||||||
|
if e.is_dir() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let ruta = e.name().replace('\\', "/");
|
||||||
|
let nombre = ruta.rsplit('/').next().unwrap_or("").to_string();
|
||||||
|
if nombre.is_empty() || nombre.contains("..") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let Some(k) = faltan.iter().position(|q| q.eq_ignore_ascii_case(&ruta)) {
|
||||||
|
faltan.remove(k);
|
||||||
|
let destino = dir.join(&nombre);
|
||||||
|
let tmp = dir.join(format!("{nombre}.parte"));
|
||||||
|
let mut out = BufWriter::new(File::create(&tmp).map_err(|e| format!("No se pudo escribir {nombre}: {e}"))?);
|
||||||
|
io::copy(&mut e, &mut out).map_err(|e| format!("No se pudo sacar {nombre}: {e}"))?;
|
||||||
|
out.flush().map_err(|e| format!("No se pudo escribir {nombre}: {e}"))?;
|
||||||
|
drop(out);
|
||||||
|
let _ = fs::remove_file(&destino);
|
||||||
|
fs::rename(&tmp, &destino).map_err(|e| format!("No se pudo guardar {nombre}: {e}"))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if faltan.is_empty() {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(format!("En lo bajado no vinieron: {}", faltan.join(", ")))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod pruebas {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn saca_del_zip_solo_lo_pedido_y_dice_lo_que_falta() {
|
||||||
|
let dir = std::env::temp_dir().join(format!("ls-ia-prueba-{}", std::process::id()));
|
||||||
|
let _ = fs::remove_dir_all(&dir);
|
||||||
|
fs::create_dir_all(&dir).unwrap();
|
||||||
|
let zp = dir.join("x.zip");
|
||||||
|
{
|
||||||
|
let mut w = zip::ZipWriter::new(File::create(&zp).unwrap());
|
||||||
|
let o: zip::write::SimpleFileOptions = Default::default();
|
||||||
|
w.start_file("bin/x64-xbox/a.dll", o).unwrap();
|
||||||
|
w.write_all(b"XBOX").unwrap();
|
||||||
|
w.start_file("bin/x64-win/a.dll", o).unwrap();
|
||||||
|
w.write_all(b"AAA").unwrap();
|
||||||
|
w.start_file("bin/x64-win/b.dll", o).unwrap();
|
||||||
|
w.write_all(b"BBB").unwrap();
|
||||||
|
w.finish().unwrap();
|
||||||
|
}
|
||||||
|
// la de la ruta pedida, no la primera con ese nombre
|
||||||
|
extraer(&zp, &dir, &["bin/x64-win/a.dll"]).unwrap();
|
||||||
|
assert_eq!(fs::read(dir.join("a.dll")).unwrap(), b"AAA");
|
||||||
|
assert!(!dir.join("b.dll").exists());
|
||||||
|
assert!(extraer(&zp, &dir, &["a.dll"]).unwrap_err().contains("a.dll"));
|
||||||
|
let p = Pieza { nombre: "x", url: "", sha256: "abc", bytes: 1, forma: Forma::Archivo("x"), con_sesion: false };
|
||||||
|
assert!(!esta(&dir, &p));
|
||||||
|
fs::write(marca(&dir, &p), "abc").unwrap();
|
||||||
|
assert!(esta(&dir, &p));
|
||||||
|
let _ = fs::remove_dir_all(&dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
88
src-tauri/src/ia/imagen.rs
Archivo normal
88
src-tauri/src/ia/imagen.rs
Archivo normal
@@ -0,0 +1,88 @@
|
|||||||
|
// ── La foto como la quiere el modelo, y su respuesta como la quiere la página ──
|
||||||
|
// Lo mismo que hace el navegador (lib/revelado/modelo-sujeto: entradaDelModelo), aquí en Rust:
|
||||||
|
// la foto RGBA (como se ve en el editor) a `lado` × `lado` entre sus cuatro píxeles más cercanos,
|
||||||
|
// en tres planos RGB normalizados como ImageNet. Y la salida, a un byte por punto.
|
||||||
|
|
||||||
|
const MEDIA: [f32; 3] = [0.485, 0.456, 0.406];
|
||||||
|
const DESVIACION: [f32; 3] = [0.229, 0.224, 0.225];
|
||||||
|
|
||||||
|
/// RGBA (`ancho` × `alto`) → [1, 3, lado, lado] en un vector plano.
|
||||||
|
pub fn entrada(rgba: &[u8], ancho: usize, alto: usize, lado: usize) -> Vec<f32> {
|
||||||
|
let plano = lado * lado;
|
||||||
|
let mut out = vec![0f32; 3 * plano];
|
||||||
|
for y in 0..lado {
|
||||||
|
let fy = (((y as f32 + 0.5) / lado as f32) * alto as f32 - 0.5).clamp(0.0, (alto - 1) as f32);
|
||||||
|
let y0 = fy.floor() as usize;
|
||||||
|
let y1 = (y0 + 1).min(alto - 1);
|
||||||
|
let wy = fy - y0 as f32;
|
||||||
|
for x in 0..lado {
|
||||||
|
let fx = (((x as f32 + 0.5) / lado as f32) * ancho as f32 - 0.5).clamp(0.0, (ancho - 1) as f32);
|
||||||
|
let x0 = fx.floor() as usize;
|
||||||
|
let x1 = (x0 + 1).min(ancho - 1);
|
||||||
|
let wx = fx - x0 as f32;
|
||||||
|
for c in 0..3 {
|
||||||
|
let p = |xx: usize, yy: usize| rgba[(yy * ancho + xx) * 4 + c] as f32;
|
||||||
|
let arriba = p(x0, y0) + (p(x1, y0) - p(x0, y0)) * wx;
|
||||||
|
let abajo = p(x0, y1) + (p(x1, y1) - p(x0, y1)) * wx;
|
||||||
|
let v = arriba + (abajo - arriba) * wy;
|
||||||
|
out[c * plano + y * lado + x] = (v / 255.0 - MEDIA[c]) / DESVIACION[c];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ¿La salida viene sin sigmoide? (BiRefNet la aplica fuera de la red; si algo cae fuera de 0..1,
|
||||||
|
/// son logits y hay que aplicarla aquí.)
|
||||||
|
pub fn son_logits(salida: &[f32]) -> bool {
|
||||||
|
salida.iter().any(|&v| !(-0.001..=1.001).contains(&v))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// La salida del modelo a un byte por punto. `logits`: la salida va sin sigmoide (BiRefNet la
|
||||||
|
/// aplica fuera de la red).
|
||||||
|
pub fn a_bytes(salida: &[f32], logits: bool) -> Vec<u8> {
|
||||||
|
salida
|
||||||
|
.iter()
|
||||||
|
.map(|&v| {
|
||||||
|
let p = if logits { 1.0 / (1.0 + (-v).exp()) } else { v };
|
||||||
|
(p.clamp(0.0, 1.0) * 255.0).round() as u8
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// La respuesta de `ia_sujeto` para la página: [ancho u32][alto u32][bytes] (little endian).
|
||||||
|
pub fn respuesta(ancho: u32, alto: u32, bytes: &[u8]) -> Vec<u8> {
|
||||||
|
let mut out = Vec::with_capacity(8 + bytes.len());
|
||||||
|
out.extend_from_slice(&ancho.to_le_bytes());
|
||||||
|
out.extend_from_slice(&alto.to_le_bytes());
|
||||||
|
out.extend_from_slice(bytes);
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod pruebas {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn la_entrada_es_la_del_navegador() {
|
||||||
|
// 2 × 1: rojo puro y blanco; a 2 × 2 cada columna toma su píxel
|
||||||
|
let rgba = [255, 0, 0, 255, 255, 255, 255, 255];
|
||||||
|
let e = entrada(&rgba, 2, 1, 2);
|
||||||
|
let norm = |v: f32, c: usize| (v / 255.0 - MEDIA[c]) / DESVIACION[c];
|
||||||
|
assert!((e[0] - norm(255.0, 0)).abs() < 1e-5); // R de (0,0)
|
||||||
|
assert!((e[4] - norm(0.0, 1)).abs() < 1e-5); // G de (0,0)
|
||||||
|
assert!((e[5] - norm(255.0, 1)).abs() < 1e-5); // G de (1,0)
|
||||||
|
assert!((e[8 + 3] - norm(255.0, 2)).abs() < 1e-5); // B de (1,1)
|
||||||
|
assert_eq!(e.len(), 12);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn la_salida_a_bytes_y_la_respuesta() {
|
||||||
|
assert_eq!(a_bytes(&[-20.0, 0.0, 20.0], true), vec![0, 128, 255]);
|
||||||
|
assert_eq!(a_bytes(&[0.0, 0.5, 1.2], false), vec![0, 128, 255]);
|
||||||
|
assert!(son_logits(&[0.2, -3.0]) && !son_logits(&[0.0, 0.5, 1.0]));
|
||||||
|
let r = respuesta(3, 2, &[1, 2, 3, 4, 5, 6]);
|
||||||
|
assert_eq!(&r[..8], &[3, 0, 0, 0, 2, 0, 0, 0]);
|
||||||
|
assert_eq!(r.len(), 14);
|
||||||
|
}
|
||||||
|
}
|
||||||
262
src-tauri/src/ia/mod.rs
Archivo normal
262
src-tauri/src/ia/mod.rs
Archivo normal
@@ -0,0 +1,262 @@
|
|||||||
|
// ── La IA EN EL EQUIPO: la máscara de sujeto de Labstream OS con la tarjeta NVIDIA (1.22) ──────
|
||||||
|
//
|
||||||
|
// Munka: «los pcs que usan esta función tienen Nvidia de 16 GB… el modelo se ejecuta en local y se
|
||||||
|
// conecta y sube el resultado a la app». En el editor de revelado (modo edición de un set), «Sujeto»
|
||||||
|
// y «Fondo» no los busca el navegador sino esta app: ONNX Runtime con DirectML sobre la tarjeta
|
||||||
|
// NVIDIA y BiRefNet en media precisión (piezas.rs): 0,3 s por foto en vez de 2,5–3 s, y sin depender
|
||||||
|
// del WebGPU de la pestaña.
|
||||||
|
//
|
||||||
|
// La página (lib/revelado/ia-local en labstream-os) llama a tres comandos, permitidos SOLO para el
|
||||||
|
// origen de la app (capabilities/default.json + el manifiesto de build.rs):
|
||||||
|
// ia_estado → ¿se puede aquí?, ¿está ya bajado?, cuánto falta, qué tarjeta
|
||||||
|
// ia_preparar → baja lo que falte (eventos «ia-progreso» { fase, parte } a esa pestaña) y abre
|
||||||
|
// el modelo en la tarjeta
|
||||||
|
// ia_sujeto ← RGBA en el cuerpo (binario) + x-ancho / x-alto
|
||||||
|
// → [ancho u32][alto u32][un byte por punto] (lib/revelado/ia-local: leerRespuesta)
|
||||||
|
// El resultado vuelve a la página, que lo pone en la máscara y lo guarda con el revelado de la foto.
|
||||||
|
//
|
||||||
|
// Nada se baja ni se carga al arrancar la app: solo cuando alguien pide la máscara. Lo bajado vive en
|
||||||
|
// los datos de la app del equipo (`carpeta`), comprobado con su huella (bajar.rs). El modelo abierto
|
||||||
|
// ocupa la tarjeta (~7 GB mientras busca: DirectML guarda lo que pidió): se suelta a los SOLTAR_TRAS
|
||||||
|
// sin usarlo, que los editores trabajan con Resolve abierto.
|
||||||
|
|
||||||
|
mod bajar;
|
||||||
|
mod imagen;
|
||||||
|
mod motor;
|
||||||
|
mod piezas;
|
||||||
|
mod tarjeta;
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::sync::atomic::{AtomicU64, Ordering};
|
||||||
|
use std::sync::Mutex;
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
use tauri::{AppHandle, Emitter, EventTarget, Manager, Runtime, Webview};
|
||||||
|
|
||||||
|
/// Sin usarlo este rato, el modelo se suelta de la tarjeta (la siguiente foto tarda ~2 s más).
|
||||||
|
const SOLTAR_TRAS: Duration = Duration::from_secs(2 * 60);
|
||||||
|
|
||||||
|
struct Abierto {
|
||||||
|
motor: motor::Motor,
|
||||||
|
usado: Instant,
|
||||||
|
}
|
||||||
|
|
||||||
|
static MODELO: Mutex<Option<Abierto>> = Mutex::new(None);
|
||||||
|
/// Una preparación a la vez (dos pestañas que piden a la vez no bajan dos veces).
|
||||||
|
static PREPARANDO: Mutex<()> = Mutex::new(());
|
||||||
|
static VIGILANTE: std::sync::Once = std::sync::Once::new();
|
||||||
|
|
||||||
|
fn carpeta<R: Runtime>(app: &AppHandle<R>) -> Result<PathBuf, String> {
|
||||||
|
app.path().app_local_data_dir().map(|d| d.join("ia")).map_err(|e| format!("No hay carpeta de datos de la app: {e}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn faltan(dir: &std::path::Path) -> u64 {
|
||||||
|
piezas::todas().iter().filter(|p| !bajar::esta(dir, p)).map(|p| p.bytes).sum()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Serialize)]
|
||||||
|
pub struct Estado {
|
||||||
|
disponible: bool,
|
||||||
|
motivo: Option<String>,
|
||||||
|
listo: bool,
|
||||||
|
faltan: u64,
|
||||||
|
modelo: &'static str,
|
||||||
|
tarjeta: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn ia_estado<R: Runtime>(app: AppHandle<R>) -> Estado {
|
||||||
|
let t = tarjeta::nvidia();
|
||||||
|
let motivo = if !cfg!(all(windows, target_arch = "x86_64")) {
|
||||||
|
Some("La IA del equipo es para Windows con tarjeta NVIDIA.".to_string())
|
||||||
|
} else if t.is_none() {
|
||||||
|
Some("Este equipo no tiene tarjeta NVIDIA.".to_string())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let dir = carpeta(&app).ok();
|
||||||
|
let falta = dir.as_deref().map(faltan).unwrap_or(u64::MAX);
|
||||||
|
Estado {
|
||||||
|
disponible: motivo.is_none() && dir.is_some(),
|
||||||
|
motivo,
|
||||||
|
listo: falta == 0,
|
||||||
|
faltan: if falta == u64::MAX { 0 } else { falta },
|
||||||
|
modelo: piezas::NOMBRE_MODELO,
|
||||||
|
tarjeta: t.map(|t| t.nombre),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn avisar<R: Runtime>(app: &AppHandle<R>, label: &str, fase: &str, parte: f64) {
|
||||||
|
let _ = app.emit_to(EventTarget::webview(label), "ia-progreso", serde_json::json!({ "fase": fase, "parte": parte }));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Baja lo que falte y deja el modelo abierto (en un hilo aparte: puede tardar minutos).
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn ia_preparar<R: Runtime>(app: AppHandle<R>, webview: Webview<R>) -> Result<(), String> {
|
||||||
|
let label = webview.label().to_string();
|
||||||
|
// La sesión de la pestaña, para bajar el modelo del servidor de la app (solo viaja a él). Aquí y
|
||||||
|
// no en el hilo de abajo: leer cookies de WebView2 desde un comando síncrono se queda colgado.
|
||||||
|
let sesion = tauri::Url::parse(crate::SERVER_URL)
|
||||||
|
.ok()
|
||||||
|
.and_then(|u| webview.cookies_for_url(u).ok())
|
||||||
|
.map(|cs| cs.iter().map(|c| format!("{}={}", c.name(), c.value())).collect::<Vec<_>>().join("; "));
|
||||||
|
tauri::async_runtime::spawn_blocking(move || preparar(&app, &label, sesion.as_deref()))
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("La IA no pudo prepararse: {e}"))?
|
||||||
|
}
|
||||||
|
|
||||||
|
fn preparar<R: Runtime>(app: &AppHandle<R>, label: &str, sesion: Option<&str>) -> Result<(), String> {
|
||||||
|
if tarjeta::nvidia().is_none() {
|
||||||
|
return Err("Este equipo no tiene tarjeta NVIDIA.".into());
|
||||||
|
}
|
||||||
|
let _uno = PREPARANDO.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
let dir = carpeta(app)?;
|
||||||
|
let total = faltan(&dir);
|
||||||
|
if total > 0 {
|
||||||
|
let hecho = AtomicU64::new(0);
|
||||||
|
let mut ultimo = 0u64;
|
||||||
|
avisar(app, label, "bajando", 0.0);
|
||||||
|
for p in piezas::todas() {
|
||||||
|
bajar::bajar(&dir, p, sesion, &mut |n| {
|
||||||
|
let h = hecho.fetch_add(n, Ordering::Relaxed) + n;
|
||||||
|
// un aviso cada ~1 %
|
||||||
|
if h - ultimo > total / 100 {
|
||||||
|
ultimo = h;
|
||||||
|
avisar(app, label, "bajando", (h as f64 / total as f64).min(1.0));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.map_err(|e| {
|
||||||
|
crate::salud::anotar("ERROR", "ia", &e);
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
crate::salud::anotar("INFO", "ia", &format!("IA bajada al equipo ({} MB)", total / 1_000_000));
|
||||||
|
}
|
||||||
|
let mut m = MODELO.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
if m.is_none() {
|
||||||
|
avisar(app, label, "preparando", 0.0);
|
||||||
|
let t0 = Instant::now();
|
||||||
|
let motor = motor::Motor::abrir(&dir).map_err(|e| {
|
||||||
|
crate::salud::anotar("ERROR", "ia", &format!("no se pudo abrir el modelo: {e}"));
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
crate::salud::anotar("INFO", "ia", &format!("modelo abierto en {:.1} s ({})", t0.elapsed().as_secs_f32(), motor.donde()));
|
||||||
|
*m = Some(Abierto { motor, usado: Instant::now() });
|
||||||
|
vigilar();
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Suelta el modelo de la tarjeta cuando lleva SOLTAR_TRAS sin usarse.
|
||||||
|
fn vigilar() {
|
||||||
|
VIGILANTE.call_once(|| {
|
||||||
|
std::thread::spawn(|| loop {
|
||||||
|
std::thread::sleep(Duration::from_secs(15));
|
||||||
|
let mut m = MODELO.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
if m.as_ref().map(|a| a.usado.elapsed() >= SOLTAR_TRAS).unwrap_or(false) {
|
||||||
|
*m = None;
|
||||||
|
crate::salud::anotar("INFO", "ia", "modelo soltado de la tarjeta (sin uso)");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Busca el sujeto en la foto que manda la página (RGBA en el cuerpo, medidas en las cabeceras).
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn ia_sujeto(request: tauri::ipc::Request<'_>) -> Result<tauri::ipc::Response, String> {
|
||||||
|
let medida = |k: &str| request.headers().get(k).and_then(|v| v.to_str().ok()).and_then(|v| v.parse::<usize>().ok()).unwrap_or(0);
|
||||||
|
let (ancho, alto) = (medida("x-ancho"), medida("x-alto"));
|
||||||
|
let tauri::ipc::InvokeBody::Raw(rgba) = request.body() else {
|
||||||
|
return Err("La foto no llegó (se esperaban sus píxeles).".into());
|
||||||
|
};
|
||||||
|
if ancho < 2 || alto < 2 || ancho > 16_384 || alto > 16_384 || rgba.len() != ancho * alto * 4 {
|
||||||
|
return Err("La foto llegó con unas medidas que no cuadran.".into());
|
||||||
|
}
|
||||||
|
let rgba = rgba.clone();
|
||||||
|
tauri::async_runtime::spawn_blocking(move || buscar(&rgba, ancho, alto))
|
||||||
|
.await
|
||||||
|
.map_err(|e| format!("La IA falló: {e}"))?
|
||||||
|
.map(tauri::ipc::Response::new)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn buscar(rgba: &[u8], ancho: usize, alto: usize) -> Result<Vec<u8>, String> {
|
||||||
|
let mut m = MODELO.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
let Some(a) = m.as_mut() else {
|
||||||
|
return Err("La IA no está preparada.".into());
|
||||||
|
};
|
||||||
|
let lado = piezas::LADO;
|
||||||
|
let t0 = Instant::now();
|
||||||
|
let salida = a.motor.correr(imagen::entrada(rgba, ancho, alto, lado), lado);
|
||||||
|
a.usado = Instant::now();
|
||||||
|
match salida {
|
||||||
|
Ok(s) => {
|
||||||
|
crate::salud::anotar("INFO", "ia", &format!("sujeto en {:.2} s", t0.elapsed().as_secs_f32()));
|
||||||
|
Ok(imagen::respuesta(lado as u32, lado as u32, &imagen::a_bytes(&s, imagen::son_logits(&s))))
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
// una tarjeta que se perdió: se suelta para abrirla de nuevo la próxima vez
|
||||||
|
*m = None;
|
||||||
|
crate::salud::anotar("ERROR", "ia", &format!("no se pudo buscar el sujeto: {e}"));
|
||||||
|
Err(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(test, windows))]
|
||||||
|
mod pruebas {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
/// De punta a punta en la tarjeta de ESTE equipo (no corre en CI: `cargo test -- --ignored`).
|
||||||
|
/// LS_IA_DIR: carpeta de la IA (se baja ahí lo que falte). LS_IA_ENTRADA: opcional, un .f32 con
|
||||||
|
/// la entrada [1,3,lado,lado] ya hecha (para comparar con la CPU); la salida va a LS_IA_SALIDA.
|
||||||
|
/// LS_IA_MODELO / LS_IA_LADO: probar otro modelo de la carpeta; LS_IA_ESPERA: segundos con el
|
||||||
|
/// modelo abierto entre vueltas (para mirar la memoria de la tarjeta).
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn de_punta_a_punta_en_la_tarjeta() {
|
||||||
|
let dir = PathBuf::from(std::env::var("LS_IA_DIR").expect("LS_IA_DIR"));
|
||||||
|
for p in piezas::todas() {
|
||||||
|
let t = Instant::now();
|
||||||
|
bajar::bajar(&dir, p, None, &mut |_| {}).unwrap();
|
||||||
|
eprintln!("{}: listo en {:.1} s", p.nombre, t.elapsed().as_secs_f32());
|
||||||
|
}
|
||||||
|
let t = Instant::now();
|
||||||
|
let mut m = match std::env::var("LS_IA_MODELO") {
|
||||||
|
Ok(f) => motor::Motor::abrir_archivo(&dir, &f).unwrap(),
|
||||||
|
Err(_) => motor::Motor::abrir(&dir).unwrap(),
|
||||||
|
};
|
||||||
|
eprintln!("modelo abierto en {:.1} s", t.elapsed().as_secs_f32());
|
||||||
|
let lado = std::env::var("LS_IA_LADO").ok().and_then(|v| v.parse().ok()).unwrap_or(piezas::LADO);
|
||||||
|
let entrada = match std::env::var("LS_IA_ENTRADA") {
|
||||||
|
Ok(f) => std::fs::read(f).unwrap().chunks_exact(4).map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])).collect(),
|
||||||
|
Err(_) => {
|
||||||
|
let (w, h) = (1600usize, 1067usize);
|
||||||
|
let mut rgba = vec![255u8; w * h * 4];
|
||||||
|
for y in 0..h {
|
||||||
|
for x in 0..w {
|
||||||
|
let i = (y * w + x) * 4;
|
||||||
|
let d = ((x as f32 - 800.0).powi(2) + (y as f32 - 560.0).powi(2)).sqrt() / 300.0;
|
||||||
|
let g = (90.0 + 60.0 * y as f32 / h as f32) as u8;
|
||||||
|
let c = if d < 1.0 { [220, 120, 60] } else { [g, g, g + 10] };
|
||||||
|
rgba[i..i + 3].copy_from_slice(&c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
imagen::entrada(&rgba, w, h, lado)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
for vuelta in 0..2 {
|
||||||
|
let t = Instant::now();
|
||||||
|
let s = m.correr(entrada.clone(), lado).unwrap();
|
||||||
|
let (min, max) = s.iter().fold((f32::MAX, f32::MIN), |(a, b), &v| (a.min(v), b.max(v)));
|
||||||
|
eprintln!("vuelta {vuelta}: {:.2} s, salida {min:.2}..{max:.2}, logits {}", t.elapsed().as_secs_f32(), imagen::son_logits(&s));
|
||||||
|
if let Ok(seg) = std::env::var("LS_IA_ESPERA") {
|
||||||
|
eprintln!("esperando {seg} s con el modelo abierto");
|
||||||
|
std::thread::sleep(Duration::from_secs(seg.parse().unwrap_or(0)));
|
||||||
|
}
|
||||||
|
if vuelta == 1 {
|
||||||
|
if let Ok(f) = std::env::var("LS_IA_SALIDA") {
|
||||||
|
std::fs::write(f, s.iter().flat_map(|v| v.to_le_bytes()).collect::<Vec<u8>>()).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
130
src-tauri/src/ia/motor.rs
Archivo normal
130
src-tauri/src/ia/motor.rs
Archivo normal
@@ -0,0 +1,130 @@
|
|||||||
|
// ── El motor: ONNX Runtime con DirectML sobre la tarjeta (Windows) ──
|
||||||
|
//
|
||||||
|
// DirectML y no CUDA: corre en cualquier tarjeta con DirectX 12 —las NVIDIA del equipo incluidas—
|
||||||
|
// sin pedir versión de controlador, y lo que hay que bajar son ~200 MB de Microsoft (NuGet) en vez
|
||||||
|
// de ~1,3 GB de bibliotecas de NVIDIA. La exportación oficial de BiRefNet lleva la convolución
|
||||||
|
// deformable deshecha en GatherND (lo que DirectML sabe hacer; DeformConv no).
|
||||||
|
//
|
||||||
|
// Las DLL no van en el instalador: las baja `ia_preparar` (piezas.rs) a la carpeta de la IA y aquí
|
||||||
|
// se cargan desde ahí. DirectML.dll se carga ANTES por su ruta: onnxruntime.dll la pide por nombre
|
||||||
|
// y, ya cargada, Windows le da esa y no la vieja de System32. ONNX Runtime se inicia UNA vez por
|
||||||
|
// proceso (`ENTORNO`); la sesión (el modelo en la tarjeta) se abre y se suelta según se use.
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
mod imp {
|
||||||
|
use super::super::piezas;
|
||||||
|
use ort::{
|
||||||
|
ep,
|
||||||
|
environment::Environment,
|
||||||
|
session::{builder::GraphOptimizationLevel, Session},
|
||||||
|
value::Tensor,
|
||||||
|
};
|
||||||
|
use std::path::Path;
|
||||||
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
|
static ENTORNO: OnceLock<Result<Environment, String>> = OnceLock::new();
|
||||||
|
|
||||||
|
fn entorno(dir: &Path) -> Result<&'static Environment, String> {
|
||||||
|
ENTORNO
|
||||||
|
.get_or_init(|| {
|
||||||
|
cargar_por_ruta(&dir.join(piezas::DLL_DIRECTML))?;
|
||||||
|
let env = ort::init_from(dir.join(piezas::DLL_ORT))
|
||||||
|
.map_err(|e| format!("No se pudo cargar ONNX Runtime: {e}"))?
|
||||||
|
.with_name("labstream-ia")
|
||||||
|
.build()
|
||||||
|
.map_err(|e| format!("No se pudo iniciar ONNX Runtime: {e}"))?;
|
||||||
|
Ok(env)
|
||||||
|
})
|
||||||
|
.as_ref()
|
||||||
|
.map_err(|e| e.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Carga una DLL por su ruta completa y la deja cargada para siempre.
|
||||||
|
fn cargar_por_ruta(ruta: &Path) -> Result<(), String> {
|
||||||
|
use std::os::windows::ffi::OsStrExt;
|
||||||
|
use windows::core::PCWSTR;
|
||||||
|
use windows::Win32::System::LibraryLoader::LoadLibraryW;
|
||||||
|
let w: Vec<u16> = ruta.as_os_str().encode_wide().chain(std::iter::once(0)).collect();
|
||||||
|
unsafe { LoadLibraryW(PCWSTR(w.as_ptr())) }.map(|_| ()).map_err(|e| format!("No se pudo cargar {}: {e}", ruta.display()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Motor {
|
||||||
|
sesion: Session,
|
||||||
|
entrada: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Motor {
|
||||||
|
pub fn abrir(dir: &Path) -> Result<Motor, String> {
|
||||||
|
Self::abrir_archivo(dir, piezas::ARCHIVO_MODELO)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn abrir_archivo(dir: &Path, archivo: &str) -> Result<Motor, String> {
|
||||||
|
let env = entorno(dir)?;
|
||||||
|
let e = |e: ort::Error<ort::session::builder::SessionBuilder>| format!("No se pudo abrir el modelo: {e}");
|
||||||
|
let sesion = Session::builder(env)
|
||||||
|
.map_err(|e| format!("No se pudo abrir el modelo: {e}"))?
|
||||||
|
.with_optimization_level(GraphOptimizationLevel::Level3)
|
||||||
|
.map_err(e)?
|
||||||
|
// lo que pide DirectML: sin patrones de memoria y en serie
|
||||||
|
.with_memory_pattern(false)
|
||||||
|
.map_err(e)?
|
||||||
|
.with_parallel_execution(false)
|
||||||
|
.map_err(e)?
|
||||||
|
// El grafo FUNDIDO de DirectML pide la memoria de toda la red de una vez: con el modelo
|
||||||
|
// HR no cabía ni en 16 GB (E_OUTOFMEMORY en DmlFusedNode, RTX 5080, 14-oct-2026) y en
|
||||||
|
// media precisión iba 6 veces más lento. Nodo a nodo, cada tensor se suelta cuando ya
|
||||||
|
// no hace falta (el general: 0,3 s).
|
||||||
|
.with_config_entry("ep.dml.disable_graph_fusion", "1")
|
||||||
|
.map_err(e)?
|
||||||
|
.with_execution_providers([ep::DirectML::default()
|
||||||
|
.with_device_filter(ep::directml::DeviceFilter::Gpu)
|
||||||
|
.with_performance_preference(ep::directml::PerformancePreference::HighPerformance)
|
||||||
|
.build()
|
||||||
|
// sin la tarjeta NO se sigue en la CPU: serían 30 s por foto
|
||||||
|
.error_on_failure()])
|
||||||
|
.map_err(e)?
|
||||||
|
.commit_from_file(dir.join(archivo))
|
||||||
|
.map_err(|e| format!("No se pudo abrir el modelo: {e}"))?;
|
||||||
|
let entrada = sesion.inputs().first().map(|i| i.name().to_string()).ok_or("El modelo no tiene entrada.")?;
|
||||||
|
Ok(Motor { sesion, entrada })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn donde(&self) -> &'static str {
|
||||||
|
"DirectML"
|
||||||
|
}
|
||||||
|
|
||||||
|
/// La entrada [1, 3, lado, lado] → la salida [1, 1, lado, lado] (la última, si hay varias).
|
||||||
|
pub fn correr(&mut self, entrada: Vec<f32>, lado: usize) -> Result<Vec<f32>, String> {
|
||||||
|
let t = Tensor::from_array(([1usize, 3, lado, lado], entrada)).map_err(|e| format!("La foto no entró al modelo: {e}"))?;
|
||||||
|
let nombre = self.entrada.clone();
|
||||||
|
let salidas = self.sesion.run(ort::inputs![nombre => t]).map_err(|e| format!("La tarjeta no pudo buscar el sujeto: {e}"))?;
|
||||||
|
let ultima = salidas.len().checked_sub(1).ok_or("El modelo no contestó.")?;
|
||||||
|
let (forma, datos) = salidas[ultima].try_extract_tensor::<f32>().map_err(|e| format!("El modelo contestó algo raro: {e}"))?;
|
||||||
|
if datos.len() != lado * lado {
|
||||||
|
return Err(format!("El modelo contestó {forma:?} y se esperaba {lado} × {lado}."));
|
||||||
|
}
|
||||||
|
Ok(datos.to_vec())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
mod imp {
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
pub struct Motor;
|
||||||
|
|
||||||
|
impl Motor {
|
||||||
|
pub fn abrir(_dir: &Path) -> Result<Motor, String> {
|
||||||
|
Err("La IA del equipo es para Windows con tarjeta NVIDIA.".into())
|
||||||
|
}
|
||||||
|
pub fn donde(&self) -> &'static str {
|
||||||
|
"-"
|
||||||
|
}
|
||||||
|
pub fn correr(&mut self, _entrada: Vec<f32>, _lado: usize) -> Result<Vec<f32>, String> {
|
||||||
|
Err("La IA del equipo es para Windows con tarjeta NVIDIA.".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub use imp::Motor;
|
||||||
57
src-tauri/src/ia/piezas.rs
Archivo normal
57
src-tauri/src/ia/piezas.rs
Archivo normal
@@ -0,0 +1,57 @@
|
|||||||
|
// ── Lo que la IA baja la primera vez (≈700 MB), de dónde, y con qué huella ──
|
||||||
|
//
|
||||||
|
// Fijado por versión y huella SHA-256 (comprobadas al bajarlo el 14-oct-2026): si algún día cambia
|
||||||
|
// lo que hay en esa dirección, no se usa.
|
||||||
|
//
|
||||||
|
// - El modelo: BiRefNet general (MIT, ZhengPeng7; el mismo del navegador) en media precisión, del
|
||||||
|
// servidor de la app (api/modelos/sujeto-equipo, con la sesión de la pestaña). Sale de la
|
||||||
|
// exportación ONNX oficial del autor (release v1 de su GitHub, float32) pasada a float16 con la
|
||||||
|
// entrada y la salida en float32 (scripts/modelo-sujeto-equipo.py de labstream-os). Entrada
|
||||||
|
// `input_image` [1, 3, 1024, 1024], salida `output_image` [1, 1, 1024, 1024] (logits). En una RTX
|
||||||
|
// 5080: 0,3 s por foto y el mismo borde que el original en la CPU.
|
||||||
|
// El HR (2048 px, matting) se probó y NO va: su convolución deformable, deshecha en GatherND en la
|
||||||
|
// exportación oficial, ocupa 14–15 GB con DirectML y tarda de 6 a 45 s (14-oct-2026).
|
||||||
|
// - ONNX Runtime 1.24.4 con DirectML (NuGet de Microsoft): onnxruntime.dll para x64.
|
||||||
|
// - DirectML 1.15.4 (NuGet de Microsoft): DirectML.dll para Windows x64 (el paquete trae también
|
||||||
|
// las de Xbox y las de depurar: se saca por su ruta exacta).
|
||||||
|
|
||||||
|
use super::bajar::{Forma, Pieza};
|
||||||
|
|
||||||
|
pub const NOMBRE_MODELO: &str = "BiRefNet";
|
||||||
|
/// El lado de la entrada y de la salida del modelo.
|
||||||
|
pub const LADO: usize = 1024;
|
||||||
|
|
||||||
|
pub const ARCHIVO_MODELO: &str = "birefnet-general-epoch_244-fp16.onnx";
|
||||||
|
pub const DLL_ORT: &str = "onnxruntime.dll";
|
||||||
|
pub const DLL_DIRECTML: &str = "DirectML.dll";
|
||||||
|
|
||||||
|
static PIEZAS: [Pieza; 3] = [
|
||||||
|
Pieza {
|
||||||
|
nombre: "onnxruntime-directml-1.24.4",
|
||||||
|
url: "https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime.directml/1.24.4/microsoft.ml.onnxruntime.directml.1.24.4.nupkg",
|
||||||
|
sha256: "57e9f11b73437bef7a309496135d4c1f96b1a8e9ddba60013fa27bfc1d788681",
|
||||||
|
bytes: 12_458_649,
|
||||||
|
forma: Forma::Zip(&["runtimes/win-x64/native/onnxruntime.dll", "runtimes/win-x64/native/onnxruntime_providers_shared.dll"]),
|
||||||
|
con_sesion: false,
|
||||||
|
},
|
||||||
|
Pieza {
|
||||||
|
nombre: "directml-1.15.4",
|
||||||
|
url: "https://api.nuget.org/v3-flatcontainer/microsoft.ai.directml/1.15.4/microsoft.ai.directml.1.15.4.nupkg",
|
||||||
|
sha256: "4e7cb7ddce8cf837a7a75dc029209b520ca0101470fcdf275c1f49736a3615b9",
|
||||||
|
bytes: 202_292_617,
|
||||||
|
forma: Forma::Zip(&["bin/x64-win/DirectML.dll"]),
|
||||||
|
con_sesion: false,
|
||||||
|
},
|
||||||
|
Pieza {
|
||||||
|
nombre: "birefnet-general-epoch_244-fp16",
|
||||||
|
url: "https://os.labstreamsas.com/api/modelos/sujeto-equipo",
|
||||||
|
sha256: "323232ec73a04ac4d0ef8c325a75aa8d69ed7062235a7cf9941769fae4c9709f",
|
||||||
|
bytes: 489_666_838,
|
||||||
|
forma: Forma::Archivo(ARCHIVO_MODELO),
|
||||||
|
con_sesion: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
pub fn todas() -> &'static [Pieza] {
|
||||||
|
&PIEZAS
|
||||||
|
}
|
||||||
36
src-tauri/src/ia/tarjeta.rs
Archivo normal
36
src-tauri/src/ia/tarjeta.rs
Archivo normal
@@ -0,0 +1,36 @@
|
|||||||
|
// ── ¿Hay tarjeta NVIDIA en este equipo? ── (DXGI: lo que Windows sabe de sus adaptadores, sin
|
||||||
|
// cargar nada de la IA). Es lo que decide si la máscara de sujeto la busca la app o el navegador.
|
||||||
|
|
||||||
|
/// Una tarjeta NVIDIA del equipo: su nombre y su memoria propia (bytes).
|
||||||
|
pub struct Tarjeta {
|
||||||
|
pub nombre: String,
|
||||||
|
pub memoria: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
const NVIDIA: u32 = 0x10DE;
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub fn nvidia() -> Option<Tarjeta> {
|
||||||
|
use windows::Win32::Graphics::Dxgi::{CreateDXGIFactory1, IDXGIFactory1, DXGI_ADAPTER_FLAG_SOFTWARE};
|
||||||
|
let factory: IDXGIFactory1 = unsafe { CreateDXGIFactory1() }.ok()?;
|
||||||
|
let mut mejor: Option<Tarjeta> = None;
|
||||||
|
for i in 0.. {
|
||||||
|
let Ok(a) = (unsafe { factory.EnumAdapters1(i) }) else { break };
|
||||||
|
let Ok(d) = (unsafe { a.GetDesc1() }) else { continue };
|
||||||
|
if d.VendorId != NVIDIA || (d.Flags & DXGI_ADAPTER_FLAG_SOFTWARE.0 as u32) != 0 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let largo = d.Description.iter().position(|&c| c == 0).unwrap_or(d.Description.len());
|
||||||
|
let t = Tarjeta { nombre: String::from_utf16_lossy(&d.Description[..largo]).trim().to_string(), memoria: d.DedicatedVideoMemory as u64 };
|
||||||
|
// con dos, la de más memoria
|
||||||
|
if mejor.as_ref().map(|m| t.memoria > m.memoria).unwrap_or(true) {
|
||||||
|
mejor = Some(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mejor
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
pub fn nvidia() -> Option<Tarjeta> {
|
||||||
|
None
|
||||||
|
}
|
||||||
@@ -38,6 +38,7 @@ mod cache;
|
|||||||
mod tracker;
|
mod tracker;
|
||||||
mod salud;
|
mod salud;
|
||||||
mod memoria;
|
mod memoria;
|
||||||
|
mod ia;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
@@ -81,6 +82,19 @@ fn es_pestana_interna(target: &Url, server: &Url) -> bool {
|
|||||||
target.origin() == server.origin()
|
target.origin() == server.origin()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// El color que pide una página para su pestaña: solo `#rrggbb` (va a un estilo de la barra; nada
|
||||||
|
// que no sea un color llega allí).
|
||||||
|
fn color_de_pagina(c: &str) -> Option<String> {
|
||||||
|
let hex = c.strip_prefix('#')?;
|
||||||
|
(hex.len() == 6 && hex.chars().all(|ch| ch.is_ascii_hexdigit())).then(|| c.to_ascii_lowercase())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Un nombre de ventana que identifica pestaña: los de la app (`ls-…`, p. ej. `ls-edicion-<set>`).
|
||||||
|
// Los reservados del navegador (_blank, _self…) y cualquier otro abren pestaña nueva como siempre.
|
||||||
|
fn nombre_de_ventana(n: &str) -> Option<String> {
|
||||||
|
(n.starts_with("ls-") && n.len() <= 80 && n.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')).then(|| n.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod navigation_tests {
|
mod navigation_tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -95,6 +109,20 @@ mod navigation_tests {
|
|||||||
assert!(is_google_host("docs.google.com"));
|
assert!(is_google_host("docs.google.com"));
|
||||||
assert!(!is_google_host("docs.google.com.evil.example"));
|
assert!(!is_google_host("docs.google.com.evil.example"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn la_pagina_solo_pide_colores_y_nombres_de_la_app() {
|
||||||
|
assert_eq!(color_de_pagina("#262626").as_deref(), Some("#262626"));
|
||||||
|
assert_eq!(color_de_pagina("#A0b1C2").as_deref(), Some("#a0b1c2"));
|
||||||
|
for malo in ["", "262626", "#26262", "#2626266", "red", "#26262g", "#262626;background:url(x)"] {
|
||||||
|
assert_eq!(color_de_pagina(malo), None, "{malo}");
|
||||||
|
}
|
||||||
|
assert_eq!(nombre_de_ventana("ls-edicion-cmg123").as_deref(), Some("ls-edicion-cmg123"));
|
||||||
|
for malo in ["", "_blank", "_self", "edicion", "ls-a b", "ls-\"<x>"] {
|
||||||
|
assert_eq!(nombre_de_ventana(malo), None, "{malo}");
|
||||||
|
}
|
||||||
|
assert_eq!(nombre_de_ventana(&format!("ls-{}", "a".repeat(80))), None);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const TAB_BAR_H: f64 = 40.0; // alto lógico de la barra de pestañas (chrome)
|
const TAB_BAR_H: f64 = 40.0; // alto lógico de la barra de pestañas (chrome)
|
||||||
const CHROME: &str = "chrome";
|
const CHROME: &str = "chrome";
|
||||||
@@ -122,6 +150,12 @@ struct TabRec {
|
|||||||
// Ahorro de memoria (memoria.rs): su webview se cerró tras DESCARTE_TRAS dormida. Sigue en la
|
// Ahorro de memoria (memoria.rs): su webview se cerró tras DESCARTE_TRAS dormida. Sigue en la
|
||||||
// barra con título, URL y color, y se crea otra vez al volver a ella.
|
// barra con título, URL y color, y se crea otra vez al volver a ella.
|
||||||
descartada: bool,
|
descartada: bool,
|
||||||
|
// El color que PIDE la página (`<html data-ls-pestana="#262626">`, ver `color_de_pagina`): el
|
||||||
|
// modo edición de un set pinta su pestaña del gris del editor. Lo manda la página, no el menú.
|
||||||
|
pagina: Option<String>,
|
||||||
|
// El nombre de ventana con que se abrió (`window.open(url, nombre)`): abrir otra vez con el
|
||||||
|
// mismo nombre lleva a esta pestaña en vez de abrir otra (ver `reusar_pestana`).
|
||||||
|
nombre: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Paleta de colores de pestaña, la misma idea que los grupos de Chrome: sirve para agrupar de
|
// Paleta de colores de pestaña, la misma idea que los grupos de Chrome: sirve para agrupar de
|
||||||
@@ -198,6 +232,12 @@ struct Persisted {
|
|||||||
// cargar (ver `registrar_diferida`) y la barra necesita algo que enseñar mientras tanto.
|
// cargar (ver `registrar_diferida`) y la barra necesita algo que enseñar mientras tanto.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
titles: Vec<String>,
|
titles: Vec<String>,
|
||||||
|
// El color que pidió la página y el nombre de ventana de cada una (mismo orden; "" = ninguno):
|
||||||
|
// la pestaña del modo edición vuelve del gris del editor y se sigue reutilizando.
|
||||||
|
#[serde(default)]
|
||||||
|
paginas: Vec<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
nombres: Vec<String>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
active: usize,
|
active: usize,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
@@ -230,6 +270,8 @@ fn save_persisted<R: Runtime>(app: &AppHandle<R>) {
|
|||||||
tabs: s.tabs.iter().map(|t| t.url.clone()).collect(),
|
tabs: s.tabs.iter().map(|t| t.url.clone()).collect(),
|
||||||
colors: s.tabs.iter().map(|t| t.color.clone().unwrap_or_default()).collect(),
|
colors: s.tabs.iter().map(|t| t.color.clone().unwrap_or_default()).collect(),
|
||||||
titles: s.tabs.iter().map(|t| t.title.clone()).collect(),
|
titles: s.tabs.iter().map(|t| t.title.clone()).collect(),
|
||||||
|
paginas: s.tabs.iter().map(|t| t.pagina.clone().unwrap_or_default()).collect(),
|
||||||
|
nombres: s.tabs.iter().map(|t| t.nombre.clone().unwrap_or_default()).collect(),
|
||||||
active: s.active,
|
active: s.active,
|
||||||
autostart: s.autostart,
|
autostart: s.autostart,
|
||||||
dark: s.dark,
|
dark: s.dark,
|
||||||
@@ -287,7 +329,9 @@ const INIT_JS_TPL: &str = r#"
|
|||||||
try { T.core.invoke('plugin:opener|open_url', { url: url, with: null }); }
|
try { T.core.invoke('plugin:opener|open_url', { url: url, with: null }); }
|
||||||
catch (e) { try { T.opener.openUrl(url); } catch (_) {} }
|
catch (e) { try { T.opener.openUrl(url); } catch (_) {} }
|
||||||
}
|
}
|
||||||
function newTab(url) { emit('ls-new-tab', { url: url }); }
|
function newTab(url, nombre) { emit('ls-new-tab', nombre ? { url: url, name: nombre } : { url: url }); }
|
||||||
|
// Una ventana con nombre de la app (`ls-…`): reabrirla lleva a la pestaña que ya la tiene.
|
||||||
|
function nombreVentana(n) { return typeof n === 'string' && /^ls-[A-Za-z0-9_-]{1,77}$/.test(n) ? n : null; }
|
||||||
|
|
||||||
// ── Errores de la página → diario de salud del shell (salud.log) ──
|
// ── Errores de la página → diario de salud del shell (salud.log) ──
|
||||||
// Solo el mensaje, el archivo:línea y la ruta (sin datos del formulario ni de la sesión). Como
|
// Solo el mensaje, el archivo:línea y la ruta (sin datos del formulario ni de la sesión). Como
|
||||||
@@ -373,13 +417,25 @@ const INIT_JS_TPL: &str = r#"
|
|||||||
} catch (e) { return null; }
|
} catch (e) { return null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── El color que la página pide para SU pestaña ── `<html data-ls-pestana='#262626'>` (el modo
|
||||||
|
// edición de un set, del gris del editor). "" = ninguno.
|
||||||
|
function colorPestana() {
|
||||||
|
try {
|
||||||
|
var c = document.documentElement && document.documentElement.getAttribute('data-ls-pestana');
|
||||||
|
return c && /^#[0-9a-fA-F]{6}$/.test(c) ? c : '';
|
||||||
|
} catch (e) { return ''; }
|
||||||
|
}
|
||||||
|
|
||||||
// Título, URL y TEMA → barra de pestañas (y para restaurar la sesión al reabrir).
|
// Título, URL y TEMA → barra de pestañas (y para restaurar la sesión al reabrir).
|
||||||
// El tema viaja aquí porque la web decide su modo con su propio botón y NO sigue al
|
// El tema viaja aquí porque la web decide su modo con su propio botón y NO sigue al
|
||||||
// sistema: la barra tiene que copiarle a ELLA.
|
// sistema: la barra tiene que copiarle a ELLA. Una página con color propio no lo dice: su
|
||||||
|
// fondo oscuro es el de su pestaña, no el tema de la app.
|
||||||
function report() {
|
function report() {
|
||||||
var carga = { label: LABEL, title: document.title || 'Labstream OS', url: location.href };
|
var carga = { label: LABEL, title: document.title || 'Labstream OS', url: location.href, pestana: colorPestana() };
|
||||||
var oscuro = temaOscuro();
|
if (!carga.pestana) {
|
||||||
if (oscuro !== null) carga.dark = oscuro;
|
var oscuro = temaOscuro();
|
||||||
|
if (oscuro !== null) carga.dark = oscuro;
|
||||||
|
}
|
||||||
emit('ls-title', carga);
|
emit('ls-title', carga);
|
||||||
}
|
}
|
||||||
function watchTitle() {
|
function watchTitle() {
|
||||||
@@ -404,7 +460,7 @@ const INIT_JS_TPL: &str = r#"
|
|||||||
// por si el tema aterriza tarde con la hidratación.
|
// por si el tema aterriza tarde con la hidratación.
|
||||||
function vigilarTema() {
|
function vigilarTema() {
|
||||||
if (!window.MutationObserver) return;
|
if (!window.MutationObserver) return;
|
||||||
var conf = { attributes: true, attributeFilter: ['class', 'style', 'data-theme'] };
|
var conf = { attributes: true, attributeFilter: ['class', 'style', 'data-theme', 'data-ls-pestana'] };
|
||||||
if (document.documentElement) new MutationObserver(report).observe(document.documentElement, conf);
|
if (document.documentElement) new MutationObserver(report).observe(document.documentElement, conf);
|
||||||
if (document.body) new MutationObserver(report).observe(document.body, conf);
|
if (document.body) new MutationObserver(report).observe(document.body, conf);
|
||||||
}
|
}
|
||||||
@@ -421,7 +477,8 @@ const INIT_JS_TPL: &str = r#"
|
|||||||
if (!u) return;
|
if (!u) return;
|
||||||
if (isExt(u)) { e.preventDefault(); openExternal(u.href); return; }
|
if (isExt(u)) { e.preventDefault(); openExternal(u.href); return; }
|
||||||
var mod = e.metaKey || e.ctrlKey;
|
var mod = e.metaKey || e.ctrlKey;
|
||||||
if (isApp(u) && (mod || a.target === '_blank')) { e.preventDefault(); newTab(u.href); }
|
var nombre = mod ? null : nombreVentana(a.target);
|
||||||
|
if (isApp(u) && (mod || a.target === '_blank' || nombre)) { e.preventDefault(); newTab(u.href, nombre); }
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
// Clic con la rueda (botón central) en un enlace interno → pestaña nueva, como en el navegador.
|
// Clic con la rueda (botón central) en un enlace interno → pestaña nueva, como en el navegador.
|
||||||
@@ -438,7 +495,7 @@ const INIT_JS_TPL: &str = r#"
|
|||||||
window.open = function (url, name, feats) {
|
window.open = function (url, name, feats) {
|
||||||
var u = url ? abs(url) : null;
|
var u = url ? abs(url) : null;
|
||||||
if (isExt(u)) { openExternal(u.href); return null; }
|
if (isExt(u)) { openExternal(u.href); return null; }
|
||||||
if (isInterno(u)) { newTab(u.href); return null; }
|
if (isInterno(u)) { newTab(u.href, nombreVentana(name)); return null; }
|
||||||
return _open ? _open.call(window, url, name, feats) : null;
|
return _open ? _open.call(window, url, name, feats) : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -641,7 +698,7 @@ fn broadcast<R: Runtime>(app: &AppHandle<R>) {
|
|||||||
.tabs
|
.tabs
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, t)| json!({ "label": t.label, "title": t.title, "url": t.url, "loading": t.loading, "active": i == s.active, "color": t.color }))
|
.map(|(i, t)| json!({ "label": t.label, "title": t.title, "url": t.url, "loading": t.loading, "active": i == s.active, "color": t.color, "pagina": t.pagina }))
|
||||||
.collect();
|
.collect();
|
||||||
json!({
|
json!({
|
||||||
"tabs": tabs,
|
"tabs": tabs,
|
||||||
@@ -814,12 +871,17 @@ fn avisar_descarga_terminada<R: Runtime>(webview: &Webview<R>, url: &Url, path:
|
|||||||
|
|
||||||
// Crea una pestaña nueva cargando `url` (o el servidor si viene vacío).
|
// Crea una pestaña nueva cargando `url` (o el servidor si viene vacío).
|
||||||
fn create_tab<R: Runtime>(app: &AppHandle<R>, url: Option<String>, activate: bool) {
|
fn create_tab<R: Runtime>(app: &AppHandle<R>, url: Option<String>, activate: bool) {
|
||||||
|
crear_pestana(app, url, activate, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lo mismo, con su nombre de ventana (ver `reusar_pestana`). Devuelve la etiqueta de la nueva.
|
||||||
|
fn crear_pestana<R: Runtime>(app: &AppHandle<R>, url: Option<String>, activate: bool, nombre: Option<String>) -> Option<String> {
|
||||||
let target = url.unwrap_or_else(|| SERVER_URL.to_string());
|
let target = url.unwrap_or_else(|| SERVER_URL.to_string());
|
||||||
// Solo el origen de la app puede abrirse en pestaña; cualquier otra cosa va al navegador.
|
// Solo el origen de la app puede abrirse en pestaña; cualquier otra cosa va al navegador.
|
||||||
let Ok(parsed) = Url::parse(&target) else { return };
|
let parsed = Url::parse(&target).ok()?;
|
||||||
let Ok(server) = Url::parse(SERVER_URL) else { return };
|
let server = Url::parse(SERVER_URL).ok()?;
|
||||||
if !es_pestana_interna(&parsed, &server) {
|
if !es_pestana_interna(&parsed, &server) {
|
||||||
return;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let label = {
|
let label = {
|
||||||
@@ -827,7 +889,7 @@ fn create_tab<R: Runtime>(app: &AppHandle<R>, url: Option<String>, activate: boo
|
|||||||
let mut s = shell.lock().unwrap();
|
let mut s = shell.lock().unwrap();
|
||||||
let label = format!("tab-{}", s.next_id);
|
let label = format!("tab-{}", s.next_id);
|
||||||
s.next_id += 1;
|
s.next_id += 1;
|
||||||
s.tabs.push(TabRec { label: label.clone(), title: "Labstream OS".into(), url: target.clone(), loading: true, color: None, oculta_desde: if activate { None } else { Some(Instant::now()) }, dormida: false, descartada: false });
|
s.tabs.push(TabRec { label: label.clone(), title: "Labstream OS".into(), url: target.clone(), loading: true, color: None, oculta_desde: if activate { None } else { Some(Instant::now()) }, dormida: false, descartada: false, pagina: None, nombre });
|
||||||
label
|
label
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -839,6 +901,7 @@ fn create_tab<R: Runtime>(app: &AppHandle<R>, url: Option<String>, activate: boo
|
|||||||
broadcast(app);
|
broadcast(app);
|
||||||
save_persisted(app);
|
save_persisted(app);
|
||||||
}
|
}
|
||||||
|
Some(label)
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
salud::anotar("ERROR", "pestaña", &format!("no se pudo crear el webview: {e}"));
|
salud::anotar("ERROR", "pestaña", &format!("no se pudo crear el webview: {e}"));
|
||||||
@@ -846,10 +909,46 @@ fn create_tab<R: Runtime>(app: &AppHandle<R>, url: Option<String>, activate: boo
|
|||||||
let shell = app.state::<ShellState>();
|
let shell = app.state::<ShellState>();
|
||||||
let mut s = shell.lock().unwrap();
|
let mut s = shell.lock().unwrap();
|
||||||
s.tabs.retain(|t| t.label != label);
|
s.tabs.retain(|t| t.label != label);
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Pestañas con NOMBRE (1.21) ──
|
||||||
|
// `window.open(url, "ls-edicion-<set>")` (el modo edición de un set) abre la pestaña la primera
|
||||||
|
// vez; las siguientes llevan a ESA pestaña, como hace el navegador con una ventana con nombre, en
|
||||||
|
// vez de amontonar una por foto. A la página se le pasa la URL nueva por `__lsAbrir` (el modo
|
||||||
|
// edición cambia de foto sin recargar, guardando lo de la que tenía); si no lo conoce, navega.
|
||||||
|
// Devuelve false si no hay pestaña con ese nombre (entonces se crea).
|
||||||
|
fn reusar_pestana<R: Runtime>(app: &AppHandle<R>, nombre: &str, url: Option<&str>) -> bool {
|
||||||
|
let Ok(server) = Url::parse(SERVER_URL) else { return false };
|
||||||
|
let destino = match url.map(Url::parse) {
|
||||||
|
None => None,
|
||||||
|
Some(Ok(u)) if es_pestana_interna(&u, &server) => Some(u),
|
||||||
|
Some(_) => return false,
|
||||||
|
};
|
||||||
|
let (label, descartada) = {
|
||||||
|
let shell = app.state::<ShellState>();
|
||||||
|
let mut s = shell.lock().unwrap();
|
||||||
|
let Some(t) = s.tabs.iter_mut().find(|t| t.nombre.as_deref() == Some(nombre)) else { return false };
|
||||||
|
// Descartada (sin webview): se crea ya en la URL nueva al activarla.
|
||||||
|
if t.descartada {
|
||||||
|
if let Some(d) = &destino {
|
||||||
|
t.url = d.to_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(t.label.clone(), t.descartada)
|
||||||
|
};
|
||||||
|
activate_tab(app, &label);
|
||||||
|
if let (Some(d), false) = (destino, descartada) {
|
||||||
|
if let Some(wv) = get_webview(app, &label) {
|
||||||
|
let u = serde_json::to_string(d.as_str()).unwrap_or_else(|_| "\"\"".into());
|
||||||
|
let _ = wv.eval(format!("(function(u){{try{{if(window.__lsAbrir&&window.__lsAbrir(u))return}}catch(e){{}}location.assign(u)}})({u})"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
// Crea el webview de una pestaña: una nueva (create_tab) o una descartada que vuelve
|
// Crea el webview de una pestaña: una nueva (create_tab) o una descartada que vuelve
|
||||||
// (revivir_pestana, al activarla). Lo vigila salud.rs: si su proceso muere, se recarga sola.
|
// (revivir_pestana, al activarla). Lo vigila salud.rs: si su proceso muere, se recarga sola.
|
||||||
fn montar_webview<R: Runtime>(app: &AppHandle<R>, label: &str, parsed: Url) -> tauri::Result<Webview<R>> {
|
fn montar_webview<R: Runtime>(app: &AppHandle<R>, label: &str, parsed: Url) -> tauri::Result<Webview<R>> {
|
||||||
@@ -935,7 +1034,7 @@ fn registrar_diferida<R: Runtime>(app: &AppHandle<R>, url: &str, title: &str) {
|
|||||||
let label = format!("tab-{}", s.next_id);
|
let label = format!("tab-{}", s.next_id);
|
||||||
s.next_id += 1;
|
s.next_id += 1;
|
||||||
let title = if title.is_empty() { "Labstream OS".to_string() } else { title.to_string() };
|
let title = if title.is_empty() { "Labstream OS".to_string() } else { title.to_string() };
|
||||||
s.tabs.push(TabRec { label, title, url: url.to_string(), loading: false, color: None, oculta_desde: Some(Instant::now()), dormida: false, descartada: true });
|
s.tabs.push(TabRec { label, title, url: url.to_string(), loading: false, color: None, oculta_desde: Some(Instant::now()), dormida: false, descartada: true, pagina: None, nombre: None });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vuelve a crear el webview de una pestaña descartada, en su última URL. Devuelve false si no se
|
// Vuelve a crear el webview de una pestaña descartada, en su última URL. Devuelve false si no se
|
||||||
@@ -1596,7 +1695,9 @@ pub fn run() {
|
|||||||
.plugin(tauri_plugin_autostart::init(MacosLauncher::LaunchAgent, None))
|
.plugin(tauri_plugin_autostart::init(MacosLauncher::LaunchAgent, None))
|
||||||
// El cajón de miniaturas (ver el módulo `cache` y el handler de arriba). Registrado en el
|
// El cajón de miniaturas (ver el módulo `cache` y el handler de arriba). Registrado en el
|
||||||
// builder para que TODAS las webviews de pestaña puedan usarlo.
|
// builder para que TODAS las webviews de pestaña puedan usarlo.
|
||||||
.register_asynchronous_uri_scheme_protocol("lsthumb", responder_lsthumb);
|
.register_asynchronous_uri_scheme_protocol("lsthumb", responder_lsthumb)
|
||||||
|
// La IA del equipo (src/ia): la máscara de sujeto con la tarjeta NVIDIA, para la página.
|
||||||
|
.invoke_handler(tauri::generate_handler![ia::ia_estado, ia::ia_preparar, ia::ia_sujeto]);
|
||||||
|
|
||||||
let app = builder
|
let app = builder
|
||||||
.manage(ShellState::default())
|
.manage(ShellState::default())
|
||||||
@@ -1815,7 +1916,7 @@ pub fn run() {
|
|||||||
// registran descartadas (título, URL y color en la barra) y se crean al hacer clic en
|
// registran descartadas (título, URL y color en la barra) y se crean al hacer clic en
|
||||||
// ellas, como hacen Chrome y Edge. Antes se cargaban todas a la vez: con 5 pestañas, 5
|
// ellas, como hacen Chrome y Edge. Antes se cargaban todas a la vez: con 5 pestañas, 5
|
||||||
// copias enteras de la web app arrancando juntas.
|
// copias enteras de la web app arrancando juntas.
|
||||||
let restore: Vec<(String, String, String)> = {
|
let restore: Vec<(String, String, String, String, String)> = {
|
||||||
let server = Url::parse(SERVER_URL).expect("URL del servidor válida");
|
let server = Url::parse(SERVER_URL).expect("URL del servidor válida");
|
||||||
saved
|
saved
|
||||||
.tabs
|
.tabs
|
||||||
@@ -1824,7 +1925,8 @@ pub fn run() {
|
|||||||
.filter(|(_, u)| Url::parse(u).map(|p| es_pestana_interna(&p, &server)).unwrap_or(false))
|
.filter(|(_, u)| Url::parse(u).map(|p| es_pestana_interna(&p, &server)).unwrap_or(false))
|
||||||
.take(12)
|
.take(12)
|
||||||
.map(|(i, u)| {
|
.map(|(i, u)| {
|
||||||
(u.clone(), saved.colors.get(i).cloned().unwrap_or_default(), saved.titles.get(i).cloned().unwrap_or_default())
|
let de = |v: &Vec<String>| v.get(i).cloned().unwrap_or_default();
|
||||||
|
(u.clone(), de(&saved.colors), de(&saved.titles), de(&saved.paginas), de(&saved.nombres))
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
};
|
};
|
||||||
@@ -1832,21 +1934,21 @@ pub fn run() {
|
|||||||
create_tab(&handle, None, true);
|
create_tab(&handle, None, true);
|
||||||
} else {
|
} else {
|
||||||
let idx = saved.active.min(restore.len() - 1);
|
let idx = saved.active.min(restore.len() - 1);
|
||||||
for (i, (url, color, title)) in restore.iter().enumerate() {
|
for (i, (url, color, title, pagina, nombre)) in restore.iter().enumerate() {
|
||||||
if i == idx {
|
if i == idx {
|
||||||
create_tab(&handle, Some(url.clone()), false);
|
create_tab(&handle, Some(url.clone()), false);
|
||||||
} else {
|
} else {
|
||||||
registrar_diferida(&handle, url, title);
|
registrar_diferida(&handle, url, title);
|
||||||
}
|
}
|
||||||
if !color.is_empty() {
|
// La pestaña se acaba de empujar al final de la lista.
|
||||||
// La pestaña se acaba de empujar al final de la lista.
|
let shell = handle.state::<ShellState>();
|
||||||
let shell = handle.state::<ShellState>();
|
let mut s = shell.lock().unwrap();
|
||||||
let mut s = shell.lock().unwrap();
|
if let Some(t) = s.tabs.last_mut().filter(|t| t.url == *url) {
|
||||||
if let Some(t) = s.tabs.last_mut() {
|
if !color.is_empty() {
|
||||||
if t.url == *url {
|
t.color = Some(color.clone());
|
||||||
t.color = Some(color.clone());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
t.pagina = color_de_pagina(pagina);
|
||||||
|
t.nombre = nombre_de_ventana(nombre);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let label = {
|
let label = {
|
||||||
@@ -1881,7 +1983,13 @@ pub fn run() {
|
|||||||
let h = handle.clone();
|
let h = handle.clone();
|
||||||
handle.listen_any("ls-new-tab", move |e| {
|
handle.listen_any("ls-new-tab", move |e| {
|
||||||
let url = field(e.payload(), "url");
|
let url = field(e.payload(), "url");
|
||||||
create_tab(&h, url, true);
|
let nombre = field(e.payload(), "name").and_then(|n| nombre_de_ventana(&n));
|
||||||
|
if let Some(n) = &nombre {
|
||||||
|
if reusar_pestana(&h, n, url.as_deref()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
crear_pestana(&h, url, true, nombre);
|
||||||
});
|
});
|
||||||
let h = handle.clone();
|
let h = handle.clone();
|
||||||
handle.listen_any("ls-activate", move |e| {
|
handle.listen_any("ls-activate", move |e| {
|
||||||
@@ -1982,11 +2090,12 @@ pub fn run() {
|
|||||||
});
|
});
|
||||||
let h = handle.clone();
|
let h = handle.clone();
|
||||||
handle.listen_any("ls-title", move |e| {
|
handle.listen_any("ls-title", move |e| {
|
||||||
let (label, title, url, dark) = (
|
let (label, title, url, dark, pestana) = (
|
||||||
field(e.payload(), "label"),
|
field(e.payload(), "label"),
|
||||||
field(e.payload(), "title"),
|
field(e.payload(), "title"),
|
||||||
field(e.payload(), "url"),
|
field(e.payload(), "url"),
|
||||||
field_bool(e.payload(), "dark"),
|
field_bool(e.payload(), "dark"),
|
||||||
|
field(e.payload(), "pestana"),
|
||||||
);
|
);
|
||||||
if let Some(label) = label {
|
if let Some(label) = label {
|
||||||
let shell = h.state::<ShellState>();
|
let shell = h.state::<ShellState>();
|
||||||
@@ -1998,6 +2107,10 @@ pub fn run() {
|
|||||||
if let Some(url) = url {
|
if let Some(url) = url {
|
||||||
t.url = url;
|
t.url = url;
|
||||||
}
|
}
|
||||||
|
// (una página de antes de la 1.21 no lo manda: se deja como estaba)
|
||||||
|
if let Some(p) = pestana {
|
||||||
|
t.pagina = color_de_pagina(&p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// El tema es global (todas las pestañas del origen comparten modo): el
|
// El tema es global (todas las pestañas del origen comparten modo): el
|
||||||
// último reporte manda, venga de la pestaña que venga.
|
// último reporte manda, venga de la pestaña que venga.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "Labstream OS",
|
"productName": "Labstream OS",
|
||||||
"version": "1.20.0",
|
"version": "1.22.0",
|
||||||
"identifier": "co.labstream.os",
|
"identifier": "co.labstream.os",
|
||||||
"build": {
|
"build": {
|
||||||
"frontendDist": "../dist"
|
"frontendDist": "../dist"
|
||||||
|
|||||||
Referencia en una nueva incidencia
Block a user