Skip to content

Commit d9156ed

Browse files
committed
Add live bandwidth monitoring settings and UI integration
1 parent 7515e34 commit d9156ed

4 files changed

Lines changed: 614 additions & 28 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@
77
5. Added minor UI changes for features' title and descriptions
88
6. Changed speedtest puffer color to match the theme
99
7. Added FPLMN Settings to help users clear forbidden network list
10+
8. Added QuecWatch's network refresh events to Network Insights
11+
9. Fixed Custom DNS disable functionality
12+
10. Added restore previous IMEI to IMEI settings
13+
11. Added auth-token checker
14+
12. Added Settings for Live Bandwidth to enable or disable it
1015

1116
Note: Using https is now recommended

app/dashboard/settings/personalization/page.tsx

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ interface TemperatureUnitResponse {
106106
};
107107
}
108108

109+
interface BandwidthSettingsResponse {
110+
status: string;
111+
message: string;
112+
data?: {
113+
enabled: boolean;
114+
running: boolean;
115+
isDefault: boolean;
116+
};
117+
}
118+
109119
const PersonalizationPage = () => {
110120
const { toast } = useToast();
111121
const [isLoading, setIsLoading] = useState<boolean>(false);
@@ -135,6 +145,9 @@ const PersonalizationPage = () => {
135145
useState<boolean>(false);
136146
const [isProfileDialogDefault, setIsProfileDialogDefault] =
137147
useState<boolean>(true);
148+
const [bandwidthEnabled, setBandwidthEnabled] = useState<boolean>(true);
149+
const [isBandwidthLoading, setIsBandwidthLoading] = useState<boolean>(false);
150+
const [isBandwidthDefault, setIsBandwidthDefault] = useState<boolean>(true);
138151
const fileInputRef = useRef<HTMLInputElement>(null);
139152

140153
// Cache keys for localStorage
@@ -150,6 +163,7 @@ const PersonalizationPage = () => {
150163
fetchPingSettings();
151164
fetchMemorySettings();
152165
fetchProfileDialogSettings();
166+
fetchBandwidthSettings();
153167
}, []);
154168

155169
const loadCachedImage = () => {
@@ -1111,6 +1125,114 @@ const PersonalizationPage = () => {
11111125
}
11121126
};
11131127

1128+
// Bandwidth monitoring settings functions
1129+
const fetchBandwidthSettings = async () => {
1130+
try {
1131+
setIsBandwidthLoading(true);
1132+
const response = await fetch(
1133+
"/cgi-bin/quecmanager/settings/bandwidth_settings.sh"
1134+
);
1135+
const data: BandwidthSettingsResponse = await response.json();
1136+
1137+
if (data.status === "success" && data.data) {
1138+
setBandwidthEnabled(data.data.enabled);
1139+
setIsBandwidthDefault(data.data.isDefault);
1140+
}
1141+
} catch (error) {
1142+
console.error("Error fetching bandwidth settings:", error);
1143+
toast({
1144+
title: "Error",
1145+
description: "Failed to load bandwidth monitoring settings.",
1146+
variant: "destructive",
1147+
});
1148+
} finally {
1149+
setIsBandwidthLoading(false);
1150+
}
1151+
};
1152+
1153+
const updateBandwidthSettings = async (enabled: boolean) => {
1154+
try {
1155+
setIsBandwidthLoading(true);
1156+
const response = await fetch(
1157+
"/cgi-bin/quecmanager/settings/bandwidth_settings.sh",
1158+
{
1159+
method: "POST",
1160+
headers: {
1161+
"Content-Type": "application/json",
1162+
},
1163+
body: JSON.stringify({ enabled }),
1164+
}
1165+
);
1166+
const data: BandwidthSettingsResponse = await response.json();
1167+
1168+
if (data.status === "success") {
1169+
setBandwidthEnabled(enabled);
1170+
setIsBandwidthDefault(false);
1171+
toast({
1172+
title: "Setting Updated",
1173+
description: `Live bandwidth monitoring has been ${
1174+
enabled ? "enabled" : "disabled"
1175+
}.`,
1176+
});
1177+
1178+
// Dispatch custom event to notify bandwidth card of the change
1179+
window.dispatchEvent(new CustomEvent("bandwidthSettingsUpdated"));
1180+
} else {
1181+
throw new Error(
1182+
data.message || "Failed to update bandwidth settings"
1183+
);
1184+
}
1185+
} catch (error) {
1186+
console.error("Error updating bandwidth settings:", error);
1187+
toast({
1188+
title: "Update Failed",
1189+
description: error instanceof Error ? error.message : "Unknown error",
1190+
variant: "destructive",
1191+
});
1192+
} finally {
1193+
setIsBandwidthLoading(false);
1194+
}
1195+
};
1196+
1197+
const resetBandwidthSettings = async () => {
1198+
try {
1199+
setIsBandwidthLoading(true);
1200+
const response = await fetch(
1201+
"/cgi-bin/quecmanager/settings/bandwidth_settings.sh",
1202+
{
1203+
method: "DELETE",
1204+
}
1205+
);
1206+
const data: BandwidthSettingsResponse = await response.json();
1207+
1208+
if (data.status === "success" && data.data) {
1209+
setBandwidthEnabled(data.data.enabled);
1210+
setIsBandwidthDefault(true);
1211+
toast({
1212+
title: "Setting Reset",
1213+
description:
1214+
"Bandwidth monitoring reset to system default (enabled).",
1215+
});
1216+
1217+
// Dispatch custom event to notify bandwidth card of the change
1218+
window.dispatchEvent(new CustomEvent("bandwidthSettingsUpdated"));
1219+
} else {
1220+
throw new Error(
1221+
data.message || "Failed to reset bandwidth settings"
1222+
);
1223+
}
1224+
} catch (error) {
1225+
console.error("Error resetting bandwidth settings:", error);
1226+
toast({
1227+
title: "Reset Failed",
1228+
description: error instanceof Error ? error.message : "Unknown error",
1229+
variant: "destructive",
1230+
});
1231+
} finally {
1232+
setIsBandwidthLoading(false);
1233+
}
1234+
};
1235+
11141236
return (
11151237
<div className="container mx-auto p-6 max-w-4xl">
11161238
<div className="mb-6">
@@ -1573,6 +1695,53 @@ const PersonalizationPage = () => {
15731695
</div>
15741696
)}
15751697
</div>
1698+
1699+
<div className="grid w-full max-w-sm items-center gap-2">
1700+
<Label htmlFor="BandwidthSettings">Live Bandwidth Monitoring</Label>
1701+
{isBandwidthLoading ? (
1702+
<Skeleton className="h-8" />
1703+
) : (
1704+
<div className="flex flex-col gap-2">
1705+
<div className="flex flex-row gap-2 items-center">
1706+
<Select
1707+
disabled={isBandwidthLoading}
1708+
value={bandwidthEnabled ? "enabled" : "disabled"}
1709+
onValueChange={(value: string) =>
1710+
updateBandwidthSettings(value === "enabled")
1711+
}
1712+
>
1713+
<SelectTrigger className="w-full">
1714+
<SelectValue>
1715+
{bandwidthEnabled ? "Enabled" : "Disabled"}
1716+
</SelectValue>
1717+
</SelectTrigger>
1718+
<SelectContent>
1719+
<SelectGroup>
1720+
<SelectLabel>Bandwidth Monitoring</SelectLabel>
1721+
<SelectItem value="enabled">
1722+
Enable live bandwidth
1723+
</SelectItem>
1724+
<SelectItem value="disabled">
1725+
Disable live bandwidth
1726+
</SelectItem>
1727+
</SelectGroup>
1728+
</SelectContent>
1729+
</Select>
1730+
<Button
1731+
variant="outline"
1732+
size="icon"
1733+
disabled={isBandwidthLoading || isBandwidthDefault}
1734+
onClick={resetBandwidthSettings}
1735+
>
1736+
<Undo2Icon className="h-4 w-4" />
1737+
</Button>
1738+
</div>
1739+
</div>
1740+
)}
1741+
<p className="text-sm text-muted-foreground">
1742+
Controls whether the device measures live network bandwidth.
1743+
</p>
1744+
</div>
15761745
</div>
15771746
</div>
15781747
</CardContent>

0 commit comments

Comments
 (0)