From bcbd1690bb31a8a1934dfbcde73da107bc0c9dfa Mon Sep 17 00:00:00 2001 From: Ryo Hilmawan <54142180+CloudHill@users.noreply.github.com> Date: Sat, 14 Nov 2020 00:15:41 +0700 Subject: [PATCH] Update mod.js to work with the new icons repo --- mods/notion-icons/mod.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/mods/notion-icons/mod.js b/mods/notion-icons/mod.js index 1b29877..c065d00 100644 --- a/mods/notion-icons/mod.js +++ b/mods/notion-icons/mod.js @@ -9,8 +9,7 @@ 'use strict'; const { createElement } = require('../../pkg/helpers.js'), - fs = require('fs-extra'), - path = require('path'); + fs = require('fs-extra'); module.exports = { id: '2d1f4809-9581-40dd-9bf3-4239db406483', @@ -37,14 +36,22 @@ module.exports = { hacks: { 'renderer/preload.js'(store, __exports) { let garbageCollector = []; + const iconsUrl = 'https://raw.githubusercontent.com/notion-enhancer/icons/main/'; + + function getAsync(urlString, callback) { + let httpReq = new XMLHttpRequest(); + httpReq.onreadystatechange = function() { + if (httpReq.readyState == 4 && httpReq.status == 200) callback(httpReq.responseText); + }; + httpReq.open('GET', urlString, true); + httpReq.send(null); + } // Retrieve Icons data let notionIconsData; - (async () => { - notionIconsData = JSON.parse( - await fs.readFile( path.resolve(`${__dirname}/icons.json`) ) - ); - })(); + getAsync(iconsUrl + 'icons.json', iconsData => { + notionIconsData = JSON.parse(iconsData); + }); // Retrieve custom Icons data let customIconsData; @@ -258,7 +265,7 @@ module.exports = { if (notionIconsData && notionIconsData.icons) { notionIconsData.icons.forEach(i => { - i.sourceUrl = i.sourceUrl || (notionIconsData.sourceUrl + i.source); + i.sourceUrl = i.sourceUrl || (iconsUrl + i.source); iconSets.push( renderIconSet(i) ); }); }