From 6636d3382b129392abbabb08076bc3537d43afd4 Mon Sep 17 00:00:00 2001 From: eight Date: Wed, 4 Oct 2017 16:32:44 +0800 Subject: [PATCH] Fix: install error when live-reload is disabled --- install-usercss/install-usercss.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/install-usercss/install-usercss.js b/install-usercss/install-usercss.js index d4597092..f32d60b4 100644 --- a/install-usercss/install-usercss.js +++ b/install-usercss/install-usercss.js @@ -148,13 +148,7 @@ updateMeta(result); - if (liveReload) { - port.postMessage({method: 'liveReloadStart'}); - } - $('.live-reload').addEventListener('change', () => { - const method = 'liveReload' + (liveReload ? 'Start' : 'Stop'); - port.postMessage({method}); - }); + window.dispatchEvent(new CustomEvent('installed')); }) .catch(err => { alert(chrome.i18n.getMessage('styleInstallFailed', String(err))); @@ -234,6 +228,15 @@ } else { setLiveReload.addEventListener('change', () => { liveReload = setLiveReload.checked; + if (installed) { + const method = 'liveReload' + (liveReload ? 'Start' : 'Stop'); + port.postMessage({method}); + } + }); + window.addEventListener('installed', () => { + if (liveReload) { + port.postMessage({method: 'liveReloadStart'}); + } }); } }