Skip to content

Commit

Permalink
feat: prepare for native integration
Browse files Browse the repository at this point in the history
  • Loading branch information
twnlink committed Jun 24, 2024
1 parent 36cd0ed commit 6242c28
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/api/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ export const getPluginById = (id) => pluginStore.find((p) => p.id == id);
export async function disablePlugin(id) {
getPluginById(id).enabled = false;
const onUnload = enabled?.[id]?.onUnload;
const unloadables = enabled?.[id]?.unloadables;

delete enabled[id];

try {
await onUnload?.();
} catch (e) {
console.error("Failed to completely clean up neptune plugin!\n", e);
} finally {
await unloadables.forEach(u => u())
}
}

Expand All @@ -43,10 +46,14 @@ async function runPlugin(plugin) {

await persistentStorageReady;

const unloadables = [];
const pluginData = {
id: plugin.id,
manifest: plugin.manifest,
storage: persistentStorage,
addUnloadable(callback) {
unloadables.push(callback)
}
};

const { onUnload, Settings } = await quartz(plugin.code, {
Expand Down Expand Up @@ -79,7 +86,7 @@ async function runPlugin(plugin) {
],
});

enabled[plugin.id] = { onUnload: onUnload ?? (() => {}) };
enabled[plugin.id] = { onUnload: onUnload ?? (() => {}), unloadables };
if (Settings) enabled[plugin.id].Settings = Settings;
} catch (e) {
await disablePlugin(plugin.id);
Expand Down
17 changes: 16 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ declare module "@neptune/plugins" {
const mod: typeof import("./api/plugins");
export = mod;
}
declare module "@neptune/componoents" {
declare module "@neptune/components" {
const mod: typeof import("./ui/components");
export = mod;
}
Expand All @@ -60,6 +60,21 @@ declare module "@neptune" {
exports: any;
}>;
}

type JSONObject = { [x: string]: JSONValue };
type JSONValue = string | number | boolean | JSONObject | Array<JSONValue>;

declare module "@plugin" {
export const id: string;
export const manifest: {
name: string;
author: string;
description: string;
};
export const storage: JSONObject;
export const addUnloadable: (callback: () => void) => void;
}

// declare module "@neptune/store" {
// type Store = import("redux").Store<import("./tidal").CoreState>;
// export default Store;
Expand Down
2 changes: 1 addition & 1 deletion types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "neptune-types",
"version": "1.0.0",
"version": "1.0.1",
"description": "TypeScript type declarations for neptune plugins",
"homepage": "https://github.com/uwu/neptune/tree/master/types",
"license": "MS-PL",
Expand Down

0 comments on commit 6242c28

Please sign in to comment.