From 8c38f66821db51dd125bc538db26bf7ea854f7ce Mon Sep 17 00:00:00 2001 From: "Stephane Lacoin (aka nxmatic)" Date: Tue, 26 Mar 2024 09:04:30 +0100 Subject: [PATCH] BDE-226 added development mode feature flags for 'studio-package-name' at first --- src/main/runtime-build-info.js | 20 ++++++++++++++++++-- src/main/service-worker.js | 6 +++--- src/popup/index.js | 8 ++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/main/runtime-build-info.js b/src/main/runtime-build-info.js index 06a3cc9e..d3da98df 100644 --- a/src/main/runtime-build-info.js +++ b/src/main/runtime-build-info.js @@ -39,6 +39,7 @@ class DevelopmentMode extends ServiceWorkerComponent { constructor(worker, isEnabled) { super(worker); this._isEnabled = isEnabled; + this._featureFlags = {}; // bind this methods Object.getOwnPropertyNames(Object.getPrototypeOf(this)) @@ -59,13 +60,28 @@ class DevelopmentMode extends ServiceWorkerComponent { this._isEnabled = !this._isEnabled; } + setFeatureFlag(flag, value) { + this._featureFlags[flag] = value; + } + + isFeatureFlagSet(flag) { + if (!this._featureFlags[flag]) { + return false; + } + return this._featureFlags[flag]; + } + + toggleFeatureFlag(flag) { + this._featureFlags[flag] = !this._featureFlags[flag]; + } + asConsole() { - return this.asPromise(); + return this.asPromise() .then(() => console) .catch(() => { const noop = () => {}; return { - log: noop, error: noop, warn: noop, info: noop, + log: noop, error: noop, warn: noop, info: noop }; }); } diff --git a/src/main/service-worker.js b/src/main/service-worker.js index c28b856d..004e5a07 100644 --- a/src/main/service-worker.js +++ b/src/main/service-worker.js @@ -57,7 +57,8 @@ class ServiceWorkerMessageHandler extends ServiceWorkerComponent { .asConsole() .then((console) => console .log(`ServiceWorkerMessageHandler.handle(${JSON.stringify(request)}) called`)); - return component[request.action](...request.params) + return component.asPromise() + .then((componentInstance) => componentInstance[request.action](...request.params)) .then((response) => this.worker.developmentMode .asConsole() .then((console) => console @@ -69,8 +70,7 @@ class ServiceWorkerMessageHandler extends ServiceWorkerComponent { .asConsole() .then((console) => console .log(`${JSON.stringify(response)} <- ServiceWorkerMessageHandler.handle(${JSON.stringify(request)})`, cause.stack)); - return Promise - .resolve(response); + return response; }); }; diff --git a/src/popup/index.js b/src/popup/index.js index c37123f0..10143668 100644 --- a/src/popup/index.js +++ b/src/popup/index.js @@ -213,6 +213,14 @@ function loadPage(worker) { // reset jQuery event handlers $('body').find('*').addBack().off(); + // update the page according to the feature flags + pendingPromises.push(worker.developmentMode + .isFeatureFlagSet('studio-package-name') + .then((isEnabled) => { + if (isEnabled) return; + $('#studio-package-name-input').remove(); + })); + // process the page const browserVendor = worker.buildInfo.browserVendor(); if (browserVendor === 'Firefox') {