<commit_before>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

import {TimeoutTimer} from 'vs/base/common/async';
import Event, {Emitter} from 'vs/base/common/event';
import {Disposable} from 'vs/base/common/lifecycle';
import * as dom from 'vs/base/browser/dom';

export enum UserStatus {
	Idle,
	Active
}

export interface IIdleMonitor {
	status: UserStatus;
	onStatusChange: Event<UserStatus>;
}

export const DEFAULT_IDLE_TIME = 60 * 60 * 1000; // 60 minutes

export class IdleMonitor extends Disposable implements IIdleMonitor {

	private _lastActiveTime: number;
	private _idleCheckTimeout: TimeoutTimer;
	private _status: UserStatus;
	private _idleTime: number;

	private _onStatusChange: Emitter<UserStatus>;
	get onStatusChange(): Event<UserStatus> { return this._onStatusChange.event; }

	constructor(idleTime: number = DEFAULT_IDLE_TIME) {
		super();

		this._status = null;
		this._idleCheckTimeout = this._register(new TimeoutTimer());
		this._lastActiveTime = -1;
		this._idleTime = idleTime;

		this._register(dom.addDisposableListener(document, 'mousemove', () => this._onUserActive()));
		this._register(dom.addDisposableListener(document, 'keydown', () => this._onUserActive()));
		this._onUserActive();
	}

	get status(): UserStatus {
		return this._status;
	}

	private _onUserActive(): void {
		this._lastActiveTime = (new Date()).getTime();

		if (this._status !== UserStatus.Active) {
			this._status = UserStatus.Active;
			this._scheduleIdleCheck();
			this._onStatusChange.fire(this._status);
		}
	}

	private _onUserIdle(): void {
		if (this._status !== UserStatus.Idle) {
			this._status = UserStatus.Idle;
			this._onStatusChange.fire(this._status);
		}
	}

	private _scheduleIdleCheck(): void {
		const minimumTimeWhenUserCanBecomeIdle = this._lastActiveTime + this._idleTime;
		const timeout = minimumTimeWhenUserCanBecomeIdle - (new Date()).getTime();<commit_msg>Revert "Revert "fix NPE on _onStatusChange""<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

import {TimeoutTimer} from 'vs/base/common/async';
import Event, {Emitter} from 'vs/base/common/event';
import {Disposable} from 'vs/base/common/lifecycle';
import * as dom from 'vs/base/browser/dom';

export enum UserStatus {
	Idle,
	Active
}

export interface IIdleMonitor {
	status: UserStatus;
	onStatusChange: Event<UserStatus>;
}

export const DEFAULT_IDLE_TIME = 60 * 60 * 1000; // 60 minutes

export class IdleMonitor extends Disposable implements IIdleMonitor {

	private _lastActiveTime: number;
	private _idleCheckTimeout: TimeoutTimer;
	private _status: UserStatus;
	private _idleTime: number;

	private _onStatusChange: Emitter<UserStatus>;
	get onStatusChange(): Event<UserStatus> { return this._onStatusChange.event; }

	constructor(idleTime: number = DEFAULT_IDLE_TIME) {
		super();

		this._status = null;
		this._idleCheckTimeout = this._register(new TimeoutTimer());
		this._lastActiveTime = -1;
		this._idleTime = idleTime;
		this._onStatusChange = new Emitter<UserStatus>();

		this._register(dom.addDisposableListener(document, 'mousemove', () => this._onUserActive()));
		this._register(dom.addDisposableListener(document, 'keydown', () => this._onUserActive()));
		this._onUserActive();
	}

	get status(): UserStatus {
		return this._status;
	}

	private _onUserActive(): void {
		this._lastActiveTime = (new Date()).getTime();

		if (this._status !== UserStatus.Active) {
			this._status = UserStatus.Active;
			this._scheduleIdleCheck();
			this._onStatusChange.fire(this._status);
		}
	}

	private _onUserIdle(): void {
		if (this._status !== UserStatus.Idle) {
			this._status = UserStatus.Idle;
			this._onStatusChange.fire(this._status);
		}
	}

	private _scheduleIdleCheck(): void {
		const minimumTimeWhenUserCanBecomeIdle = this._lastActiveTime + this._idleTime;
		const timeout = minimumTimeWhenUserCanBecomeIdle - (new Date()).getTime();
{'fraction_non_alphanumeric': 0.19397029483484815, 'fraction_numerical': 0.004876967412990468, 'mean_word_length': 3.268684957426679, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '228905', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1297, 'n_words': 303}