jan/web/app/page.tsx
Louis b46042654c
chore: update core services and module export (#376)
* chore: update core services and module export

* Correct version of plugins (#374)

Co-authored-by: Hien To <tominhhien97@gmail.com>

* janhq/jan: Update tag build 1.0.2 for data-plugin

* janhq/jan: Update tag build 1.0.2 for inference-plugin

* janhq/jan: Update tag build 1.0.2 for model-management-plugin

* janhq/jan: Update tag build 1.0.2 for monitoring-plugin

* janhq/jan: Update tag build 1.0.2 for openai-plugin

* chore: update web to use @janhq/core module

---------

Co-authored-by: hiento09 <136591877+hiento09@users.noreply.github.com>
Co-authored-by: Hien To <tominhhien97@gmail.com>
Co-authored-by: Service Account <service@jan.ai>
2023-10-17 19:48:43 +07:00

84 lines
2.5 KiB
TypeScript

"use client";
import { PluginService } from "@janhq/core";
import { ThemeWrapper } from "./_helpers/ThemeWrapper";
import JotaiWrapper from "./_helpers/JotaiWrapper";
import { ModalWrapper } from "./_helpers/ModalWrapper";
import { useEffect, useState } from "react";
import Image from "next/image";
import { setup, plugins, activationPoints, extensionPoints } from "../../electron/core/plugin-manager/execution/index";
import { isCorePluginInstalled, setupBasePlugins } from "./_services/pluginService";
import EventListenerWrapper from "./_helpers/EventListenerWrapper";
import { setupCoreServices } from "./_services/coreService";
import MainContainer from "./_components/MainContainer";
import { executeSerial } from "../../electron/core/plugin-manager/execution/extension-manager";
const Page: React.FC = () => {
const [setupCore, setSetupCore] = useState(false);
const [activated, setActivated] = useState(false);
async function setupPE() {
// Enable activation point management
setup({
importer: (plugin: string) =>
import(/* webpackIgnore: true */ plugin).catch((err) => {
console.log(err);
}),
});
// Register all active plugins with their activation points
await plugins.registerActive();
setTimeout(async () => {
// Trigger activation points
await activationPoints.trigger("init");
if (!isCorePluginInstalled()) {
setupBasePlugins();
return;
}
if (extensionPoints.get(PluginService.OnStart)) {
await executeSerial(PluginService.OnStart);
}
setActivated(true);
}, 500);
}
// Services Setup
useEffect(() => {
setupCoreServices();
setSetupCore(true);
}, []);
useEffect(() => {
if (setupCore) {
// Electron
if (window && window.electronAPI) {
setupPE();
} else {
// Host
setActivated(true);
}
}
}, [setupCore]);
return (
<JotaiWrapper>
{setupCore && (
<EventListenerWrapper>
<ThemeWrapper>
<ModalWrapper>
{activated ? (
<MainContainer />
) : (
<div className="bg-white w-screen h-screen items-center justify-center flex">
<Image width={50} height={50} src="icons/app_icon.svg" alt="" />
</div>
)}
</ModalWrapper>
</ThemeWrapper>
</EventListenerWrapper>
)}
</JotaiWrapper>
);
};
export default Page;