Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) Fix network issues #1320

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions rust/agama-server/src/network/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ async fn connect(
.await
.map_err(|_| NetworkError::CannotApplyConfig)?;

state
.network
.apply()
.await
.map_err(|_| NetworkError::CannotApplyConfig)?;

Ok(StatusCode::NO_CONTENT)
}

Expand All @@ -341,6 +347,12 @@ async fn disconnect(
.await
.map_err(|_| NetworkError::CannotApplyConfig)?;

state
.network
.apply()
.await
.map_err(|_| NetworkError::CannotApplyConfig)?;

Ok(StatusCode::NO_CONTENT)
}

Expand Down
4 changes: 2 additions & 2 deletions web/src/client/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class NetworkClient {
* @param {Connection} connection - connection to be activated
*/
async connectTo(connection) {
return this.client.get(`/network/${connection.id}/connect`);
return this.client.get(`/network/connections/${connection.id}/connect`);
}

/**
Expand All @@ -234,7 +234,7 @@ class NetworkClient {
* @param {Connection} connection - connection to be activated
*/
async disconnect(connection) {
return this.client.get(`/network/${connection.id}/disconnect`);
return this.client.get(`/network/connections/${connection.id}/disconnect`);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/network/WifiNetworkListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function WifiNetworkListItem({ network, isSelected, isActive, onSelect, onCancel
{networkState(network.device?.state)}
</Text>
{network.settings &&
<WifiNetworkMenu settings={network.settings} />}
<WifiNetworkMenu settings={network.settings} device={network.device} onConnect={onSelect} />}
</Split>
</Flex>
{isSelected && (!network.settings || network.error) &&
Expand Down
23 changes: 22 additions & 1 deletion web/src/components/network/WifiNetworkMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const KebabToggle = ({ toggleRef, onClick }) => (
</MenuToggle>
);

export default function WifiNetworkMenu({ settings, position = "right" }) {
export default function WifiNetworkMenu({ settings, position = "right", device, onConnect }) {
const client = useInstallerClient();
const [isOpen, setIsOpen] = useState(false);
const toggle = () => setIsOpen(!isOpen);
Expand All @@ -45,6 +45,27 @@ export default function WifiNetworkMenu({ settings, position = "right" }) {
position={position}
>
<DropdownList>
{!device &&
<DropdownItem
key="connect"
onClick={async () => {
await client.network.connectTo(settings);
onConnect();
}}
icon={<Icon name="delete" size="s" />}
>
{/* TRANSLATORS: menu label, connect to the selected WiFi network */}
{_("Connect")}
</DropdownItem>}
{device &&
<DropdownItem
key="discconnect"
onClick={async () => await client.network.disconnect(settings)}
icon={<Icon name="delete" size="s" />}
>
{/* TRANSLATORS: menu label, disconnect from the selected WiFi network */}
{_("Disconnect")}
</DropdownItem>}
<DropdownItem
isDanger
key="forget-network"
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/network/WifiSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function WifiSelector({ isOpen = false, onClose }) {

case NetworkEventTypes.DEVICE_UPDATED: {
const [name, data] = payload;
if (data.state === "failed") {
if (data.state === "failed" && selectedNetwork) {
selectedNetwork.error = "Failed";
}
setDevices(devs => {
Expand Down Expand Up @@ -139,7 +139,7 @@ function WifiSelector({ isOpen = false, onClose }) {
onSelectionCallback={(network) => {
switchSelectedNetwork(network);
if (network.settings && !network.device) {
client.network.connectTo(network.settings);
client.connectTo(network.settings);
}
}}
onCancelSelectionCallback={() => switchSelectedNetwork(activeNetwork)}
Expand Down
Loading