diff options
author | 2020-04-14 14:56:16 +0530 | |
---|---|---|
committer | 2020-04-14 10:26:16 +0100 | |
commit | 100016e38098ff389b2d6899dee76413da26f2ae (patch) | |
tree | bcb0f69ef87b4fb91905da2a58538d3e8cc828e5 | |
parent | New Crowdin translations (#495) (diff) | |
download | ferdium-app-100016e38098ff389b2d6899dee76413da26f2ae.tar.gz ferdium-app-100016e38098ff389b2d6899dee76413da26f2ae.tar.zst ferdium-app-100016e38098ff389b2d6899dee76413da26f2ae.zip |
Expose Dark Reader settings (#568)
* feat: Expose DarkReader settings to users
- In the service model, expose an object darkReaderSetting which contains brightness, contrast and sepia values.
- In EditServiceScreen, provide 3 form options for brightness, contrast and Sepia. Additionally onSubmit() form, capture the darkreader settings data onto formdata.darkReaderSettings to update in the service
- In EditServiceForm, if darkModeEnabled is checked, show 3 sliders for controlling darkreader settings
- Create a new Slider control and customize it according to the application's theme and dark theme.
- In Webview Recipe, load the darkReader settings from service settings and pass it to the darkReader library.
* feat: Darkreader settings
- Lint fixes
* feat: DarkReader settings
- refactor code in editservicescreen.js
Co-Authored-By: Sampath Kumar Krishnan <sampath3493@gmail.com>
* feat: Darkreader settings
- Fix a crash where service.darkReaderSettings is null while creating a new service
- Remove isDarkModeEnabled prop to EditServiceForm as it is no longer required.
* fix: Update EditServiceScreen
- Set the default value of darkReader Brightness, Contrast and Sepia to undefined as per @vantezzen 's suggestion.
- Updated the check provided by @mahadevans87
Co-authored-by: Sampath Kumar Krishnan <sampath3493@gmail.com>
Co-authored-by: Sampath Kumar Krishnan <sampathBlam@users.noreply.github.com>
-rw-r--r-- | src/components/settings/services/EditServiceForm.js | 17 | ||||
-rw-r--r-- | src/components/ui/Slider.js | 65 | ||||
-rw-r--r-- | src/containers/settings/EditServiceScreen.js | 35 | ||||
-rw-r--r-- | src/i18n/locales/en-US.json | 4 | ||||
-rw-r--r-- | src/i18n/locales/en.json | 4 | ||||
-rw-r--r-- | src/models/Service.js | 5 | ||||
-rw-r--r-- | src/styles/main.scss | 1 | ||||
-rw-r--r-- | src/styles/slider.scss | 54 | ||||
-rw-r--r-- | src/webview/recipe.js | 4 |
9 files changed, 187 insertions, 2 deletions
diff --git a/src/components/settings/services/EditServiceForm.js b/src/components/settings/services/EditServiceForm.js index 98051d78f..bb4f4a76f 100644 --- a/src/components/settings/services/EditServiceForm.js +++ b/src/components/settings/services/EditServiceForm.js | |||
@@ -12,6 +12,7 @@ import Service from '../../../models/Service'; | |||
12 | import Tabs, { TabItem } from '../../ui/Tabs'; | 12 | import Tabs, { TabItem } from '../../ui/Tabs'; |
13 | import Input from '../../ui/Input'; | 13 | import Input from '../../ui/Input'; |
14 | import Toggle from '../../ui/Toggle'; | 14 | import Toggle from '../../ui/Toggle'; |
15 | import Slider from '../../ui/Slider'; | ||
15 | import Button from '../../ui/Button'; | 16 | import Button from '../../ui/Button'; |
16 | import ImageUpload from '../../ui/ImageUpload'; | 17 | import ImageUpload from '../../ui/ImageUpload'; |
17 | import Select from '../../ui/Select'; | 18 | import Select from '../../ui/Select'; |
@@ -105,6 +106,10 @@ const messages = defineMessages({ | |||
105 | id: 'settings.service.form.headlineGeneral', | 106 | id: 'settings.service.form.headlineGeneral', |
106 | defaultMessage: '!!!General', | 107 | defaultMessage: '!!!General', |
107 | }, | 108 | }, |
109 | headlineDarkReaderSettings: { | ||
110 | id: 'settings.service.form.headlineDarkReaderSettings', | ||
111 | defaultMessage: '!!!DarkReader Settings', | ||
112 | }, | ||
108 | iconDelete: { | 113 | iconDelete: { |
109 | id: 'settings.service.form.iconDelete', | 114 | id: 'settings.service.form.iconDelete', |
110 | defaultMessage: '!!!Delete', | 115 | defaultMessage: '!!!Delete', |
@@ -359,8 +364,18 @@ export default @observer class EditServiceForm extends Component { | |||
359 | 364 | ||
360 | <div className="settings__settings-group"> | 365 | <div className="settings__settings-group"> |
361 | <h3>{intl.formatMessage(messages.headlineGeneral)}</h3> | 366 | <h3>{intl.formatMessage(messages.headlineGeneral)}</h3> |
362 | <Toggle field={form.$('isDarkModeEnabled')} /> | ||
363 | <Toggle field={form.$('isEnabled')} /> | 367 | <Toggle field={form.$('isEnabled')} /> |
368 | <Toggle field={form.$('isDarkModeEnabled')} /> | ||
369 | {form.$('isDarkModeEnabled').value | ||
370 | && ( | ||
371 | <> | ||
372 | <h3>{intl.formatMessage(messages.headlineDarkReaderSettings)}</h3> | ||
373 | <Slider field={form.$('darkReaderBrightness')} /> | ||
374 | <Slider field={form.$('darkReaderContrast')} /> | ||
375 | <Slider field={form.$('darkReaderSepia')} /> | ||
376 | </> | ||
377 | ) | ||
378 | } | ||
364 | </div> | 379 | </div> |
365 | </div> | 380 | </div> |
366 | <div className="service-icon"> | 381 | <div className="service-icon"> |
diff --git a/src/components/ui/Slider.js b/src/components/ui/Slider.js new file mode 100644 index 000000000..b00a6a3f8 --- /dev/null +++ b/src/components/ui/Slider.js | |||
@@ -0,0 +1,65 @@ | |||
1 | import React, { Component } from 'react'; | ||
2 | import PropTypes from 'prop-types'; | ||
3 | import { observer } from 'mobx-react'; | ||
4 | import classnames from 'classnames'; | ||
5 | import { Field } from 'mobx-react-form'; | ||
6 | |||
7 | export default @observer class Slider extends Component { | ||
8 | static propTypes = { | ||
9 | field: PropTypes.instanceOf(Field).isRequired, | ||
10 | className: PropTypes.string, | ||
11 | showLabel: PropTypes.bool, | ||
12 | disabled: PropTypes.bool, | ||
13 | }; | ||
14 | |||
15 | static defaultProps = { | ||
16 | className: '', | ||
17 | showLabel: true, | ||
18 | disabled: false, | ||
19 | }; | ||
20 | |||
21 | onChange(e) { | ||
22 | const { field } = this.props; | ||
23 | |||
24 | field.onChange(e); | ||
25 | } | ||
26 | |||
27 | render() { | ||
28 | const { | ||
29 | field, | ||
30 | className, | ||
31 | showLabel, | ||
32 | disabled, | ||
33 | } = this.props; | ||
34 | |||
35 | if (field.value === '' && field.default !== '') { | ||
36 | field.value = field.default; | ||
37 | } | ||
38 | |||
39 | return ( | ||
40 | <div | ||
41 | className={classnames([ | ||
42 | 'franz-form__field', | ||
43 | 'franz-form__slider-wrapper', | ||
44 | className, | ||
45 | ])} | ||
46 | > | ||
47 | <div className="slider-container"> | ||
48 | <input | ||
49 | className="slider" | ||
50 | type="range" | ||
51 | id={field.id} | ||
52 | name={field.name} | ||
53 | value={field.value} | ||
54 | min="1" | ||
55 | max="100" | ||
56 | onChange={e => (!disabled ? this.onChange(e) : null)} | ||
57 | /> | ||
58 | </div> | ||
59 | |||
60 | {field.error && <div className={field.error}>{field.error}</div>} | ||
61 | {field.label && showLabel && <label className="franz-form__label" htmlFor={field.id}>{field.label}</label>} | ||
62 | </div> | ||
63 | ); | ||
64 | } | ||
65 | } | ||
diff --git a/src/containers/settings/EditServiceScreen.js b/src/containers/settings/EditServiceScreen.js index a7d33a3ea..560068efc 100644 --- a/src/containers/settings/EditServiceScreen.js +++ b/src/containers/settings/EditServiceScreen.js | |||
@@ -65,6 +65,18 @@ const messages = defineMessages({ | |||
65 | id: 'settings.service.form.enableDarkMode', | 65 | id: 'settings.service.form.enableDarkMode', |
66 | defaultMessage: '!!!Enable Dark Mode', | 66 | defaultMessage: '!!!Enable Dark Mode', |
67 | }, | 67 | }, |
68 | darkReaderBrightness: { | ||
69 | id: 'settings.service.form.darkReaderBrightness', | ||
70 | defaultMessage: '!!!Darkreader Brightness', | ||
71 | }, | ||
72 | darkReaderContrast: { | ||
73 | id: 'settings.service.form.darkReaderContrast', | ||
74 | defaultMessage: '!!!Darkreader Contrast', | ||
75 | }, | ||
76 | darkReaderSepia: { | ||
77 | id: 'settings.service.form.darkReaderSepia', | ||
78 | defaultMessage: '!!!Darkreader Sepia', | ||
79 | }, | ||
68 | enableProxy: { | 80 | enableProxy: { |
69 | id: 'settings.service.form.proxy.isEnabled', | 81 | id: 'settings.service.form.proxy.isEnabled', |
70 | defaultMessage: '!!!Use Proxy', | 82 | defaultMessage: '!!!Use Proxy', |
@@ -96,6 +108,14 @@ export default @inject('stores', 'actions') @observer class EditServiceScreen ex | |||
96 | const { action } = this.props.router.params; | 108 | const { action } = this.props.router.params; |
97 | const { recipes, services } = this.props.stores; | 109 | const { recipes, services } = this.props.stores; |
98 | const { createService, updateService } = this.props.actions.service; | 110 | const { createService, updateService } = this.props.actions.service; |
111 | data.darkReaderSettings = { | ||
112 | brightness: data.darkReaderBrightness, | ||
113 | contrast: data.darkReaderContrast, | ||
114 | sepia: data.darkReaderSepia, | ||
115 | }; | ||
116 | delete data.darkReaderContrast; | ||
117 | delete data.darkReaderBrightness; | ||
118 | delete data.darkReaderSepia; | ||
99 | 119 | ||
100 | const serviceData = data; | 120 | const serviceData = data; |
101 | serviceData.isMuted = !serviceData.isMuted; | 121 | serviceData.isMuted = !serviceData.isMuted; |
@@ -166,6 +186,21 @@ export default @inject('stores', 'actions') @observer class EditServiceScreen ex | |||
166 | value: service.isDarkModeEnabled, | 186 | value: service.isDarkModeEnabled, |
167 | default: stores.settings.app.darkMode, | 187 | default: stores.settings.app.darkMode, |
168 | }, | 188 | }, |
189 | darkReaderBrightness: { | ||
190 | label: intl.formatMessage(messages.darkReaderBrightness), | ||
191 | value: service.darkReaderSettings ? service.darkReaderSettings.brightness : undefined, | ||
192 | default: 100, | ||
193 | }, | ||
194 | darkReaderContrast: { | ||
195 | label: intl.formatMessage(messages.darkReaderContrast), | ||
196 | value: service.darkReaderSettings ? service.darkReaderSettings.contrast : undefined, | ||
197 | default: 90, | ||
198 | }, | ||
199 | darkReaderSepia: { | ||
200 | label: intl.formatMessage(messages.darkReaderSepia), | ||
201 | value: service.darkReaderSettings ? service.darkReaderSettings.sepia : undefined, | ||
202 | default: 10, | ||
203 | }, | ||
169 | spellcheckerLanguage: { | 204 | spellcheckerLanguage: { |
170 | label: intl.formatMessage(globalMessages.spellcheckerLanguage), | 205 | label: intl.formatMessage(globalMessages.spellcheckerLanguage), |
171 | value: service.spellcheckerLanguage, | 206 | value: service.spellcheckerLanguage, |
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.json index 9f19ad742..947f927e7 100644 --- a/src/i18n/locales/en-US.json +++ b/src/i18n/locales/en-US.json | |||
@@ -370,6 +370,10 @@ | |||
370 | "settings.service.form.enableAudio": "Enable audio", | 370 | "settings.service.form.enableAudio": "Enable audio", |
371 | "settings.service.form.enableBadge": "Show unread message badges", | 371 | "settings.service.form.enableBadge": "Show unread message badges", |
372 | "settings.service.form.enableDarkMode": "Enable Dark Mode", | 372 | "settings.service.form.enableDarkMode": "Enable Dark Mode", |
373 | "settings.service.form.darkReaderBrightness": "Brightness", | ||
374 | "settings.service.form.darkReaderContrast": "Contrast", | ||
375 | "settings.service.form.darkReaderSepia": "Sepia", | ||
376 | "settings.service.form.headlineDarkReaderSettings": "Dark Reader Settings", | ||
373 | "settings.service.form.enableNotification": "Enable notifications", | 377 | "settings.service.form.enableNotification": "Enable notifications", |
374 | "settings.service.form.enableService": "Enable service", | 378 | "settings.service.form.enableService": "Enable service", |
375 | "settings.service.form.headlineBadges": "Unread message badges", | 379 | "settings.service.form.headlineBadges": "Unread message badges", |
diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index ff0d57435..544ad997d 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json | |||
@@ -300,6 +300,10 @@ | |||
300 | "settings.service.form.enableAudio": "Cumasaigh fuaim", | 300 | "settings.service.form.enableAudio": "Cumasaigh fuaim", |
301 | "settings.service.form.enableBadge": "Taispeáin comhartha do theachtaireachtaí neamhléite", | 301 | "settings.service.form.enableBadge": "Taispeáin comhartha do theachtaireachtaí neamhléite", |
302 | "settings.service.form.enableDarkMode": "Enable Dark Mode", | 302 | "settings.service.form.enableDarkMode": "Enable Dark Mode", |
303 | "settings.service.form.darkReaderBrightness": "Darkreader Brightness", | ||
304 | "settings.service.form.darkReaderContrast": "Darkreader Contrast", | ||
305 | "settings.service.form.darkReaderSepia": "Darkreader Sepia", | ||
306 | "settings.service.form.headlineDarkReaderSettings": "Dark Reader Settings", | ||
303 | "settings.service.form.enableNotification": "Cumasaigh fógraí", | 307 | "settings.service.form.enableNotification": "Cumasaigh fógraí", |
304 | "settings.service.form.enableService": "Cumasaigh seirbhís", | 308 | "settings.service.form.enableService": "Cumasaigh seirbhís", |
305 | "settings.service.form.headlineBadges": "Comhartha do theachtaireachtaí neamhléite", | 309 | "settings.service.form.headlineBadges": "Comhartha do theachtaireachtaí neamhléite", |
diff --git a/src/models/Service.js b/src/models/Service.js index 12a2d4af9..f073ac9fc 100644 --- a/src/models/Service.js +++ b/src/models/Service.js | |||
@@ -56,6 +56,8 @@ export default class Service { | |||
56 | 56 | ||
57 | @observable isDarkModeEnabled = false; | 57 | @observable isDarkModeEnabled = false; |
58 | 58 | ||
59 | @observable darkReaderSettings = { brightness: 100, contrast: 90, sepia: 10 }; | ||
60 | |||
59 | @observable spellcheckerLanguage = null; | 61 | @observable spellcheckerLanguage = null; |
60 | 62 | ||
61 | @observable isFirstLoad = true; | 63 | @observable isFirstLoad = true; |
@@ -109,6 +111,8 @@ export default class Service { | |||
109 | 111 | ||
110 | this.isDarkModeEnabled = data.isDarkModeEnabled !== undefined ? data.isDarkModeEnabled : this.isDarkModeEnabled; | 112 | this.isDarkModeEnabled = data.isDarkModeEnabled !== undefined ? data.isDarkModeEnabled : this.isDarkModeEnabled; |
111 | 113 | ||
114 | this.darkReaderSettings = data.darkReaderSettings !== undefined ? data.darkReaderSettings : this.darkReaderSettings; | ||
115 | |||
112 | this.hasCustomUploadedIcon = data.hasCustomIcon !== undefined ? data.hasCustomIcon : this.hasCustomUploadedIcon; | 116 | this.hasCustomUploadedIcon = data.hasCustomIcon !== undefined ? data.hasCustomIcon : this.hasCustomUploadedIcon; |
113 | 117 | ||
114 | this.proxy = data.proxy !== undefined ? data.proxy : this.proxy; | 118 | this.proxy = data.proxy !== undefined ? data.proxy : this.proxy; |
@@ -136,6 +140,7 @@ export default class Service { | |||
136 | id: this.id, | 140 | id: this.id, |
137 | spellcheckerLanguage: this.spellcheckerLanguage, | 141 | spellcheckerLanguage: this.spellcheckerLanguage, |
138 | isDarkModeEnabled: this.isDarkModeEnabled, | 142 | isDarkModeEnabled: this.isDarkModeEnabled, |
143 | darkReaderSettings: this.darkReaderSettings, | ||
139 | team: this.team, | 144 | team: this.team, |
140 | url: this.url, | 145 | url: this.url, |
141 | hasCustomIcon: this.hasCustomIcon, | 146 | hasCustomIcon: this.hasCustomIcon, |
diff --git a/src/styles/main.scss b/src/styles/main.scss index 1e9ed5714..ceec4a95e 100644 --- a/src/styles/main.scss +++ b/src/styles/main.scss | |||
@@ -40,3 +40,4 @@ $mdi-font-path: '../node_modules/mdi/fonts'; | |||
40 | @import './searchInput.scss'; | 40 | @import './searchInput.scss'; |
41 | @import './select.scss'; | 41 | @import './select.scss'; |
42 | @import './image-upload.scss'; | 42 | @import './image-upload.scss'; |
43 | @import './slider.scss'; \ No newline at end of file | ||
diff --git a/src/styles/slider.scss b/src/styles/slider.scss new file mode 100644 index 000000000..36e0638c4 --- /dev/null +++ b/src/styles/slider.scss | |||
@@ -0,0 +1,54 @@ | |||
1 | @import './config.scss'; | ||
2 | |||
3 | .theme__dark .franz-form .franz-form__slider-wrapper .slider { | ||
4 | border: 1px solid $dark-theme-gray; | ||
5 | background: $dark-theme-gray; | ||
6 | |||
7 | } | ||
8 | |||
9 | |||
10 | .franz-form { | ||
11 | .franz-form__slider-wrapper { | ||
12 | display: flex; | ||
13 | flex-direction: row; | ||
14 | |||
15 | .franz-form__label { margin-left: 20px; } | ||
16 | |||
17 | .slider-container { | ||
18 | width: 100%; /* Width of the outside container */ | ||
19 | } | ||
20 | |||
21 | /* The slider itself */ | ||
22 | .slider { | ||
23 | -webkit-appearance: none; | ||
24 | width: 100%; | ||
25 | height: 14px; | ||
26 | border-radius: $theme-border-radius; | ||
27 | background: $theme-gray-lighter; | ||
28 | outline: none; | ||
29 | opacity: 1.0; | ||
30 | -webkit-transition: .2s; | ||
31 | transition: opacity .2s; | ||
32 | } | ||
33 | |||
34 | .slider::-webkit-slider-thumb { | ||
35 | -webkit-appearance: none; | ||
36 | appearance: none; | ||
37 | width: 14px; | ||
38 | height: 14px; | ||
39 | border-radius: 50%; | ||
40 | background: $theme-brand-primary; | ||
41 | box-shadow: 0 1px 4px rgba(0, 0, 0, .3); | ||
42 | cursor: pointer; | ||
43 | } | ||
44 | |||
45 | .slider::-moz-range-thumb { | ||
46 | width: 14px; | ||
47 | height: 14px; | ||
48 | border-radius: 50%; | ||
49 | background: $theme-brand-primary; | ||
50 | box-shadow: 0 1px 4px rgba(0, 0, 0, .3); | ||
51 | cursor: pointer; | ||
52 | } | ||
53 | } | ||
54 | } | ||
diff --git a/src/webview/recipe.js b/src/webview/recipe.js index 7b762af17..8125ec064 100644 --- a/src/webview/recipe.js +++ b/src/webview/recipe.js | |||
@@ -157,6 +157,7 @@ class RecipeController { | |||
157 | debug('isDarkModeEnabled', this.settings.service.isDarkModeEnabled); | 157 | debug('isDarkModeEnabled', this.settings.service.isDarkModeEnabled); |
158 | debug('System spellcheckerLanguage', this.settings.app.spellcheckerLanguage); | 158 | debug('System spellcheckerLanguage', this.settings.app.spellcheckerLanguage); |
159 | debug('Service spellcheckerLanguage', this.settings.service.spellcheckerLanguage); | 159 | debug('Service spellcheckerLanguage', this.settings.service.spellcheckerLanguage); |
160 | debug('darkReaderSettigs', this.settings.service.darkReaderSettings); | ||
160 | 161 | ||
161 | if (this.userscript && this.userscript.internal_setSettings) { | 162 | if (this.userscript && this.userscript.internal_setSettings) { |
162 | this.userscript.internal_setSettings(this.settings); | 163 | this.userscript.internal_setSettings(this.settings); |
@@ -233,7 +234,8 @@ class RecipeController { | |||
233 | console.log('Injecting DarkReader'); | 234 | console.log('Injecting DarkReader'); |
234 | 235 | ||
235 | // Use darkreader instead | 236 | // Use darkreader instead |
236 | enableDarkMode({}, { | 237 | const { brightness, contrast, sepia } = this.settings.service.darkReaderSettings; |
238 | enableDarkMode({ brightness, contrast, sepia }, { | ||
237 | css: customDarkModeCss[window.location.host] || '', | 239 | css: customDarkModeCss[window.location.host] || '', |
238 | }); | 240 | }); |
239 | this.universalDarkModeInjected = true; | 241 | this.universalDarkModeInjected = true; |