From ea1c1b51003f76667b6213183860bb55296ca040 Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Fri, 16 Nov 2018 14:58:01 -0600 Subject: [PATCH] Always set currentMd5 & add a delay before firing USO event --- content/install-hook-userstyles.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/content/install-hook-userstyles.js b/content/install-hook-userstyles.js index a79675af..24745d6c 100644 --- a/content/install-hook-userstyles.js +++ b/content/install-hook-userstyles.js @@ -75,13 +75,13 @@ document.dispatchEvent(new CustomEvent('stylusFixBuggyUSOsettings', { detail: installedStyle && installedStyle.updateUrl, })); + currentMd5 = md5; if (!installedStyle) { sendEvent({type: 'styleCanBeInstalledChrome'}); return; } const isCustomizable = /\?/.test(installedStyle.updateUrl); const md5Url = getMeta('stylish-md5-url'); - currentMd5 = md5; if (md5Url && installedStyle.md5Url && installedStyle.originalMd5) { reportUpdatable(isCustomizable || md5 !== installedStyle.originalMd5); } else { @@ -94,14 +94,17 @@ } function reportUpdatable(isUpdatable) { - sendEvent({ - type: isUpdatable - ? 'styleCanBeUpdatedChrome' - : 'styleAlreadyInstalledChrome', - detail: { - updateUrl: installedStyle.updateUrl - }, - }); + // USO doesn't bind these listeners immediately + setTimeout(() => { + sendEvent({ + type: isUpdatable + ? 'styleCanBeUpdatedChrome' + : 'styleAlreadyInstalledChrome', + detail: { + updateUrl: installedStyle.updateUrl + }, + }); + }, 300); } }