Skip to content

Commit fe3598f

Browse files
committed
extract Firefox-specific manifest stuff
+ don't auto-open the side panel on install/upgrade
1 parent 931d297 commit fe3598f

File tree

5 files changed

+48
-52
lines changed

5 files changed

+48
-52
lines changed

src/manifest-mv2-firefox.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"browser_specific_settings": {
3+
"gecko": {
4+
"id": "{7a7a4a92-a2a0-41d1-9fd7-1e92480d612d}",
5+
"strict_min_version": "58.0"
6+
}
7+
},
8+
"options_ui": {
9+
"page": "manage.html",
10+
"open_in_tab": true
11+
},
12+
"sidebar_action": {
13+
"default_panel": "sidepanel.html",
14+
"default_icon": {
15+
"16": "icon/16.png",
16+
"32": "icon/32.png",
17+
"19": "icon/19.png",
18+
"38": "icon/38.png"
19+
},
20+
"open_at_install": false
21+
}
22+
}

src/manifest-mv2.json

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,5 @@
99
},
1010
"commands": {
1111
"_execute_browser_action": {}
12-
},
13-
"sidebar_action": {
14-
"default_panel": "sidepanel.html",
15-
"default_icon": {
16-
"16": "icon/16.png",
17-
"32": "icon/32.png",
18-
"19": "icon/19.png",
19-
"38": "icon/38.png"
20-
}
21-
},
22-
"browser_specific_settings": {
23-
"gecko": {
24-
"id": "{7a7a4a92-a2a0-41d1-9fd7-1e92480d612d}",
25-
"strict_min_version": "58.0"
26-
}
2712
}
2813
}

src/sidepanel/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ import configDialog from '@/js/dlg/config-dialog';
33
import {urlParams} from '@/js/dom';
44
import './index.css';
55

6-
configDialog(+urlParams.get('id')).then(close);
6+
const id = +urlParams.get('id');
7+
if (id) configDialog(id).then(close);

tools/util.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ const fs = require('fs');
44
const path = require('path');
55
const babel = require('@babel/core');
66

7-
const MANIFEST = 'manifest.json';
87
const ROOT = path.dirname(__dirname.replaceAll('\\', '/')) + '/';
98
const SRC = ROOT + 'src/';
109

1110
const [TARGET, ZIP] = process.env.NODE_ENV?.split(':') || [''];
12-
const [BUILD, FLAVOR, CHANNEL] = TARGET.split('-');
11+
const [BUILD, FLAVOR = 'mv2', CHANNEL] = TARGET.split('-');
1312
const MV3 = FLAVOR === 'mv3';
1413
const DEV = process.env.npm_lifecycle_event?.startsWith('watch');
1514

