Skip to content

Commit

Permalink
Merge pull request #7 from ivanyu/support-chromium
Browse files Browse the repository at this point in the history
Support Chromium-based browsers
  • Loading branch information
ivanyu authored Dec 7, 2024
2 parents 582158f + c0de0dd commit b028c8b
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 13 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/node_modules
web-ext-artifacts
/dist
/dist-dev
/web-ext-artifacts-firefox
/web-ext-artifacts-chrome
/dist-firefox
/dist-chrome
27 changes: 22 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: clean
clean:
rm -rf dist web-ext-artifacts
rm -rf dist-firefox dist-chrome web-ext-artifacts-firefox web-ext-artifacts-chrome

.PHONY: dev-prepare
dev-prepare:
Expand All @@ -12,9 +12,26 @@ dev-build:

.PHONY: dev-run
dev-run:
npx web-ext run --source-dir dist
npx web-ext run --source-dir dist-firefox

.PHONY: build
build:

dist-firefox:
npm run build
npx web-ext build --source-dir dist

.PHONY: build-firefox
build-firefox: dist-firefox
npx web-ext build --source-dir dist-firefox --artifacts-dir web-ext-artifacts-firefox --overwrite-dest


dist-chrome: dist-firefox
cp -r dist-firefox dist-chrome
jq '.background = {"service_worker": .background.scripts[1]}' < dist-chrome/manifest.json > dist-chrome/manifest-tmp.json
mv dist-chrome/manifest-tmp.json dist-chrome/manifest.json

.PHONY: build-chrome
build-chrome: dist-chrome
npx web-ext build --source-dir dist-chrome --artifacts-dir web-ext-artifacts-chrome --overwrite-dest


.PHONY: build
build: build-firefox build-chrome
File renamed without changes
Binary file added icons/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/icon150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/icon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/icon32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/icon96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions manifest.json → manifest-firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
"version": "0.1.0",
"description": "A bring-your-own-key extension for summarizing Hacker News articles with LLMs.",
"icons": {
"48": "icon.svg",
"96": "icon.svg"
"16": "icon16.png",
"32": "icon32.png",
"48": "icon48.png",
"96": "icon96.png",
"128": "icon128.png"
},
"browser_specific_settings": {
"gecko": {
Expand Down
12 changes: 12 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
try {
// Load `browser-polyfill.js` for Chrome.
importScripts("browser-polyfill.js");
} catch (e) {
if (e instanceof ReferenceError) {
// It's probably Firefox, where `browser-polyfill.js` is provided through `background.scripts`.
// Do nothing.
} else {
throw e;
}
}

async function onInstalled() {
const settings = await browser.storage.sync.get('internal.intro_shown');
if (!settings['internal.intro_shown']) {
Expand Down
6 changes: 3 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = (env, argv) => {
},
output: {
// filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist')
path: path.resolve(__dirname, 'dist-firefox')
},
devtool: argv.mode === 'production' ? "source-map" : "inline-cheap-source-map",
optimization: {
Expand All @@ -25,8 +25,8 @@ module.exports = (env, argv) => {
{ from: 'src/content.js', to: 'content.js' },
{ from: 'src/options.html', to: 'options.html' },
{ from: 'src/options.js', to: 'options.js' },
{ from: 'manifest.json', to: 'manifest.json' },
{ from: 'icon.svg', to: 'icon.svg' }
{ from: 'manifest-firefox.json', to: 'manifest.json' },
{ from: 'icons/*.png', to: '[name][ext]' }
]
})
]
Expand Down

0 comments on commit b028c8b

Please sign in to comment.