Skip to content

Commit

Permalink
Bump addon to manifest v3
Browse files Browse the repository at this point in the history
Due to manifest incompatibilities between Mozilla and Chrome different
packages are built for each browser vendor.
  • Loading branch information
1nfiniteloop committed Feb 20, 2024
1 parent 149411b commit 4d6b503
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 21 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ name: Build release

on:
push:
tags:
- 'v*'
branches:
- main

jobs:
main:
Expand All @@ -32,15 +28,15 @@ jobs:
run: tools/package

# ref: https://github.com/actions/upload-artifact
- name: Upload build artifact
uses: actions/upload-artifact@v2
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: json-bookmarks.zip
path: out/json-bookmarks-*.zip
name: json-bookmarks
path: out/

# ref: https://github.com/softprops/action-gh-release
- name: Create release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
if: startsWith(github.ref, 'refs/tags/v')
with:
files: out/json-bookmarks-*.zip
6 changes: 4 additions & 2 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
browser.browserAction.onClicked.addListener((tab) => {
// Entrypoint for extension in Mozilla which only supports background script in
// manifest version 3.
browser.action.onClicked.addListener((tab) => {
browser.tabs.create({ url: "bookmarks.html" });
});
});
22 changes: 22 additions & 0 deletions manifest.chrome.json.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"manifest_version": 3,
"name": "Json Bookmarks",
"version": "${version}",
"homepage_url": "https://github.com/1nfiniteloop/json-bookmarks",
"description": "Import and export bookmarks between browsers with a json file",
"permissions": ["bookmarks"],
"action": {
"default_title": "JSON Bookmarks"
},
"icons": {
"16": "icon/16.png",
"32": "icon/32.png",
"48": "icon/48.png",
"96": "icon/96.png",
"128": "icon/128.png"
},
"background": {
"service_worker": "service_worker.js",
"type": "module"
}
}
9 changes: 7 additions & 2 deletions manifest.json.in → manifest.mozilla.json.in
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{
"manifest_version": 2,
"manifest_version": 3,
"name": "Json Bookmarks",
"version": "${version}",
"homepage_url": "https://github.com/1nfiniteloop/json-bookmarks",
"description": "Import and export bookmarks between browsers with a json file",
"browser_specific_settings": {
"gecko": {
"id": "{c46bac9d-a680-46b9-ab8f-15dc7f5a8c71}"
}
},
"permissions": ["bookmarks"],
"browser_action": {
"action": {
"default_title": "JSON Bookmarks"
},
"icons": {
Expand Down
7 changes: 7 additions & 0 deletions service_worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Entrypoint for extension in Chrome which only supports service workers in
// manifest version 3.
import "./third_party/browser-polyfill.min.js";

browser.action.onClicked.addListener((tab) => {
browser.tabs.create({ url: "bookmarks.html" });
});
31 changes: 23 additions & 8 deletions tools/package
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -ue

readonly ext_name="json-bookmarks"

Expand All @@ -13,16 +14,30 @@ get_mainfest_version()
echo "${semver#v}"
}

create_manifest()
create_manifest_for()
{
version="$(get_mainfest_version)" envsubst < manifest.json.in > manifest.json
browser_vendor="${1}"
version="$(get_mainfest_version)" envsubst < manifest.${browser_vendor}.json.in > manifest.json
}

create_manifest \
&& mkdir --parents out/ \
&& zip \
create_package_for()
{
browser_vendor="${1}"
create_manifest_for "${browser_vendor}"
mkdir --parents "out/"
zip \
--recurse-paths \
--filesync \
out/${ext_name}-$(get_version).zip \
* \
--exclude .git icon/src/\* out/\* TODO.md manifest.json.in
out/${ext_name}-${browser_vendor}-$(get_version).zip \
bookmark \
icon \
third_party \
*.js \
*.html \
*.css \
LICENSE \
manifest.json
}

create_package_for "mozilla"
create_package_for "chrome"

0 comments on commit 4d6b503

Please sign in to comment.