blob: 16ebcee84f9a6c9b5e77e0355a78813da14928ea [file] [log] [blame] [view]
avm99963ea37fdf2021-02-03 01:27:13 +01001# Add a new feature
avm99963cf837592021-02-15 20:02:54 +01002All the features are hidden behind a switch, so users can turn them on or off as
3desired. This doc explains how to add this feature switch option to the options
4page, and some guidance on where should the feature be developed.
5
6## Add an option
7Each feature has a boolean option "linked" to it, which determines whether the
8feature will be enabled or not.
9
10### How to add the feature switch option
111. First of all, think of a short codename for the feature.
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +0200122. Modify the `//src/common/optionsPrototype.json5` file by adding an entry.
avm99963cf837592021-02-15 20:02:54 +010013 - All features should have the `false` value set as a default, so existing
14 users have to explicitly enable the option after they receive the extension
15 update. Otherwise, it might cause confusion, because users wouldn't know if
16 the feature was added by the extension or Google.
Adrià Vilanova Martínez974189b2022-01-17 14:39:31 +0100173. Now, modify the `//src/options/optionsPage.json5` file by adding an entry to
18the corresponding section. The _experimental_ property is optional and should
19only be used with features which are unreliable (or could be at some point in
20the future) due to their nature.
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +0200214. Finally, add the option string at `//src/static/_locales/en/manifest.json`,
22by adding the string under the `options_{{codename}}` key.
avm99963cf837592021-02-15 20:02:54 +010023
24### How to add additional options for the feature
25Apart from the feature switch option, additional options can be defined in order
26to further customize the behavior of a feature.
27
28This is not usually the case, and it is preferred that the number of options is
29kept to a minimum so the extension is as simple as possible. In any case, this
30section explains how to add them in case they are needed.
31
32*** promo
33As a source of inspiration, take a look at the Community Console dark mode
34feature: apart from the feature switch option (`ccdarktheme`) it has 2
35additional options associated with it:
36
37- The `ccdarktheme_mode` option can be configured in the options page with a
38selector, and determines whether the dark/light themes are set according to the
39OS's dark mode setting, or whether the user is the one in charge of switching
40between them by clicking a button/switch in the Community Console.
41 - Note that this option is only applied when the feature switch is turned
42 on.
43- The `ccdarktheme_switch_enabled` option is used to save whether the user
44manually enabled the dark theme or not by using the switch/button in the
45Community Console.
46 - It is only applied when `ccdarktheme_mode` is set to `switch` and the
47 feature is enabled.
48***
49
50These are the steps which you should generally follow when adding additional
51options:
52
531. Think of a codename for the additional option. It should be the feature
54codename appended by an underscore and a suffix
55(`{{feature_codename}}_{{suffix}}`).
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +0200562. Modify the following files:
57 1. Add an entry for the option in the `//src/common/optionsPrototype.json5`
58 file.
59 2. Append the option's codename to the `//src/common/specialOptions.json5`
60 file. This is so the option can be handled in a specific way when
61 showing/saving it in the options page, or so it is handled outside of the
62 options page.
avm99963cf837592021-02-15 20:02:54 +0100633. If you want to handle the option from the options page, follow these steps:
Adrià Vilanova Martínez09f35be2021-09-06 19:50:09 +020064 1. Modify the `//src/static/options/optionsPage.json5` file to add the
65 appropriate code which implements the option under the `customHTML`
66 property.
avm99963cf837592021-02-15 20:02:54 +010067 - Don't include text, only the HTML structure. If you add a `data-i18n`
68 attribute to an HTML element, its contents will be replaced with the
69 corresponding i18n string (for instance,
70 `<span data-i18n="test"></span>` will be rendered as
71 `<span data-i18n="test">Test</span>` if `Test` was the string defined
72 with the key `options_test`).
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020073 2. Modify the `//src/optionsCommon.js` file to add the following things:
avm99963cf837592021-02-15 20:02:54 +010074 1. In the switch statement inside the save function, add a case to
75 handle saving your additional option.
76 2. In the switch statement inside the load event listener, add another
77 case so your option is correctly set in the options page with the saved
78 value.
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020079 3. Add the corresponding i18n strings at
80 `//src/static/_locales/en/manifest.json`.
avm99963cf837592021-02-15 20:02:54 +0100814. If you want to handle the option outside of the options page, include an
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020082empty case in both switches at `//src/optionsCommon.js`, so the option is not
avm99963cf837592021-02-15 20:02:54 +010083handled there.
84
85## Develop the feature
86TODO(issue #32): Write this section.