diff --git a/pkg/lib/cockpit.d.ts b/pkg/lib/cockpit.d.ts index 6f07c440985d..6572bf8b3375 100644 --- a/pkg/lib/cockpit.d.ts +++ b/pkg/lib/cockpit.d.ts @@ -33,6 +33,7 @@ declare module 'cockpit' { export const manifests: { [package in string]?: JsonObject }; export let language: string; + export let language_direction: string; interface Transport { csrf_token: string; @@ -98,6 +99,8 @@ declare module 'cockpit' { changed(): void; } + function event_target(obj: T): T & EventSource; + /* === Channel =============================== */ interface ControlMessage extends JsonObject { diff --git a/pkg/shell/state.jsx b/pkg/shell/state.tsx similarity index 98% rename from pkg/shell/state.jsx rename to pkg/shell/state.tsx index f7d0cc6f6ebd..eefa45f7f124 100644 --- a/pkg/shell/state.jsx +++ b/pkg/shell/state.tsx @@ -17,6 +17,8 @@ * along with Cockpit; If not, see . */ +// @cockpit-ts-relaxed + import cockpit from "cockpit"; import { Router } from "./router.jsx"; @@ -27,6 +29,8 @@ import { } from "./util.jsx"; export function ShellState() { + let self = null; + /* CONFIG */ @@ -75,26 +79,23 @@ export function ShellState() { machines.addEventListener("ready", on_ready); - machines.addEventListener("removed", (ev, machine) => { + machines.addEventListener("removed", (_, machine) => { remove_machine_frames(machine); }); - machines.addEventListener("added", (ev, machine) => { + machines.addEventListener("added", (_, machine) => { preload_machine_frames(machine); }); - machines.addEventListener("updated", (ev, machine) => { + machines.addEventListener("updated", (_, machine) => { if (!machine.visible || machine.problem) remove_machine_frames(machine); else preload_machine_frames(machine); }); - if (machines.ready) - on_ready(); - function on_ready() { if (machines.ready && config_ready) { self.ready = true; - window.addEventListener("popstate", ev => { + window.addEventListener("popstate", () => { update(); ensure_frame_loaded(); ensure_connection(); @@ -110,7 +111,7 @@ export function ShellState() { */ const watchdog = cockpit.channel({ payload: "null" }); - watchdog.addEventListener("close", (event, options) => { + watchdog.addEventListener("close", (_, options) => { const watchdog_problem = options.problem || "disconnected"; console.warn("transport closed: " + watchdog_problem); self.problem = watchdog_problem; @@ -337,13 +338,13 @@ export function ShellState() { }, }; + const router = new Router(router_callbacks); + function send_frame_hidden_hint (frame_name) { const hidden = !self.current_frame || self.current_frame.name != frame_name; router.hint(frame_name, { hidden }); } - const router = new Router(router_callbacks); - /* NAVIGATION * * The main navigation function, jump(), will change @@ -501,35 +502,6 @@ export function ShellState() { * for the "Overview" menu entry from the "system" package. */ - const self = { - ready: false, - problem: null, - has_oops: false, - - config, - page_status, - frames, - - current_location: null, - current_machine: null, - current_manifest_item: null, - current_machine_manifest_items: null, - current_manifest: null, - - // Methods - jump, - remove_frame, - most_recent_path_for_host, - - // Access to the inner parts of the machinery, use with - // caution. - machines, - loader, - router, - }; - - cockpit.event_target(self); - function update() { if (!self.ready || self.problem) { self.dispatchEvent("update"); @@ -553,6 +525,7 @@ export function ShellState() { if (!machine || !machine.visible) { machine = { key: location.host, + connection_string: location.host, address: location.host, label: location.host, state: "failed", @@ -608,7 +581,36 @@ export function ShellState() { self.dispatchEvent("update"); } - self.update = update; + self = { + ready: false, + problem: null, + has_oops: false, + + config, + page_status, + frames, + + current_location: null, + current_machine: null, + current_manifest_item: null, + current_machine_manifest_items: null, + current_manifest: null, + + // Methods + jump, + remove_frame, + most_recent_path_for_host, + update, + + // Access to the inner parts of the machinery, use with + // caution. + machines, + loader, + router, + }; + + cockpit.event_target(self); + on_ready(); return self; }