CH-J Toolsgestión de servidores a través de SSH
Menú
Fuente publicada

CH-J Tools

Busque directorios y archivos para obtener una versión de aplicación específica.

Descargar fuente ZIP
CH-J / Server Manager 1704 archivos
0.1.2-beta Añadido: · Construido:
module-bridge.ts Añadido: Fecha no registrada 5,3 KB · 118 líneas
Código Descargar archivo
1/**
2 * Module-window bridge. Exposes the public Module API as `window.chjModule` and, for
3 * backwards compatibility, under the 0.1.0 name `window.chjPlugin` (same object, same
4 * method names). Also injects the shared Core window chrome (title + "Collapse").
5 */
6import { moduleApi } from "../index";
7import { subscribe } from "../transport";
8import { bootInfo } from "./boot";
9import { installWindowChrome, setWindowControlsEnabled } from "./windowChrome";
10import { installActivityReporter } from "./activity";
12const boot = bootInfo();
14const api = Object.freeze({
15 apiVersion: moduleApi.version,
16 getInfo: moduleApi.getInfo,
17 host: moduleApi.host,
18 ui: moduleApi.ui,
19 close: moduleApi.close,
20 sessions: moduleApi.sessions,
21 system: moduleApi.system,
22 disks: moduleApi.disks,
23 keys: moduleApi.keys,
24 logs: moduleApi.logs,
25 users: moduleApi.users,
26 apache: moduleApi.apache,
27 rsync: moduleApi.rsync,
28 network: moduleApi.network,
29 nginx: moduleApi.nginx,
30 files: moduleApi.files,
31 hashing: moduleApi.hashing
32});
34for (const name of ["chjModule", "chjPlugin"]) {
35 Object.defineProperty(window, name, { value: api, writable: false, configurable: false, enumerable: true });
38// "Collapse" texts come from the core catalogs (i18n/core/<language>.json), injected by the Core.
39declare global { var __CHJ_I18N__: { catalogs?: { chrome?: Record<string, Record<string, string>> } } | undefined }
40function chromeCopy(language: string): [string, string] {
41 const catalogs = globalThis.__CHJ_I18N__?.catalogs?.chrome || {};
42 const entry = catalogs[language] || catalogs.en || {};
43 return [entry["chrome.collapse"] || "Collapse", entry["chrome.collapseDescription"] || "Collapse into the application's bottom bar"];
46let chromeRoot: ShadowRoot | null = null;
48window.addEventListener("DOMContentLoaded", () => {
49 document.documentElement.toggleAttribute("data-chj-embedded", true);
50 const styleUrl = new URL("/__chj_core__/window-chrome.css", window.location.href).href;
51 const host = document.createElement("chj-plugin-chrome");
52 host.id = "chj-plugin-window-chrome";
53 const shadow = host.attachShadow({ mode: "open" });
54 chromeRoot = shadow;
55 let loaded = 0;
56 const theme = document.createElement("link");
57 theme.rel = "stylesheet";
58 theme.href = new URL("/__chj_core__/theme.css", window.location.href).href;
59 document.head.prepend(theme);
60 const stylesheet = () => {
61 const link = document.createElement("link");
62 link.rel = "stylesheet";
63 link.href = styleUrl;
64 link.addEventListener("load", () => { if (++loaded === 2) host.dataset.ready = "true"; });
65 return link;
66 };
67 document.head.append(stylesheet());
68 const header = document.createElement("header");
69 header.id = "chj-chrome-header";
70 if (boot.platform === "win32" || boot.platform === "linux") header.className = "native-controls";
71 const mark = document.createElement("span");
72 mark.id = "chj-chrome-mark";
73 mark.textContent = "CH-J";
74 const title = document.createElement("span");
75 title.id = "chj-chrome-title";
76 title.textContent = document.title || "CH-J Tools";
77 const collapse = document.createElement("button");
78 collapse.type = "button";
79 collapse.id = "chj-chrome-collapse";
80 const hostButton = document.createElement("button");
81 hostButton.type = "button";
82 hostButton.id = "chj-chrome-host";
83 let embedded = true;
84 let currentLanguage = "en";
85 const renderHost = () => {
86 const entry = globalThis.__CHJ_I18N__?.catalogs?.chrome?.[currentLanguage] || globalThis.__CHJ_I18N__?.catalogs?.chrome?.en || {};
87 const label = embedded ? entry["chrome.detach"] || "Open in a window" : entry["chrome.attach"] || "Return to the app";
88 hostButton.textContent = label;
89 hostButton.title = label;
90 hostButton.setAttribute("aria-label", label);
91 if (boot.platform === "win32" || boot.platform === "linux") header.classList.toggle("native-controls", !embedded);
92 setWindowControlsEnabled(!embedded);
93 document.documentElement.toggleAttribute("data-chj-embedded", embedded);
94 };
95 const applyHost = (state: { embedded: boolean }) => { embedded = state.embedded !== false; renderHost(); };
96 hostButton.addEventListener("click", () => { void (embedded ? moduleApi.host.detach() : moduleApi.host.attach()).then(applyHost).catch((error: unknown) => console.error("Module window change failed.", error)); });
97 subscribe<{ embedded: boolean }>("module:ui:hostChanged", applyHost);
98 void moduleApi.host.state().then(applyHost).catch(() => {});
99 const translate = (language: string) => {
100 currentLanguage = language;
101 renderHost();
102 const [label, description] = chromeCopy(language);
103 collapse.textContent = label;
104 collapse.title = description;
105 collapse.setAttribute("aria-label", description);
106 };
107 translate("en");
108 collapse.addEventListener("click", () => { void moduleApi.minimize().catch((error) => console.error("Module collapse failed.", error)); });
109 subscribe<string>("module:ui:languageChanged", translate);
110 void moduleApi.ui.getLanguage().then(translate).catch(() => {});
111 void moduleApi.getInfo().then((manifest) => { title.textContent = manifest.name; }).catch(() => {});
112 header.append(mark, title, hostButton, collapse);
113 shadow.append(stylesheet(), header);
114 document.body.prepend(host);
115});
117installWindowChrome(boot.platform, ["#chj-chrome-header"], () => (chromeRoot ? [document, chromeRoot] : [document]));
118installActivityReporter();
SHA-2569d04f068fe7b7082802f5126cd1d617f7428713723b7af3354e5b675e70b8dbb

CH-J Proprietary Software License 1.14 · La fuente se proporciona en el CH-J Proprietary Software License 1.14. Su disponibilidad no cambia los términos de la licencia ni otorga derechos adicionales.

Archivo SHA-256ac8fe790f4ba60fc098f8c985fc2656cfcc6cdc21fb34b30e308a2b54e62258f
Archivos