Skip to content

feat(theme-handler): browser://theme/ Protocol for Cross-Browser Theming with Base16 #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from

Conversation

akhileshthite
Copy link
Contributor

@akhileshthite akhileshthite commented May 5, 2025

Related Issue: p2plabsxyz/peersky-browser#37
Related PR: p2plabsxyz/peersky-browser#43

@RangerMauve can you add base16 here? #289

@akhileshthite
Copy link
Contributor Author

Couldn't test it locally because of this #287

Copy link
Member

@RangerMauve RangerMauve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start, ty! Sadly not working at the moment due to missing vars.css. If you give me write access to your repo I can finish it off. 👍

@@ -90,6 +93,10 @@ export async function setupProtocols (session) {
sessionProtocol.registerStreamProtocol('agregore', browserProtocolHandler)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename the current browserProtocolHandler to the agregoreProtocolHandler, I think this will make the code more readable and more obvious.

@@ -90,6 +93,10 @@ export async function setupProtocols (session) {
sessionProtocol.registerStreamProtocol('agregore', browserProtocolHandler)
globalProtocol.registerStreamProtocol('agregore', browserProtocolHandler)

const { handler: themeProtocolHandler } = await createThemeHandler()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename the themeHandler to be the Agregore theme handler.

const parsedUrl = new URL(url)
let filePath

if (parsedUrl.hostname === 'theme') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a check for pathname === '/vars.css' and generate it dynamically the way we do in the current handler here: https://github.com/AgregoreWeb/agregore-browser/blob/master/app/protocols/browser-protocol.js#L76

That's also where the base16 vars should get defined.

filePath = path.join(__dirname, '../pages/theme', fileName)
console.log('Attempting to serve:', filePath)

if (!fs.existsSync(filePath)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using sync methods whenever possible. In this case we should use the existing resolveFile logic from the agregore handler. https://github.com/AgregoreWeb/agregore-browser/blob/master/app/protocols/browser-protocol.js#L154

data
})
} else {
sendResponse({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,54 @@
import path from 'path'
import { fileURLToPath } from 'url'
import fs from 'fs'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whenever you read from the file system, make sure you use ScopedFS otherwise users can use malicious path names like ../../../config/yourpasswords to extract arbitrary files from the filesystem

@@ -69,3 +69,91 @@ code {
```

This font provides built-in syntax highlighting for code blocks, making it easier to read and understand code snippets.

## Theme Protocol (`browser://theme/`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Gotta remember to update the website docs with this too.

https://github.com/AgregoreWeb/website/blob/main/docs/theming.md

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akhileshthite
Copy link
Contributor Author

akhileshthite commented May 7, 2025

Great start, ty! Sadly not working at the moment due to missing vars.css. If you give me write access to your repo I can finish it off. 👍

Oh, I added base16 to Peersky (p2plabsxyz/peersky-browser#43). I meant to say here (with Agregore standards) - once I add the dynamic vars.css generation (f1c3852).

I had given you the maintainer role, which also comes with write access, right? 🤔

@RangerMauve
Copy link
Member

I actually ended up doing something more simple: I registered the existing agregore handler as browser://, also added a redirect for browser://theme/base.css to point to pages/style.css

b4e56ef

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants