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 | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 17 | 3. Now, modify the `//src/static/options/options.html` file by appending the |
| 18 | following HTML code in the corresponding section: |
avm99963 | cf83759 | 2021-02-15 20:02:54 +0100 | [diff] [blame] | 19 | ``` |
| 20 | <div class="option"><input type="checkbox" id="{{codename}}"> <label for="{{codename}}" data-i18n="{{codename}}"></label> <span class="experimental-label" data-i18n="experimental_label"></span></div> |
| 21 | ``` |
| 22 | where you should substitute `{{codename}}` with the codename you've chosen. |
| 23 | The _experimental_ label is optional and should only be used with features which |
| 24 | are unreliable (or could be at some point in the future) due to their nature. |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 25 | 4. Finally, add the option string at `//src/static/_locales/en/manifest.json`, |
| 26 | by adding the string under the `options_{{codename}}` key. |
avm99963 | cf83759 | 2021-02-15 20:02:54 +0100 | [diff] [blame] | 27 | |
| 28 | ### How to add additional options for the feature |
| 29 | Apart from the feature switch option, additional options can be defined in order |
| 30 | to further customize the behavior of a feature. |
| 31 | |
| 32 | This is not usually the case, and it is preferred that the number of options is |
| 33 | kept to a minimum so the extension is as simple as possible. In any case, this |
| 34 | section explains how to add them in case they are needed. |
| 35 | |
| 36 | *** promo |
| 37 | As a source of inspiration, take a look at the Community Console dark mode |
| 38 | feature: apart from the feature switch option (`ccdarktheme`) it has 2 |
| 39 | additional options associated with it: |
| 40 | |
| 41 | - The `ccdarktheme_mode` option can be configured in the options page with a |
| 42 | selector, and determines whether the dark/light themes are set according to the |
| 43 | OS's dark mode setting, or whether the user is the one in charge of switching |
| 44 | between them by clicking a button/switch in the Community Console. |
| 45 | - Note that this option is only applied when the feature switch is turned |
| 46 | on. |
| 47 | - The `ccdarktheme_switch_enabled` option is used to save whether the user |
| 48 | manually enabled the dark theme or not by using the switch/button in the |
| 49 | Community Console. |
| 50 | - It is only applied when `ccdarktheme_mode` is set to `switch` and the |
| 51 | feature is enabled. |
| 52 | *** |
| 53 | |
| 54 | These are the steps which you should generally follow when adding additional |
| 55 | options: |
| 56 | |
| 57 | 1. Think of a codename for the additional option. It should be the feature |
| 58 | codename appended by an underscore and a suffix |
| 59 | (`{{feature_codename}}_{{suffix}}`). |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 60 | 2. Modify the following files: |
| 61 | 1. Add an entry for the option in the `//src/common/optionsPrototype.json5` |
| 62 | file. |
| 63 | 2. Append the option's codename to the `//src/common/specialOptions.json5` |
| 64 | file. This is so the option can be handled in a specific way when |
| 65 | showing/saving it in the options page, or so it is handled outside of the |
| 66 | options page. |
avm99963 | cf83759 | 2021-02-15 20:02:54 +0100 | [diff] [blame] | 67 | 3. If you want to handle the option from the options page, follow these steps: |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 68 | 1. Modify the `//src/static/options/options.html` file to add the |
| 69 | appropriate code which implements the option (usually in the same `.option` |
| 70 | div as the feature switch). |
avm99963 | cf83759 | 2021-02-15 20:02:54 +0100 | [diff] [blame] | 71 | - Don't include text, only the HTML structure. If you add a `data-i18n` |
| 72 | attribute to an HTML element, its contents will be replaced with the |
| 73 | corresponding i18n string (for instance, |
| 74 | `<span data-i18n="test"></span>` will be rendered as |
| 75 | `<span data-i18n="test">Test</span>` if `Test` was the string defined |
| 76 | with the key `options_test`). |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 77 | 2. Modify the `//src/optionsCommon.js` file to add the following things: |
avm99963 | cf83759 | 2021-02-15 20:02:54 +0100 | [diff] [blame] | 78 | 1. In the switch statement inside the save function, add a case to |
| 79 | handle saving your additional option. |
| 80 | 2. In the switch statement inside the load event listener, add another |
| 81 | case so your option is correctly set in the options page with the saved |
| 82 | value. |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 83 | 3. Add the corresponding i18n strings at |
| 84 | `//src/static/_locales/en/manifest.json`. |
avm99963 | cf83759 | 2021-02-15 20:02:54 +0100 | [diff] [blame] | 85 | 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] | 86 | 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] | 87 | handled there. |
| 88 | |
| 89 | ## Develop the feature |
| 90 | TODO(issue #32): Write this section. |