From 85299e157b6fe06d5f760cd957a45542ccabb8e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Smolarek?= <34063647+Razz4780@users.noreply.github.com> Date: Tue, 21 May 2024 17:09:22 +0200 Subject: [PATCH] disabling mfT notification and menu item (#127) --- changelog.d/120.fixed.md | 1 + src/api.ts | 14 +++++++++++--- src/debugger.ts | 7 ++++++- src/mirrordForTeams.ts | 13 ++++++++++++- src/status.ts | 5 ++++- 5 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 changelog.d/120.fixed.md diff --git a/changelog.d/120.fixed.md b/changelog.d/120.fixed.md new file mode 100644 index 00000000..6ac8a186 --- /dev/null +++ b/changelog.d/120.fixed.md @@ -0,0 +1 @@ +When the plugin detects operator usage it stops proposing mirrord for Teams to the user. diff --git a/src/api.ts b/src/api.ts index c8d1be8b..007eb408 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,7 +1,7 @@ import * as vscode from 'vscode'; import { ChildProcessWithoutNullStreams, spawn } from 'child_process'; import { globalContext } from './extension'; -import { tickMirrordForTeamsCounter } from './mirrordForTeams'; +import { setOperatorUsed, tickMirrordForTeamsCounter } from './mirrordForTeams'; import { NotificationBuilder } from './notification'; import { MirrordStatus } from './status'; import { EnvVars, VerifiedConfig } from './config'; @@ -208,16 +208,23 @@ export class MirrordExecution { env: Map; patchedPath: string | null; envToUnset: undefined | string[]; + usesOperator?: boolean; - constructor(env: Map, patchedPath: string | null, envToUnset: string[]) { + constructor(env: Map, patchedPath: string | null, envToUnset: string[], usesOperator: boolean | undefined) { this.env = env; this.patchedPath = patchedPath; this.envToUnset = envToUnset; + this.usesOperator = usesOperator; } static mirrordExecutionFromJson(data: string): MirrordExecution { const parsed = JSON.parse(data); - return new MirrordExecution(new Map(Object.entries(parsed["environment"])), parsed["patched_path"], parsed["env_to_unset"]); + return new MirrordExecution( + new Map(Object.entries(parsed["environment"])), + parsed["patched_path"], + parsed["env_to_unset"], + parsed["uses_operator"], + ); } } @@ -464,6 +471,7 @@ export class MirrordAPI { if ((message["name"] === "mirrord preparing to launch") && (message["type"]) === "FinishedTask") { if (message["success"]) { progress.report({ message: "mirrord started successfully, launching target." }); + return resolve(MirrordExecution.mirrordExecutionFromJson(message["message"])); } } diff --git a/src/debugger.ts b/src/debugger.ts index 1a65c7ef..27ada1fc 100644 --- a/src/debugger.ts +++ b/src/debugger.ts @@ -6,6 +6,7 @@ import { updateTelemetries } from './versionCheck'; import { getMirrordBinary } from './binaryManager'; import { platform } from 'node:os'; import { NotificationBuilder } from './notification'; +import { setOperatorUsed } from './mirrordForTeams'; const DYLD_ENV_VAR_NAME = "DYLD_INSERT_LIBRARIES"; @@ -181,6 +182,10 @@ async function main( return null; } + if (executionInfo.usesOperator === true) { + setOperatorUsed(); + } + if (isMac) { changeConfigForSip(config, executableFieldName as string, executionInfo); } @@ -191,7 +196,7 @@ async function main( if (executionInfo.envToUnset) { for (let key of executionInfo.envToUnset) { - delete config.env[key] + delete config.env[key]; } } diff --git a/src/mirrordForTeams.ts b/src/mirrordForTeams.ts index e6e5ff28..79a5cfc8 100644 --- a/src/mirrordForTeams.ts +++ b/src/mirrordForTeams.ts @@ -7,6 +7,8 @@ const RUN_COUNTER = 'mirrord-for-teams-counter'; const NOTIFICATION_STARTS_AT = 100; const NOTIFICATION_REPEATS_EVERY = 30; +const OPERATOR_USED = 'mirrord-operator-used'; + async function showMirrordForTeamsNotification(message: string) { new NotificationBuilder() .withMessage(message) @@ -19,9 +21,10 @@ async function showMirrordForTeamsNotification(message: string) { export function tickMirrordForTeamsCounter() { const counter = parseInt(globalContext.globalState.get(RUN_COUNTER) ?? '0') || 0; + const operatorUsed = globalContext.globalState.get(OPERATOR_USED) ?? false; if (counter >= NOTIFICATION_STARTS_AT) { - if (counter === NOTIFICATION_STARTS_AT || (counter - NOTIFICATION_STARTS_AT) % NOTIFICATION_REPEATS_EVERY === 0) { + if (((counter - NOTIFICATION_STARTS_AT) % NOTIFICATION_REPEATS_EVERY === 0) && !operatorUsed) { showMirrordForTeamsNotification( 'For more features of mirrord, including multi-pod impersonation, check out mirrord for Teams.' ); @@ -30,3 +33,11 @@ export function tickMirrordForTeamsCounter() { globalContext.globalState.update(RUN_COUNTER, `${counter + 1}`); } + +export function setOperatorUsed() { + globalContext.globalState.update(OPERATOR_USED, true); +} + +export function getOperatorUsed(): boolean { + return globalContext.globalState.get(OPERATOR_USED) ?? false; +} diff --git a/src/status.ts b/src/status.ts index 77d8432f..eef360b0 100644 --- a/src/status.ts +++ b/src/status.ts @@ -2,6 +2,7 @@ import * as vscode from 'vscode'; import { MirrordConfigManager } from './config'; import { globalContext } from './extension'; import { NotificationBuilder } from './notification'; +import { getOperatorUsed } from './mirrordForTeams'; export class MirrordStatus { readonly statusBar: vscode.StatusBarItem; @@ -39,7 +40,9 @@ export class MirrordStatus { } statusBar.tooltip.appendMarkdown(`\n\n[Select active config](command:${MirrordStatus.selectActiveConfigId})`); statusBar.tooltip.appendMarkdown(`\n\n[Settings](command:${MirrordStatus.settingsCommandId})`); - statusBar.tooltip.appendMarkdown(`\n\n[mirrord for Teams](command:${MirrordStatus.mirrordForTeamsCommandId})`); + if (!getOperatorUsed()) { + statusBar.tooltip.appendMarkdown(`\n\n[mirrord for Teams](command:${MirrordStatus.mirrordForTeamsCommandId})`); + } statusBar.tooltip.appendMarkdown(`\n\n[Get help on Discord](command:${MirrordStatus.joinDiscordCommandId})`); statusBar.tooltip.appendMarkdown(`\n\n[Walkthrough](command:${MirrordStatus.helpCommandId})`);