Skip to content

Commit

Permalink
BDE-226 added development mode feature flags for 'studio-package-name…
Browse files Browse the repository at this point in the history
…' at first
  • Loading branch information
nxmatic committed Mar 26, 2024
1 parent 222294b commit 8c38f66
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
20 changes: 18 additions & 2 deletions src/main/runtime-build-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
};
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
});
};

Expand Down
8 changes: 8 additions & 0 deletions src/popup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down

0 comments on commit 8c38f66

Please sign in to comment.