"use client"; import { useEffect, useRef, useState } from "react"; import { setup, plugins, extensionPoints, activationPoints, } from "@/../../electron/core/plugin-manager/execution/index"; import { ChartPieIcon, CommandLineIcon, PlayIcon, } from "@heroicons/react/24/outline"; import { MagnifyingGlassIcon } from "@heroicons/react/20/solid"; import classNames from "classnames"; /* eslint-disable @next/next/no-sync-scripts */ export const Preferences = () => { const [search, setSearch] = useState(""); const [activePlugins, setActivePlugins] = useState([]); const [isTestAvailable, setIsTestAvailable] = useState(false); const [fileName, setFileName] = useState(""); const handleFileChange = (event: React.ChangeEvent) => { const file = event.target.files?.[0]; if (file) { setFileName(file.name); } else { setFileName(""); } }; const preferenceRef = useRef(null); useEffect(() => { async function setupPE() { // Enable activation point management setup({ //@ts-ignore importer: (plugin) => import(/* webpackIgnore: true */ plugin).catch((err) => { console.log(err); }), }); // Register all active plugins with their activation points await plugins.registerActive(); } const activePlugins = async () => { const plgs = await plugins.getActive(); setActivePlugins(plgs); // Activate alls setTimeout(async () => { await activationPoints.trigger("init"); if (extensionPoints.get("experimentComponent")) { const components = await Promise.all( extensionPoints.execute("experimentComponent") ); if (components.length > 0) { setIsTestAvailable(true); } components.forEach((e) => { if (preferenceRef.current) { // @ts-ignore preferenceRef.current.appendChild(e); } }); } }, 500); }; setupPE().then(() => activePlugins()); }, []); // Install a new plugin on clicking the install button const install = async (e: any) => { e.preventDefault(); //@ts-ignore const pluginFile = new FormData(e.target).get("plugin-file").path; // Send the filename of the to be installed plugin // to the main process for installation const installed = await plugins.install([pluginFile]); if (installed) window.electronAPI.relaunch(); }; // Uninstall a plugin on clicking uninstall const uninstall = async (name: string) => { //@ts-ignore // Send the filename of the to be uninstalled plugin // to the main process for removal //@ts-ignore const res = await plugins.uninstall([name]); console.log( res ? "Plugin successfully uninstalled" : "Plugin could not be uninstalled" ); if (res) window.electronAPI.relaunch(); }; // Update all plugins on clicking update plugins const update = async (plugin: string) => { if (typeof window !== "undefined") { // @ts-ignore await window.pluggableElectronIpc.update([plugin], true); window.electronAPI.relaunch(); } // plugins.update(active.map((plg) => plg.name)); }; return (
{/* Separator */}
{/* Content */}
Install Plugin
Installed Plugins
{activePlugins .filter( (e) => search.trim() === "" || e.name.toLowerCase().includes(search.toLowerCase()) ) .map((e) => (

{e.name.replaceAll("-", " ")}

Version: {e.version}

{e.description ?? "Jan's Plugin"}

))}
{activePlugins.length > 0 && isTestAvailable && (
Test Plugins
)}
{/* Content */}
); };