Skip to content

Commit 468da6f

Browse files
authored
Merge pull request scratchfoundation#5059 from paulkaplan/fix-save-after-recording
Fix saving after recording a sound
2 parents 043cbec + b07c645 commit 468da6f

File tree

2 files changed

+53
-7
lines changed

2 files changed

+53
-7
lines changed

src/lib/vm-listener-hoc.jsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ const vmListenerHOC = function (WrappedComponent) {
6060
this.props.vm.postIOData('userData', {username: this.props.username});
6161
}
6262

63-
// Re-request a targets update when the shouldEmitUpdate state changes to true
63+
// Re-request a targets update when the shouldUpdateTargets state changes to true
6464
// i.e. when the editor transitions out of fullscreen/player only modes
65-
if (this.props.shouldEmitUpdates && !prevProps.shouldEmitUpdates) {
65+
if (this.props.shouldUpdateTargets && !prevProps.shouldUpdateTargets) {
6666
this.props.vm.emitTargetsUpdate(false /* Emit the event, but do not trigger project change */);
6767
}
6868
}
@@ -74,12 +74,12 @@ const vmListenerHOC = function (WrappedComponent) {
7474
}
7575
}
7676
handleProjectChanged () {
77-
if (this.props.shouldEmitUpdates && !this.props.projectChanged) {
77+
if (this.props.shouldUpdateProjectChanged && !this.props.projectChanged) {
7878
this.props.onProjectChanged();
7979
}
8080
}
8181
handleTargetsUpdate (data) {
82-
if (this.props.shouldEmitUpdates) {
82+
if (this.props.shouldUpdateTargets) {
8383
this.props.onTargetsUpdate(data);
8484
}
8585
}
@@ -118,7 +118,8 @@ const vmListenerHOC = function (WrappedComponent) {
118118
/* eslint-disable no-unused-vars */
119119
attachKeyboardEvents,
120120
projectChanged,
121-
shouldEmitUpdates,
121+
shouldUpdateTargets,
122+
shouldUpdateProjectChanged,
122123
onBlockDragUpdate,
123124
onGreenFlag,
124125
onKeyDown,
@@ -158,7 +159,8 @@ const vmListenerHOC = function (WrappedComponent) {
158159
onTurboModeOff: PropTypes.func.isRequired,
159160
onTurboModeOn: PropTypes.func.isRequired,
160161
projectChanged: PropTypes.bool,
161-
shouldEmitUpdates: PropTypes.bool,
162+
shouldUpdateTargets: PropTypes.bool,
163+
shouldUpdateProjectChanged: PropTypes.bool,
162164
username: PropTypes.string,
163165
vm: PropTypes.instanceOf(VM).isRequired
164166
};
@@ -170,8 +172,10 @@ const vmListenerHOC = function (WrappedComponent) {
170172
projectChanged: state.scratchGui.projectChanged,
171173
// Do not emit target or project updates in fullscreen or player only mode
172174
// or when recording sounds (it leads to garbled recordings on low-power machines)
173-
shouldEmitUpdates: !state.scratchGui.mode.isFullScreen && !state.scratchGui.mode.isPlayerOnly &&
175+
shouldUpdateTargets: !state.scratchGui.mode.isFullScreen && !state.scratchGui.mode.isPlayerOnly &&
174176
!state.scratchGui.modals.soundRecorder,
177+
// Do not update the projectChanged state in fullscreen or player only mode
178+
shouldUpdateProjectChanged: !state.scratchGui.mode.isFullScreen && !state.scratchGui.mode.isPlayerOnly,
175179
vm: state.scratchGui.vm,
176180
username: state.session && state.session.session && state.session.session.user ?
177181
state.session.session.user.username : ''

test/unit/util/vm-listener-hoc.test.jsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,46 @@ describe('VMListenerHOC', () => {
9191
const actions = store.getActions();
9292
expect(actions.length).toEqual(0);
9393
});
94+
95+
test('PROJECT_CHANGED does dispatch if the sound recorder is visible', () => {
96+
const Component = () => (<div />);
97+
const WrappedComponent = vmListenerHOC(Component);
98+
store = mockStore({
99+
scratchGui: {
100+
mode: {},
101+
modals: {soundRecorder: true},
102+
vm: vm
103+
}
104+
});
105+
mount(
106+
<WrappedComponent
107+
store={store}
108+
vm={vm}
109+
/>
110+
);
111+
vm.emit('PROJECT_CHANGED');
112+
const actions = store.getActions();
113+
expect(actions.length).toEqual(1);
114+
});
115+
116+
test('PROJECT_CHANGED does not dispatch if in fullscreen mode', () => {
117+
const Component = () => (<div />);
118+
const WrappedComponent = vmListenerHOC(Component);
119+
store = mockStore({
120+
scratchGui: {
121+
mode: {isFullScreen: true},
122+
modals: {soundRecorder: true},
123+
vm: vm
124+
}
125+
});
126+
mount(
127+
<WrappedComponent
128+
store={store}
129+
vm={vm}
130+
/>
131+
);
132+
vm.emit('PROJECT_CHANGED');
133+
const actions = store.getActions();
134+
expect(actions.length).toEqual(0);
135+
});
94136
});

0 commit comments

Comments
 (0)