Skip to content
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
20 changes: 14 additions & 6 deletions src/stores/connectivity/bluetooth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function createBluetoothPageState(active: Accessor<boolean>): BluetoothPa
};

const discover = () => {
if (!adapter) return;
if (!adapter || !bluetooth.is_powered) return;

updateError('');
stopDiscovery();
Expand All @@ -156,6 +156,16 @@ export function createBluetoothPageState(active: Accessor<boolean>): BluetoothPa
}
};

const syncDiscovery = () => {
if (active.peek() && bluetooth.is_powered) {
discover();
return;
}

updateError('');
stopDiscovery();
};

const connectDevice = async (device: Bluetooth.Device) => {
updateError('');
try {
Expand Down Expand Up @@ -199,13 +209,11 @@ export function createBluetoothPageState(active: Accessor<boolean>): BluetoothPa
bluetooth.connect('notify::devices', refreshDevices),
bluetooth.connect('device-added', refreshDevices),
bluetooth.connect('device-removed', refreshDevices),
bluetooth.connect('notify::is-powered', syncDiscovery),
];
const unsubscribeActive = active.subscribe(() => {
if (active.peek()) discover();
else stopDiscovery();
});
const unsubscribeActive = active.subscribe(syncDiscovery);

if (active.peek()) discover();
syncDiscovery();
refreshDevices();

onCleanup(() => {
Expand Down
47 changes: 35 additions & 12 deletions src/stores/connectivity/wifiPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ export interface WifiPageState {
setError: (message: string) => void;
}

function isAuthenticationFailure(reason: NM.DeviceStateReason) {
return [
NM.DeviceStateReason.NO_SECRETS,
NM.DeviceStateReason.SUPPLICANT_DISCONNECT,
NM.DeviceStateReason.SUPPLICANT_CONFIG_FAILED,
NM.DeviceStateReason.SUPPLICANT_FAILED,
NM.DeviceStateReason.SUPPLICANT_TIMEOUT,
].includes(reason);
}

export function createWifiPageState(monitorConnector: string): WifiPageState {
const network = Network.get_default();
const wifi = network.wifi;
Expand Down Expand Up @@ -181,19 +191,32 @@ export function createWifiPageState(monitorConnector: string): WifiPageState {
]
: [];
const deviceHook = wifi
? wifi.device.connect('state-changed', (_device, state: NM.DeviceState) => {
const pending = pendingAccessPoint;
if (!pending) return;
if (state === NM.DeviceState.ACTIVATED) {
pendingAccessPoint = null;
} else if (state === NM.DeviceState.NEED_AUTH || state === NM.DeviceState.FAILED) {
pendingAccessPoint = null;
retryAccessPoint = pending;
setError(
`Could not connect to ${pending.ssid || 'this network'}. Enter the password and retry.`
);
? wifi.device.connect(
'state-changed',
(
_device,
state: NM.DeviceState,
_oldState: NM.DeviceState,
reason: NM.DeviceStateReason
) => {
const pending = pendingAccessPoint;
if (!pending) return;
if (state === NM.DeviceState.ACTIVATED) {
pendingAccessPoint = null;
} else if (state === NM.DeviceState.FAILED) {
pendingAccessPoint = null;
if (pending.requires_password && isAuthenticationFailure(reason)) {
retryAccessPoint = pending;
setError(
`Could not connect to ${pending.ssid || 'this network'}. Enter the password and retry.`
);
} else {
retryAccessPoint = null;
setError(`Could not connect to ${pending.ssid || 'this network'}.`);
}
}
Comment on lines +204 to +217
}
})
)
: null;

if (wifi) scan();
Expand Down