avm99963 | ea37fdf | 2021-02-03 01:27:13 +0100 | [diff] [blame] | 1 | # Add a new feature |
avm99963 | cf83759 | 2021-02-15 20:02:54 +0100 | [diff] [blame] | 2 | All the features are hidden behind a switch, so users can turn them on or off as |
| 3 | desired. This doc explains how to add this feature switch option to the options |
| 4 | page, and some guidance on where should the feature be developed. |
| 5 | |
| 6 | ## Add an option |
| 7 | Each feature has a boolean option "linked" to it, which determines whether the |
| 8 | feature will be enabled or not. |
| 9 | |
| 10 | ### How to add the feature switch option |
| 11 | 1. First of all, think of a short codename for the feature. |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 12 | 2. Modify the `//src/common/optionsPrototype.json5` file by adding an entry. |
avm99963 | cf83759 | 2021-02-15 20:02:54 +0100 | [diff] [blame] | 13 | - 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ínez | 974189b | 2022-01-17 14:39:31 +0100 | [diff] [blame] | 17 | 3. Now, modify the `//src/options/optionsPage.json5` file by adding an entry to |
| 18 | the corresponding section. The _experimental_ property is optional and should |
| 19 | only be used with features which are unreliable (or could be at some point in |
| 20 | the future) due to their nature. |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 21 | 4. Finally, add the option string at `//src/static/_locales/en/manifest.json`, |
| 22 | by adding the string under the `options_{{codename}}` key. |
avm99963 | cf83759 | 2021-02-15 20:02:54 +0100 | [diff] [blame] | 23 | |
| 24 | ### How to add additional options for the feature |
| 25 | Apart from the feature switch option, additional options can be defined in order |
| 26 | to further customize the behavior of a feature. |
| 27 | |
| 28 | This is not usually the case, and it is preferred that the number of options is |
| 29 | kept to a minimum so the extension is as simple as possible. In any case, this |
| 30 | section explains how to add them in case they are needed. |
| 31 | |
| 32 | *** promo |
| 33 | As a source of inspiration, take a look at the Community Console dark mode |
| 34 | feature: apart from the feature switch option (`ccdarktheme`) it has 2 |
| 35 | additional options associated with it: |
| 36 | |
| 37 | - The `ccdarktheme_mode` option can be configured in the options page with a |
| 38 | selector, and determines whether the dark/light themes are set according to the |
| 39 | OS's dark mode setting, or whether the user is the one in charge of switching |
| 40 | between 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 |
| 44 | manually enabled the dark theme or not by using the switch/button in the |
| 45 | Community Console. |
| 46 | - It is only applied when `ccdarktheme_mode` is set to `switch` and the |
| 47 | feature is enabled. |
| 48 | *** |
| 49 | |
| 50 | These are the steps which you should generally follow when adding additional |
| 51 | options: |
| 52 | |
| 53 | 1. Think of a codename for the additional option. It should be the feature |
| 54 | codename appended by an underscore and a suffix |
| 55 | (`{{feature_codename}}_{{suffix}}`). |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 56 | 2. 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. |
avm99963 | cf83759 | 2021-02-15 20:02:54 +0100 | [diff] [blame] | 63 | 3. If you want to handle the option from the options page, follow these steps: |
Adrià Vilanova Martínez | 09f35be | 2021-09-06 19:50:09 +0200 | [diff] [blame] | 64 | 1. Modify the `//src/static/options/optionsPage.json5` file to add the |
| 65 | appropriate code which implements the option under the `customHTML` |
| 66 | property. |
avm99963 | cf83759 | 2021-02-15 20:02:54 +0100 | [diff] [blame] | 67 | - 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ínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 73 | 2. Modify the `//src/optionsCommon.js` file to add the following things: |
avm99963 | cf83759 | 2021-02-15 20:02:54 +0100 | [diff] [blame] | 74 | 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ínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 79 | 3. Add the corresponding i18n strings at |
| 80 | `//src/static/_locales/en/manifest.json`. |
avm99963 | cf83759 | 2021-02-15 20:02:54 +0100 | [diff] [blame] | 81 | 4. If you want to handle the option outside of the options page, include an |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 82 | empty case in both switches at `//src/optionsCommon.js`, so the option is not |
avm99963 | cf83759 | 2021-02-15 20:02:54 +0100 | [diff] [blame] | 83 | handled there. |
| 84 | |
| 85 | ## Develop the feature |
| 86 | TODO(issue #32): Write this section. |