Skip to content
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
10 changes: 8 additions & 2 deletions src/engine/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ class Runtime extends EventEmitter {
*/
this.enforcePrivacy = true;

/**
* If true, an external communication method exists and enforcePrivacy is enabled.
* Do not update this directly. Must be changed via public functions that call Runtime.updatePrivacy().
*/
this.privacyRestrictionsActive = false;

/**
* Internal map of opaque identifiers to the callback to run that function.
* @type {Map<string, function>}
Expand Down Expand Up @@ -3420,12 +3426,12 @@ class Runtime extends EventEmitter {
}

updatePrivacy () {
const enforceRestrictions = (
this.privacyRestrictionsActive = (
this.enforcePrivacy &&
Object.values(this.externalCommunicationMethods).some(i => i)
);
if (this.renderer && this.renderer.setPrivateSkinAccess) {
this.renderer.setPrivateSkinAccess(!enforceRestrictions);
this.renderer.setPrivateSkinAccess(!this.privacyRestrictionsActive);
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/extensions/scratch3_video_sensing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,10 @@ class Scratch3VideoSensingBlocks {
* @returns {number} the motion amount or direction of the stage or sprite
*/
videoOn (args, util) {
if (this.runtime.privacyRestrictionsActive) {
return -1;
}

this.detect.analyzeFrame();

let state = this.detect;
Expand All @@ -554,6 +558,10 @@ class Scratch3VideoSensingBlocks {
* reference
*/
whenMotionGreaterThan (args, util) {
if (this.runtime.privacyRestrictionsActive) {
return false;
}

this.detect.analyzeFrame();
const state = this._analyzeLocalMotion(util.target);
return state.motionAmount > Number(args.REFERENCE);
Expand Down
14 changes: 14 additions & 0 deletions test/integration/tw_privacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,17 @@ test('custom extensions', async t => {
t.equal(vm.renderer.privateSkinAccess, false);
t.end();
});

test('hasExternalCommunicationMethod', t => {
const vm = new VM();
t.equal(vm.runtime.privacyRestrictionsActive, false);
vm.runtime.setExternalCommunicationMethod('cloudVariables', true);
t.equal(vm.runtime.privacyRestrictionsActive, true);
vm.runtime.setExternalCommunicationMethod('customExtensions', true);
t.equal(vm.runtime.privacyRestrictionsActive, true);
vm.runtime.setExternalCommunicationMethod('cloudVariables', false);
t.equal(vm.runtime.privacyRestrictionsActive, true);
vm.runtime.setExternalCommunicationMethod('customExtensions', false);
t.equal(vm.runtime.privacyRestrictionsActive, false);
t.end();
});