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

Open the specific version directory and manifest.json (or other specified file) when version is downloaded #47

Merged
merged 13 commits into from
Jun 10, 2024
6 changes: 6 additions & 0 deletions media/commentIcons/link.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions media/commentIcons/link_inverse.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 40 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"Other"
],
"activationEvents": [
"onUri"
"onUri",
"onStartupFinished"
],
"main": "./dist/extension.js",
"contributes": {
Expand All @@ -36,38 +37,50 @@
"menus": {
"explorer/context": [
{
"when": "explorerResourceIsFolder && listDoubleSelection",

"command": "assay.openInDiffTool",
"group": "navigation"
"group": "navigation",
"when": "assay.commentsEnabled && explorerResourceIsFolder && listDoubleSelection"
},
{
"when": "explorerResourceIsFolder",

"command": "assay.exportCommentsFromContext",
"group": "navigation"
"group": "navigation",
"when": "assay.commentsEnabled && explorerResourceIsFolder"
}
],
"comments/commentThread/title": [
{
"command": "assay.exportComments",
"group": "inline@1",
"when": "!commentThreadIsEmpty"
"when": "assay.commentsEnabled && !commentThreadIsEmpty"
},
{
"command": "assay.editComment",
"group": "inline@2",
"when": "commentController == assay-comments && !commentThreadIsEmpty"
"when": "assay.commentsEnabled && commentController == assay-comments && !commentThreadIsEmpty"
},
{
"command": "assay.copyLinkFromThread",
"group": "inline@3",
"when": "assay.commentsEnabled && !commentThreadIsEmpty"
},
{
"command": "assay.deleteComment",
"group": "inline@3",
"when": "commentController == assay-comments && !commentThreadIsEmpty"
"group": "inline@5",
"when": "assay.commentsEnabled && commentController == assay-comments && !commentThreadIsEmpty"
}
],
"comments/commentThread/context": [
{
{
"command": "assay.addComment",
"group": "inline",
"when": "commentController == assay-comments && commentThreadIsEmpty"
"group": "inline@1",
"when": "assay.commentsEnabled && commentController == assay-comments && commentThreadIsEmpty"
},
{
"command": "assay.copyLinkFromReply",
"group": "inline@2",
"when": "assay.commentsEnabled && commentController == assay-comments && commentThreadIsEmpty"
}
],
"comments/comment/title": [
Expand All @@ -77,12 +90,12 @@
{
"command": "assay.cancelSaveComment",
"group": "inline@3",
"when": "commentController == assay-comments"
"when": "assay.commentsEnabled && commentController == assay-comments"
},
{
"command": "assay.saveComment",
"group": "inline@2",
"when": "commentController == assay-comments"
"when": "assay.commentsEnabled && commentController == assay-comments"
}
]
},
Expand Down Expand Up @@ -111,7 +124,10 @@
"command": "assay.checkForUpdates",
"title": "(Assay) Check For Updates"
},

{
"command": "assay.copyLinkFromReply",
"title": "Copy Link"
},
{
"command": "assay.addComment",
"title": "Mark for Review"
Expand Down Expand Up @@ -151,6 +167,14 @@
"dark": "media/commentIcons/export_inverse.svg",
"light": "media/commentIcons/export.svg"
}
},
{
"command": "assay.copyLinkFromThread",
"title": "Copy Link",
"icon": {
"dark": "media/commentIcons/link_inverse.svg",
"light": "media/commentIcons/link.svg"
}
}
]
},
Expand Down Expand Up @@ -214,4 +238,4 @@
"jsonwebtoken": "^9.0.1",
"jszip": "^3.10.1"
}
}
}
13 changes: 7 additions & 6 deletions src/commands/getAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,21 @@ export async function downloadAndExtract(

const versionInfo = await getVersionChoice(input, urlVersion);
const addonFileId = versionInfo.fileID;
const addonVersion = versionInfo.version;
const addonGUID = json.guid;
const version = versionInfo.version;
const guid = json.guid;

const workspaceFolder = await getRootFolderPath();
const compressedFilePath = `${workspaceFolder}/${addonGUID}_${addonVersion}.xpi`;
const compressedFilePath = `${workspaceFolder}/${guid}_${version}.xpi`;

await addToCache("reviewUrls", [addonGUID], json.review_url);
await addToCache("reviewUrls", [guid], json.review_url);

await downloadAddon(addonFileId, compressedFilePath);

await extractAddon(
compressedFilePath,
`${workspaceFolder}/${addonGUID}`,
`${workspaceFolder}/${addonGUID}/${addonVersion}`
`${workspaceFolder}/${guid}/${version}`
);
return { workspaceFolder, guid, version };
} catch (error) {
console.error(error);
}
Expand Down
74 changes: 45 additions & 29 deletions src/commands/openFromUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,70 @@ import * as vscode from "vscode";

