Skip to content

Commit 415bff0

Browse files
committed
#wip 92
1 parent 1452a77 commit 415bff0

File tree

4 files changed

+49
-72
lines changed

4 files changed

+49
-72
lines changed

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default {
4949
data() {
5050
return {
5151
drawer: null,
52-
status: null,
52+
status: 200,
5353
dialog: true,
5454
carouselItems: [
5555
{

src/common/coderbot.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class CoderBot {
77
this.$axios = axios;
88
this.$store = store;
99
this.$i18n = i18n;
10+
this.config_loaded = false;
1011
this.initActivity();
1112
}
1213

@@ -17,6 +18,14 @@ class CoderBot {
1718
return Promise.all([p1, p2, p3]);
1819
}
1920

21+
setConfigLoaded(status) {
22+
this.config_loaded = status;
23+
}
24+
25+
getConfigLoaded() {
26+
return this.config_loaded;
27+
}
28+
2029
initActivity() {
2130
this.loadActivity(null, true).then((activity) => {
2231
if (activity.data == '') {

src/components/Settings.vue

Lines changed: 28 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,10 @@
66
<v-app-bar-nav-icon @click.stop="toggleSidebar()"></v-app-bar-nav-icon>
77
<v-app-bar-title class="title"><div>{{ $t("message.settings_title") }}</div></v-app-bar-title>
88
<v-spacer></v-spacer>
9-
<template v-if="status == 200">
10-
<v-btn text @click="save">
11-
<v-icon icon="mdi-content-save"></v-icon>
12-
{{ $t('message.save') }}
13-
</v-btn>
14-
</template>
15-
<template v-else>
16-
<v-btn text>
17-
<v-progress-circular :size="30" :width="2" indeterminate></v-progress-circular>
18-
</v-btn>
19-
</template>
9+
<v-btn text @click="save">
10+
<v-icon icon="mdi-content-save"></v-icon>
11+
{{ $t('message.save') }}
12+
</v-btn>
2013
<template v-slot:extension>
2114
<v-tabs slot="extension" v-model="tab" centered slider-color="white">
2215
<v-tab v-for="item in tabs" :key="item">
@@ -360,7 +353,6 @@
360353
</v-card-title>
361354
<div class="cardContent">
362355
<v-select
363-
:disabled="settings.wifiMode!='client'"
364356
v-model="settings.startupProgram"
365357
@change="v$.settings.startupProgram.$touch"
366358
:items="programList"
@@ -393,7 +385,6 @@
393385
>
394386
<v-radio v-bind:label="$t('message.settings_network_mode_ap')" value="ap"></v-radio>
395387
<v-radio v-bind:label="$t('message.settings_network_mode_client')" value="client"></v-radio>
396-
397388
</v-radio-group>
398389
<div v-if="settings.wifiMode=='client'">
399390
<v-select
@@ -777,10 +768,8 @@ export default {
777768
};
778769
},
779770
mounted() {
780-
this.pollStatus();
781-
setInterval(() => {
782-
this.pollStatus();
783-
}, 1000);
771+
this.pollWifiStatus()
772+
setInterval(() => { this.pollWifiStatus(); }, 1000);
784773
this.getInfoAndStatus();
785774
this.prepopulate();
786775
this.settings.packagesInstalled = this.$store.getters.musicPackages;
@@ -789,7 +778,7 @@ export default {
789778
this.cb.status = this.$store.getters.status;
790779
this.adminPassword_dialog = this.settings.adminPassword != null && this.settings.adminPassword != '';
791780
this.$wifi_connect.networks().then((result) => {
792-
this.networks = result.data.ssids;
781+
this.networks = result.data.ssids;
793782
});
794783
this.$coderbot.listPrograms()
795784
.then((response) => {
@@ -882,6 +871,11 @@ export default {
882871
rawFile.send(null);
883872
*/
884873
},
874+
pollWifiStatus() {
875+
this.$wifi_connect.status().then((result) => {
876+
this.wifi_status = result.data;
877+
});
878+
},
885879
restoreSettings() {
886880
this.$coderbot.restoreSettings()
887881
.then(() => {
@@ -926,31 +920,6 @@ export default {
926920
// Get bot info and status
927921
return this.$coderbot.getInfoAndStatus();
928922
},
929-
pollStatus() {
930-
this.getInfoAndStatus()
931-
.then((response) => {
932-
if (this.status == 0 && response.status) {
933-
this.snackText = this.$i18n.t('message.coderbot_status_online');
934-
this.snackbar = true;
935-
this.getInfoAndStatus();
936-
this.prepopulate();
937-
}
938-
this.status = this.$store.getters.status != null ? 200 : 500;
939-
this.cb.logs.log = this.$store.getters.status.log;
940-
})
941-
.catch((error) => {
942-
// handle error
943-
console.log(error);
944-
if (this.status) {
945-
this.snackText = this.$i18n.t('message.coderbot_status_offline');
946-
this.snackbar = true;
947-
}
948-
this.status = 0;
949-
});
950-
this.$wifi_connect.status().then((result) => {
951-
this.wifi_status = result.data;
952-
});
953-
},
954923
deletePkg(pkgNameID) {
955924
this.$coderbot.deleteMusicPackage(pkgNameID).then(() => {
956925
console.log('Pacchetto rimosso');
@@ -988,28 +957,23 @@ export default {
988957
const network = this.networks.find(item => { return item.ssid==this.settings.wifiSSID });
989958
if(network != null) {
990959
this.wifi_overlay = true;
991-
this.$wifi_connect.disconnect().then((result) => {
992-
setTimeout(() => {
993-
this.$wifi_connect.connect(network.ssid, network.conn_type, this.settings.wifiUser, this.settings.wifiPsw)
994-
.then((result) => {
995-
this.snackText = this.$i18n.t('message.settings_network_updated');
996-
this.snackbar = true;
997-
this.wifi_overlay = false;
998-
})
999-
.catch((error) => {
1000-
console.error(error);
1001-
this.wifi_overlay = false;
1002-
});
1003-
}, 10000);
1004-
})
1005-
.catch((error) => {
1006-
console.error(error);
1007-
this.wifi_overlay = false;
1008-
});
960+
this.$wifi_connect.connect(network.ssid, network.conn_type, this.settings.wifiUser, this.settings.wifiPsw)
961+
.then((result) => {
962+
this.snackText = this.$i18n.t('message.settings_network_updated');
963+
this.snackbar = true;
964+
this.wifi_overlay = false;
965+
})
966+
.catch((error) => {
967+
console.error(error);
968+
this.wifi_overlay = false;
969+
});
1009970
}
971+
} else {
972+
console.log("disconnecting")
973+
this.$wifi_connect.disconnect().then((result) => {
974+
console.log(result);
975+
});
1010976
}
1011-
} else {
1012-
this.$wifi_connect.disconnect().then((result) => {});
1013977
}
1014978
}
1015979
},
@@ -1062,7 +1026,6 @@ export default {
10621026
return {
10631027
formdata: null,
10641028
files: null,
1065-
status: null,
10661029
dialog_reset: false,
10671030
dialog_logs: false,
10681031
lastCommit: 'N/A',
@@ -1128,7 +1091,7 @@ export default {
11281091
confirm_exit_dialog: null,
11291092
router_next: null,
11301093
adminPassword: null,
1131-
adminPassword_dialog: true,
1094+
adminPassword_dialog: false,
11321095
tabs: [
11331096
this.$i18n.t('message.settings_tabs_general'),
11341097
this.$i18n.t('message.settings_tabs_movement'),

src/main.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,14 @@ app.config.globalProperties.$coderbot = $coderbot;
6161
app.config.globalProperties.$wifi_connect = $wifi_connect;
6262
app.mount('#app');
6363
app.defaultTheme = 'dark';
64-
$coderbot.load().then(() => {
65-
console.log('config loaded');
66-
}).catch((errors) => {
67-
console.log('oops');
68-
console.error(errors);
69-
});
64+
65+
function loadConfig() {
66+
$coderbot.load().then(() => {
67+
console.log('config loaded');
68+
$coderbot.setConfigLoaded(true);
69+
}).catch((errors) => {
70+
console.log('error loading config: ', errors);
71+
setTimeout(loadConfig, 1000);
72+
});
73+
}
74+
loadConfig();

0 commit comments

Comments
 (0)