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: improve network provider error handling #44

Merged
merged 5 commits into from
Jun 20, 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
124 changes: 43 additions & 81 deletions packages/client-api/src/providers/network/create-network-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,52 @@ import type { NetworkProviderConfig } from '~/user-config';
import { createProviderListener } from '../create-provider-listener';

export interface NetworkVariables {
defaultInterface: NetworkInterface;
defaultGateway: Gateway;
defaultInterface: NetworkInterface | null;
defaultGateway: NetworkGateway | null;
interfaces: NetworkInterface[];
}

export interface NetworkInterface {
name: string;
friendlyName: string | null;
description: string | null;
type: InterfaceType;
ipv4Addresses: string[];
ipv6Addresses: string[];
macAddress: string | null;
transmitSeed: number | null;
receiveSpeed: number | null;
dnsServers: string[];
isDefault: boolean;
}

export interface NetworkGateway {
macAddress: string;
ipv4Addresses: string[];
ipv6Addresses: string[];
ssid: string | null;
signalStrength: number | null;
}

export enum InterfaceType {
UNKNOWN = 'unknown',
ETHERNET = 'ethernet',
TOKEN_RING = 'token_ring',
FDDI = 'fddi',
PPP = 'ppp',
LOOPBACK = 'loopback',
SLIP = 'slip',
ATM = 'atm',
GENERIC_MODEM = 'generic_modem',
ISDN = 'isdn',
WIFI = 'wifi',
DSL = 'dsl',
TUNNEL = 'tunnel',
HIGH_PERFORMANCE_SERIAL_BUS = 'high_performance_serial_bus',
MOBILE_BROADBAND = 'mobile_broadband',
BRIDGE = 'bridge',
}

export async function createNetworkProvider(
config: NetworkProviderConfig,
owner: Owner,
Expand All @@ -30,82 +71,3 @@ export async function createNetworkProvider(
},
};
}

export interface NetworkInterface {
name: string;
friendlName: string;
description: string;
interfaceType: InterfaceType;
ipv4: Ipv4Net;
ipv6: Ipv6Net;
macAddress: MacAddress;
transmitSeed: number;
receiveSpeed: number;
dnsServers: (Ipv4Addr | Ipv6Addr)[];
default: boolean;
}

export interface Gateway {
macAddress: MacAddress;
ipv4: Ipv4Addr[];
ipv6: Ipv6Addr[];
ssid: string;
signal_strength: number;
connected: boolean;
}

enum InterfaceType {
Unknown,
Ethernet,
TokenRing,
Fddi,
BasicIsdn,
PrimaryIsdn,
Ppp,
Loopback,
Ethernet3Megabit,
Slip,
Atm,
GenericModem,
FastEthernetT,
Isdn,
FastEthernetFx,
Wireless80211,
AsymmetricDsl,
RateAdaptDsl,
SymmetricDsl,
VeryHighSpeedDsl,
IPOverAtm,
GigabitEthernet,
Tunnel,
MultiRateSymmetricDsl,
HighPerformanceSerialBus,
Wman,
Wwanpp,
Wwanpp2,
Bridge,
}

interface Ipv4Net {
addr: Ipv4Addr;
netmask: Ipv4Addr;
prefixLength: number;
}

interface Ipv6Net {
addr: Ipv6Addr;
netmask: Ipv6Addr;
prefixLength: number;
}

interface Ipv6Addr {
octects: number[];
}

interface Ipv4Addr {
octects: number[];
}

interface MacAddress {
octects: number[];
}
21 changes: 11 additions & 10 deletions packages/desktop/resources/sample-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,19 @@ window/bar:
template/network:
providers: ['network']
template: |
<!-- Ethernet is currently untested and may need to be adjusted. -->
<!-- Show icon based on signal strength. -->
@if (network.defaultInterface.type === 'Ethernet') {
@if (network.defaultGateway.isConnected !== true) { <i class="nf-md-ethernet_off"></i> }
@else { <i class="nf-md-ethernet_cable"></i> }
@if (network.defaultInterface?.type === 'ethernet') {
<i class="nf nf-md-ethernet_cable"></i>
} @else if (network.defaultInterface?.type === 'wifi') {
@if (network.defaultGateway?.signalStrength >= 80) { <i class="nf nf-md-wifi_strength_4"></i> }
@else if (network.defaultGateway?.signalStrength >= 65) { <i class="nf nf-md-wifi_strength_3"></i> }
@else if (network.defaultGateway?.signalStrength >= 40) { <i class="nf nf-md-wifi_strength_2"></i> }
@else if (network.defaultGateway?.signalStrength >= 25) { <i class="nf nf-md-wifi_strength_1"></i> }
@else { <i class="nf-md-wifi_strength_outline"></i> }
{{ network.defaultGateway?.ssid }}
} @else {
<i class="nf nf-md-wifi_strength_off_outline"></i>
}
@else if (network.defaultGateway.isConnected !== true) { <i class="nf-md-wifi_strength_off_outline"></i> }
@else if (network.defaultGateway.signalStrengthPercent >= 80) { <i class="nf-md-wifi_strength_4"></i> }
@else if (network.defaultGateway.signalStrengthPercent >= 65) { <i class="nf-md-wifi_strength_3"></i> }
@else if (network.defaultGateway.signalStrengthPercent >= 40) { <i class="nf-md-wifi_strength_2"></i> }
@else if (network.defaultGateway.signalStrengthPercent >= 25) { <i class="nf-md-wifi_strength_1"></i> }
@else { <i class="nf-md-wifi_strength_outline"></i> }

template/memory:
providers: ['memory']
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/src/providers/network/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod config;
mod provider;
mod variables;
mod parse_netsh;
mod wifi_hotspot;

pub use config::*;
pub use provider::*;
Expand Down
61 changes: 0 additions & 61 deletions packages/desktop/src/providers/network/parse_netsh.rs

This file was deleted.

Loading
Loading