Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop monitoring events when no longer required #15528

Merged
merged 4 commits into from
Apr 10, 2024
Merged
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
15 changes: 11 additions & 4 deletions src/standalone/survey/dataScienceSurveyBanner.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { inject, injectable } from 'inversify';
import {
Disposable,
NotebookCellExecutionState,
NotebookCellExecutionStateChangeEvent,
UIKind,
Expand All @@ -25,6 +26,7 @@ import { isJupyterNotebook } from '../../platform/common/utils';
import { noop } from '../../platform/common/utils/misc';
import { openInBrowser } from '../../platform/common/net/browser';
import { getVSCodeChannel } from '../../platform/common/application/applicationEnvironment';
import type { IDisposable } from '@c4312/evt';

export const ISurveyBanner = Symbol('ISurveyBanner');
export interface ISurveyBanner extends IExtensionSyncActivationService, IJupyterExtensionBanner {}
Expand Down Expand Up @@ -101,7 +103,7 @@ export class DataScienceSurveyBanner implements IJupyterExtensionBanner, IExtens
private readonly showBannerState = new Map<BannerType, IPersistentState<ShowBannerWithExpiryTime>>();
private static surveyDelay = false;
private readonly NotebookExecutionThreshold = 250; // Cell executions before showing survey

private onDidChangeNotebookCellExecutionStateHandler?: IDisposable;
constructor(
@inject(IPersistentStateFactory) private persistentState: IPersistentStateFactory,
@inject(IDisposableRegistry) private disposables: IDisposableRegistry
Expand All @@ -110,16 +112,17 @@ export class DataScienceSurveyBanner implements IJupyterExtensionBanner, IExtens
this.setPersistentState(BannerType.ExperimentNotebookSurvey, ExperimentNotebookSurveyStateKeys.ShowBanner);

// Change the surveyDelay flag after 10 minutes
setTimeout(
const timer = setTimeout(
() => {
DataScienceSurveyBanner.surveyDelay = true;
},
10 * 60 * 1000
);
this.disposables.push(new Disposable(() => clearTimeout(timer)));
}

public activate() {
notebooks.onDidChangeNotebookCellExecutionState(
this.onDidChangeNotebookCellExecutionStateHandler = notebooks.onDidChangeNotebookCellExecutionState(
this.onDidChangeNotebookCellExecutionState,
this,
this.disposables
Expand All @@ -128,12 +131,12 @@ export class DataScienceSurveyBanner implements IJupyterExtensionBanner, IExtens

public async showBanner(type: BannerType): Promise<void> {
const show = this.shouldShowBanner(type);
this.onDidChangeNotebookCellExecutionStateHandler?.dispose();
if (!show) {
return;
}
// Disable for the current session.
this.disabledInCurrentSession = true;

const response = await window.showInformationMessage(this.getBannerMessage(type), ...this.bannerLabels);
switch (response) {
case this.bannerLabels[DSSurveyLabelIndex.Yes]: {
Expand Down Expand Up @@ -226,6 +229,10 @@ export class DataScienceSurveyBanner implements IJupyterExtensionBanner, IExtens
}

private async updateStateAndShowBanner(val: string, banner: BannerType) {
if (!this.shouldShowBanner(banner)) {
this.onDidChangeNotebookCellExecutionStateHandler?.dispose();
return;
}
const state = this.persistentState.createGlobalPersistentState<number>(val, 0);
await state.updateValue(state.value + 1);
this.showBanner(banner).catch(noop);
Expand Down
Loading