11<script setup>
2+ import {onMounted , watch , ref } from ' vue' ;
23import {store } from " ../js/state.js" ;
4+ import {getSettings , saveSettings , clearSettings as clearStoredSettings } from " ../js/storage.js" ;
35
46import BindPhraseInput from " ../components/BindPhraseInput.vue" ;
57import RFSelect from " ../components/RFSelect.vue" ;
@@ -9,6 +11,84 @@ import WiFiAutoOn from "../components/WiFiAutoOn.vue";
911import RXasTX from " ../components/RXasTX.vue" ;
1012import RXOptions from " ../components/RXOptions.vue" ;
1113import TXOptions from " ../components/TXOptions.vue" ;
14+
15+ const bindPhraseText = ref (null );
16+
17+ onMounted (() => {
18+ const savedSettings = getSettings ();
19+ if (savedSettings) {
20+ if (savedSettings .uid !== undefined ) store .options .uid = savedSettings .uid ;
21+ if (savedSettings .bindPhraseText !== undefined ) bindPhraseText .value = savedSettings .bindPhraseText ;
22+ if (savedSettings .region !== undefined ) store .options .region = savedSettings .region ;
23+ if (savedSettings .domain !== undefined ) store .options .domain = savedSettings .domain ;
24+ if (savedSettings .ssid !== undefined ) store .options .ssid = savedSettings .ssid ;
25+ if (savedSettings .password !== undefined ) store .options .password = savedSettings .password ;
26+ if (savedSettings .wifiOnInternal !== undefined ) store .options .wifiOnInternal = savedSettings .wifiOnInternal ;
27+
28+ if (savedSettings .rx ) {
29+ if (savedSettings .rx .uartBaud !== undefined ) store .options .rx .uartBaud = savedSettings .rx .uartBaud ;
30+ if (savedSettings .rx .lockOnFirstConnect !== undefined ) store .options .rx .lockOnFirstConnect = savedSettings .rx .lockOnFirstConnect ;
31+ if (savedSettings .rx .r9mmMiniSBUS !== undefined ) store .options .rx .r9mmMiniSBUS = savedSettings .rx .r9mmMiniSBUS ;
32+ if (savedSettings .rx .fanMinRuntime !== undefined ) store .options .rx .fanMinRuntime = savedSettings .rx .fanMinRuntime ;
33+ if (savedSettings .rx .rxAsTx !== undefined ) store .options .rx .rxAsTx = savedSettings .rx .rxAsTx ;
34+ if (savedSettings .rx .rxAsTxType !== undefined ) store .options .rx .rxAsTxType = savedSettings .rx .rxAsTxType ;
35+ }
36+ }
37+ });
38+
39+ // Helper function to save all settings
40+ function saveAllSettings () {
41+ const settings = getSettings () || {};
42+ settings .uid = store .options .uid ;
43+ settings .bindPhraseText = bindPhraseText .value ;
44+ settings .region = store .options .region ;
45+ settings .domain = store .options .domain ;
46+ settings .ssid = store .options .ssid ;
47+ settings .password = store .options .password ;
48+ settings .wifiOnInternal = store .options .wifiOnInternal ;
49+
50+ if (! settings .rx ) settings .rx = {};
51+ settings .rx .uartBaud = store .options .rx .uartBaud ;
52+ settings .rx .lockOnFirstConnect = store .options .rx .lockOnFirstConnect ;
53+ settings .rx .r9mmMiniSBUS = store .options .rx .r9mmMiniSBUS ;
54+ settings .rx .fanMinRuntime = store .options .rx .fanMinRuntime ;
55+ settings .rx .rxAsTx = store .options .rx .rxAsTx ;
56+ settings .rx .rxAsTxType = store .options .rx .rxAsTxType ;
57+
58+ saveSettings (settings);
59+ }
60+
61+ watch (() => store .options .uid , () => saveAllSettings (), { deep: false });
62+ watch (bindPhraseText, () => saveAllSettings ());
63+ watch (() => store .options .region , () => saveAllSettings ());
64+ watch (() => store .options .domain , () => saveAllSettings ());
65+ watch (() => store .options .ssid , () => saveAllSettings ());
66+ watch (() => store .options .password , () => saveAllSettings ());
67+ watch (() => store .options .wifiOnInternal , () => saveAllSettings ());
68+ watch (() => store .options .rx .uartBaud , () => saveAllSettings ());
69+ watch (() => store .options .rx .lockOnFirstConnect , () => saveAllSettings ());
70+ watch (() => store .options .rx .r9mmMiniSBUS , () => saveAllSettings ());
71+ watch (() => store .options .rx .fanMinRuntime , () => saveAllSettings ());
72+ watch (() => store .options .rx .rxAsTx , () => saveAllSettings ());
73+ watch (() => store .options .rx .rxAsTxType , () => saveAllSettings ());
74+
75+ function clearSettings () {
76+ clearStoredSettings ();
77+ store .options .uid = null ;
78+ bindPhraseText .value = null ;
79+ store .options .region = ' FCC' ;
80+ store .options .domain = 1 ;
81+ store .options .ssid = null ;
82+ store .options .password = null ;
83+ store .options .wifiOnInternal = 60 ;
84+ store .options .flashMethod = null ;
85+ store .options .rx .uartBaud = 420000 ;
86+ store .options .rx .lockOnFirstConnect = true ;
87+ store .options .rx .r9mmMiniSBUS = false ;
88+ store .options .rx .fanMinRuntime = 30 ;
89+ store .options .rx .rxAsTx = false ;
90+ store .options .rx .rxAsTxType = 0 ;
91+ }
1292 </script >
1393
1494<template >
@@ -17,7 +97,7 @@ import TXOptions from "../components/TXOptions.vue";
1797 <VCardText >Set the flashing options and method for your <b >{{ store.target?.config?.product_name }}</b ></VCardText >
1898 <br >
1999 <VForm autocomplete =" on" method =" POST" >
20- <BindPhraseInput v-model =" store.options.uid" />
100+ <BindPhraseInput v-model =" store.options.uid" :bind-phrase-text = " bindPhraseText " @update:bindPhraseText = " bindPhraseText = $event " />
21101 <RFSelect v-model:region =" store.options.region" v-model:domain =" store.options.domain" :radio =" store.radio" />
22102 <WiFiSettingsInput v-model:ssid =" store.options.ssid" v-model:password =" store.options.password"
23103 v-if =" store.target?.config?.platform!=='stm32'" />
@@ -34,6 +114,10 @@ import TXOptions from "../components/TXOptions.vue";
34114 </VExpansionPanelText >
35115 </VExpansionPanel >
36116 </VExpansionPanels >
117+
118+ <VBtn color =" error" variant =" outlined" size =" small" @click =" clearSettings" class =" mt-4" >
119+ Clear Stored Settings
120+ </VBtn >
37121 </VForm >
38122 </VContainer >
39123</template >
0 commit comments