Skip to content

Commit

Permalink
disabling mfT notification and menu item (metalbear-co#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
Razz4780 authored May 22, 2024
1 parent df49f7b commit f8acc3b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.d/120.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When the plugin detects operator usage it stops proposing mirrord for Teams to the user.
14 changes: 11 additions & 3 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -208,16 +208,23 @@ export class MirrordExecution {
env: Map<string, string>;
patchedPath: string | null;
envToUnset: undefined | string[];
usesOperator?: boolean;

constructor(env: Map<string, string>, patchedPath: string | null, envToUnset: string[]) {
constructor(env: Map<string, string>, 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"],
);
}

}
Expand Down Expand Up @@ -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"]));
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -181,6 +182,10 @@ async function main(
return null;
}

if (executionInfo.usesOperator === true) {
setOperatorUsed();
}

if (isMac) {
changeConfigForSip(config, executableFieldName as string, executionInfo);
}
Expand All @@ -191,7 +196,7 @@ async function main(

if (executionInfo.envToUnset) {
for (let key of executionInfo.envToUnset) {
delete config.env[key]
delete config.env[key];
}
}

Expand Down
13 changes: 12 additions & 1 deletion src/mirrordForTeams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<boolean>(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.'
);
Expand All @@ -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<boolean>(OPERATOR_USED) ?? false;
}
5 changes: 4 additions & 1 deletion src/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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})`);

Expand Down

0 comments on commit f8acc3b

Please sign in to comment.