Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make system setting the default theme preference #1581

Merged
merged 4 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Future release

### Enhancements

- Add ability to select system as a theme option and make it the default

### Fixes

- Rework WordPress.com signin to prevent infinite looping and login failures [#1627](https://github.com/Automattic/simplenote-electron/pull/1627)
Expand Down
16 changes: 14 additions & 2 deletions lib/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,20 @@ export const App = connect(
preferencesBucket: this.props.preferencesBucket,
});

getSystemColorMode = () =>
window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark'
: 'light';

getTheme = () => {
const {
settings: { theme },
} = this.props;
return 'system' === theme ? this.getSystemColorMode() : theme;
};

initializeElectron = () => {
const remote = __non_webpack_require__('electron').remote; // eslint-disable-line no-undef
const { remote } = __non_webpack_require__('electron'); // eslint-disable-line no-undef

this.setState({
electron: {
Expand Down Expand Up @@ -404,7 +416,7 @@ export const App = connect(
} = this.props;
const isMacApp = isElectronMac();

const themeClass = `theme-${settings.theme}`;
const themeClass = `theme-${this.getTheme()}`;

const appClasses = classNames('app', themeClass, {
'is-line-length-full': settings.lineLength === 'full',
Expand Down
4 changes: 3 additions & 1 deletion lib/dialogs/settings-group.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ export const SettingsGroup = ({
</a>
);

const childElements = React.Children.toArray(children).filter(o => o);

return (
<div className="settings-group">
<PanelTitle headingLevel="3">{groupTitle}</PanelTitle>
<div className="settings-items theme-color-border">
{React.Children.map(children, ({ props: { slug, title } }) => (
{childElements.map(({ props: { slug, title } }) => (
<label
className="settings-item theme-color-border"
htmlFor={`settings-field-${groupSlug}-${slug}`}
Expand Down
3 changes: 3 additions & 0 deletions lib/dialogs/settings/panels/display.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ const DisplayPanel = props => {
onChange={actions.activateTheme}
renderer={RadioGroup}
>
{navigator.userAgent.toLowerCase().indexOf(' electron/') === -1 && (
<Item title="System" slug="system" />
)}
<Item title="Light" slug="light" />
<Item title="Dark" slug="dark" />
</SettingsGroup>
Expand Down
2 changes: 1 addition & 1 deletion lib/state/settings/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const initialState = {
sortTagsAlpha: false,
sortType: 'modificationDate',
spellCheckEnabled: true,
theme: 'light',
theme: 'system',
wpToken: false,
};

Expand Down