src/vs/workbench/services/userActivity/common/userActivityService.ts
103 LOC · 103 covered · 0 uncovered · 9 ranges · 5 concepts · 4 introducers · 5 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
userActivityRegistry.ts ×3
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { disposableTimeout, RunOnceScheduler, runWhenGlobalIdle } from '../../../../base/common/async.js';
import { Emitter, Event } from '../../../../base/common/event.js';
import { Disposable, DisposableStore, IDisposable, toDisposable } from '../../../../base/common/lifecycle.js';
import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';
import { IInstantiationService, createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
import { userActivityRegistry } from './userActivityRegistry.js';
export interface IMarkActiveOptions {
whenHeldFor?: number;
/**
* Only consider this progress if the state is already active. Used to avoid
* background work from incorrectly marking the user as active (#237386)
*/
extendOnly?: boolean;
}
/**
* Service that observes user activity in the window.
*/
export interface IUserActivityService {
_serviceBrand: undefined;
/**
* Whether the user is currently active.
*/
readonly isActive: boolean;
/**
* Fires when the activity state changes.
*/
readonly onDidChangeIsActive: Event<boolean>;
/**
* Marks the user as being active until the Disposable is disposed of.
* Multiple consumers call this method; the user will only be considered
* inactive once all consumers have disposed of their Disposables.
*/
markActive(opts?: IMarkActiveOptions): IDisposable;
}
const MARK_INACTIVE_DEBOUNCE = 10_000;
export const IUserActivityService = createDecorator<IUserActivityService>('IUserActivityService');
export class UserActivityService extends Disposable implements IUserActivityService {
declare readonly _serviceBrand: undefined;
private readonly markInactive = this._register(new RunOnceScheduler(() => {
this.changeEmitter.fire(false);
private readonly changeEmitter = this._register(new Emitter<boolean>);
private active = 0;
/**
* @inheritdoc
*
* Note: initialized to true, since the user just did something to open the
* window. The bundled DomActivityTracker will initially assume activity
* as well in order to unset this if the window gets abandoned.
*/
public isActive = true;
/** @inheritdoc */
readonly onDidChangeIsActive: Event<boolean> = this.changeEmitter.event;
constructor(@IInstantiationService instantiationService: IInstantiationService) {
super();
this._register(runWhenGlobalIdle(() => userActivityRegistry.take(this, instantiationService)));
}
/** @inheritdoc */
markActive(opts?: IMarkActiveOptions): IDisposable {
}
if (opts?.whenHeldFor) {
store.add(disposableTimeout(() => store.add(this.markActive()), opts.whenHeldFor));
return store;
}
if (++this.active === 1) {
this.isActive = true;
this.changeEmitter.fire(true);
this.markInactive.cancel();
}
return toDisposable(() => {
if (--this.active === 0) {
this.markInactive.schedule();
}
});
}
registerSingleton(IUserActivityService, UserActivityService, InstantiationType.Delayed);