Skip to content

Commit

Permalink
added mirror select component
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Gadorek committed Oct 2, 2024
1 parent 31b6d69 commit c033d22
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ async fn get_idf_versions() -> Vec<String> {
available_versions
}

#[tauri::command]
fn get_idf_mirror_list() -> &'static [&'static str] {
idf_im_lib::get_idf_mirrors_list()
}

#[tauri::command]
fn get_tools_mirror_list() -> &'static [&'static str] {
idf_im_lib::get_idf_tools_mirrors_list()
}

use tauri::Manager;

#[cfg_attr(mobile, tauri::mobile_entry_point)]
Expand All @@ -140,7 +150,9 @@ pub fn run() {
python_sanity_check,
python_install,
get_available_targets,
get_idf_versions
get_idf_versions,
get_idf_mirror_list,
get_tools_mirror_list
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
4 changes: 3 additions & 1 deletion src/components/WizardStep.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<PythonSanitycheck :nextstep=nextStep v-if="currentStep === 2" />
<TargetSelect :nextstep=nextStep v-if="currentStep === 3" />
<VersionSelect :nextstep=nextStep v-if="currentStep === 4" />
<MirrorSelect :nextstep=nextStep v-if="currentStep === 5" />
<div>
<!-- <n-button @click="previousStep" :disabled="currentStep === 1">Previous</n-button>
<n-button @click="nextStep" :disabled="currentStep === totalSteps" type="primary">
Expand All @@ -23,9 +24,10 @@ import PrerequisitiesCheck from './wizard_steps/PrerequisitiesCheck.vue';
import PythonSanitycheck from './wizard_steps/PythonSanitycheck.vue';
import TargetSelect from './wizard_steps/TargetSelect.vue';
import VersionSelect from './wizard_steps/VersionSelect.vue';
import MirrorSelect from './wizard_steps/MirrorSelect.vue';
export default {
components: { NButton, NCheckbox, Greet, PrerequisitiesCheck, PythonSanitycheck, TargetSelect, VersionSelect },
components: { NButton, NCheckbox, Greet, PrerequisitiesCheck, PythonSanitycheck, TargetSelect, VersionSelect, MirrorSelect },
setup() {
const store = useWizardStore()
Expand Down
109 changes: 109 additions & 0 deletions src/components/wizard_steps/MirrorSelect.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<template>
<p>Please select download mirrors. If you are outside mainland china you probably want to use the defaults.</p>
<n-split direction="horizontal" style="height: 200px" :max="0.75" :min="0.25">
<template #1>
<n-spin :show="loading_idfs">
<template #default>
<n-radio-group v-model:value="selected_idf_mirror" name="radiogroup">
<ul>
<n-space>
<li v-for="mirror in idf_mirrors" :key="mirror.value">
<n-radio :value="mirror.value" :label="mirror.label" />
</li>
</n-space>
</ul>
</n-radio-group>
</template>
<template #description>
loading available IDF download mirrors...
</template>
</n-spin>
</template>
<template #2>
<n-spin :show="loading_tools">
<template #default>
<n-radio-group v-model:value="selected_tools_mirror" name="radiogroup">
<ul>
<n-space>
<li v-for="mirror in tools_mirrors" :key="mirror.value">
<n-radio :value="mirror.value" :label="mirror.label" />
</li>
</n-space>
</ul>
</n-radio-group>
</template>
<template #description>
loading available tools download mirrors...
</template>
</n-spin>
</template>
</n-split>

<n-space>
<n-button @click="processChoices" type="primary"
:disabled="selected_idf_mirror == null || selected_tools_mirror == null">Next</n-button>
</n-space>
</template>

<script>
import { ref, version } from "vue";
import { invoke } from "@tauri-apps/api/core";
import { NButton, NSpin } from 'naive-ui'
import loading from "naive-ui/es/_internal/loading";
export default {
name: 'MirrorSelect',
props: {
nextstep: Function
},
components: { NButton, NSpin },
data: () => ({
loading_idfs: true,
loading_tools: true,
selected_idf_mirror: null,
selected_tools_mirror: null,
idf_mirrors: [],
tools_mirrors: [],
}),
methods: {
get_avalible_idf_mirrors: async function () {
const idf_mirrors = await invoke("get_idf_mirror_list", {});
this.idf_mirrors = idf_mirrors.map((mirror, index) => {
return {
value: mirror,
label: mirror,
}
});
this.selected_idf_mirror = this.idf_mirrors[0].value;
this.loading_idfs = false;
return false;
},
get_avalible_tools_mirrors: async function () {
const tools_mirrors = await invoke("get_tools_mirror_list", {});
this.tools_mirrors = tools_mirrors.map((mirror, index) => {
return {
value: mirror,
label: mirror,
}
});
this.selected_tools_mirror = this.tools_mirrors[0].value;
this.loading_tools = false;
return false;
},
processChoices: function () {
// todo: send to backend
console.log("Mirror choices:", {
idf_mirror: this.selected_idf_mirror,
tools_mirror: this.selected_tools_mirror,
});
if (!this.loading_idfs && !this.loading_tools) {
this.nextstep();
}
}
},
mounted() {
this.get_avalible_idf_mirrors();
this.get_avalible_tools_mirrors();
}
}
</script>
2 changes: 1 addition & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineStore } from "pinia";
export const useWizardStore = defineStore("wizard", {
state: () => ({
currentStep: 1,
totalSteps: 4,
totalSteps: 6,
wizardData: {},
}),
actions: {
Expand Down

0 comments on commit c033d22

Please sign in to comment.