Skip to content

[PARKED] (DO NOT MERGE) Fixes #577 : Add high contrast display #799

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

Closed
wants to merge 8 commits into from
Closed
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
2 changes: 2 additions & 0 deletions src/common/redux/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as lcpActions from "./lcp";
import * as loggerActions from "./logger";
import * as netActions from "./net";
import * as readerActions from "./reader";
import * as styleActions from "./style";
import * as toastActions from "./toast";
import * as updateActions from "./update";

Expand All @@ -29,4 +30,5 @@ export {
importActions,
toastActions,
downloadActions,
styleActions,
};
19 changes: 19 additions & 0 deletions src/common/redux/actions/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { HighContrastColors } from "readium-desktop/renderer/redux/states/style";

// ==LICENSE-BEGIN==
// Copyright 2017 European Digital Reading Lab. All rights reserved.
// Licensed to the Readium Foundation under one or more contributor license agreements.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file exposed on Github (readium) in the project repository.
// ==LICENSE-END==

export enum ActionType {
HighContrastChanged = "HIGH_CONTRAST_CHANGED",
}

export function highContrastChanged(enabled: boolean, colors: HighContrastColors) {
return {
type: ActionType.HighContrastChanged,
payload: { enabled, colors },
};
}
File renamed without changes.
3 changes: 1 addition & 2 deletions src/index_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import { ipcRenderer } from "electron";
import * as React from "react";
import * as ReactDOM from "react-dom";
import { syncIpc, winIpc } from "readium-desktop/common/ipc";
// import { setLcpNativePluginPath } from "@r2-lcp-js/parser/epub/lcp";
import { ActionWithSender } from "readium-desktop/common/models/sync";
import { winInit } from "readium-desktop/common/redux/actions/win";
import { IS_DEV } from "readium-desktop/preprocessor-directives";
import App from "readium-desktop/renderer/components/App";
import { diRendererGet } from "readium-desktop/renderer/di";
import { winInit } from "readium-desktop/renderer/redux/actions/win";
import { WinStatus } from "readium-desktop/renderer/redux/states/win";

import { initGlobalConverters_OPDS } from "@r2-opds-js/opds/init-globals";
Expand Down
3 changes: 1 addition & 2 deletions src/index_reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import { ipcRenderer } from "electron";
import * as React from "react";
import * as ReactDOM from "react-dom";
import { syncIpc, winIpc } from "readium-desktop/common/ipc";
// import { setLcpNativePluginPath } from "@r2-lcp-js/parser/epub/lcp";
import { ActionWithSender } from "readium-desktop/common/models/sync";
import { winInit } from "readium-desktop/common/redux/actions/win";
import { IS_DEV } from "readium-desktop/preprocessor-directives";
import App from "readium-desktop/renderer/components/reader/App";
import { diRendererGet } from "readium-desktop/renderer/di";
import { winInit } from "readium-desktop/renderer/redux/actions/win";
import { WinStatus } from "readium-desktop/renderer/redux/states/win";

import { initGlobalConverters_OPDS } from "@r2-opds-js/opds/init-globals";
Expand Down
18 changes: 17 additions & 1 deletion src/main/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// ==LICENSE-END=

import * as debug_ from "debug";
import { app, protocol } from "electron";
import { app, protocol, systemPreferences } from "electron";
import * as path from "path";
import { syncIpc, winIpc } from "readium-desktop/common/ipc";
import { ReaderMode } from "readium-desktop/common/models/reader";
Expand All @@ -24,6 +24,9 @@ import {
ReaderStateConfig, ReaderStateMode, ReaderStateReader,
} from "readium-desktop/main/redux/states/reader";

import { highContrastChanged } from "readium-desktop/common/redux/actions/style";
import { HighContrastColors } from "readium-desktop/renderer/redux/states/style";

// Logger
const debug = debug_("readium-desktop:main");

