mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
server plugin list
This commit is contained in:
@@ -21,7 +21,7 @@ function createNavEl(tab, setting) {
|
||||
return nav;
|
||||
}
|
||||
|
||||
function createTab(id, name, displayFn) {
|
||||
function createTab(id, name, displayFn, app) {
|
||||
const tab = {
|
||||
id,
|
||||
name,
|
||||
@@ -30,7 +30,7 @@ function createTab(id, name, displayFn) {
|
||||
|
||||
display() {
|
||||
this.containerEl.empty();
|
||||
displayFn(this.containerEl);
|
||||
displayFn(this.containerEl, app);
|
||||
},
|
||||
|
||||
hide() {
|
||||
@@ -41,7 +41,7 @@ function createTab(id, name, displayFn) {
|
||||
return tab;
|
||||
}
|
||||
|
||||
function injectIgnisSettings(setting) {
|
||||
function injectIgnisSettings(setting, app) {
|
||||
const group = document.createElement("div");
|
||||
group.className = "vertical-tab-header-group";
|
||||
|
||||
@@ -55,8 +55,8 @@ function injectIgnisSettings(setting) {
|
||||
group.appendChild(items);
|
||||
|
||||
const tabs = [
|
||||
createTab("ignis-general", "General", generalTab.display),
|
||||
createTab("ignis-server-plugins", "Server Plugins", serverPluginsTab.display),
|
||||
createTab("ignis-general", "General", generalTab.display, app),
|
||||
createTab("ignis-server-plugins", "Server Plugins", serverPluginsTab.display, app),
|
||||
];
|
||||
|
||||
for (const tab of tabs) {
|
||||
@@ -69,11 +69,12 @@ function injectIgnisSettings(setting) {
|
||||
|
||||
function patchSettingsModal(plugin) {
|
||||
const original = plugin.app.setting.onOpen;
|
||||
const app = plugin.app;
|
||||
plugin._originalOnOpen = original;
|
||||
|
||||
plugin.app.setting.onOpen = function () {
|
||||
original.call(this);
|
||||
injectIgnisSettings(this);
|
||||
injectIgnisSettings(this, app);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,102 @@
|
||||
const { Setting } = require("obsidian");
|
||||
const { Setting, Notice } = require("obsidian");
|
||||
|
||||
function display(containerEl) {
|
||||
function getVaultId() {
|
||||
return window.__currentVaultId || "";
|
||||
}
|
||||
|
||||
async function fetchPlugins() {
|
||||
const res = await fetch("/api/plugins");
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error("Failed to fetch plugins");
|
||||
}
|
||||
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function togglePlugin(pluginId, enable, app) {
|
||||
const action = enable ? "enable" : "disable";
|
||||
const vaultId = getVaultId();
|
||||
|
||||
const res = await fetch(`/api/plugins/${pluginId}/${action}`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ vault: vaultId }),
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
throw new Error(data.error || `Failed to ${action} plugin`);
|
||||
}
|
||||
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function activateBundledPlugin(bundledPluginId, enable, app) {
|
||||
if (!bundledPluginId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const plugins = app.plugins;
|
||||
|
||||
if (enable) {
|
||||
await plugins.loadManifests();
|
||||
await plugins.enablePluginAndSave(bundledPluginId);
|
||||
} else {
|
||||
await plugins.disablePluginAndSave(bundledPluginId);
|
||||
}
|
||||
}
|
||||
|
||||
function display(containerEl, app) {
|
||||
containerEl.createEl("h2", { text: "Server Plugins" });
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Example text input")
|
||||
.setDesc("This is a test input to prove a second tab works.")
|
||||
.addText((text) => {
|
||||
text.setPlaceholder("Type something...");
|
||||
const loadingEl = containerEl.createEl("p", { text: "Loading plugins..." });
|
||||
|
||||
fetchPlugins()
|
||||
.then((plugins) => {
|
||||
loadingEl.remove();
|
||||
|
||||
if (plugins.length === 0) {
|
||||
containerEl.createEl("p", {
|
||||
text: "No server plugins available.",
|
||||
cls: "setting-item-description",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const vaultId = getVaultId();
|
||||
|
||||
for (const plugin of plugins) {
|
||||
const enabled = plugin.enabledVaults.includes(vaultId);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(plugin.name)
|
||||
.setDesc(plugin.description || "")
|
||||
.addToggle((toggle) => {
|
||||
toggle.setValue(enabled);
|
||||
toggle.onChange(async (value) => {
|
||||
try {
|
||||
await togglePlugin(plugin.id, value, app);
|
||||
await activateBundledPlugin(
|
||||
plugin.bundledPluginId,
|
||||
value,
|
||||
app,
|
||||
);
|
||||
|
||||
new Notice(
|
||||
`${plugin.name} ${value ? "enabled" : "disabled"} for this vault.`,
|
||||
);
|
||||
} catch (e) {
|
||||
new Notice(`Failed: ${e.message}`);
|
||||
toggle.setValue(!value);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
loadingEl.setText("Failed to load plugins.");
|
||||
console.error("[ignis-bridge] Server plugins error:", e);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user