Skip to content

Commit

Permalink
Ensure default styles get applied if page has no css
Browse files Browse the repository at this point in the history
  • Loading branch information
RangerMauve committed Mar 14, 2024
1 parent f2fb789 commit e31a905
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/extensions/builtins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"url": "https://github.com/AgregoreWeb/extension-agregore-history/releases/download/v{version}/agregore-history-v{version}.zip"
},
"agregore-renderer": {
"version": "2.1.3",
"version": "2.1.5",
"url": "https://github.com/AgregoreWeb/extension-agregore-renderer/releases/download/v{version}/agregore-renderer-v{version}.zip"
},
"agregore-qr-share": {
Expand Down
1 change: 1 addition & 0 deletions app/pages/theme/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ body > h6 {
max-width: var(--ag-theme-max-width);
margin-left: auto;
margin-right: auto;
display: block;
}

input, button, textarea, select, select *, option {
Expand Down
30 changes: 30 additions & 0 deletions app/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ const PERSIST_FILE = path.join(app.getPath('userData'), 'lastOpened.json')

const DEFAULT_SAVE_INTERVAL = 30 * 1000

// See if we have any stylesheets with rules
// If not manually inject styles to be like Agregore
const HAS_SHEET = `
[...document.styleSheets].filter((sheet) => {
try {sheet.cssRules; return true} catch {return false}
}).length
`

const WINDOW_METHODS = [
'goBack',
'goForward',
Expand Down Expand Up @@ -323,6 +331,15 @@ export class Window extends EventEmitter {
this.send('update-target-url', url)
})

this.web.on('dom-ready', async () => {
const hasStyles = await this.web.executeJavaScript(HAS_SHEET)
console.log({ hasStyles })
if (!hasStyles) {
const style = await getDefaultStylesheet(this.web)
await this.web.insertCSS(style)
}
})

this.web.once('dom-ready', () => {
showQueue.add(async () => {
await this.window.show()
Expand Down Expand Up @@ -467,3 +484,16 @@ export class Window extends EventEmitter {
return this.window.webContents.id
}
}

async function getDefaultStylesheet (webContents) {
const [r1, r2] = await Promise.all([
webContents.session.fetch('agregore://theme/vars.css'),
webContents.session.fetch('agregore://theme/style.css')
])

const [vars, style] = await Promise.all([
r1.text(),
r2.text()
])
return vars + style
}

0 comments on commit e31a905

Please sign in to comment.