Skip to content

Commit

Permalink
Merge pull request #132 from KKoukiou/wait-for-backend-to-be-ready
Browse files Browse the repository at this point in the history
Use flag file to get signaled when backend is ready
  • Loading branch information
KKoukiou committed Jan 23, 2024
2 parents 3055387 + 34ac9f9 commit d89f701
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import cockpit from "cockpit";
import React, { useCallback, useEffect, useState } from "react";

import {
Bullseye,
Page, PageGroup,
} from "@patternfly/react-core";

Expand All @@ -37,6 +38,7 @@ import { PayloadsClient } from "../apis/payloads";
import { RuntimeClient, initDataRuntime, startEventMonitorRuntime } from "../apis/runtime";
import { NetworkClient, initDataNetwork, startEventMonitorNetwork } from "../apis/network.js";
import { UsersClient } from "../apis/users";
import { EmptyStatePanel } from "cockpit-components-empty-state";

import { setCriticalErrorAction } from "../actions/miscellaneous-actions.js";

Expand All @@ -48,6 +50,7 @@ const _ = cockpit.gettext;
const N_ = cockpit.noop;

export const Application = () => {
const [backendReady, setBackendReady] = useState(false);
const [address, setAddress] = useState();
const [conf, setConf] = useState();
const [language, setLanguage] = useState();
Expand All @@ -62,6 +65,16 @@ export const Application = () => {
}, [dispatch]);

useEffect(() => {
cockpit.file("/run/anaconda/backend_ready").watch(
res => setBackendReady(res !== null)
);
}, []);

useEffect(() => {
if (!backendReady) {
return;
}

// Before unload ask the user for verification
window.onbeforeunload = e => "";

Expand Down Expand Up @@ -106,12 +119,18 @@ export const Application = () => {
);

readOsRelease().then(osRelease => setOsRelease(osRelease));
}, [dispatch, onCritFail]);
}, [dispatch, onCritFail, backendReady]);

// Postpone rendering anything until we read the dbus address and the default configuration
if (!criticalError && (!address || !conf || !osRelease || !storeInitilized)) {
debug("Loading initial data...");
return null;
return (
<Page>
<Bullseye>
<EmptyStatePanel loading title={_("Initializing...")} />
</Bullseye>
</Page>
);
}

// On live media rebooting the system will actually shut it off
Expand Down

0 comments on commit d89f701

Please sign in to comment.