blob: 12ec32874d7f88089f2a14d65aa8e94eb8bab87a [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ínez3465e772021-07-11 19:18:41 +0200173. Now, modify the `//src/static/options/options.html` file by appending the
18following HTML code in the corresponding section:
avm99963cf837592021-02-15 20:02:54 +010019 ```
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.
23The _experimental_ label is optional and should only be used with features which
24are unreliable (or could be at some point in the future) due to their nature.
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +0200254. Finally, add the option string at `//src/static/_locales/en/manifest.json`,
26by adding the string under the `options_{{codename}}` key.
avm99963cf837592021-02-15 20:02:54 +010027
28### How to add additional options for the feature
29Apart from the feature switch option, additional options can be defined in order
30to further customize the behavior of a feature.
31
32This is not usually the case, and it is preferred that the number of options is
33kept to a minimum so the extension is as simple as possible. In any case, this
34section explains how to add them in case they are needed.
35
36*** promo
37As a source of inspiration, take a look at the Community Console dark mode
38feature: apart from the feature switch option (`ccdarktheme`) it has 2
39additional options associated with it:
40
41- The `ccdarktheme_mode` option can be configured in the options page with a
42selector, and determines whether the dark/light themes are set according to the
43OS's dark mode setting, or whether the user is the one in charge of switching
44between 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
48manually enabled the dark theme or not by using the switch/button in the
49Community Console.
50 - It is only applied when `ccdarktheme_mode` is set to `switch` and the
51 feature is enabled.
52***
53
54These are the steps which you should generally follow when adding additional
55options:
56
571. Think of a codename for the additional option. It should be the feature
58codename appended by an underscore and a suffix
59(`{{feature_codename}}_{{suffix}}`).
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +0200602. 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.
avm99963cf837592021-02-15 20:02:54 +0100673. If you want to handle the option from the options page, follow these steps:
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020068 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).
avm99963cf837592021-02-15 20:02:54 +010071 - 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ínez3465e772021-07-11 19:18:41 +020077 2. Modify the `//src/optionsCommon.js` file to add the following things:
avm99963cf837592021-02-15 20:02:54 +010078 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ínez3465e772021-07-11 19:18:41 +020083 3. Add the corresponding i18n strings at
84 `//src/static/_locales/en/manifest.json`.
avm99963cf837592021-02-15 20:02:54 +0100854. If you want to handle the option outside of the options page, include an
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020086empty case in both switches at `//src/optionsCommon.js`, so the option is not
avm99963cf837592021-02-15 20:02:54 +010087handled there.
88
89## Develop the feature
90TODO(issue #32): Write this section.