mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
implement demo mode
This commit is contained in:
54
plugin/src/demo-guards.js
Normal file
54
plugin/src/demo-guards.js
Normal file
@@ -0,0 +1,54 @@
|
||||
// Demo-mode UX guards that run at the document level.
|
||||
//
|
||||
// Disable any email/password inputs to prevent users from entering credentials into a server they don't control.
|
||||
|
||||
const PLACEHOLDER =
|
||||
"Disabled in demo. Don't enter credentials on a server you don't control.";
|
||||
|
||||
function isDemoMode() {
|
||||
return document.body && document.body.dataset.demoMode === "true";
|
||||
}
|
||||
|
||||
function disableInputs(root) {
|
||||
const inputs = root.querySelectorAll(
|
||||
'input[type="email"], input[type="password"]',
|
||||
);
|
||||
|
||||
for (const input of inputs) {
|
||||
if (input.dataset.ignisDemoDisabled === "1") {
|
||||
continue;
|
||||
}
|
||||
|
||||
input.disabled = true;
|
||||
input.value = "";
|
||||
input.placeholder = PLACEHOLDER;
|
||||
input.dataset.ignisDemoDisabled = "1";
|
||||
}
|
||||
}
|
||||
|
||||
let observer = null;
|
||||
|
||||
function startDemoGuards() {
|
||||
if (!isDemoMode() || observer) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Walk what's already there.
|
||||
disableInputs(document.body);
|
||||
|
||||
// And watch for anything added later (login modals, plugin dialogs, etc.).
|
||||
observer = new MutationObserver(() => {
|
||||
disableInputs(document.body);
|
||||
});
|
||||
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
}
|
||||
|
||||
function stopDemoGuards() {
|
||||
if (observer) {
|
||||
observer.disconnect();
|
||||
observer = null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { startDemoGuards, stopDemoGuards };
|
||||
@@ -4,6 +4,7 @@ const { patchSettingsModal, unpatchSettingsModal } = require("./settings/inject"
|
||||
const pluginRegistry = require("./plugin-registry");
|
||||
const { initStatusBar } = require("./status-bar");
|
||||
const { WorkspacePickerModal } = require("./workspace-picker");
|
||||
const { startDemoGuards, stopDemoGuards } = require("./demo-guards");
|
||||
|
||||
window.__obsidianAPI = require("obsidian");
|
||||
|
||||
@@ -13,6 +14,7 @@ class IgnisBridgePlugin extends Plugin {
|
||||
|
||||
await pluginRegistry.refresh();
|
||||
patchSettingsModal(this);
|
||||
startDemoGuards();
|
||||
this._statusBarInterval = initStatusBar(this);
|
||||
|
||||
this.addRibbonIcon("upload", "Upload file", () => {
|
||||
@@ -44,6 +46,7 @@ class IgnisBridgePlugin extends Plugin {
|
||||
}
|
||||
|
||||
unpatchSettingsModal(this);
|
||||
stopDemoGuards();
|
||||
console.log("[ignis-bridge] Plugin unloaded");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user