blob: 15053e4885ef8ba98350495e7da0280ad13282ad [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.
avm99963bf8eece2021-04-22 00:27:03 +0200122. Modify the `//src/common/common.js` file by adding an entry in the
13`optionsPrototype` object.
avm99963cf837592021-02-15 20:02:54 +010014 - All features should have the `false` value set as a default, so existing
15 users have to explicitly enable the option after they receive the extension
16 update. Otherwise, it might cause confusion, because users wouldn't know if
17 the feature was added by the extension or Google.
183. Now, modify the `//src/options/options.html` file by appending the following
19HTML code in the corresponding section:
20 ```
21 <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>
22 ```
23 where you should substitute `{{codename}}` with the codename you've chosen.
24The _experimental_ label is optional and should only be used with features which
25are unreliable (or could be at some point in the future) due to their nature.
264. Finally, add the option string at `//src/_locales/en/manifest.json`, by
27adding the string under the `options_{{codename}}` key.
28
29### How to add additional options for the feature
30Apart from the feature switch option, additional options can be defined in order
31to further customize the behavior of a feature.
32
33This is not usually the case, and it is preferred that the number of options is
34kept to a minimum so the extension is as simple as possible. In any case, this
35section explains how to add them in case they are needed.
36
37*** promo
38As a source of inspiration, take a look at the Community Console dark mode
39feature: apart from the feature switch option (`ccdarktheme`) it has 2
40additional options associated with it:
41
42- The `ccdarktheme_mode` option can be configured in the options page with a
43selector, and determines whether the dark/light themes are set according to the
44OS's dark mode setting, or whether the user is the one in charge of switching
45between them by clicking a button/switch in the Community Console.
46 - Note that this option is only applied when the feature switch is turned
47 on.
48- The `ccdarktheme_switch_enabled` option is used to save whether the user
49manually enabled the dark theme or not by using the switch/button in the
50Community Console.
51 - It is only applied when `ccdarktheme_mode` is set to `switch` and the
52 feature is enabled.
53***
54
55These are the steps which you should generally follow when adding additional
56options:
57
581. Think of a codename for the additional option. It should be the feature
59codename appended by an underscore and a suffix
60(`{{feature_codename}}_{{suffix}}`).
612. Modify the `//src/common/common.js` file by doing the following things:
avm99963bf8eece2021-04-22 00:27:03 +020062 1. Add an entry for the option in the `optionsPrototype` object.
avm99963cf837592021-02-15 20:02:54 +010063 2. Append the option's codename to the `specialOptions` object. This is so
64 the option can be handled in a specific way when showing/saving it in the
65 options page, or so it is handled outside of the options page.
663. If you want to handle the option from the options page, follow these steps:
67 1. Modify the `//src/options/options.html` file to add the appropriate code
68 which implements the option (usually in the same `.option` div as the
69 feature switch).
70 - Don't include text, only the HTML structure. If you add a `data-i18n`
71 attribute to an HTML element, its contents will be replaced with the
72 corresponding i18n string (for instance,
73 `<span data-i18n="test"></span>` will be rendered as
74 `<span data-i18n="test">Test</span>` if `Test` was the string defined
75 with the key `options_test`).
76 2. Modify the `//src/options/options.js` file to add the following things:
77 1. In the switch statement inside the save function, add a case to
78 handle saving your additional option.
79 2. In the switch statement inside the load event listener, add another
80 case so your option is correctly set in the options page with the saved
81 value.
82 3. Add the corresponding i18n strings at `//src/_locales/en/manifest.json`.
834. If you want to handle the option outside of the options page, include an
84empty case in both switches at `//src/options/options.js`, so the option is not
85handled there.
86
87## Develop the feature
88TODO(issue #32): Write this section.