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

Feat/ipc redux #702

Merged
merged 9 commits into from
Apr 25, 2020
Prev Previous commit
refactor(ipc): move window ipc events in ipc middleware
  • Loading branch information
Charles Jacquin committed Apr 22, 2020
commit d8c2d4bb31d76e7b07213e3403d66289c114857a
12 changes: 10 additions & 2 deletions packages/app/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as ScrobblingActions from './actions/scrobbling';
import * as ImportFavActions from './actions/importfavs';
import * as ConnectivityActions from './actions/connectivity';
import * as GithubContribActions from './actions/githubContrib';
import * as WindowActions from './actions/window';

import './app.global.scss';
import styles from './styles.scss';
Expand Down Expand Up @@ -124,7 +125,13 @@ class App extends React.PureComponent {
<SearchBoxContainer />
<Spacer className={styles.navbar_spacer}/>
<HelpModalContainer />
{this.props.settings.framelessWindow && <WindowControls />}
{this.props.settings.framelessWindow && (
<WindowControls
onCloseClick={this.props.actions.closeWindow}
onMaxClick={this.props.actions.maximizeWindow}
onMinClick={this.props.actions.minimizeWindow}
/>
)}
</Navbar>
);
}
Expand Down Expand Up @@ -403,7 +410,8 @@ function mapDispatchToProps (dispatch) {
PluginsActions,
ConnectivityActions,
SearchActions,
GithubContribActions
GithubContribActions,
WindowActions
),
dispatch
)
Expand Down
15 changes: 15 additions & 0 deletions packages/app/app/actions/window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const MAXIMIZE_WINDOW = 'MAXIMIZE_WINDOW';
export const MINIMIZE_WINDOW = 'MINIMIZE_WINDOW';
export const CLOSE_WINDOW = 'CLOSE_WINDOW';

export const maximizeWindow = () => ({
type: MAXIMIZE_WINDOW
});

export const minimizeWindow = () => ({
type: MINIMIZE_WINDOW
});

export const closeWindow = () => ({
type: CLOSE_WINDOW
});
22 changes: 11 additions & 11 deletions packages/app/app/components/WindowControls/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { IpcEvents } from '@nuclear/core';
import React from 'react';
import PropTypes from 'prop-types';

import styles from './styles.scss';

import WindowButton from './WindowButton';
import { ipcRenderer } from 'electron';

// TODO move this elsewhere (redux middleware ?)
const handleMinimize = () => ipcRenderer.send(IpcEvents.WINDOW_MINIMIZE);
const handleMaximize = () => ipcRenderer.send(IpcEvents.WINDOW_MAXIMIZE);
const handleClose = () => ipcRenderer.send(IpcEvents.WINDOW_CLOSE);

const WindowControls = () => (
const WindowControls = ({ onCloseClick, onMaxClick, onMinClick }) => (
<div className={styles.window_controls_container}>
<WindowButton icon='window-minimize' onClick={handleMinimize} />
<WindowButton icon='window-maximize' onClick={handleMaximize} />
<WindowButton icon='close' onClick={handleClose} />
<WindowButton icon='window-minimize' onClick={onMinClick} />
<WindowButton icon='window-maximize' onClick={onMaxClick} />
<WindowButton icon='close' onClick={onCloseClick} />
</div>
);

WindowControls.propTypes = {
onMaxClick: PropTypes.func,
onMinClick: PropTypes.func,
onCloseClick: PropTypes.func
};

export default WindowControls;
11 changes: 9 additions & 2 deletions packages/app/app/store/middlewares/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ADD_QUEUE_ITEM, CLEAR_QUEUE, REMOVE_QUEUE_ITEM, QUEUE_DROP } from '../.
import { SET_BOOLEAN_OPTION, SET_NUMBER_OPTION } from '../../actions/settings';
import { CHANGE_CONNECTIVITY } from '../../actions/connectivity';
import { ADD_TO_DOWNLOADS, DOWNLOAD_RESUMED, DOWNLOAD_PAUSED, DOWNLOAD_FINISHED, DOWNLOAD_ERROR } from '../../actions/downloads';
import { CLOSE_WINDOW, MINIMIZE_WINDOW, MAXIMIZE_WINDOW } from '../../actions/window';

const ipcConnect = () => next => {
next({
Expand Down Expand Up @@ -57,8 +58,7 @@ const ipcConnect = () => next => {
ipcRenderer.send(IpcEvents.TRACK_REMOVE, payload);
break;
case QUEUE_DROP:
ipcRenderer.send(IpcEvents.QUEUE_DROP, payload);
break;
return ipcRenderer.send(IpcEvents.QUEUE_DROP, payload);

case SET_BOOLEAN_OPTION:
switch (payload.option) {
Expand Down Expand Up @@ -113,6 +113,13 @@ const ipcConnect = () => next => {
nextDownload ? ipcRenderer.send(IpcEvents.DOWNLOAD_START, nextDownload.track) : null;
break;
}

case CLOSE_WINDOW:
return ipcRenderer.send(IpcEvents.WINDOW_CLOSE);
case MAXIMIZE_WINDOW:
return ipcRenderer.send(IpcEvents.WINDOW_MAXIMIZE);
case MINIMIZE_WINDOW:
return ipcRenderer.send(IpcEvents.WINDOW_MINIMIZE);
}

next({ type, payload });
Expand Down