2017-11-29 09:57:37 +01:00
|
|
|
// @flow
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
import * as ACTIONS from 'constants/action_types';
|
2017-11-29 09:57:37 +01:00
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
import { remote } from 'electron';
|
2017-11-29 09:57:37 +01:00
|
|
|
|
2017-06-24 10:57:37 +02:00
|
|
|
const win = remote.BrowserWindow.getFocusedWindow();
|
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
const reducers = {};
|
2017-11-30 07:53:23 +01:00
|
|
|
|
|
|
|
export type SnackBar = {
|
|
|
|
message: string,
|
|
|
|
linkText: string,
|
|
|
|
linkTarget: string,
|
|
|
|
isError: boolean,
|
|
|
|
};
|
|
|
|
export type AppState = {
|
2017-11-29 09:57:37 +01:00
|
|
|
isLoaded: boolean,
|
2017-11-30 07:53:23 +01:00
|
|
|
modal: ?string,
|
2017-11-29 09:57:37 +01:00
|
|
|
modalProps: mixed,
|
|
|
|
platform: string,
|
2017-11-29 23:43:27 +01:00
|
|
|
upgradeSkipped: boolean,
|
|
|
|
daemonVersionMatched: ?boolean,
|
2017-11-29 09:57:37 +01:00
|
|
|
daemonReady: boolean,
|
|
|
|
hasSignature: boolean,
|
|
|
|
badgeNumber: number,
|
2017-11-29 23:43:27 +01:00
|
|
|
volume: number,
|
2018-01-17 11:50:02 +01:00
|
|
|
autoUpdateDeclined: boolean,
|
|
|
|
modalsAllowed: boolean,
|
2017-11-30 07:53:23 +01:00
|
|
|
downloadProgress: ?number,
|
|
|
|
upgradeDownloading: ?boolean,
|
|
|
|
upgradeDownloadComplete: ?boolean,
|
|
|
|
checkUpgradeTimer: ?number,
|
|
|
|
isUpgradeAvailable: ?boolean,
|
|
|
|
isUpgradeSkipped: ?boolean,
|
|
|
|
snackBar: ?SnackBar,
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultState: AppState = {
|
2017-04-07 07:15:22 +02:00
|
|
|
isLoaded: false,
|
2017-09-08 05:15:05 +02:00
|
|
|
modal: null,
|
|
|
|
modalProps: {},
|
2017-04-07 07:15:22 +02:00
|
|
|
platform: process.platform,
|
2017-12-21 18:32:51 +01:00
|
|
|
upgradeSkipped: sessionStorage.getItem('upgradeSkipped') === 'true',
|
2017-07-19 23:05:08 +02:00
|
|
|
daemonVersionMatched: null,
|
2017-04-22 15:17:01 +02:00
|
|
|
daemonReady: false,
|
2017-04-29 11:50:29 +02:00
|
|
|
hasSignature: false,
|
2017-06-24 10:57:37 +02:00
|
|
|
badgeNumber: 0,
|
2017-12-21 18:32:51 +01:00
|
|
|
volume: Number(sessionStorage.getItem('volume')) || 1,
|
2018-01-16 06:38:23 +01:00
|
|
|
autoUpdateDownloaded: false,
|
2018-01-17 11:50:02 +01:00
|
|
|
autoUpdateDeclined: false,
|
|
|
|
modalsAllowed: true,
|
2017-11-30 18:47:05 +01:00
|
|
|
|
2017-11-30 07:53:23 +01:00
|
|
|
downloadProgress: undefined,
|
|
|
|
upgradeDownloading: undefined,
|
|
|
|
upgradeDownloadComplete: undefined,
|
|
|
|
checkUpgradeTimer: undefined,
|
|
|
|
isUpgradeAvailable: undefined,
|
|
|
|
isUpgradeSkipped: undefined,
|
|
|
|
snackBar: undefined,
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.DAEMON_READY] = state =>
|
|
|
|
Object.assign({}, state, {
|
2017-05-02 05:57:50 +02:00
|
|
|
daemonReady: true,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-05-02 05:57:50 +02:00
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.DAEMON_VERSION_MATCH] = state =>
|
|
|
|
Object.assign({}, state, {
|
2017-07-19 23:05:08 +02:00
|
|
|
daemonVersionMatched: true,
|
|
|
|
});
|
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.DAEMON_VERSION_MISMATCH] = state =>
|
|
|
|
Object.assign({}, state, {
|
2017-07-19 23:05:08 +02:00
|
|
|
daemonVersionMatched: false,
|
|
|
|
});
|
2017-05-02 05:57:50 +02:00
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.UPGRADE_CANCELLED] = state =>
|
|
|
|
Object.assign({}, state, {
|
2017-04-07 07:15:22 +02:00
|
|
|
downloadProgress: null,
|
2017-05-25 22:07:32 +02:00
|
|
|
upgradeDownloadComplete: false,
|
2017-04-07 07:15:22 +02:00
|
|
|
modal: null,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2018-01-16 06:38:23 +01:00
|
|
|
reducers[ACTIONS.AUTO_UPDATE_DOWNLOADED] = state =>
|
|
|
|
Object.assign({}, state, {
|
|
|
|
autoUpdateDownloaded: true,
|
|
|
|
});
|
|
|
|
|
2018-04-18 06:03:01 +02:00
|
|
|
reducers[ACTIONS.AUTO_UPDATE_DECLINED] = state =>
|
|
|
|
Object.assign({}, state, {
|
2018-01-17 11:50:02 +01:00
|
|
|
autoUpdateDeclined: true,
|
|
|
|
});
|
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.UPGRADE_DOWNLOAD_COMPLETED] = (state, action) =>
|
|
|
|
Object.assign({}, state, {
|
2017-06-01 08:51:16 +02:00
|
|
|
downloadPath: action.data.path,
|
2017-05-25 22:07:32 +02:00
|
|
|
upgradeDownloading: false,
|
2017-06-06 23:19:12 +02:00
|
|
|
upgradeDownloadCompleted: true,
|
|
|
|
});
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.UPGRADE_DOWNLOAD_STARTED] = state =>
|
|
|
|
Object.assign({}, state, {
|
2017-06-06 23:19:12 +02:00
|
|
|
upgradeDownloading: true,
|
|
|
|
});
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2018-01-17 11:50:02 +01:00
|
|
|
reducers[ACTIONS.CHANGE_MODALS_ALLOWED] = (state, action) =>
|
|
|
|
Object.assign({}, state, {
|
|
|
|
modalsAllowed: action.data.modalsAllowed,
|
|
|
|
});
|
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.SKIP_UPGRADE] = state => {
|
2017-12-21 18:32:51 +01:00
|
|
|
sessionStorage.setItem('upgradeSkipped', 'true');
|
2017-04-07 07:15:22 +02:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
2017-11-15 02:50:21 +01:00
|
|
|
isUpgradeSkipped: true,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2018-04-18 06:03:01 +02:00
|
|
|
reducers[ACTIONS.MEDIA_PLAY] = state =>
|
|
|
|
Object.assign({}, state, {
|
2018-01-17 11:50:02 +01:00
|
|
|
modalsAllowed: false,
|
|
|
|
});
|
|
|
|
|
2018-04-18 06:03:01 +02:00
|
|
|
reducers[ACTIONS.MEDIA_PAUSE] = state =>
|
|
|
|
Object.assign({}, state, {
|
2018-01-17 11:50:02 +01:00
|
|
|
modalsAllowed: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
reducers[ACTIONS.SET_PLAYING_URI] = (state, action) => {
|
|
|
|
if (action.data.uri === null) {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
modalsAllowed: true,
|
|
|
|
});
|
|
|
|
}
|
2018-03-26 23:32:43 +02:00
|
|
|
return state;
|
2018-01-17 11:50:02 +01:00
|
|
|
};
|
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.UPDATE_VERSION] = (state, action) =>
|
|
|
|
Object.assign({}, state, {
|
2017-06-06 23:19:12 +02:00
|
|
|
version: action.data.version,
|
|
|
|
});
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.CHECK_UPGRADE_SUCCESS] = (state, action) =>
|
|
|
|
Object.assign({}, state, {
|
2017-11-15 02:50:21 +01:00
|
|
|
isUpgradeAvailable: action.data.upgradeAvailable,
|
|
|
|
remoteVersion: action.data.remoteVersion,
|
|
|
|
});
|
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.CHECK_UPGRADE_SUBSCRIBE] = (state, action) =>
|
|
|
|
Object.assign({}, state, {
|
2017-11-15 02:50:21 +01:00
|
|
|
checkUpgradeTimer: action.data.checkUpgradeTimer,
|
|
|
|
});
|
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.UPGRADE_DOWNLOAD_PROGRESSED] = (state, action) =>
|
|
|
|
Object.assign({}, state, {
|
2017-06-06 23:19:12 +02:00
|
|
|
downloadProgress: action.data.percent,
|
|
|
|
});
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.DOWNLOADING_COMPLETED] = state => {
|
2017-12-21 18:32:51 +01:00
|
|
|
const { badgeNumber } = state;
|
2017-06-24 10:57:37 +02:00
|
|
|
|
|
|
|
// Don't update the badge number if the window is focused
|
2017-10-13 22:33:37 +02:00
|
|
|
if (win && win.isFocused()) return Object.assign({}, state);
|
2017-06-24 10:57:37 +02:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
badgeNumber: badgeNumber + 1,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.WINDOW_FOCUSED] = state =>
|
|
|
|
Object.assign({}, state, {
|
2017-06-24 10:57:37 +02:00
|
|
|
badgeNumber: 0,
|
|
|
|
});
|
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.VOLUME_CHANGED] = (state, action) =>
|
|
|
|
Object.assign({}, state, {
|
2017-08-25 21:05:00 +02:00
|
|
|
volume: action.data.volume,
|
|
|
|
});
|
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
reducers[ACTIONS.HISTORY_NAVIGATE] = state =>
|
|
|
|
Object.assign({}, state, {
|
|
|
|
modal: undefined,
|
|
|
|
modalProps: {},
|
|
|
|
});
|
|
|
|
|
2017-11-30 07:53:23 +01:00
|
|
|
export default function reducer(state: AppState = defaultState, action: any) {
|
2017-04-07 07:15:22 +02:00
|
|
|
const handler = reducers[action.type];
|
|
|
|
if (handler) return handler(state, action);
|
|
|
|
return state;
|
|
|
|
}
|