Skip to content

Commit

Permalink
Refactor OrgChangeNotifier and Copilot Notification (#1044)
Browse files Browse the repository at this point in the history
* Refactor OrgChangeNotifier and Copilot Notification

* Refactor OrgChangeNotifier and Copilot Notification

* Refactor extension.ts and remove unnecessary lines

---------

Co-authored-by: amitjoshi <[email protected]>
  • Loading branch information
amitjoshi438 and amitjoshi authored Oct 3, 2024
1 parent 87a43b3 commit 8f1e2c1
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ export async function activate(
_context.subscriptions.push(cli);
_context.subscriptions.push(pacTerminal);

let copilotNotificationShown = false;

const workspaceFolders =
vscode.workspace.workspaceFolders?.map(
(fl) => ({ ...fl, uri: fl.uri.fsPath } as WorkspaceFolder)
) || [];


_context.subscriptions.push(
orgChangeEvent(async (orgDetails: ActiveOrgOutput) => {
const orgID = orgDetails.OrgId;
Expand Down Expand Up @@ -221,28 +229,32 @@ export async function activate(
}
oneDSLoggerWrapper.getLogger().traceInfo(desktopTelemetryEventNames.DESKTOP_EXTENSION_INIT_CONTEXT, initContext);
}

if (!copilotNotificationShown) {
let telemetryData = '';
let listOfActivePortals = [];
try {
listOfActivePortals = getPortalsOrgURLs(workspaceFolders, _telemetry);
telemetryData = JSON.stringify(listOfActivePortals);
_telemetry.sendTelemetryEvent("VscodeDesktopUsage", { listOfActivePortals: telemetryData, countOfActivePortals: listOfActivePortals.length.toString() });
oneDSLoggerWrapper.getLogger().traceInfo("VscodeDesktopUsage", { listOfActivePortals: telemetryData, countOfActivePortals: listOfActivePortals.length.toString() });
} catch (exception) {
const exceptionError = exception as Error;
_telemetry.sendTelemetryException(exceptionError, { eventName: 'VscodeDesktopUsage' });
oneDSLoggerWrapper.getLogger().traceError(exceptionError.name, exceptionError.message, exceptionError, { eventName: 'VscodeDesktopUsage' });
}

// Show Copilot notification after ECS initialization and workspace check
showNotificationForCopilot(_telemetry, telemetryData, listOfActivePortals.length.toString());
copilotNotificationShown = true;

}

})
);


const workspaceFolders =
vscode.workspace.workspaceFolders?.map(
(fl) => ({ ...fl, uri: fl.uri.fsPath } as WorkspaceFolder)
) || [];
// TODO: Handle for VSCode.dev also
if (workspaceContainsPortalConfigFolder(workspaceFolders)) {
let telemetryData = '';
let listOfActivePortals = [];
try {
listOfActivePortals = getPortalsOrgURLs(workspaceFolders, _telemetry);
telemetryData = JSON.stringify(listOfActivePortals);
_telemetry.sendTelemetryEvent("VscodeDesktopUsage", { listOfActivePortals: telemetryData, countOfActivePortals: listOfActivePortals.length.toString() });
oneDSLoggerWrapper.getLogger().traceInfo("VscodeDesktopUsage", { listOfActivePortals: telemetryData, countOfActivePortals: listOfActivePortals.length.toString() });
} catch (exception) {
const exceptionError = exception as Error;
_telemetry.sendTelemetryException(exceptionError, { eventName: 'VscodeDesktopUsage' });
oneDSLoggerWrapper.getLogger().traceError(exceptionError.name, exceptionError.message, exceptionError, { eventName: 'VscodeDesktopUsage' });
}

// Init OrgChangeNotifier instance
OrgChangeNotifier.createOrgChangeNotifierInstance(pacTerminal.getWrapper());

Expand All @@ -253,7 +265,6 @@ export async function activate(
oneDSLoggerWrapper.getLogger().traceInfo("PowerPagesWebsiteYmlExists");
vscode.commands.executeCommand('setContext', 'powerpages.websiteYmlExists', true);
initializeGenerator(_context, cliContext, _telemetry); // Showing the create command only if website.yml exists
showNotificationForCopilot(_telemetry, telemetryData, listOfActivePortals.length.toString());
}
else {
vscode.commands.executeCommand('setContext', 'powerpages.websiteYmlExists', false);
Expand Down

0 comments on commit 8f1e2c1

Please sign in to comment.