diff --git a/apps/remixdesktop/src/plugins/circomElectronBasePlugin.ts b/apps/remixdesktop/src/plugins/circomElectronBasePlugin.ts index cb55dbc064..bf7944e8ee 100644 --- a/apps/remixdesktop/src/plugins/circomElectronBasePlugin.ts +++ b/apps/remixdesktop/src/plugins/circomElectronBasePlugin.ts @@ -1,6 +1,6 @@ import { ElectronBasePlugin, ElectronBasePluginClient } from "@remixproject/plugin-electron" import { Profile } from "@remixproject/plugin-utils" -import { CIRCOM_INSTALLATION_PATH, circomCli, extractParentFromKey } from "../tools/circom" +import { getInstallationPath, circomCli, extractParentFromKey } from "../tools/circom" import path from "path" import { existsSync, readFileSync } from "fs" @@ -58,7 +58,7 @@ class CircomElectronPluginClient extends ElectronBasePluginClient { } getInputs() { - const inputsFile = extractParentFromKey(CIRCOM_INSTALLATION_PATH) + '/log_input_signals.txt' + const inputsFile = extractParentFromKey(getInstallationPath()) + '/log_input_signals.txt' const inputsFileExists = existsSync(inputsFile) const signals: string[] = [] diff --git a/apps/remixdesktop/src/tools/circom.ts b/apps/remixdesktop/src/tools/circom.ts index 2f616d3700..9ffb9f1d30 100644 --- a/apps/remixdesktop/src/tools/circom.ts +++ b/apps/remixdesktop/src/tools/circom.ts @@ -6,8 +6,6 @@ import fs, { existsSync } from 'fs' import axios from 'axios' const execAsync = promisify(exec) -export const CIRCOM_INSTALLATION_PATH = getInstallationPath() -const CIRCOM_INSTALLATION_URL = getInstallationUrl() async function downloadFile(url: string, dest: string) { const writer = fs.createWriteStream(dest) @@ -37,37 +35,39 @@ async function downloadFile(url: string, dest: string) { }) } -function getInstallationPath() { +export function getInstallationPath(version = 'latest') { switch (process.platform) { case 'win32': - return path.join(app.getPath('temp'), 'circom-windows-amd64.exe') + return path.join(app.getPath('temp'), version, 'circom-windows-amd64.exe') case 'darwin': - return path.join(app.getAppPath(), 'circom-macos-amd64') + return path.join(app.getAppPath(), version, 'circom-macos-amd64') case 'linux': - return path.join(app.getAppPath(), 'circom-linux-amd64') + return path.join(app.getAppPath(), version, 'circom-linux-amd64') } } -function getInstallationUrl() { +function getInstallationUrl(version = 'latest') { switch (process.platform) { case 'win32': - return "https://github.com/iden3/circom/releases/latest/download/circom-windows-amd64.exe" + return `https://github.com/iden3/circom/releases/${version}/download/circom-windows-amd64.exe` case 'darwin': - return "https://github.com/iden3/circom/releases/latest/download/circom-macos-amd64" + return `https://github.com/iden3/circom/releases/${version}/download/circom-macos-amd64` case 'linux': - return "https://github.com/iden3/circom/releases/latest/download/circom-linux-amd64" + return `https://github.com/iden3/circom/releases/${version}/download/circom-linux-amd64` } } export const circomCli = { async installCircom () { try { - console.log('downloading circom to ', CIRCOM_INSTALLATION_PATH) - await downloadFile(CIRCOM_INSTALLATION_URL, CIRCOM_INSTALLATION_PATH) + const installationPath = getInstallationPath() + console.log('downloading circom to ', installationPath) + const installationUrl = getInstallationUrl() + await downloadFile(installationUrl, installationPath) console.log('downloading done') } catch (e) { console.error(e) @@ -76,14 +76,16 @@ export const circomCli = { async isCircomInstalled () { try { - return existsSync(CIRCOM_INSTALLATION_PATH) + const installationPath = getInstallationPath() + return existsSync(installationPath) } catch (e) { return false } }, async run (filePath: string, options?: Record) { - const cmd = `${CIRCOM_INSTALLATION_PATH} ${filePath} ${Object.keys(options || {}).map((key) => options[key] ? `--${key} ${options[key]}` : `--${key}`).join(' ')}` + const installationPath = getInstallationPath() + const cmd = `${installationPath} ${filePath} ${Object.keys(options || {}).map((key) => options[key] ? `--${key} ${options[key]}` : `--${key}`).join(' ')}` return await execAsync(cmd) }