Skip to content

Commit

Permalink
feat: correct variable naming
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Mar 18, 2024
1 parent b49fe0b commit adeadff
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 92 deletions.
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/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct NetworkGateway {
}

#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
#[serde(rename_all = "snake_case")]
pub enum InterfaceType {
Unknown,
Ethernet,
Expand Down

0 comments on commit adeadff

Please sign in to comment.