File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed
extensions/scratch3_video_sensing Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -505,6 +505,12 @@ class Runtime extends EventEmitter {
505505 */
506506 this . enforcePrivacy = true ;
507507
508+ /**
509+ * If true, an external communication method exists and enforcePrivacy is enabled.
510+ * Do not update this directly. Must be changed via public functions that call Runtime.updatePrivacy().
511+ */
512+ this . privacyRestrictionsActive = false ;
513+
508514 /**
509515 * Internal map of opaque identifiers to the callback to run that function.
510516 * @type {Map<string, function> }
@@ -3420,12 +3426,12 @@ class Runtime extends EventEmitter {
34203426 }
34213427
34223428 updatePrivacy ( ) {
3423- const enforceRestrictions = (
3429+ this . privacyRestrictionsActive = (
34243430 this . enforcePrivacy &&
34253431 Object . values ( this . externalCommunicationMethods ) . some ( i => i )
34263432 ) ;
34273433 if ( this . renderer && this . renderer . setPrivateSkinAccess ) {
3428- this . renderer . setPrivateSkinAccess ( ! enforceRestrictions ) ;
3434+ this . renderer . setPrivateSkinAccess ( ! this . privacyRestrictionsActive ) ;
34293435 }
34303436 }
34313437
Original file line number Diff line number Diff line change @@ -531,6 +531,10 @@ class Scratch3VideoSensingBlocks {
531531 * @returns {number } the motion amount or direction of the stage or sprite
532532 */
533533 videoOn ( args , util ) {
534+ if ( this . runtime . privacyRestrictionsActive ) {
535+ return - 1 ;
536+ }
537+
534538 this . detect . analyzeFrame ( ) ;
535539
536540 let state = this . detect ;
@@ -554,6 +558,10 @@ class Scratch3VideoSensingBlocks {
554558 * reference
555559 */
556560 whenMotionGreaterThan ( args , util ) {
561+ if ( this . runtime . privacyRestrictionsActive ) {
562+ return false ;
563+ }
564+
557565 this . detect . analyzeFrame ( ) ;
558566 const state = this . _analyzeLocalMotion ( util . target ) ;
559567 return state . motionAmount > Number ( args . REFERENCE ) ;
Original file line number Diff line number Diff line change @@ -114,3 +114,17 @@ test('custom extensions', async t => {
114114 t . equal ( vm . renderer . privateSkinAccess , false ) ;
115115 t . end ( ) ;
116116} ) ;
117+
118+ test ( 'hasExternalCommunicationMethod' , t => {
119+ const vm = new VM ( ) ;
120+ t . equal ( vm . runtime . privacyRestrictionsActive , false ) ;
121+ vm . runtime . setExternalCommunicationMethod ( 'cloudVariables' , true ) ;
122+ t . equal ( vm . runtime . privacyRestrictionsActive , true ) ;
123+ vm . runtime . setExternalCommunicationMethod ( 'customExtensions' , true ) ;
124+ t . equal ( vm . runtime . privacyRestrictionsActive , true ) ;
125+ vm . runtime . setExternalCommunicationMethod ( 'cloudVariables' , false ) ;
126+ t . equal ( vm . runtime . privacyRestrictionsActive , true ) ;
127+ vm . runtime . setExternalCommunicationMethod ( 'customExtensions' , false ) ;
128+ t . equal ( vm . runtime . privacyRestrictionsActive , false ) ;
129+ t . end ( ) ;
130+ } ) ;
You can’t perform that action at this time.
0 commit comments