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

fix: bug 27332508: disable auto install dependencies for manifest-only office add-in #11234

Merged
merged 13 commits into from
May 23, 2024
Merged
6 changes: 6 additions & 0 deletions packages/fx-core/src/common/projectSettingsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export function isValidOfficeAddInProject(workspacePath?: string): boolean {
}
}

export function isManifestOnlyOfficeAddinProject(workspacePath?: string): boolean {
if (!workspacePath) return false;
const srcPath = path.join(workspacePath, "src");
return !fs.existsSync(srcPath);
}

export function fetchManifestList(
workspacePath?: string,
officeManifestType?: OfficeManifestType
Expand Down
7 changes: 6 additions & 1 deletion packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@
{
"command": "fx-extension.localdebug",
"title": "%teamstoolkit.commands.localDebug.title%",
"enablement": "!fx-extension.commandLocked",
"enablement": "!fx-extension.commandLocked && !fx-extension.isOfficeAddIn || fx-extension.isOfficeAddIn && !fx-extension.isManifestOnlyOfficeAddIn",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the command can only be enabled when command unlocked

"category": "Teams"
},
{
Expand Down Expand Up @@ -888,6 +888,11 @@
"title": "%teamstoolkit.commands.feedbackLink.title%",
"icon": "$(info)"
},
{
"command": "fx-extension.stopDebugging",
"title": "%teamstoolkit.commandsTreeViewProvider.officeAddIn.stopDebugTitle%",
"enablement": "fx-extension.isOfficeAddIn && !fx-extension.isManifestOnlyOfficeAddIn"
},
{
"command": "fx-extension.invokeChat",
"title": "%teamstoolkit.commandsTreeViewProvider.getCopilotHelpTitle%",
Expand Down
8 changes: 8 additions & 0 deletions packages/vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ import {
isOfficeAddInProject,
isSPFxProject,
isTeamsFxProject,
isOfficeAddInProject,
isOfficeManifestOnlyProject,
setUriEventHandler,
unsetIsTeamsFxProject,
workspaceUri,
Expand Down Expand Up @@ -147,6 +149,12 @@ export async function activate(context: vscode.ExtensionContext) {
isOfficeAddInProject
);

await vscode.commands.executeCommand(
"setContext",
"fx-extension.isManifestOnlyOfficeAddIn",
isOfficeManifestOnlyProject
);

void VsCodeLogInstance.info("Teams Toolkit extension is now active!");

// Don't wait this async method to let it run in background.
Expand Down
10 changes: 9 additions & 1 deletion packages/vscode-extension/src/globalVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import * as path from "path";
import * as vscode from "vscode";
import { UserState } from "./constants";
import { UriHandler } from "./uriHandler";
import { isValidProject, isValidOfficeAddInProject } from "@microsoft/teamsfx-core";
import {
isValidProject,
isValidOfficeAddInProject,
isManifestOnlyOfficeAddinProject,
} from "@microsoft/teamsfx-core";

/**
* Common variables used throughout the extension. They must be initialized in the activate() method of extension.ts
Expand All @@ -15,6 +19,7 @@ export let context: vscode.ExtensionContext;
export let workspaceUri: vscode.Uri | undefined;
export let isTeamsFxProject = false;
export let isOfficeAddInProject = false;
export let isOfficeManifestOnlyProject = false;
export let isSPFxProject = false;
export let isExistingUser = "no";
export let uriEventHandler: UriHandler;
Expand All @@ -32,6 +37,9 @@ export function initializeGlobalVariables(ctx: vscode.ExtensionContext): void {
isExistingUser = context.globalState.get<string>(UserState.IsExisting) || "no";
isTeamsFxProject = isValidProject(workspaceUri?.fsPath);
isOfficeAddInProject = isValidOfficeAddInProject(workspaceUri?.fsPath);
if (isOfficeAddInProject) {
isOfficeManifestOnlyProject = isManifestOnlyOfficeAddinProject(workspaceUri?.fsPath);
}
// Default Extension log path
// e.g. C:/Users/xx/AppData/Roaming/Code/logs/20230221T095340/window7/exthost/TeamsDevApp.ms-teams-vscode-extension
defaultExtensionLogPath = ctx.logUri.fsPath;
Expand Down
12 changes: 9 additions & 3 deletions packages/vscode-extension/src/officeDevHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"use strict";

import { FxError, Result, Warning, ok } from "@microsoft/teamsfx-api";
import { globalStateGet, globalStateUpdate } from "@microsoft/teamsfx-core";
import {
globalStateGet,
globalStateUpdate,
isManifestOnlyOfficeAddinProject,
} from "@microsoft/teamsfx-core";
import * as fs from "fs-extra";
import * as path from "path";
import * as vscode from "vscode";
Expand Down Expand Up @@ -248,12 +252,14 @@ export async function autoOpenOfficeDevProjectHandler(): Promise<void> {
await globalStateUpdate(GlobalKey.OpenSampleReadMe, false);
}
if (autoInstallDependency) {
void popupOfficeAddInDependenciesMessage();
if (!isManifestOnlyOfficeAddinProject(globalVariables.workspaceUri?.fsPath ?? ""))
void popupOfficeAddInDependenciesMessage();
await globalStateUpdate(GlobalKey.AutoInstallDependency, false);
}
if (
globalVariables.isOfficeAddInProject &&
!checkOfficeAddInInstalled(globalVariables.workspaceUri?.fsPath ?? "")
!checkOfficeAddInInstalled(globalVariables.workspaceUri?.fsPath ?? "") &&
!isManifestOnlyOfficeAddinProject(globalVariables.workspaceUri?.fsPath ?? "")
) {
void popupOfficeAddInDependenciesMessage();
}
Expand Down