import { downloadAndExtract } from "./getAddon";
import { getExtensionContext } from "../config/globals";
import revealFile from "../utils/revealFile";
import { getRootFolderPath } from "../utils/reviewRootDir";

export async function openWorkspace(manifestPath: string) {
const rootUri = vscode.Uri.file(await getRootFolderPath());
const manifestUri = vscode.Uri.file(manifestPath);
export async function openWorkspace(
versionPath: string,
filepath?: string,
lineNumber?: string
) {
const versionUri = vscode.Uri.file(versionPath);
const filePath = `${versionPath}/${filepath ?? "manifest.json"}`;
const workspace = vscode.workspace.workspaceFolders;

// if the workspace is already open, just open the manifest
const existingWorkspaceFolder = vscode.workspace.workspaceFolders?.find(
(folder) => folder.uri.fsPath === rootUri.fsPath
);
// If user already has the version folder opened, open the manifest.json
if (workspace && workspace[0].uri.fsPath === versionUri.fsPath) {
revealFile(vscode.Uri.file(filePath), lineNumber);
}
// Otherwise, store the filePath (since the extension must restart) to open on launch.
else {
const context = getExtensionContext();
await context.globalState.update("filePath", filePath);
if (lineNumber) {
await context.globalState.update("lineNumber", lineNumber);
}
vscode.commands.executeCommand("vscode.openFolder", versionUri, true);
}
}

if (existingWorkspaceFolder) {
await vscode.commands.executeCommand(
"workbench.files.action.collapseExplorerFolders"
);
await vscode.window.showTextDocument(manifestUri);
// handles assay.get input
export async function getAddonByUrl() {
const result = await downloadAndExtract();
if (!result) {
return;
}

// otherwise, open the workspace and store the manifest URI to be opened when the workspace is ready
vscode.workspace.updateWorkspaceFolders(0, 0, {
uri: rootUri,
name: "Assay",
});
const context = getExtensionContext();
context.globalState.update("manifestPath", manifestPath);
const { workspaceFolder, guid, version } = result;
const versionPath = `${workspaceFolder}/${guid}/${version}`;
await openWorkspace(versionPath);
}

// handles urls of the form /review/<guid>/<version>
export async function handleReviewUrl(guid: string, version: string) {
// handles urls of the form /review/<guid>/<version>?path=<file>
export async function handleReviewUrl(
guid: string,
version: string,
filepath?: string,
lineNumber?: string
) {
const rootPath = await getRootFolderPath();
const addonManifestPath = `${rootPath}/${guid}/${version}/manifest.json`;
const versionPath = `${rootPath}/${guid}/${version}`;
try {
await fs.promises.stat(addonManifestPath);
await fs.promises.stat(versionPath);
} catch (error) {
await downloadAndExtract(guid, version);
}

await openWorkspace(addonManifestPath);
await openWorkspace(versionPath, filepath, lineNumber);
}

// handles vscode://mozilla.assay/... urls
export async function handleUri(uri: vscode.Uri) {
const { path } = uri;
const [_, action, ...rest] = path.split("/");
const { path, query, fragment } = uri;
const filepath = new URLSearchParams(query).get("path");
const lineNumber = filepath ? `#${fragment}` : undefined;

const [_, action, ...rest] = path.split("/");
if (action === "review") {
const [guid, version] = rest;
await handleReviewUrl(guid, version);
await handleReviewUrl(guid, version, filepath || undefined, lineNumber);
}
}
Loading