revise ignis loading method

This commit is contained in:
Nystik
2026-04-05 22:32:23 +02:00
parent 1c56a1fa45
commit fade3c30c5
8 changed files with 100 additions and 74 deletions

View File

@@ -52,12 +52,6 @@ else
echo "[ignis] Obsidian already set up."
fi
# Always patch and copy latest bundles (they may have been updated between rebuilds)
node /app/scripts/patch-obsidian.js "$OBSIDIAN_DIR"
cp /app/dist/ignis-ui.js "$OBSIDIAN_DIR/ignis-ui.js"
cp /app/dist/shim-loader.js "$OBSIDIAN_DIR/shim-loader.js"
cp /app/images/favicon.png "$OBSIDIAN_DIR/favicon.png"
cp /app/server/assets/* "$OBSIDIAN_DIR/" 2>/dev/null || true
# Install obsidian-headless (ob CLI) if not already present.
# Not included in the image for legal reasons - installed at runtime.

View File

@@ -1,61 +0,0 @@
#!/usr/bin/env node
// Patches the extracted Obsidian asar for browser use:
// 1. Removes Content-Security-Policy meta tag
// 2. Injects shim-loader.js script (non-deferred, before all other scripts)
// 3. Injects favicon link
const fs = require("fs");
const path = require("path");
const { getVersion } = require("../server/version");
const asarDir = process.argv[2];
if (!asarDir) {
console.error("Usage: node patch-obsidian.js <extracted-asar-dir>");
process.exit(1);
}
function patchHtml(filePath, version) {
const backupPath = filePath + ".orig";
if (!fs.existsSync(filePath) && !fs.existsSync(backupPath)) {
console.warn(`[patch] Skipping (not found): ${filePath}`);
return;
}
// Create backup of the original on first patch; restore from it on subsequent runs
if (!fs.existsSync(backupPath)) {
fs.copyFileSync(filePath, backupPath);
console.log(`[patch] Backed up original: ${backupPath}`);
} else {
fs.copyFileSync(backupPath, filePath);
}
let html = fs.readFileSync(filePath, "utf-8");
// Remove CSP meta tag
html = html.replace(
/\s*<meta\s+http-equiv="Content-Security-Policy"[^>]*>\s*/g,
"\n",
);
// Inject favicon into <head>
html = html.replace(
"</head>",
' <link rel="icon" type="image/png" href="favicon.png">\n</head>',
);
// Inject ignis scripts before the first <script> tag
html = html.replace(
'<script type="text/javascript"',
`<script type="text/javascript" src="ignis-ui.js?v=${version}"></script>\n` +
`<script type="text/javascript" src="shim-loader.js?v=${version}"></script>\n` +
'<script type="text/javascript"',
);
fs.writeFileSync(filePath, html);
console.log(`[patch] Patched ${filePath}`);
}
const version = getVersion();
patchHtml(path.join(asarDir, "index.html"), version);
console.log(`[patch] Injected version: ${version}`);