Skip to content

Commit e9b4dd8

Browse files
wip
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
1 parent 8ff7472 commit e9b4dd8

File tree

11 files changed

+587
-90
lines changed

11 files changed

+587
-90
lines changed

core/frontend/src/components/wifi/ConnectionDialog.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ export default Vue.extend({
145145
type: Boolean,
146146
default: false,
147147
},
148+
interfaceName: {
149+
type: String,
150+
default: null,
151+
},
148152
},
149153
data() {
150154
return {
@@ -201,14 +205,18 @@ export default Vue.extend({
201205
async connectToWifiNetwork(): Promise<void> {
202206
const credentials: NetworkCredentials = { ssid: this.real_ssid, password: this.password }
203207
this.connection_status = ConnectionStatus.Connecting
208+
const params: Record<string, unknown> = { hidden: this.is_hidden }
209+
if (this.interfaceName) {
210+
params.interface = this.interfaceName
211+
}
204212
try {
205213
wifi.setLoading(true)
206214
await back_axios({
207215
method: 'post',
208216
url: `${wifi.API_URL}/connect`,
209217
timeout: 50000,
210218
data: credentials,
211-
params: { hidden: this.is_hidden },
219+
params,
212220
})
213221
this.showDialog(false)
214222
this.connection_status = ConnectionStatus.Succeeded
@@ -225,11 +233,15 @@ export default Vue.extend({
225233
},
226234
async removeSavedWifiNetwork(): Promise<void> {
227235
wifi.setLoading(true)
236+
const params: Record<string, unknown> = { ssid: this.network.ssid }
237+
if (this.interfaceName) {
238+
params.interface = this.interfaceName
239+
}
228240
await back_axios({
229241
method: 'post',
230242
url: `${wifi.API_URL}/remove`,
231243
timeout: 10000,
232-
params: { ssid: this.network.ssid },
244+
params,
233245
}).then(() => {
234246
this.$emit('forget', this.network)
235247
})

core/frontend/src/components/wifi/DisconnectionDialog.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ export default Vue.extend({
105105
type: Boolean,
106106
default: false,
107107
},
108+
interfaceName: {
109+
type: String,
110+
default: null,
111+
},
108112
},
109113
data() {
110114
return {
@@ -135,14 +139,22 @@ export default Vue.extend({
135139
async disconnectFromWifiNetwork(): Promise<void> {
136140
wifi.setLoading(true)
137141
this.showDialog(false)
142+
const params: Record<string, unknown> = {}
143+
if (this.interfaceName) {
144+
params.interface = this.interfaceName
145+
}
138146
await back_axios({
139147
method: 'get',
140148
url: `${wifi.API_URL}/disconnect`,
149+
params,
141150
timeout: 10000,
142151
})
143152
.then(() => {
144153
wifi.setNetworkStatus(null)
145154
wifi.setCurrentNetwork(null)
155+
if (this.interfaceName) {
156+
wifi.setInterfaceCurrentNetwork({ interfaceName: this.interfaceName, network: null })
157+
}
146158
})
147159
.catch((error) => {
148160
const message = `Could not disconnect from wifi network: ${error.message}.`

core/frontend/src/components/wifi/WifiManager.vue

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
v-if="selected_network"
115115
v-model="show_connection_dialog"
116116
:network="selected_network"
117+
:interface-name="active_interface"
117118
@forget="forgetNetwork"
118119
/>
119120

@@ -122,6 +123,7 @@
122123
v-model="show_disconnection_dialog"
123124
:network="current_network"
124125
:status="wifi_status"
126+
:interface-name="active_interface"
125127
/>
126128

127129
<wifi-settings-dialog v-model="show_settings_menu" />
@@ -182,6 +184,10 @@ export default Vue.extend({
182184
type: Boolean,
183185
default: true,
184186
},
187+
interfaceName: {
188+
type: String,
189+
default: null,
190+
},
185191
},
186192
data() {
187193
return {
@@ -196,18 +202,52 @@ export default Vue.extend({
196202
}
197203
},
198204
computed: {
205+
active_interface(): string | null {
206+
return this.interfaceName || wifi.current_interface
207+
},
199208
wifi_is_loading(): boolean {
209+
if (this.active_interface) {
210+
const data = wifi.interface_data[this.active_interface]
211+
return !data || data.available_networks === null
212+
}
200213
return wifi.is_loading
201214
},
202215
wifi_status(): WifiStatus | null {
216+
if (this.active_interface) {
217+
return wifi.interface_data[this.active_interface]?.network_status ?? null
218+
}
203219
return wifi.network_status
204220
},
205221
current_network(): Network | null {
206-
this.$emit('current-network', wifi.current_network)
207-
return wifi.current_network
222+
let network: Network | null = null
223+
if (this.active_interface) {
224+
network = wifi.interface_data[this.active_interface]?.current_network ?? null
225+
} else {
226+
network = wifi.current_network
227+
}
228+
this.$emit('current-network', network)
229+
return network
230+
},
231+
interface_available_networks(): Network[] | null {
232+
if (this.active_interface) {
233+
return wifi.interface_data[this.active_interface]?.available_networks ?? null
234+
}
235+
return wifi.available_networks
236+
},
237+
interface_connectable_networks(): Network[] | null {
238+
const networks = this.interface_available_networks
239+
if (networks === null) {
240+
return null
241+
}
242+
const currentSsid = this.current_network?.ssid
243+
return networks.filter((network: Network) => network.ssid !== currentSsid)
208244
},
209245
connectable_networks(): Network[] | undefined {
210-
return uniqBy(wifi.connectable_networks, 'ssid')
246+
const networks = this.interface_connectable_networks
247+
if (networks === null) {
248+
return undefined
249+
}
250+
return uniqBy(networks, 'ssid')
211251
// Move known networks to the top
212252
.sort((a: Network, b: Network) => Number(b.saved) - Number(a.saved))
213253
},
@@ -283,10 +323,14 @@ export default Vue.extend({
283323
},
284324
async toggleHotspot(): Promise<void> {
285325
this.hotspot_status_loading = true
326+
const params: Record<string, unknown> = { enable: !this.hotspot_status }
327+
if (this.active_interface) {
328+
params.interface = this.active_interface
329+
}
286330
await back_axios({
287331
method: 'post',
288332
url: `${wifi.API_URL}/hotspot`,
289-
params: { enable: !this.hotspot_status },
333+
params,
290334
timeout: 20000,
291335
})
292336
.then(() => {

core/frontend/src/components/wifi/WifiTrayMenu.vue

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,55 @@
11
<template>
2-
<div>
2+
<div class="d-flex">
33
<wifi-updater v-if="!wifi_service_disabled" />
44
<v-menu
5+
v-for="iface in displayed_interfaces"
6+
:key="iface.name"
7+
:close-on-content-click="false"
8+
nudge-left="500"
9+
nudge-bottom="25"
10+
>
11+
<template
12+
#activator="{ on, attrs }"
13+
>
14+
<v-card
15+
:id="`wifi-tray-menu-button-${iface.name}`"
16+
class="px-1"
17+
elevation="0"
18+
color="transparent"
19+
v-bind="attrs"
20+
v-on="on"
21+
>
22+
<v-icon
23+
v-tooltip="{
24+
content: get_interface_tooltip(iface.name),
25+
bottom: true,
26+
offset: 5,
27+
}"
28+
color="white"
29+
>
30+
{{ get_interface_icon(iface.name) }}
31+
</v-icon>
32+
</v-card>
33+
</template>
34+
<wifi-manager
35+
v-if="!wifi_service_disabled"
36+
:interface-name="iface.name"
37+
/>
38+
<v-card
39+
v-else
40+
elevation="1"
41+
width="500"
42+
>
43+
<v-card-title class="text-subtitle-1 pa-4">
44+
Wifi is disabled via environment variable. <br>
45+
Re-enable it by removing "wifi" from <code>BLUEOS_DISABLE_SERVICES</code>
46+
in <code>/root/.config/bootstrap/startup.json</code>
47+
</v-card-title>
48+
</v-card>
49+
</v-menu>
50+
<!-- Fallback icon when no interfaces are available yet -->
51+
<v-menu
52+
v-if="displayed_interfaces.length === 0"
553
:close-on-content-click="false"
654
nudge-left="500"
755
nudge-bottom="25"
@@ -19,7 +67,7 @@
1967
>
2068
<v-icon
2169
v-tooltip="{
22-
content: wifi_service_disabled ? 'Wifi is disabled' : undefined,
70+
content: wifi_service_disabled ? 'Wifi is disabled' : 'WiFi',
2371
bottom: true,
2472
offset: 5,
2573
}"
@@ -50,6 +98,7 @@ import Vue from 'vue'
5098
5199
import commander from '@/store/commander'
52100
import wifi from '@/store/wifi'
101+
import { InterfaceStatus, WlanInterface } from '@/types/wifi'
53102
import { wifi_strenght_icon } from '@/utils/wifi'
54103
55104
import WifiManager from './WifiManager.vue'
@@ -70,6 +119,18 @@ export default Vue.extend({
70119
wifi_service_disabled(): boolean {
71120
return this.disabled_services?.includes('wifi') ?? false
72121
},
122+
available_interfaces(): WlanInterface[] {
123+
return wifi.available_interfaces
124+
},
125+
interface_statuses(): InterfaceStatus[] {
126+
return wifi.interface_statuses
127+
},
128+
displayed_interfaces(): WlanInterface[] {
129+
if (this.wifi_service_disabled) {
130+
return []
131+
}
132+
return this.available_interfaces
133+
},
73134
wifi_icon(): string {
74135
if (this.wifi_service_disabled) {
75136
return 'mdi-wifi-cancel'
@@ -85,9 +146,37 @@ export default Vue.extend({
85146
},
86147
mounted() {
87148
commander.getEnvironmentVariables().then((environment_variables) => {
88-
this.disabled_services = ((environment_variables?.BLUEOS_DISABLE_SERVICES as string) ?? '').split(',') as string[]
149+
this.disabled_services = (environment_variables?.BLUEOS_DISABLE_SERVICES as string ?? '').split(',') as string[]
89150
})
90151
},
152+
methods: {
153+
get_interface_status(interfaceName: string): InterfaceStatus | undefined {
154+
return this.interface_statuses.find((status) => status.interface === interfaceName)
155+
},
156+
get_interface_icon(interfaceName: string): string {
157+
const status = this.get_interface_status(interfaceName)
158+
if (!status) {
159+
return 'mdi-wifi-sync'
160+
}
161+
if (!status.connected) {
162+
return 'mdi-wifi-off'
163+
}
164+
if (status.signal !== null) {
165+
return wifi_strenght_icon(status.signal)
166+
}
167+
return 'mdi-wifi'
168+
},
169+
get_interface_tooltip(interfaceName: string): string {
170+
const status = this.get_interface_status(interfaceName)
171+
if (!status) {
172+
return `${interfaceName}: Scanning...`
173+
}
174+
if (!status.connected) {
175+
return `${interfaceName}: Disconnected`
176+
}
177+
return `${interfaceName}: ${status.ssid || 'Connected'}`
178+
},
179+
},
91180
})
92181
</script>
93182

0 commit comments

Comments
 (0)