2019-10-24 23:41:18 +02:00
|
|
|
import { Lbry, ACTIONS } from 'lbry-redux';
|
|
|
|
import * as SETTINGS from 'constants/settings';
|
2018-02-16 10:16:50 +01:00
|
|
|
import analytics from 'analytics';
|
2018-01-14 10:14:15 +01:00
|
|
|
|
2019-08-18 18:54:55 +02:00
|
|
|
const UPDATE_IS_NIGHT_INTERVAL = 5 * 60 * 1000;
|
2017-12-26 21:13:05 +01:00
|
|
|
|
2017-05-17 23:52:45 +02:00
|
|
|
export function doFetchDaemonSettings() {
|
2017-12-28 00:48:11 +01:00
|
|
|
return dispatch => {
|
2017-12-21 18:32:51 +01:00
|
|
|
Lbry.settings_get().then(settings => {
|
2018-02-16 10:16:50 +01:00
|
|
|
analytics.toggle(settings.share_usage_data);
|
2017-05-17 23:52:45 +02:00
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.DAEMON_SETTINGS_RECEIVED,
|
2017-05-17 23:52:45 +02:00
|
|
|
data: {
|
2017-06-06 23:19:12 +02:00
|
|
|
settings,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2017-05-17 23:52:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function doSetDaemonSetting(key, value) {
|
2017-12-28 00:48:11 +01:00
|
|
|
return dispatch => {
|
2019-02-12 18:26:50 +01:00
|
|
|
const newSettings = {
|
|
|
|
key,
|
|
|
|
value: !value && value !== false ? null : value,
|
|
|
|
};
|
2017-12-26 21:13:05 +01:00
|
|
|
Lbry.settings_set(newSettings).then(newSettings);
|
|
|
|
Lbry.settings_get().then(settings => {
|
2019-04-01 16:30:19 +02:00
|
|
|
analytics.toggle(settings.share_usage_data);
|
2017-05-17 23:52:45 +02:00
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.DAEMON_SETTINGS_RECEIVED,
|
2017-05-17 23:52:45 +02:00
|
|
|
data: {
|
2017-12-26 21:13:05 +01:00
|
|
|
settings,
|
2017-06-06 23:19:12 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2017-06-06 06:21:55 +02:00
|
|
|
}
|
2017-06-28 09:12:01 +02:00
|
|
|
|
|
|
|
export function doSetClientSetting(key, value) {
|
|
|
|
return {
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.CLIENT_SETTING_CHANGED,
|
2017-06-28 09:12:01 +02:00
|
|
|
data: {
|
|
|
|
key,
|
|
|
|
value,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2017-08-08 11:36:14 +02:00
|
|
|
|
2018-01-14 10:14:15 +01:00
|
|
|
export function doUpdateIsNight() {
|
|
|
|
return {
|
|
|
|
type: ACTIONS.UPDATE_IS_NIGHT,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-03-08 00:03:45 +01:00
|
|
|
export function doUpdateIsNightAsync() {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(doUpdateIsNight());
|
2019-02-12 18:26:50 +01:00
|
|
|
|
2019-03-05 05:46:57 +01:00
|
|
|
setInterval(() => dispatch(doUpdateIsNight()), UPDATE_IS_NIGHT_INTERVAL);
|
2018-03-08 00:03:45 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-08-18 18:54:55 +02:00
|
|
|
export function doSetDarkTime(value, options) {
|
|
|
|
const { fromTo, time } = options;
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const state = getState();
|
2019-09-17 20:49:03 +02:00
|
|
|
const darkModeTimes = state.settings.clientSettings[SETTINGS.DARK_MODE_TIMES];
|
2019-08-18 18:54:55 +02:00
|
|
|
const { hour, min } = darkModeTimes[fromTo];
|
|
|
|
const newHour = time === 'hour' ? value : hour;
|
|
|
|
const newMin = time === 'min' ? value : min;
|
|
|
|
const modifiedTimes = {
|
|
|
|
[fromTo]: {
|
|
|
|
hour: newHour,
|
|
|
|
min: newMin,
|
|
|
|
formattedTime: newHour + ':' + newMin,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const mergedTimes = { ...darkModeTimes, ...modifiedTimes };
|
|
|
|
|
2019-09-24 01:47:58 +02:00
|
|
|
dispatch(doSetClientSetting(SETTINGS.DARK_MODE_TIMES, mergedTimes));
|
2019-08-18 18:54:55 +02:00
|
|
|
dispatch(doUpdateIsNight());
|
|
|
|
};
|
|
|
|
}
|