From f0c68e0b394a08ad04881b6e9c8fb40277a6bd7a Mon Sep 17 00:00:00 2001 From: Steef Hegeman Date: Thu, 16 Apr 2020 14:08:16 +0200 Subject: [PATCH] widen search paths / fix vector-im/riot-web#13190 This does two things related to search paths: - also search for webapp symlink in the case of packaged applications (e.g. Archlinux used to provide a symlink this way, linking to a riot-web copy installed elsewhere, instead of creating an asar of it) - also take dirname(asarPath) as a valid resources path, as this is how riot-desktop currently is packaged. Fixes vector-im/riot-web#13190. --- src/electron-main.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/electron-main.js b/src/electron-main.js index 25bf433..34a6a5a 100644 --- a/src/electron-main.js +++ b/src/electron-main.js @@ -96,9 +96,9 @@ if (userDataPathInProtocol) { app.setPath('userData', `${app.getPath('userData')}-${argv['profile']}`); } -async function tryAsarPaths(rawPaths) { - // Make everything relative to the current file - const paths = rawPaths.map(p => path.join(__dirname, p)); +async function tryPaths(name, root, rawPaths) { + // Make everything relative to root + const paths = rawPaths.map(p => path.join(root, p)); for (const p of paths) { try { @@ -107,27 +107,35 @@ async function tryAsarPaths(rawPaths) { } catch (e) { } } - console.log("Couldn't find webapp files in any of: "); + console.log(`Couldn't find ${name} files in any of: `); for (const p of paths) { console.log("\t"+path.resolve(p)); } - throw new Error("Failed to find webapp files"); + throw new Error(`Failed to find ${name} files`); } // Find the webapp resources and set up things that require them async function setupGlobals() { // find the webapp asar. - asarPath = await tryAsarPaths([ + asarPath = await tryPaths("webapp", __dirname, [ // If run from the source checkout, this will be in the directory above '../webapp.asar', // but if run from a packaged application, electron-main.js will be in // a different asar file so it will be two levels above '../../webapp.asar', - // also try without the 'asar' suffix to allow symlinking in a directory + // also try without the 'asar' suffix to allow symlinking in a directory '../webapp', + // from a packaged application + '../../webapp', ]); + // we assume the resources path is in the same place as the asar - resPath = path.join(path.dirname(asarPath), 'res'); + resPath = await tryPaths("res", path.dirname(asarPath), [ + // If run from the source checkout + 'res', + // if run from packaged application + '', + ]); try { vectorConfig = require(asarPath + 'config.json');