Skip to content

Commit bff0cdf

Browse files
authored
Show warning message on simplified Internet page when wlan1 is missing (#26)
This PR shows a warning message if a user has removed the USB Wi-Fi dongle (or if the dongle has broken) indicating that fact on the simplified Internet page, so that the user will know why the machine isn't attempting to connect to an external Wi-Fi network even if the user has populated the settings for connecting to an external Wi-Fi network.
1 parent dd58e54 commit bff0cdf

5 files changed

Lines changed: 55 additions & 15 deletions

File tree

internal/app/deviceadmin/routes/internet/conn-profiles.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (h *Handlers) HandleConnProfilePostByUUID() echo.HandlerFunc {
160160
}
161161
// Redirect user
162162
return c.Redirect(http.StatusSeeOther, redirectTarget)
163-
case "simplified-updated":
163+
case "simplified-updated", "simplified-updated-activated":
164164
formValues, err := c.FormParams()
165165
if err != nil {
166166
return errors.Wrap(err, "couldn't load form parameters")
@@ -170,8 +170,10 @@ func (h *Handlers) HandleConnProfilePostByUUID() echo.HandlerFunc {
170170
); err != nil {
171171
return errors.Wrapf(err, "couldn't update connection profile %s", rawUUID)
172172
}
173-
if err := h.nmc.ActivateConnProfile(c.Request().Context(), uid); err != nil {
174-
return err
173+
if state == "simplified-updated-activated" {
174+
if err := h.nmc.ActivateConnProfile(c.Request().Context(), uid); err != nil {
175+
return err
176+
}
175177
}
176178
// Redirect user
177179
return c.Redirect(http.StatusSeeOther, redirectTarget)

internal/app/deviceadmin/routes/internet/routes.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package internet
33

44
import (
5+
"cmp"
56
"context"
67
"slices"
78
"time"
@@ -84,6 +85,7 @@ type InternetViewData struct {
8485
AvailableSSIDs []string
8586
Wlan0HotspotConnProfile nm.ConnProfile
8687
Wlan1InternetConnProfile nm.ConnProfile
88+
Wlan1Device nm.Device
8789

8890
WifiDevices []nm.Device
8991
EthernetDevices []nm.Device
@@ -123,6 +125,9 @@ func getInternetViewData(ctx context.Context, nmc *nm.Client) (vd InternetViewDa
123125
default:
124126
vd.OtherDevices = append(vd.OtherDevices, device)
125127
case "wifi":
128+
if cmp.Or(device.IpInterface, device.ControlInterface) == "wlan1" {
129+
vd.Wlan1Device = device
130+
}
126131
vd.WifiDevices = append(vd.WifiDevices, device)
127132
case "ethernet":
128133
vd.EthernetDevices = append(vd.EthernetDevices, device)

web/templates/internet/external-network-form.partial.tmpl

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{{$connProfile := (get . "ConnProfile")}}
2+
{{$device := (get . "Device")}}
23
{{$availableSSIDs := (get . "AvailableSSIDs")}}
34
{{$Meta := (get . "Meta")}}
45

@@ -64,7 +65,16 @@
6465
data-controller="form-submission"
6566
data-action="submit->form-submission#submit"
6667
>
67-
<input type="hidden" name="state" value="simplified-updated">
68+
<turbo-frame
69+
id="internet_devices_wlan1_conn-profile-internet_update-type.frame"
70+
data-turbo-reload
71+
>
72+
{{if ne (or $device.IpInterface $device.ControlInterface) "wlan1"}}
73+
<input type="hidden" name="state" value="simplified-updated">
74+
{{else}}
75+
<input type="hidden" name="state" value="simplified-updated-activated">
76+
{{end}}
77+
</turbo-frame>
6878
<input type="hidden" name="redirect-target" value="{{urlJoin (dict
6979
"path" $Meta.Path
7080
"query" $Meta.Form.Encode
@@ -228,13 +238,22 @@
228238
<div class="field" data-form-submission-target="submitter">
229239
<div class="field is-grouped">
230240
<div class="control">
231-
<input
232-
class="button is-primary"
233-
type="submit"
234-
name="update-type"
235-
value="Save and connect"
236-
data-form-submission-target="submit"
241+
<turbo-frame
242+
id="internet_devices_wlan1_conn-profile-internet_submit.frame"
243+
data-turbo-reload
237244
>
245+
<input
246+
class="button is-primary"
247+
type="submit"
248+
name="update-type"
249+
{{if ne (or $device.IpInterface $device.ControlInterface) "wlan1"}}
250+
value="Save"
251+
{{else}}
252+
value="Save and connect"
253+
{{end}}
254+
data-form-submission-target="submit"
255+
>
256+
</turbo-frame>
238257
</div>
239258
</div>
240259
</div>

web/templates/internet/index.page.tmpl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,26 @@
6565
</div>
6666
</article>
6767
{{else}}
68+
<h3>External Wi-Fi network</h3>
69+
<turbo-frame
70+
id="internet_wifi_external-network_no-device-message.frame"
71+
data-turbo-reload
72+
>
73+
{{if ne (or .Data.Wlan1Device.IpInterface .Data.Wlan1Device.ControlInterface) "wlan1"}}
74+
<article class="message is-warning two-card-width">
75+
<div class="message-body">
76+
No recognized USB Wi-Fi module is plugged into the machine! Such a module will be
77+
needed before this machine can connect to an external Wi-Fi network.
78+
</div>
79+
</article>
80+
{{end}}
81+
</turbo-frame>
6882
<div class="card section-card">
6983
<div class="card-content">
70-
<h3>External Wi-Fi network</h3>
7184
{{
7285
template "internet/external-network-form.partial.tmpl" dict
7386
"ConnProfile" .Data.Wlan1InternetConnProfile
87+
"Device" .Data.Wlan1Device
7488
"AvailableSSIDs" .Data.AvailableSSIDs
7589
"Meta" .Meta
7690
}}

web/templates/shared/nav/navbar.partial.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@
3030
template "shared/nav/navlink.partial.tmpl" dict
3131
"Display" true
3232
"Href" (urlJoin (dict
33-
"path" (print .Meta.BasePath "remote")
33+
"path" (print .Meta.BasePath "internet")
3434
"query" .Meta.Form.Encode
3535
))
36-
"Name" "Remote"
36+
"Name" "Internet"
3737
"Meta" .Meta
3838
}}
3939
{{
4040
template "shared/nav/navlink.partial.tmpl" dict
4141
"Display" true
4242
"Href" (urlJoin (dict
43-
"path" (print .Meta.BasePath "internet")
43+
"path" (print .Meta.BasePath "remote")
4444
"query" .Meta.Form.Encode
4545
))
46-
"Name" "Internet"
46+
"Name" "Remote"
4747
"Meta" .Meta
4848
}}
4949
{{

0 commit comments

Comments
 (0)