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

Stop simulation on closing debugger tab #1661

Merged
merged 1 commit into from
Feb 5, 2019
Merged
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
11 changes: 2 additions & 9 deletions packages/xod-client-electron/src/debugger/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,12 @@ import { DEBUG_SESSION_STOPPED_ON_TAB_CLOSE } from '../shared/messages';

export default store => next => action => {
const state = store.getState();
const isDebugSession = client.isDebugSession(state);
const prevProject = client.getProject(state);
const isSerialDebugRunning = client.isSerialDebugRunning(state);
const result = next(action);

const newProject = client.getProject(store.getState());

if (isDebugSession && prevProject !== newProject) {
store.dispatch(client.markDebugSessionOutdated());
}

// Stop debug session if Debugger tab is closed
if (
isDebugSession &&
isSerialDebugRunning &&
action.type === client.TAB_CLOSE &&
action.payload.id === 'debugger'
) {
Expand Down
4 changes: 4 additions & 0 deletions packages/xod-client/src/core/middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import sidebarsMiddleware from '../editor/sidebarsMiddleware';
import crashReporter from './crashReporterMiddleware';
import hintingMiddleware from '../hinting/middleware';
import domSideeffectsMiddleware from './domSideeffectsMiddleware';
import outdaterMiddleware from '../debugger/outdaterMiddleware';
import stopSimulationMiddleware from '../editor/stopSimulationMiddleware';

export default (extraMiddlewares = []) =>
compose(
Expand All @@ -17,6 +19,8 @@ export default (extraMiddlewares = []) =>
sidebarsMiddleware,
hintingMiddleware,
domSideeffectsMiddleware,
outdaterMiddleware,
stopSimulationMiddleware,
...extraMiddlewares
),
devtoolsMiddleware
Expand Down
21 changes: 21 additions & 0 deletions packages/xod-client/src/debugger/outdaterMiddleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Middleware marks Debugger session as outdated on any change of the project.
*/

import { isDebugSession } from './selectors';
import { markDebugSessionOutdated } from './actions';
import { getProject } from '../project/selectors';

export default store => next => action => {
const state = store.getState();
const prevProject = getProject(state);
const result = next(action);

const newProject = getProject(store.getState());

if (isDebugSession(state) && prevProject !== newProject) {
store.dispatch(markDebugSessionOutdated());
}

return result;
};
2 changes: 2 additions & 0 deletions packages/xod-client/src/debugger/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ export default (state = initialState, action) => {
R.assoc('numberOfSkippedSerialLogLines', 0),
R.assoc('nodeIdsMap', invertMap(action.payload.nodeIdsMap)),
R.assoc('isRunning', true),
R.assoc('isSerialConnected', true),
R.assoc('isOutdated', false),
showDebuggerPane
)(state);
Expand All @@ -384,6 +385,7 @@ export default (state = initialState, action) => {
R.assoc('numberOfSkippedSerialLogLines', 0),
R.assoc('watchNodeValues', {}),
R.assoc('nodeIdsMap', {}),
R.assoc('isSerialConnected', false),
R.assoc('isRunning', false)
)(state);
case MARK_DEBUG_SESSION_OUTDATED:
Expand Down
5 changes: 5 additions & 0 deletions packages/xod-client/src/debugger/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export const isDebuggerVisible = R.compose(
getDebuggerState
);

export const isSerialDebugRunning = R.compose(
R.prop('isSerialConnected'),
getDebuggerState
);

export const isDebugSessionOutdated = R.compose(
R.prop('isOutdated'),
getDebuggerState
Expand Down
1 change: 1 addition & 0 deletions packages/xod-client/src/debugger/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { LOG_TAB_TYPE } from './constants';
export default {
isVisible: false,
isRunning: false,
isSerialConnected: false,
isOutdated: false,
[LOG_TAB_TYPE.INSTALLER]: {
log: '',
Expand Down
6 changes: 6 additions & 0 deletions packages/xod-client/src/editor/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ export const SIMULATION_ALREADY_RUNNING = {
solution: 'Stop the current simulation and try again',
persistent: true,
};

export const SIMULATION_STOPPED_BY_CLOSING_TAB = {
title: 'Simulation stopped',
note: 'You closed the debugger tab.',
persistent: false,
};
25 changes: 25 additions & 0 deletions packages/xod-client/src/editor/stopSimulationMiddleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Middleware stops simulation on close debugger tab
*/

import { isSimulationRunning } from './selectors';
import { abortSimulation } from './actions';
import { TAB_CLOSE } from './actionTypes';
import { DEBUGGER_TAB_ID } from './constants';
import { SIMULATION_STOPPED_BY_CLOSING_TAB } from './messages';
import { addError } from '../messages/actions';

export default store => next => action => {
const result = next(action);

if (
isSimulationRunning(store.getState()) &&
action.type === TAB_CLOSE &&
action.payload.id === DEBUGGER_TAB_ID
) {
store.dispatch(abortSimulation());
store.dispatch(addError(SIMULATION_STOPPED_BY_CLOSING_TAB));
}

return result;
};