Skip to content

Commit

Permalink
frontend: disable wifi-updater and let user know if wifi service is d…
Browse files Browse the repository at this point in the history
…isabled
  • Loading branch information
Williangalvani authored and patrickelectric committed Jan 10, 2025
1 parent 5d668d9 commit 00a01da
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 23 deletions.
3 changes: 0 additions & 3 deletions core/frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@
<div id="tour-center-hook" />
</v-main>
<ethernet-updater />
<wifi-updater />
<mavlink-updater />
<new-version-notificator />
<Wizard />
Expand Down Expand Up @@ -419,7 +418,6 @@ import HealthTrayMenu from './components/health/HealthTrayMenu.vue'
import MavlinkUpdater from './components/mavlink/MavlinkUpdater.vue'
import NotificationTrayButton from './components/notifications/TrayButton.vue'
import WifiTrayMenu from './components/wifi/WifiTrayMenu.vue'
import WifiUpdater from './components/wifi/WifiUpdater.vue'
import menus, { menuItem } from './menus'
import autopilot_data from './store/autopilot'
import Cpu from './widgets/Cpu.vue'
Expand All @@ -436,7 +434,6 @@ export default Vue.extend({
'pirate-mode-tray-menu': PiradeModeTrayMenu,
'theme-tray-menu': ThemeTrayMenu,
'wifi-tray-menu': WifiTrayMenu,
'wifi-updater': WifiUpdater,
'ethernet-tray-menu': EthernetTrayMenu,
'cloud-tray-menu': CloudTrayMenu,
'ethernet-updater': EthernetUpdater,
Expand Down
78 changes: 59 additions & 19 deletions core/frontend/src/components/wifi/WifiTrayMenu.vue
Original file line number Diff line number Diff line change
@@ -1,44 +1,79 @@
<template>
<v-menu
:close-on-content-click="false"
nudge-left="500"
nudge-bottom="25"
>
<template
#activator="{ on, attrs }"
<div>
<wifi-updater v-if="!wifi_service_disabled" />
<v-menu
:close-on-content-click="false"
nudge-left="500"
nudge-bottom="25"
>
<template
#activator="{ on, attrs }"
>
<v-card
id="wifi-tray-menu-button"
class="px-1"
elevation="0"
color="transparent"
v-bind="attrs"
v-on="on"
>
<v-icon
v-tooltip="{
content: wifi_service_disabled ? 'Wifi is disabled' : undefined,
bottom: true,
offset: 5,
}"
color="white"
>
{{ wifi_icon }}
</v-icon>
</v-card>
</template>
<wifi-manager v-if="!wifi_service_disabled" />
<v-card
id="wifi-tray-menu-button"
class="px-1"
elevation="0"
color="transparent"
v-bind="attrs"
v-on="on"
v-else
elevation="1"
width="500"
>
<v-icon color="white">
{{ wifi_icon }}
</v-icon>
<v-card-title class="text-subtitle-1 pa-4">
Wifi is disabled via environment variable. <br>
Re-enable it by removing "wifi" from <code>BLUEOS_DISABLE_SERVICES</code>
in <code>/root/.config/bootstrap/startup.json</code>
</v-card-title>
</v-card>
</template>
<wifi-manager />
</v-menu>
</v-menu>
</div>
</template>

<script lang="ts">
import Vue from 'vue'
import commander from '@/store/commander'
import wifi from '@/store/wifi'
import { wifi_strenght_icon } from '@/utils/wifi'
import WifiManager from './WifiManager.vue'
import WifiUpdater from './WifiUpdater.vue'
export default Vue.extend({
name: 'WifiTrayMenu',
components: {
WifiManager,
WifiUpdater,
},
data() {
return {
disabled_services: undefined as string[] | undefined,
}
},
computed: {
wifi_service_disabled(): boolean {
return this.disabled_services?.includes('wifi') ?? false
},
wifi_icon(): string {
if (this.wifi_service_disabled) {
return 'mdi-wifi-cancel'
}
if (wifi.connectable_networks === null) {
return 'mdi-wifi-sync'
}
Expand All @@ -48,6 +83,11 @@ export default Vue.extend({
return wifi_strenght_icon(wifi.current_network.signal)
},
},
mounted() {
commander.getEnvironmentVariables().then((environment_variables) => {
this.disabled_services = ((environment_variables?.BLUEOS_DISABLE_SERVICES as string) ?? '').split(',') as string[]
})
},
})
</script>

Expand Down
10 changes: 9 additions & 1 deletion core/frontend/src/store/commander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class CommanderStore {
API_URL = '/commander/v1.0'

private static instance: CommanderStore
// environment variables need a full reboot to take effect, so we should be able to cache them
private environmentVariables: Record<string, unknown> | undefined

public static getInstance(): CommanderStore {
if (!CommanderStore.instance) {
Expand Down Expand Up @@ -145,12 +147,18 @@ class CommanderStore {
}

async getEnvironmentVariables(): Promise<Record<string, unknown> | undefined> {
if (this.environmentVariables) {
return this.environmentVariables
}
return back_axios({
method: 'get',
url: `${this.API_URL}/environment_variables`,
timeout: 5000,
})
.then((response) => response.data)
.then((response) => {
this.environmentVariables = response.data
return response.data
})
.catch((error) => {
if (error === backend_offline_error) {
return undefined
Expand Down

0 comments on commit 00a01da

Please sign in to comment.