fix: wrong ways to connect context with outside world
This commit is contained in:
parent
46d1336079
commit
3be84cc724
|
@ -1,19 +1,19 @@
|
||||||
import {
|
|
||||||
Browser,
|
|
||||||
BrowserStateProvider,
|
|
||||||
Navigator,
|
|
||||||
} from "@/components/Browser.tsx";
|
|
||||||
import Lume from "@/components/Lume.tsx";
|
|
||||||
import {
|
import {
|
||||||
AuthProvider,
|
AuthProvider,
|
||||||
LumeStatusProvider,
|
LumeStatusProvider,
|
||||||
NetworksProvider,
|
NetworksProvider,
|
||||||
} from "@lumeweb/sdk";
|
} from "@lumeweb/sdk";
|
||||||
|
|
||||||
export default function () {
|
import {
|
||||||
|
Browser,
|
||||||
|
BrowserStateProvider,
|
||||||
|
Navigator,
|
||||||
|
} from "@/components/Browser.tsx";
|
||||||
|
import Lume from "@/components/Lume.tsx";
|
||||||
|
|
||||||
|
const App: React.FC = () => {
|
||||||
return (
|
return (
|
||||||
<BrowserStateProvider>
|
<BrowserStateProvider>
|
||||||
<>
|
|
||||||
<LumeStatusProvider>
|
<LumeStatusProvider>
|
||||||
<AuthProvider>
|
<AuthProvider>
|
||||||
<header className="relative h-14 px-2 pl-2 py-2 w-full bg-neutral-900 flex">
|
<header className="relative h-14 px-2 pl-2 py-2 w-full bg-neutral-900 flex">
|
||||||
|
@ -30,7 +30,8 @@ export default function () {
|
||||||
<Browser />
|
<Browser />
|
||||||
</AuthProvider>
|
</AuthProvider>
|
||||||
</LumeStatusProvider>
|
</LumeStatusProvider>
|
||||||
</>
|
|
||||||
</BrowserStateProvider>
|
</BrowserStateProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default App;
|
||||||
|
|
|
@ -65,19 +65,24 @@ export function useBrowserState() {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function boot(status: LumeStatusContextType, auth: AuthContextType) {
|
async function boot({
|
||||||
|
onInit,
|
||||||
|
onAuth,
|
||||||
|
onBoot,
|
||||||
|
}: {onInit: (inited: boolean) => Promise<void> | void, onAuth: (authed: boolean) => Promise<void> | void, onBoot: (booted: boolean) => Promise<void> | void}) {
|
||||||
const reg = await navigator.serviceWorker.register("/sw.js");
|
const reg = await navigator.serviceWorker.register("/sw.js");
|
||||||
await reg.update();
|
await reg.update();
|
||||||
|
|
||||||
await kernel.serviceWorkerReady();
|
await kernel.serviceWorkerReady();
|
||||||
|
|
||||||
kernel.init().then(() => {
|
await kernel.init().catch((err) => {
|
||||||
status.setInited(true);
|
console.error("[Browser.tsx] Failed to init kernel", {error: err});
|
||||||
});
|
});
|
||||||
|
await onInit(true);
|
||||||
await kernelLoaded();
|
await kernelLoaded().catch((err) => {
|
||||||
|
console.error("[Browser.tsx] Failed to load kernel", {error: err});
|
||||||
auth.setIsLoggedIn(true);
|
});
|
||||||
|
await onAuth(true);
|
||||||
|
|
||||||
BOOT_FUNCTIONS.push(
|
BOOT_FUNCTIONS.push(
|
||||||
async () =>
|
async () =>
|
||||||
|
@ -112,7 +117,7 @@ async function boot(status: LumeStatusContextType, auth: AuthContextType) {
|
||||||
for (const resolver of resolvers) {
|
for (const resolver of resolvers) {
|
||||||
BOOT_FUNCTIONS.push(async () => dnsClient.registerResolver(resolver));
|
BOOT_FUNCTIONS.push(async () => dnsClient.registerResolver(resolver));
|
||||||
}
|
}
|
||||||
BOOT_FUNCTIONS.push(async () => status.setReady(true));
|
BOOT_FUNCTIONS.push(async () => onBoot(true));
|
||||||
|
|
||||||
await bootup();
|
await bootup();
|
||||||
|
|
||||||
|
@ -186,7 +191,17 @@ export function Browser() {
|
||||||
const iframeRef = useRef<HTMLIFrameElement>(null);
|
const iframeRef = useRef<HTMLIFrameElement>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
boot(status, auth);
|
boot({
|
||||||
|
onAuth(authed) {
|
||||||
|
auth.setIsLoggedIn(authed)
|
||||||
|
},
|
||||||
|
onBoot(booted) {
|
||||||
|
status.setReady(booted)
|
||||||
|
},
|
||||||
|
onInit(inited) {
|
||||||
|
status.setInited(inited)
|
||||||
|
}
|
||||||
|
}).catch((err) => console.error("[Browser.tsx] Failed to Boot Lume", {error: err}));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleIframeLoad = () => {
|
const handleIframeLoad = () => {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import {
|
||||||
useLumeStatus,
|
useLumeStatus,
|
||||||
} from "@lumeweb/sdk";
|
} from "@lumeweb/sdk";
|
||||||
|
|
||||||
export default function () {
|
const Lume: React.FC = () => {
|
||||||
const { isLoggedIn } = useAuth();
|
const { isLoggedIn } = useAuth();
|
||||||
const { ready, inited } = useLumeStatus();
|
const { ready, inited } = useLumeStatus();
|
||||||
|
|
||||||
|
@ -30,3 +30,5 @@ export default function () {
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Lume;
|
Loading…
Reference in New Issue