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

Add validation for existing setup path #1228

Merged
merged 12 commits into from
Aug 5, 2024
Next Next commit
Add validation for existing setup path
  • Loading branch information
radurentea committed Jul 2, 2024
commit b040edef24dca51841193c2d32430e1276e0c747
20 changes: 19 additions & 1 deletion src/setup/SetupPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { getOpenOcdRules } from "./addOpenOcdRules";
import { checkSpacesInPath, getEspIdfFromCMake } from "../utils";
import { useIdfSetupSettings } from "./setupValidation/espIdfSetup";
import { clearPreviousIdfSetups } from "./existingIdfSetups";
import * as fs from "fs";

export class SetupPanel {
public static currentPanel: SetupPanel | undefined;
Expand Down Expand Up @@ -83,6 +84,14 @@ export class SetupPanel {
private readonly panel: WebviewPanel;
private disposables: Disposable[] = [];

private async checkFileExists(filePath: string): Promise<boolean> {
radurentea marked this conversation as resolved.
Show resolved Hide resolved
return new Promise((resolve) => {
fs.access(filePath, fs.constants.F_OK, (err) => {
resolve(!err);
});
});
}

constructor(
private context: ExtensionContext,
column: ViewColumn,
Expand Down Expand Up @@ -325,6 +334,16 @@ export class SetupPanel {
case "exploreComponents":
await commands.executeCommand("esp.component-manager.ui.show");
break;
case "checkFileExists":
if (message.path) {
const fileExists = await this.checkFileExists(message.path);
this.panel.webview.postMessage({
command: "checkFileExistsResponse",
path: message.path,
exists: fileExists,
});
}
break;
default:
break;
}
Expand Down Expand Up @@ -443,7 +462,6 @@ export class SetupPanel {
? espIdfPath
: idfContainerPath;
this.checkSpacesInPaths(toolsPath);

if (idfPathToCheck === toolsPath) {
const idfPathSameIdfToolsPathMsg = `IDF_PATH and IDF_TOOLS_PATH can't be the same. Please use another location. (ERROR_SAME_IDF_PATH_AND__IDF_TOOLS_PATH)`;
throw new Error(idfPathSameIdfToolsPathMsg);
Expand Down
117 changes: 59 additions & 58 deletions src/views/setup/Install.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,61 @@
<template>
<div id="install">
<div class="notification is-danger error-message" v-if="espIdfErrorStatus">
<p>{{ espIdfErrorStatus }}</p>
<div class="icon is-large is-size-4" @click="setEspIdfErrorStatus">
<IconClose />
</div>
</div>

<div class="notification is-danger error-message" v-if="pyExecErrorStatus">
<p>{{ pyExecErrorStatus }}</p>
<div class="icon is-large is-size-4" @click="setPyExecErrorStatus">
<IconClose />
</div>
</div>

<div class="notification">
<div class="field" v-if="isNotWinPlatform && gitVersion">
<label data-config-id="git-version"
>Git version: {{ gitVersion }}</label
>
</div>

<selectEspIdf />

<folderOpen
propLabel="Enter ESP-IDF Tools directory (IDF_TOOLS_PATH):"
:propModel="toolsFolder"
:propMutate="setToolsFolder"
:openMethod="store.openEspIdfToolsFolder"
/>

<div v-if="hasToolsWhitespace" class="notification is-danger">
White spaces are not allowed in the ESP-IDF Tools path.
</div>

<div v-if="!toolsFolder" class="notification is-danger">
ESP-IDF Tools path should not be empty.
</div>

<selectPyVersion v-if="isNotWinPlatform" />

<div class="field install-btn">
<div class="control">
<button
@click="store.installEspIdf"
class="button"
data-config-id="start-install-btn"
:disabled="isInstallDisabled || store.isInstallButtonDisabled"
>
{{ actionButtonText }}
</button>
</div>
</div>
</div>
</div>
</template>

<script setup lang="ts">
import { storeToRefs } from "pinia";
import { useSetupStore } from "./store";
Expand All @@ -20,6 +78,7 @@ const {
selectedEspIdfVersion,
espIdf,
espIdfContainer,
isInstallButtonDisabled,
} = storeToRefs(store);

const isNotWinPlatform = computed(() => {
Expand Down Expand Up @@ -101,64 +160,6 @@ function setToolsFolder(newToolsPath: string) {
}
</script>

<template>
<div id="install">
<div class="notification is-danger error-message" v-if="espIdfErrorStatus">
<p>{{ espIdfErrorStatus }}</p>
<div class="icon is-large is-size-4" @click="setEspIdfErrorStatus">
<IconClose />
radurentea marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>

<div class="notification is-danger error-message" v-if="pyExecErrorStatus">
<p>{{ pyExecErrorStatus }}</p>
<div class="icon is-large is-size-4" @click="setPyExecErrorStatus">
<IconClose />
</div>
</div>

<div class="notification">
<div class="field" v-if="isNotWinPlatform && gitVersion">
<label data-config-id="git-version"
>Git version: {{ gitVersion }}</label
>
</div>

<selectEspIdf />

<folderOpen
propLabel="Enter ESP-IDF Tools directory (IDF_TOOLS_PATH):"
:propModel="toolsFolder"
:propMutate="setToolsFolder"
:openMethod="store.openEspIdfToolsFolder"
/>

<div v-if="hasToolsWhitespace" class="notification is-danger">
White spaces are not allowed in the ESP-IDF Tools path.
</div>

<div v-if="!toolsFolder" class="notification is-danger">
ESP-IDF Tools path should not be empty.
</div>

<selectPyVersion v-if="isNotWinPlatform" />

<div class="field install-btn">
<div class="control">
<button
@click="store.installEspIdf"
class="button"
data-config-id="start-install-btn"
:disabled="isInstallDisabled"
>
{{ actionButtonText }}
</button>
</div>
</div>
</div>
</div>
</template>

<style scoped>
#install {
margin: 1% 5%;
Expand Down
26 changes: 21 additions & 5 deletions src/views/setup/components/folderOpen.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
<script setup lang="ts">
import { IconFolder, IconFolderOpened } from "@iconify-prerendered/vue-codicon";
import { computed } from "vue";
import { defineProps, defineEmits } from "vue";
import { useSetupStore } from "../store";

let folderIcon = "folder";
const store = useSetupStore();
const props = defineProps<{
keyEnterMethod?: () => void;
onChangeMethod?: () => void;
openMethod: () => void;
openMethod: () => Promise<string | undefined>;
propLabel: string;
propModel: string;
propMutate: (val: string) => void;
staticText?: string;
}>();

const store = useSetupStore();
const emit = defineEmits(["blur"]);

const dataModel = computed({
get() {
return props.propModel;
Expand All @@ -31,6 +35,17 @@ function onKeyEnter() {
props.keyEnterMethod();
}
}

async function selectFolder() {
const folder = await props.openMethod();
if (folder !== undefined) {
props.propMutate(folder);
emit("blur", folder);
if (props.onChangeMethod) {
props.onChangeMethod();
}
}
}
</script>

<template>
Expand All @@ -42,6 +57,7 @@ function onKeyEnter() {
type="text"
class="input"
v-model="dataModel"
@blur="$emit('blur', dataModel)"
@keyup.enter="onKeyEnter"
/>
</div>
Expand All @@ -54,10 +70,10 @@ function onKeyEnter() {
style="text-decoration: none;"
@mouseover="folderIcon = 'folder-opened'"
@mouseout="folderIcon = 'folder'"
v-on:click="openMethod"
@click="selectFolder"
>
<IconFolderOpened v-if="(folderIcon === 'folder-opened')" />
<IconFolder v-if="(folderIcon === 'folder')" />
<IconFolderOpened v-if="folderIcon === 'folder-opened'" />
<IconFolder v-if="folderIcon === 'folder'" />
</div>
</div>
</div>
Expand Down
Loading