From 7610e8b9dac23ce2a487336dfd87f1f60ebead74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C5=A0?= Date: Mon, 22 Jan 2024 20:39:01 +0100 Subject: [PATCH] Fix crash when installing web app on Linux and macOS (fixes #452) --- extension/src/sites/install.js | 36 ++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/extension/src/sites/install.js b/extension/src/sites/install.js index cc62067e..a271fca3 100644 --- a/extension/src/sites/install.js +++ b/extension/src/sites/install.js @@ -8,6 +8,7 @@ import Tags from 'bootstrap5-tags/tags' import * as DOMPurify from 'dompurify' import { + EVENT_LOCALIZATION_READY, obtainManifest, obtainProfileList, obtainSiteList, @@ -18,6 +19,24 @@ import { import { getMessage } from '../utils/i18n' import { knownCategories } from './categories' +function displayProfileWarning (platform) { + if (platform.os === 'linux' || platform.os === 'mac' || platform.os === 'openbsd') { + const issueLink = document.getElementById('web-app-profile-warn-issue') + switch (platform.os) { + case 'linux': + case 'openbsd': + issueLink.href = 'https://github.com/filips123/PWAsForFirefox/issues/322' + issueLink.innerText = '#322' + break + case 'mac': + issueLink.href = 'https://github.com/filips123/PWAsForFirefox/issues/81' + issueLink.innerText = '#81' + } + + document.getElementById('web-app-profile-warn-box').classList.remove('d-none') + } +} + async function initializeForm () { const form = document.getElementById('web-app-form') const submit = document.getElementById('web-app-submit') @@ -33,23 +52,10 @@ async function initializeForm () { element.tagsInstance = new Tags(element) } - // Display profile warning on Linux, macOS and BSD const platform = await browser.runtime.getPlatformInfo() - if (platform.os === 'linux' || platform.os === 'mac' || platform.os === 'openbsd') { - const issueLink = document.getElementById('web-app-profile-warn-issue') - switch (platform.os) { - case 'linux': - case 'openbsd': - issueLink.href = 'https://github.com/filips123/PWAsForFirefox/issues/322' - issueLink.innerText = '#322' - break - case 'mac': - issueLink.href = 'https://github.com/filips123/PWAsForFirefox/issues/81' - issueLink.innerText = '#81' - } - document.getElementById('web-app-profile-warn-box').classList.remove('d-none') - } + // Display profile warning on Linux, macOS and BSD + document.addEventListener(EVENT_LOCALIZATION_READY, displayProfileWarning.bind(null, platform)) // Obtain manifest and document URLs for the current site let manifestUrl, documentUrl, pageInfo