jan/web/app/page.tsx
Louis 5fc1ba7067
feature: @janhq/plugin-core module & plugins update (#321)
* @janhq/plugin-core module

* refactor web to use exported services from module

* refactor data-plugin to provide DAL & move model logics to model management plugin

* model-management in TS

* add ci auto package, increate version, and publish to npm repository

* chore: storage operations

* chore: hybrid data-plugin esm & cjs module

* chore: PouchDB Driver

* chore: documentation

---------

Co-authored-by: Hien To <hien@jan.ai>
Co-authored-by: Service Account <service@jan.ai>
2023-10-14 15:59:28 +07:00

85 lines
2.2 KiB
TypeScript

"use client";
import { ThemeWrapper } from "./_helpers/ThemeWrapper";
import JotaiWrapper from "./_helpers/JotaiWrapper";
import RightContainer from "./_components/RightContainer";
import { ModalWrapper } from "./_helpers/ModalWrapper";
import { useEffect, useState } from "react";
import Image from "next/image";
import {
setup,
plugins,
activationPoints,
} from "../../electron/core/plugin-manager/execution/index";
import {
isCorePluginInstalled,
setupBasePlugins,
} from "./_services/pluginService";
import LeftContainer from "./_components/LeftContainer";
import EventListenerWrapper from "./_helpers/EventListenerWrapper";
import { setupCoreServices } from "./_services/coreService";
const Page: React.FC = () => {
const [activated, setActivated] = useState(false);
// Services Setup
useEffect(() => {
// Setup Core Service
setupCoreServices();
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;
}
setActivated(true);
}, 500);
}
// Electron
if (window && window.electronAPI) {
setupPE();
} else {
// Host
setActivated(true);
}
}, []);
return (
<JotaiWrapper>
<EventListenerWrapper>
<ThemeWrapper>
<ModalWrapper>
{activated && (
<div className="flex">
<LeftContainer />
<RightContainer />
</div>
)}
{!activated && (
<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;