mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
make patching more robust. backup original html and patch fresh on every container start.
This commit is contained in:
@@ -14,11 +14,21 @@ if (!asarDir) {
|
||||
}
|
||||
|
||||
function patchHtml(filePath) {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
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
|
||||
@@ -27,18 +37,15 @@ function patchHtml(filePath) {
|
||||
"\n",
|
||||
);
|
||||
|
||||
// Inject favicon into <head>
|
||||
html = html.replace(
|
||||
"</head>",
|
||||
' <link rel="icon" type="image/png" href="favicon.png">\n</head>',
|
||||
);
|
||||
// Inject ignis assets before the first <script> tag
|
||||
const ignisBlock =
|
||||
' <link rel="icon" type="image/png" href="favicon.png">\n' +
|
||||
' <script type="text/javascript" src="ignis-ui.js"></script>\n' +
|
||||
' <script type="text/javascript" src="shim-loader.js"></script>\n';
|
||||
|
||||
// Inject ignis-ui and shim-loader before the first <script> tag
|
||||
html = html.replace(
|
||||
'<script type="text/javascript"',
|
||||
'<script type="text/javascript" src="ignis-ui.js"></script>\n' +
|
||||
'<script type="text/javascript" src="shim-loader.js"></script>\n' +
|
||||
'<script type="text/javascript"',
|
||||
ignisBlock + '<script type="text/javascript"',
|
||||
);
|
||||
|
||||
fs.writeFileSync(filePath, html);
|
||||
|
||||
Reference in New Issue
Block a user