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.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filesrc/vs/workbench/services/userActivity/common/userActivityRegistry.ts · 23 LOCcommon/userActivityRegis…userActivityService.test|title=UserActivityService markActive sets active whenHeldFor|occurrence=1 · 0 introduced LOCuserActivityService.test…userActivityService.ts ×1 · 4 introduced LOCuserActivityService.ts ×…userActivityService.ts ×1 · 2 introduced LOCuserActivityService.ts ×…userActivityService.ts ×4 · 22 introduced LOCuserActivityService.ts ×…userActivityRegistry.ts ×3 · 96 introduced LOCuserActivityRegistry.ts …userActivityService.test|title=UserActivityService isActive should be true initially|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/services/userActivity/test/common/userActivityService.test|title=UserActivityService isActive should be true initially|occurrence=1userActivityService.test…userActivityService.test|title=UserActivityService markActive sets active whenHeldFor|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/services/userActivity/test/common/userActivityService.test|title=UserActivityService markActive sets active whenHeldFor|occurrence=1userActivityService.test…userActivityService.test|title=UserActivityService markActive should be inactive when all handles gone|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/services/userActivity/test/common/userActivityService.test|title=UserActivityService markActive should be inactive when all handles gone|occurrence=1userActivityService.test…userActivityService.test|title=UserActivityService markActive whenHeldFor before triggers|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/services/userActivity/test/common/userActivityService.test|title=UserActivityService markActive whenHeldFor before triggers|occurrence=1userActivityService.test…userActivityService.test|title=UserActivityService markActive with extendOnly only extends if already active|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/workbench/services/userActivity/test/common/userActivityService.test|title=UserActivityService markActive with extendOnly only extends if already active|occurrence=1userActivityService.test…Focused file · src/vs/workbench/services/userActivity/common/userActivityService.ts · 103 LOCcommon/userActivityServi…

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.

1 > /*--------------------------------------------------------------------------------------------- userActivityRegistry.ts ×3
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { disposableTimeout, RunOnceScheduler, runWhenGlobalIdle } from '../../../../base/common/async.js';
7 > import { Emitter, Event } from '../../../../base/common/event.js';
8 > import { Disposable, DisposableStore, IDisposable, toDisposable } from '../../../../base/common/lifecycle.js';
9 > import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';
10 > import { IInstantiationService, createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
11 > import { userActivityRegistry } from './userActivityRegistry.js';
12 >
13 > export interface IMarkActiveOptions {
14 > whenHeldFor?: number;
15 > /**
16 > * Only consider this progress if the state is already active. Used to avoid
17 > * background work from incorrectly marking the user as active (#237386)
18 > */
19 > extendOnly?: boolean;
20 > }
21 >
22 > /**
23 > * Service that observes user activity in the window.
24 > */
25 > export interface IUserActivityService {
26 > _serviceBrand: undefined;
27 >
28 > /**
29 > * Whether the user is currently active.
30 > */
31 > readonly isActive: boolean;
32 >
33 > /**
34 > * Fires when the activity state changes.
35 > */
36 > readonly onDidChangeIsActive: Event<boolean>;
37 >
38 > /**
39 > * Marks the user as being active until the Disposable is disposed of.
40 > * Multiple consumers call this method; the user will only be considered
41 > * inactive once all consumers have disposed of their Disposables.
42 > */
43 > markActive(opts?: IMarkActiveOptions): IDisposable;
44 > }
45 >
46 > const MARK_INACTIVE_DEBOUNCE = 10_000;
47 >
48 > export const IUserActivityService = createDecorator<IUserActivityService>('IUserActivityService');
49 >
50 > export class UserActivityService extends Disposable implements IUserActivityService {
51 > declare readonly _serviceBrand: undefined;
52 > private readonly markInactive = this._register(new RunOnceScheduler(() => {
53 > this.isActive = false; userActivityService.ts ×4
54 > this.changeEmitter.fire(false);
55 > }, MARK_INACTIVE_DEBOUNCE)); userActivityRegistry.ts ×3
56 >
57 > private readonly changeEmitter = this._register(new Emitter<boolean>);
58 > private active = 0;
59 >
60 > /**
61 > * @inheritdoc
62 > *
63 > * Note: initialized to true, since the user just did something to open the
64 > * window. The bundled DomActivityTracker will initially assume activity
65 > * as well in order to unset this if the window gets abandoned.
66 > */
67 > public isActive = true;
68 >
69 > /** @inheritdoc */
70 > readonly onDidChangeIsActive: Event<boolean> = this.changeEmitter.event;
71 >
72 > constructor(@IInstantiationService instantiationService: IInstantiationService) {
73 > super();
74 > this._register(runWhenGlobalIdle(() => userActivityRegistry.take(this, instantiationService)));
75 > }
76 >
77 > /** @inheritdoc */
78 > markActive(opts?: IMarkActiveOptions): IDisposable {
79 > if (opts?.extendOnly && !this.isActive) { userActivityService.ts ×4
80 > return Disposable.None; userActivityService.ts ×1
81 > }
83 > if (opts?.whenHeldFor) {
84 > const store = new DisposableStore(); userActivityService.ts ×1
85 > store.add(disposableTimeout(() => store.add(this.markActive()), opts.whenHeldFor));
86 > return store;
87 > }
89 > if (++this.active === 1) {
90 > this.isActive = true;
91 > this.changeEmitter.fire(true);
92 > this.markInactive.cancel();
93 > }
94 >
95 > return toDisposable(() => {
96 > if (--this.active === 0) {
97 > this.markInactive.schedule();
98 > }
99 > });
100 > }
102 >
103 > registerSingleton(IUserActivityService, UserActivityService, InstantiationType.Delayed);