From 143617afb1cf5f0c1fb5baa3e629b3bc92064eae Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 10 Mar 2021 19:53:09 +0300 Subject: [PATCH] * it feels weird for requireIdleCallback() to be optional while more modern browser features are required * simplify browser startup feature check a bit --- js/App.js | 11 ++++++----- js/Feeds.js | 7 ++----- js/Headlines.js | 9 +++------ js/PrefHelpers.js | 8 +++----- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/js/App.js b/js/App.js index e19b3e878..649571593 100644 --- a/js/App.js +++ b/js/App.js @@ -688,15 +688,16 @@ const App = { checkBrowserFeatures: function() { let errorMsg = ""; - ['MutationObserver'].forEach(function(wf) { - if (!(wf in window)) { - errorMsg = `Browser feature check failed: window.${wf} not found.`; + ['MutationObserver', 'requestIdleCallback'].forEach((t) => { + if (!(t in window)) { + errorMsg = `Browser check failed: window.${t} not found.`; throw new Error(errorMsg); } }); - if (errorMsg) { - this.Error.fatal(errorMsg, {info: navigator.userAgent}); + if (typeof Promise.allSettled == "undefined") { + errorMsg = `Browser check failed: Promise.allSettled is not defined.`; + throw new Error(errorMsg); } return errorMsg == ""; diff --git a/js/Feeds.js b/js/Feeds.js index 46d978cb4..7b6366959 100644 --- a/js/Feeds.js +++ b/js/Feeds.js @@ -311,12 +311,9 @@ const Feeds = { setActive: function(id, is_cat) { console.log('setActive', id, is_cat); - if ('requestIdleCallback' in window) - window.requestIdleCallback(() => { - App.Hash.set({f: id, c: is_cat ? 1 : 0}); - }); - else + window.requestIdleCallback(() => { App.Hash.set({f: id, c: is_cat ? 1 : 0}); + }); this._active_feed_id = id; this._active_feed_is_cat = is_cat; diff --git a/js/Headlines.js b/js/Headlines.js index 028f277ff..08192ea6b 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -76,12 +76,9 @@ const Headlines = { Headlines.updateSelectedPrompt(); - if ('requestIdleCallback' in window) - window.requestIdleCallback(() => { - Headlines.syncModified(modified); - }); - else + window.requestIdleCallback(() => { Headlines.syncModified(modified); + }); }), syncModified: function (modified) { const ops = { @@ -175,7 +172,7 @@ const Headlines = { }); } - Promise.all(promises).then((results) => { + Promise.allSettled(promises).then((results) => { let feeds = []; let labels = []; diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index 3f738aa95..8a5c5857e 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -510,12 +510,10 @@ const Helpers = { search: function() { this.search_query = this.attr('value').search.toLowerCase(); - if ('requestIdleCallback' in window) - window.requestIdleCallback(() => { - this.render_contents(); - }); - else + window.requestIdleCallback(() => { this.render_contents(); + }); + }, render_contents: function() { const container = dialog.domNode.querySelector(".contents");