Patch electron-builder to use our custom mime.xml

This commit is contained in:
Muffin 2024-06-21 00:33:37 -05:00
parent 511282ef18
commit dd81e44f52
2 changed files with 28 additions and 0 deletions

View File

@ -1,3 +1,5 @@
require('./patch-electron-builder');
const pathUtil = require('path');
const fs = require('fs');
const builder = require('electron-builder');

View File

@ -0,0 +1,26 @@
// Very bad things happen in here!
const fsPromises = require('fs/promises');
const pathUtil = require('path');
const packageJSON = require('../package.json');
// Override https://github.com/electron-userland/electron-builder/blob/14942b70a5da79a5e36e330f64de66ec501b4ac6/packages/app-builder-lib/src/targets/LinuxTargetHelper.ts#L28-L53
// The upstream Linux file association support is not great so we'll just replace it with the one
// that we wrote by hand until we can send an upstream-ready PR.
const LinuxTargetHelper = require('../node_modules/app-builder-lib/out/targets/LinuxTargetHelper.js').LinuxTargetHelper;
LinuxTargetHelper.prototype.computeMimeTypeFiles = async function (...args) {
const tempFile = await this.packager.getTempFile('.xml');
console.log(`${packageJSON.name}: LinuxTargetHelper.prototype.computeMimeTypeFiles has been patched. mime.xml to be saved to ${tempFile}`);
const xmlPath = pathUtil.join(__dirname, '../linux-files/org.turbowarp.TurboWarp.mime.xml');
const rawXml = await fsPromises.readFile(xmlPath, 'utf-8');
const newXml = rawXml.replace(/org\.turbowarp\.TurboWarp/g, packageJSON.name);
// Roughly equivalent to fs-extra's outputFile (creates parent directories as needed)
await fsPromises.mkdir(pathUtil.dirname(tempFile), {
recursive: true
});
await fsPromises.writeFile(tempFile, newXml);
return tempFile;
};