MCPcopy Index your code
hub / github.com/APKLab/APKLab / updateTools

Function updateTools

src/utils/updater.ts:59–121  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

57 * If any tool does not exist or does not match given file name, download it.
58 */
59export async function updateTools(): Promise<void> {
60 // create first_run_completed file if it doesn't exist
61 const firstRunFile = path.resolve(apklabDataDir, "first_run_completed");
62 if (!fs.existsSync(firstRunFile)) {
63 fs.writeFileSync(firstRunFile, "");
64 return;
65 }
66 const extensionConfig =
67 vscode.workspace.getConfiguration(extensionConfigName);
68 if (!extensionConfig.get("updateTools")) return; // if updates are disabled, skip it
69
70 const needsUpdate: Tool[] = [];
71
72 const config = await getUpdateConfig();
73 config.tools.forEach((tool) => {
74 const toolPath = extensionConfig.get(tool.configName);
75 if (
76 !toolPath ||
77 !fs.existsSync(String(toolPath)) ||
78 (!tool.zipped &&
79 path.basename(String(toolPath)) !== tool.fileName) ||
80 (tool.zipped && path.basename(String(toolPath)) !== tool.unzipDir)
81 ) {
82 needsUpdate.push(tool);
83 }
84 });
85
86 if (needsUpdate.length > 0) {
87 // show update notification
88 vscode.window
89 .showInformationMessage(
90 "APKLab: Some of the needed tools are missing or outdated.",
91 "Update tools",
92 "Cancel",
93 )
94 .then(async (updateAction) => {
95 if (updateAction === "Update tools") {
96 // Use Promise.allSettled to properly handle async operations
97 const downloadPromises = needsUpdate.map(async (tool) => {
98 // remove tool path from configuration & download it
99 await vscode.workspace
100 .getConfiguration(extensionConfigName)
101 .update(
102 tool.configName,
103 "",
104 vscode.ConfigurationTarget.Global,
105 );
106 return await downloadTool(tool);
107 });
108
109 const results = await Promise.allSettled(downloadPromises);
110 const failures = results.filter(
111 (r) => r.status === "rejected",
112 );
113 if (failures.length > 0) {
114 outputChannel.appendLine(
115 `Failed to update ${failures.length} tool(s)`,
116 );

Callers 1

activateFunction · 0.90

Calls 2

downloadToolFunction · 0.90
getUpdateConfigFunction · 0.85

Tested by

no test coverage detected