Expand Down Expand Up @@ -179,6 +182,19 @@ export function initApp() {
const store = diMainGet("store");
store.dispatch(appInit());

systemPreferences.on("high-contrast-color-scheme-changed", (__, enabled) => {
const colors: HighContrastColors = {
background: systemPreferences.getColor("window"),
text: systemPreferences.getColor("window-text"),
buttonBackground: systemPreferences.getColor("window"),
buttonText: systemPreferences.getColor("button-text"),
highlight: systemPreferences.getColor("highlight"),
highlightText: systemPreferences.getColor("highlight-text"),
disabled: systemPreferences.getColor("disabled-text"),
};
store.dispatch(highContrastChanged(enabled, colors));
});

const configRepository = diMainGet("config-repository");
configRepository.get("i18n").then((i18nLocale) => {
if (i18nLocale && i18nLocale.value && i18nLocale.value.locale) {
Expand Down
19 changes: 16 additions & 3 deletions src/main/redux/middleware/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@

import * as debug_ from "debug";
import { syncIpc } from "readium-desktop/common/ipc";
import { ActionWithSender, SenderType } from "readium-desktop/common/models/sync";
import {
ActionWithSender,
SenderType,
} from "readium-desktop/common/models/sync";
import { AppWindow } from "readium-desktop/common/models/win";
import {
apiActions, dialogActions, downloadActions, i18nActions, lcpActions, netActions, readerActions,
toastActions, updateActions,
apiActions,
dialogActions,
downloadActions,
i18nActions,
lcpActions,
netActions,
readerActions,
styleActions,
toastActions,
updateActions,
} from "readium-desktop/common/redux/actions";
import { diMainGet } from "readium-desktop/main/di";
import { AnyAction, Dispatch, Middleware, MiddlewareAPI } from "redux";
Expand Down Expand Up @@ -50,6 +61,8 @@ const SYNCHRONIZABLE_ACTIONS: any = [

downloadActions.ActionType.DownloadRequest,
downloadActions.ActionType.DownloadSuccess,

styleActions.ActionType.HighContrastChanged,
];

export const reduxSyncMiddleware: Middleware
Expand Down
18 changes: 7 additions & 11 deletions src/main/redux/sagas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,14 @@

import { all, call } from "redux-saga/effects";

import * as api from "./api";
import { appInitWatcher } from "./app";

import * as i18n from "./i18n";
import { netStatusWatcher } from "./net";

import * as reader from "./reader";

import * as api from "./api";

import * as i18n from "./i18n";

import * as streamer from "./streamer";

import {
updateStatusWatcher,
} from "./update";
import { updateStatusWatcher } from "./update";
import { winInitSuccessWatcher } from "./win";

export function* rootSaga() {
yield all([
Expand All @@ -44,5 +37,8 @@ export function* rootSaga() {

// Update checker
call(updateStatusWatcher),

// Window
call(winInitSuccessWatcher),
]);
}
34 changes: 34 additions & 0 deletions src/main/redux/sagas/win.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// ==LICENSE-BEGIN==
// Copyright 2017 European Digital Reading Lab. All rights reserved.
// Licensed to the Readium Foundation under one or more contributor license agreements.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file exposed on Github (readium) in the project repository.
// ==LICENSE-END==

import { systemPreferences } from "electron";
import { SagaIterator } from "redux-saga";
import { put, take } from "redux-saga/effects";

import { winActions } from "readium-desktop/renderer/redux/actions";

import { highContrastChanged } from "readium-desktop/common/redux/actions/style";
import { HighContrastColors } from "readium-desktop/renderer/redux/states/style";

export function* winInitSuccessWatcher(): SagaIterator {
while (true) {
yield take(winActions.ActionType.InitSuccess);

if (systemPreferences.isHighContrastColorScheme()) {
const colors: HighContrastColors = {
background: systemPreferences.getColor("window"),
text: systemPreferences.getColor("window-text"),
buttonBackground: systemPreferences.getColor("button-text"),
buttonText: systemPreferences.getColor("button-text"),
highlight: systemPreferences.getColor("highlight"),
disabled: systemPreferences.getColor("disabled-text"),
highlightText: systemPreferences.getColor("highlight-text"),
};
yield put(highContrastChanged(true, colors));
}
}
}
5 changes: 1 addition & 4 deletions src/renderer/assets/icons/baseline-close-24px-blue.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 52 additions & 2 deletions src/renderer/assets/styles/app.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import "./focus.css";
@import "./variable.css";

:root {
user-select: none;
Expand All @@ -9,7 +10,8 @@ body {
padding: 0;
width: 100%;
font: 1.1rem "Open Sans", sans-serif;
background:#fbfbfb;
background: var(--secondary-background-color);
color: var(--main-text-color);
}

.commonButton {
Expand All @@ -32,15 +34,63 @@ button {
border: 0;
height: 30px;
width: 30px;
fill: black;
fill: var(--button-text-color);
margin: 3px;
cursor: pointer;
color: var(--button-text-color);

&:hover {
opacity: 1;
}
}

svg {
fill: var(--main-text-color);
}

.primary {
color: rgb(0, 188, 212);
}

:global(#high_contrast) {
box-shadow: none;

& button {
color: var(--button-text-color) !important;
background-color: var(--button-background-color) !important;
border-color: var(--button-text-color) !important;

&:disabled {
color: var(--disabled-color) !important;
border-color: var(--disabled-color) !important;
}

&:hover {
background-color: var(--button-background-color) !important;
}
}
& svg {
fill: var(--button-text-color) !important;
}

& a {
&:disabled {
color: var(--disabled-color) !important;
}
}

& label:hover {
background-color: inherit !important;
}

& input {
color: var(--button-text-color) !important;
background-color: var(--button-background-color) !important;
border-color: var(--button-text-color) !important;
}

& *::selection {
color: var(--hc-highlight-text) !important;
background: var(--hc-highlight) !important;
}
}
Loading