15+
const MANIFEST = 'manifest.json';
16+
const MANIFEST_OVR = `manifest-${FLAVOR}.json`;
17+
1618
/** Nuking comments and whitespace between tags on separate lines as we don't rely on it.
1719
* The only exception we use is a same-line space e.g. <b>foo</b> <b>bar</b> */
1820
const RX_HTML_WS = /^\s+|(?<=[>"',.]|&nbsp;)[ \t]*[\r\n]\s*|\s+(?=>|<\/)|<!--.*?-->|\s+$/gs;
@@ -31,21 +33,14 @@ function escapeToRe(str, flags) {
3133
}
3234

3335
function getBrowserlist() {
34-
const mj = require(SRC + getManifestOvrName());
35-
const FF = parseFloat(mj.browser_specific_settings?.gecko.strict_min_version);
36-
const CH = parseFloat(mj.minimum_chrome_version);
37-
return [
38-
FF && 'Firefox >= ' + FF,
39-
CH && 'Chrome >= ' + CH,
40-
].filter(Boolean);
41-
}
42-
43-
function getManifestOvrName(
44-
mv3 = /-mv3/.test(process.env.NODE_ENV),
45-
asGlob
46-
) {
47-
const s = '-mv' + (mv3 ? 3 : 2);
48-
return MANIFEST.replace('.', asGlob ? `?(${s}).` : s + '.');
36+
return Object.entries({
37+
Chrome: BUILD !== 'firefox' &&
38+
require(SRC + MANIFEST_OVR).minimum_chrome_version,
39+
Firefox: BUILD !== 'chrome' &&
40+
require(SRC + MANIFEST_OVR.replace('.', '-firefox.'))
41+
.browser_specific_settings.gecko.strict_min_version,
42+
}).map(([name, ver]) => ver && `${name} >= ${parseFloat(ver)}`)
43+
.filter(Boolean);
4944
}
5045

5146
function transBabel(buf, from) {
@@ -97,7 +92,6 @@ module.exports = {
9792
escapeForRe,
9893
escapeToRe,
9994
getBrowserlist,
100-
getManifestOvrName,
10195
nukeHtmlSpaces,
10296
transBabel,
10397
transESM2var,

webpack.config.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');
1515
const {RawEnvPlugin} = require('./tools/wp-raw-patch-plugin');
1616
const patchCodemirror = require('./tools/wp-patch-codemirror');
1717
const {
18-
escapeForRe, getManifestOvrName, transESM2var, transSourceMap,
19-
BUILD, CHANNEL, CM_PACKAGE_PATH, DEV, MANIFEST, MV3, ROOT, TARGET, ZIP, nukeHtmlSpaces,
18+
escapeForRe, nukeHtmlSpaces, transESM2var, transSourceMap,
19+
BUILD, CHANNEL, CM_PACKAGE_PATH, DEV, FLAVOR, MANIFEST, MV3, ROOT, TARGET, ZIP,
2020
} = require('./tools/util');
2121

2222
global.localStorage = {}; // workaround for node 25 and HtmlWebpackPlugin's `...global`
@@ -354,27 +354,21 @@ function makeContentScript(name) {
354354
}
355355

356356
function makeManifest(files) {
357-
let [base, ovr] = (files[0].sourceFilename.endsWith(MANIFEST) ? files : files.reverse())
357+
let [base, ...mods] = (files[0].sourceFilename.endsWith(MANIFEST) ? files : files.reverse())
358358
.map(file => file.data.toString());
359359
base = JSON.parse(MV3 ? base.replace('"browser_action"', '"action"') : base);
360-
ovr = JSON.parse(ovr);
361-
for (const [key, val] of Object.entries(ovr)) {
362-
const old = base[key];
363-
if (Array.isArray(old)) old.push(...val);
364-
else if (old && typeof old === 'object') Object.assign(old, val);
365-
else base[key] = val;
360+
for (let ovr of mods) {
361+
ovr = JSON.parse(ovr);
362+
for (const [key, val] of Object.entries(ovr)) {
363+
const old = base[key];
364+
if (Array.isArray(old)) old.push(...val);
365+
else if (old && typeof old === 'object') Object.assign(old, val);
366+
else base[key] = val;
367+
}
366368
}
367369
let ver = base.version;
368370
if (BUILD === 'firefox') {
369371
delete base.key;
370-
base.options_ui = {
371-
/*
372-
* Linking to dashboard, not to options, because this is aimed at users who removed the icon
373-
* from the toolbar (they rarely use Stylus) so they visit about:addons instead.
374-
*/
375-
page: 'manage.html',
376-
open_in_tab: true,
377-
};
378372
}
379373
if (CHANNEL) {
380374
base.name += ` (${CHANNEL})`;
@@ -469,7 +463,7 @@ module.exports = [
469463
patterns: [
470464
{context: SRC, from: 'icon/**', to: DST},
471465
{context: SRC + 'content', from: 'install*.js', to: DST + JS},
472-
{context: SRC, from: getManifestOvrName(MV3, true), to: MANIFEST,
466+
{context: SRC, from: MANIFEST.replace('.', `?(-${FLAVOR}*).`), to: MANIFEST,
473467
transformAll: makeManifest},
474468
{context: SRC, from: '_locales/**', to: DST},
475469
{context: THEME_PATH, from: '*.css', to: DST + CM_PATH},

0 commit comments

Comments
 (0)