Skip to content

Commit e31a905

Browse files
committed
Ensure default styles get applied if page has no css
1 parent f2fb789 commit e31a905

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

app/extensions/builtins.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"url": "https://github.com/AgregoreWeb/extension-agregore-history/releases/download/v{version}/agregore-history-v{version}.zip"
55
},
66
"agregore-renderer": {
7-
"version": "2.1.3",
7+
"version": "2.1.5",
88
"url": "https://github.com/AgregoreWeb/extension-agregore-renderer/releases/download/v{version}/agregore-renderer-v{version}.zip"
99
},
1010
"agregore-qr-share": {

app/pages/theme/style.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ body > h6 {
3636
max-width: var(--ag-theme-max-width);
3737
margin-left: auto;
3838
margin-right: auto;
39+
display: block;
3940
}
4041

4142
input, button, textarea, select, select *, option {

app/window.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ const PERSIST_FILE = path.join(app.getPath('userData'), 'lastOpened.json')
2929

3030
const DEFAULT_SAVE_INTERVAL = 30 * 1000
3131

32+
// See if we have any stylesheets with rules
33+
// If not manually inject styles to be like Agregore
34+
const HAS_SHEET = `
35+
[...document.styleSheets].filter((sheet) => {
36+
try {sheet.cssRules; return true} catch {return false}
37+
}).length
38+
`
39+
3240
const WINDOW_METHODS = [
3341
'goBack',
3442
'goForward',
@@ -323,6 +331,15 @@ export class Window extends EventEmitter {
323331
this.send('update-target-url', url)
324332
})
325333

334+
this.web.on('dom-ready', async () => {
335+
const hasStyles = await this.web.executeJavaScript(HAS_SHEET)
336+
console.log({ hasStyles })
337+
if (!hasStyles) {
338+
const style = await getDefaultStylesheet(this.web)
339+
await this.web.insertCSS(style)
340+
}
341+
})
342+
326343
this.web.once('dom-ready', () => {
327344
showQueue.add(async () => {
328345
await this.window.show()
@@ -467,3 +484,16 @@ export class Window extends EventEmitter {
467484
return this.window.webContents.id
468485
}
469486
}
487+
488+
async function getDefaultStylesheet (webContents) {
489+
const [r1, r2] = await Promise.all([
490+
webContents.session.fetch('agregore://theme/vars.css'),
491+
webContents.session.fetch('agregore://theme/style.css')
492+
])
493+
494+
const [vars, style] = await Promise.all([
495+
r1.text(),
496+
r2.text()
497+
])
498+
return vars + style
499+
}

0 commit comments

Comments
 (0)