in apps/vs-code-designer/src/app/commands/workflows/exportLogicApp.ts [320:444]
export async function exportLogicApp(context: IActionContext): Promise<void> {
const panelName: string = localize('export', 'Export');
const panelGroupKey = ext.webViewKey.export;
const apiVersion = '2021-03-01';
const existingPanel: vscode.WebviewPanel | undefined = tryGetWebviewPanel(panelGroupKey, panelName);
const cloudHost = await getCloudHost();
let accessToken: string;
accessToken = await getAuthorizationToken();
if (existingPanel) {
if (!existingPanel.active) {
existingPanel.reveal(vscode.ViewColumn.Active);
}
return;
}
const options: vscode.WebviewOptions & vscode.WebviewPanelOptions = {
enableScripts: true,
retainContextWhenHidden: true,
};
const panel: vscode.WebviewPanel = vscode.window.createWebviewPanel('ExportLA', `${panelName}`, vscode.ViewColumn.Active, options);
panel.iconPath = {
light: vscode.Uri.file(path.join(ext.context.extensionPath, 'assets', 'light', 'export.svg')),
dark: vscode.Uri.file(path.join(ext.context.extensionPath, 'assets', 'dark', 'export.svg')),
};
panel.webview.html = await getWebViewHTML('vs-code-react', panel);
let interval: NodeJS.Timeout;
panel.webview.onDidReceiveMessage(async (message) => {
switch (message.command) {
case ExtensionCommand.initialize: {
panel.webview.postMessage({
command: ExtensionCommand.initialize_frame,
data: {
apiVersion,
accessToken,
cloudHost,
project: ProjectName.export,
hostVersion: ext.extensionVersion,
},
});
interval = setInterval(async () => {
const updatedAccessToken = await getAuthorizationToken();
if (updatedAccessToken !== accessToken) {
accessToken = updatedAccessToken;
panel.webview.postMessage({
command: ExtensionCommand.update_access_token,
data: {
accessToken,
},
});
}
}, 5000);
break;
}
case ExtensionCommand.select_folder: {
vscode.window.showOpenDialog(exportDialogOptions).then((fileUri) => {
if (fileUri && fileUri[0]) {
panel.webview.postMessage({
command: ExtensionCommand.update_export_path,
data: {
targetDirectory: {
fsPath: fileUri[0].fsPath,
path: fileUri[0].path,
},
},
});
}
});
break;
}
case ExtensionCommand.export_package: {
const { targetDirectory, packageUrl, selectedSubscription, resourceGroupName, location } = message;
const baseGraphUri = getBaseGraphApi(cloudHost);
const engine = new ExportEngine(
() => accessToken,
packageUrl,
targetDirectory.fsPath,
selectedSubscription,
resourceGroupName,
location,
(status: string) => {
panel.webview.postMessage({
command: ExtensionCommand.add_status,
data: {
status,
},
});
},
(status: string) => {
panel.webview.postMessage({
command: ExtensionCommand.set_final_status,
data: {
status,
},
});
},
baseGraphUri,
context
);
engine.export();
break;
}
case ExtensionCommand.log_telemtry: {
ext.logTelemetry(context, message.key, message.value);
break;
}
default:
break;
}
}, ext.context.subscriptions);
panel.onDidDispose(
() => {
removeWebviewPanelFromCache(panelGroupKey, panelName);
clearInterval(interval);
},
null,
ext.context.subscriptions
);
cacheWebviewPanel(panelGroupKey, panelName, panel);
}