Skip to content

Commit 21c58f8

Browse files
committed
Current changes according to discovery
1 parent a65c8b0 commit 21c58f8

File tree

5 files changed

+42
-32
lines changed

5 files changed

+42
-32
lines changed

core/build.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ async function build(browser) {
3535
bundle: true,
3636
// minify: true,
3737
format: 'esm',
38-
outdir
38+
outdir,
39+
define: {
40+
global: 'window'
41+
}
3942
})
4043
.then(() => {
4144
const css = fs.readFileSync(path.join(outdir, 'index.css'), 'utf8');

src/content/init-discovery.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1+
import { Widget, router, utils } from '@discoveryjs/discovery';
2+
import settingsPage from '../settings';
3+
14
/**
25
* Discovery initialization
36
* @param {Object} options
47
* @param {Object} data
58
* @returns {Discovery}
69
*/
710
export function initDiscovery(options, data) {
8-
const { Widget, router, utils } = require('@discoveryjs/discovery/dist/discovery.js');
9-
const settingsPage = require('../settings').default;
10-
1111
const { settings } = options;
1212
const { darkmode = 'auto' } = settings;
1313
const discovery = new Widget(options.node, null, {
1414
darkmode,
15-
styles: [{ type: 'link', data: chrome.runtime.getURL('index.css') }]
15+
styles: [{ type: 'link', href: chrome.runtime.getURL('index.css') }]
1616
});
1717

1818
discovery.apply(router);

src/content/init.js

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,31 @@ export const init = initDiscoveryBundled => {
5454

5555
// Firefox bundled version
5656
if (typeof initDiscoveryBundled === 'function') {
57-
getSettings(settings => {
58-
initDiscoveryBundled({
59-
node: document.body,
60-
raw: textContent,
61-
settings,
62-
styles: [chrome.runtime.getURL('index.css')]
63-
}, json);
64-
});
57+
const settings = await getSettings();
58+
59+
initDiscoveryBundled({
60+
node: document.body,
61+
raw: textContent,
62+
settings,
63+
styles: [chrome.runtime.getURL('index.css')]
64+
}, json);
6565
}
6666

6767
try {
68+
const settings = await getSettings();
69+
const data = await loader({
70+
data: json,
71+
darkmode: settings.darkmode
72+
});
73+
6874
const { initDiscovery } = await import(chrome.runtime.getURL('init-discovery.js'));
6975

70-
getSettings(settings => {
71-
loader({
72-
module: initDiscovery,
73-
data: json,
74-
options: {
75-
node: document.body,
76-
raw: textContent,
77-
settings
78-
}
79-
});
80-
});
76+
initDiscovery({
77+
node: document.body,
78+
raw: textContent,
79+
settings,
80+
styles: [chrome.runtime.getURL('index.css')]
81+
}, data);
8182
} catch (_) {}
8283
}
8384
});
@@ -87,13 +88,15 @@ export const init = initDiscoveryBundled => {
8788

8889
/**
8990
* Restores settings from storage
90-
* @param {Function} cb
91+
* @returns {Promise}
9192
*/
92-
function getSettings(cb) {
93-
chrome.storage.sync.get({
94-
expandLevel: 3,
95-
darkmode: 'auto'
96-
}, settings => {
97-
cb(settings);
93+
function getSettings() {
94+
return new Promise(resolve => {
95+
chrome.storage.sync.get({
96+
expandLevel: 3,
97+
darkmode: 'auto'
98+
}, settings => {
99+
resolve(settings);
100+
});
98101
});
99102
}

src/settings.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { utils } from '@discoveryjs/discovery';
2+
13
export default discovery => {
24
discovery.view.define('label', function(el, config = {}) {
35
const { text } = config;
@@ -34,7 +36,9 @@ export default discovery => {
3436
let selfValue;
3537

3638
detachToggleDarkMode();
37-
detachToggleDarkMode = discovery.darkmode.on((value, mode) => {
39+
detachToggleDarkMode = discovery.darkmode.subscribe((value, mode) => {
40+
utils.applyContainerStyles(discovery.dom.wrapper.parentNode, { darkmode: value });
41+
3842
const newValue = mode === 'auto' ? 'auto' : value;
3943

4044
if (newValue === selfValue) {

0 commit comments

Comments
 (0)