Skip to content

Commit

Permalink
WIP - get rid of Index.current_frame()
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer committed Sep 25, 2024
1 parent a865869 commit 3444e8b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 68 deletions.
14 changes: 0 additions & 14 deletions pkg/shell/base_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const shell_embedded = window.location.pathname.indexOf(".html") !== -1;

function Index() {
const self = this;
let current_frame;

cockpit.event_target(self);

Expand Down Expand Up @@ -128,19 +127,6 @@ function Index() {
self.dispatchEvent("update");
};

self.current_frame = function (frame) {
if (frame !== undefined) {
if (current_frame !== frame) {
if (current_frame)
self.router.hint(current_frame.name, { hidden: true });
if (frame)
self.router.hint(frame.name, { hidden: false });
}
current_frame = frame;
}
return current_frame;
};

self.start = function() {
self.router.start([]);
};
Expand Down
1 change: 0 additions & 1 deletion pkg/shell/frames.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ export const Frames = ({ state, idle_state, hidden }) => {
for (const name in frames) {
const frame = frames[name];
let iframe = iframes_by_name[name];
let need_poll = false;

if (!iframe) {
iframe = iframe_new(name);
Expand Down
38 changes: 10 additions & 28 deletions pkg/shell/router.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,39 +77,23 @@ export function Router(index) {
}, false);

function perform_jump(child, control) {
const current_frame = index.current_frame();
if (child !== window) {
if (!current_frame || current_frame.name != child.name)
return;
}
let str = control.location || "";
if (str[0] != "/")
str = "/" + str;
if (control.host)
str = "/@" + encodeURIComponent(control.host) + str;
index.jump(str);
index.ensure_connection();

index.perform_frame_jump_command(child.name, str);
}

function perform_track(child) {
const current_frame = index.current_frame();
/* Note that we ignore tracking for old shell code */
if (current_frame && current_frame.name === child.name &&
child.name && child.name.indexOf("/shell/shell") === -1) {
let hash = child.location.hash;
if (hash.indexOf("#") === 0)
hash = hash.substring(1);
if (hash === "/")
hash = "";
/* The browser has already pushed an appropriate entry to
the history, so let's just replace it with one that
includes the right hash.
*/
const location = Object.assign({}, decode_window_location(), { hash });
replace_window_location(location);
index.track_hash(location.host, location.path, location.hash);
index.navigate();
}
let hash = child.location.hash;
if (hash.indexOf("#") === 0)
hash = hash.substring(1);
if (hash === "/")
hash = "";

index.perform_frame_hash_track(child.name, hash);
}

function on_unload(ev) {
Expand Down Expand Up @@ -257,9 +241,7 @@ export function Router(index) {
child.postMessage("\n" + JSON.stringify(reply), origin);
source.inited = true;

/* If this new frame is not the current one, tell it */
if (child.frameElement.name != index.current_frame()?.name)
self.hint(child.frameElement.name, { hidden: true });
index.perform_frame_hidden_hint(child.frameElement.name);
}
} else if (control.command === "jump") {
perform_jump(child, control);
Expand Down
75 changes: 50 additions & 25 deletions pkg/shell/state.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ export function ShellState(trigger_connection_flow) {

cockpit.event_target(self);

function perform_frame_hidden_hint (frame_name) {
const hidden = !self.current_frame || self.current_frame.name != frame_name;
console.log("HIDDEN HINT", frame_name, hidden);
self.index.router.hint(frame_name, { hidden });
}

const index_options = {
navigate: function () {
return update();
Expand All @@ -283,6 +289,33 @@ export function ShellState(trigger_connection_flow) {
ensure_connection();
},

perform_frame_jump_command: function (frame_name, location) {
console.log("FRAME JUMP", frame_name, location);
if (frame_name == "cockpit1" || (self.current_frame && self.current_frame.name == frame_name)) {
self.index.jump(location);
ensure_connection();
}
},

perform_frame_hash_track: function (frame_name, hash) {
// XXX - why do we only track the hash of the current frame?

/* Note that we ignore tracking for old shell code */
if (self.current_frame && self.current_frame.name === frame_name &&
frame_name && frame_name.indexOf("/shell/shell") === -1) {
/* The browser has already pushed an appropriate entry to
the history, so let's just replace it with one that
includes the right hash.
*/
const location = Object.assign({}, decode_window_location(), { hash });
replace_window_location(location);
index.track_hash(location.host, location.path, location.hash);
update();
}
},

perform_frame_hidden_hint,

handle_notifications: function (host, page, data) {
if (data.page_status !== undefined)
notify_page_status(host, page, data.page_status);
Expand Down Expand Up @@ -348,7 +381,7 @@ export function ShellState(trigger_connection_flow) {
function update() {
self.has_oops = index.has_oops;

if (self.problem) {
if (!self.ready || self.problem) {
self.dispatchEvent("update");
return;
}
Expand Down Expand Up @@ -392,9 +425,22 @@ export function ShellState(trigger_connection_flow) {
self.current_machine_manifest_items = compiled;
self.current_manifest_item = item;

update_frame(machine, location, self.current_manifest_item.label);

self.current_frame = Object.values(frames).find(f => f.host == location.host && f.path == location.path);
const frame = (((machine.state == "connected" || machine.state == "connecting") && location.path)
? ensure_frame(machine,
location.path,
location.hash,
self.current_manifest_item.label)
: null);

if (frame != self.current_frame) {
const prev_frame = self.current_frame;
self.current_frame = frame;

if (prev_frame)
perform_frame_hidden_hint(prev_frame.name);
if (frame)
perform_frame_hidden_hint(frame.name);
}

self.dispatchEvent("update");
}
Expand All @@ -418,27 +464,6 @@ export function ShellState(trigger_connection_flow) {
}
}

function update_frame(machine, location, title) {
let current_frame = index.current_frame();

if (machine.state != "connected") {
current_frame = null;
index.current_frame(current_frame);

/* Fall through when connecting, and allow frame to load at same time */
if (machine.state != "connecting")
return;
}

const hash = location.hash;
const path = location.path;

const frame = path ? ensure_frame(machine, path, hash, title) : undefined;
if (frame != current_frame) {
index.current_frame(frame);
}
}

function choose_path(location, compiled) {
/* Go for the first item */
const menu_items = compiled.ordered("menu");
Expand Down

0 comments on commit 3444e8b

Please sign in to comment.