hyper/app/lib/index.js
Mike b76e004309 Dynamically change the font-smoothing pref (#205)
* Dynamically change the `font-smoothing` pref

By default, hterm defaults to `font-smoothing: 'antialiased'`, which
works really well on retina displays. On non-retina displays, however,
the type looks very thin and is hard to read.

This will look at the devicePixelRatio of the device anytime the term
prefs are set, and change between `antialiased` and
`subpixel-antialiased` dynamically.

* Refactor to add the font smoothing override into state

This also subscribes to the electron `move` event to control when this
piece of state gets updated.

* Add UI_WINDOW_MOVE action with a side effect for font smoothing
2016-07-19 11:30:57 -07:00

117 lines
3 KiB
JavaScript

import rpc from './rpc';
import React from 'react';
import { render } from 'react-dom';
import thunk from 'redux-thunk';
import { Provider } from 'react-redux';
import { init } from './actions/index';
import effects from './utils/effects';
import * as config from './utils/config';
import rootReducer from './reducers/index';
import * as plugins from './utils/plugins';
import * as uiActions from './actions/ui';
import forceUpdate from 'react-deep-force-update';
import * as updaterActions from './actions/updater';
import * as sessionActions from './actions/sessions';
import { createStore, applyMiddleware } from 'redux';
import HyperTermContainer from './containers/hyperterm';
import { loadConfig, reloadConfig } from './actions/config';
const store_ = createStore(
rootReducer,
applyMiddleware(
thunk,
plugins.middleware,
thunk,
effects
)
);
window.__defineGetter__('store', () => store_);
window.__defineGetter__('rpc', () => rpc);
window.__defineGetter__('config', () => config);
window.__defineGetter__('plugins', () => plugins);
// initialize config
store_.dispatch(loadConfig(config.getConfig()));
config.subscribe(() => {
store_.dispatch(reloadConfig(config.getConfig()));
});
// initialize communication with main electron process
// and subscribe to all user intents for example from menus
rpc.on('ready', () => {
store_.dispatch(init());
store_.dispatch(uiActions.setFontSmoothing());
});
rpc.on('session add', ({ uid, shell, pid }) => {
store_.dispatch(sessionActions.addSession(uid, shell, pid));
});
rpc.on('session data', ({ uid, data }) => {
store_.dispatch(sessionActions.addSessionData(uid, data));
});
rpc.on('session title', ({ uid, title }) => {
store_.dispatch(sessionActions.setSessionProcessTitle(uid, title));
});
rpc.on('session exit', ({ uid }) => {
store_.dispatch(sessionActions.sessionExit(uid));
});
rpc.on('session add req', () => {
store_.dispatch(sessionActions.requestSession());
});
rpc.on('session close req', () => {
store_.dispatch(sessionActions.userExitActiveSession());
});
rpc.on('session clear req', () => {
store_.dispatch(sessionActions.clearActiveSession());
});
rpc.on('reset fontSize req', () => {
store_.dispatch(uiActions.resetFontSize());
});
rpc.on('increase fontSize req', () => {
store_.dispatch(uiActions.increaseFontSize());
});
rpc.on('decrease fontSize req', () => {
store_.dispatch(uiActions.decreaseFontSize());
});
rpc.on('move left req', () => {
store_.dispatch(uiActions.moveLeft());
});
rpc.on('move right req', () => {
store_.dispatch(uiActions.moveRight());
});
rpc.on('preferences', () => {
store_.dispatch(uiActions.showPreferences());
});
rpc.on('update available', ({ releaseName, releaseNotes }) => {
store_.dispatch(updaterActions.updateAvailable(releaseName, releaseNotes));
});
rpc.on('move', () => {
store_.dispatch(uiActions.windowMove());
});
const app = render(
<Provider store={ store_ }>
<HyperTermContainer />
</Provider>,
document.getElementById('mount')
);
rpc.on('reload', () => {
plugins.reload();
forceUpdate(app);
});