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

Add missing vscode api in env namespace #11446

Merged
merged 3 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ export class WorkerEnvExtImpl extends EnvExtImpl {
throw new Error('There is no app root in worker context');
}

get isNewAppInstall(): boolean {
throw new Error('Cannot determine the installation date in worker context');
vince-fugnitto marked this conversation as resolved.
Show resolved Hide resolved
}

}
28 changes: 28 additions & 0 deletions packages/plugin-ext/src/plugin/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { RPCProtocol } from '../common/rpc-protocol';
import { EnvMain, PLUGIN_RPC_CONTEXT } from '../common/plugin-api-rpc';
import { QueryParameters } from '../common/env';
import { v4 } from 'uuid';
import { Emitter, Event } from '@theia/core/lib/common/event';

export abstract class EnvExtImpl {
private proxy: EnvMain;
Expand All @@ -29,11 +30,20 @@ export abstract class EnvExtImpl {
private ui: theia.UIKind;
private envMachineId: string;
private envSessionId: string;
private host: string;
private _isTelemetryEnabled: boolean;
private _remoteName: string | undefined;
private onDidChangeTelemetryEnabledEmitter: Emitter<boolean>;

constructor(rpc: RPCProtocol) {
this.proxy = rpc.getProxy(PLUGIN_RPC_CONTEXT.ENV_MAIN);
this.envSessionId = v4();
this.envMachineId = v4();
this.host = 'desktop';
msujew marked this conversation as resolved.
Show resolved Hide resolved
// we don't support telemetry at the moment
this._isTelemetryEnabled = false;
this._remoteName = undefined;
this.onDidChangeTelemetryEnabledEmitter = new Emitter();
}

getEnvVariable(envVarName: string): Promise<string | undefined> {
Expand Down Expand Up @@ -83,6 +93,24 @@ export abstract class EnvExtImpl {

abstract get appRoot(): string;

abstract get isNewAppInstall(): boolean;

get appHost(): string {
return this.host;
}

get isTelemetryEnabled(): boolean {
return this._isTelemetryEnabled;
}

get onDidChangeTelemetryEnabled(): Event<boolean> {
return this.onDidChangeTelemetryEnabledEmitter.event;
}

get remoteName(): string | undefined {
return this._remoteName;
}

get language(): string {
return this.lang;
}
Expand Down
13 changes: 13 additions & 0 deletions packages/plugin-ext/src/plugin/node/env-node-ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { EnvExtImpl } from '../env';
import { RPCProtocol } from '../../common/rpc-protocol';
import { createHash } from 'crypto';
import { v4 } from 'uuid';
import fs = require('fs');

/**
* Provides machineId using mac address. It's only possible on node side
Expand All @@ -27,6 +28,7 @@ import { v4 } from 'uuid';
export class EnvNodeExtImpl extends EnvExtImpl {

private macMachineId: string;
private _isNewAppInstall: boolean;

constructor(rpc: RPCProtocol) {
super(rpc);
Expand All @@ -37,7 +39,14 @@ export class EnvNodeExtImpl extends EnvExtImpl {
this.macMachineId = createHash('sha256').update(macAddress, 'utf8').digest('hex');
}
});
this._isNewAppInstall = this.computeIsNewAppInstall();
}

private computeIsNewAppInstall(): boolean {
const creation = fs.statSync(__filename).birthtimeMs;
const current = Date.now();
const dayMs = 24 * 3600 * 1000;
return (current - creation) < dayMs;
}

/**
Expand All @@ -54,4 +63,8 @@ export class EnvNodeExtImpl extends EnvExtImpl {
return __dirname;
}

get isNewAppInstall(): boolean {
return this._isNewAppInstall;
}

}
7 changes: 7 additions & 0 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,14 @@ export function createAPIFactory(
const env: typeof theia.env = Object.freeze({
get appName(): string { return envExt.appName; },
get appRoot(): string { return envExt.appRoot; },
get appHost(): string { return envExt.appHost; },
get language(): string { return envExt.language; },
get isNewAppInstall(): boolean { return envExt.isNewAppInstall; },
get isTelemetryEnabled(): boolean { return envExt.isTelemetryEnabled; },
get onDidChangeTelemetryEnabled(): theia.Event<boolean> {
return envExt.onDidChangeTelemetryEnabled;
},
get remoteName(): string | undefined { return envExt.remoteName; },
get machineId(): string { return envExt.machineId; },
get sessionId(): string { return envExt.sessionId; },
get uriScheme(): string { return envExt.uriScheme; },
Expand Down
37 changes: 37 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6473,6 +6473,14 @@ export module '@theia/plugin' {
*/
export const appRoot: string;

/**
* The hosted location of the application
* On desktop this is 'desktop'
* In the web this is the specified embedder i.e. 'github.dev', 'codespaces', or 'web' if the embedder
* does not provide that information
*/
export const appHost: string;

/**
* The custom uri scheme the editor registers to in the operating system.
*/
Expand All @@ -6483,6 +6491,35 @@ export module '@theia/plugin' {
*/
export const language: string;

/**
* Indicates that this is a fresh install of the application.
* `true` if within the first day of installation otherwise `false`.
*/
export const isNewAppInstall: boolean;

/**
* Indicates whether the users has telemetry enabled.
* Can be observed to determine if the extension should send telemetry.
*/
export const isTelemetryEnabled: boolean;

/**
* An {@link Event} which fires when the user enabled or disables telemetry.
* `true` if the user has enabled telemetry or `false` if the user has disabled telemetry.
*/
export const onDidChangeTelemetryEnabled: Event<boolean>;

/**
* The name of a remote. Defined by extensions, popular samples are `wsl` for the Windows
* Subsystem for Linux or `ssh-remote` for remotes using a secure shell.
*
* *Note* that the value is `undefined` when there is no remote extension host but that the
* value is defined in all extension hosts (local and remote) in case a remote extension host
* exists. Use {@link Extension.extensionKind} to know if
* a specific extension runs remote or not.
*/
export const remoteName: string | undefined;

/**
* The detected default shell for the extension host.
*/
Expand Down