Release Vulpes OS 2.7 Preview 25 for Desktop, Android and Pixel 3a
This commit is contained in:
parent
6a44daeaaa
commit
3a1fba4efe
1 changed files with 1301 additions and 196 deletions
|
|
@ -19,24 +19,31 @@
|
|||
emit(enabled ? 'enabled' : 'disabled');
|
||||
if (!enabled) update(null);
|
||||
}
|
||||
function update(network) {
|
||||
const status = network ? 'connected' : 'disconnected';
|
||||
let pendingNetwork = null;
|
||||
function update(network, status = network ? 'connected' : 'disconnected') {
|
||||
const changed = manager.connection.status !== status || manager.connection.network?.ssid !== network?.ssid;
|
||||
manager.connection = {status, network};
|
||||
manager.connectionInformation = network ? {...connectionInfo,relSignalStrength:network.relSignalStrength} : null;
|
||||
manager.connectionInformation = status === 'connected' && network ? {...connectionInfo,relSignalStrength:network.relSignalStrength} : null;
|
||||
if (changed) emit('statuschange', manager.connection);
|
||||
// Gaia's signal listeners require the associated network. A scan while
|
||||
// disconnected must not announce connection information for a missing AP.
|
||||
if (network) emit('connectioninfoupdate', {network, ...manager.connectionInformation});
|
||||
if (manager.connectionInformation) emit('connectioninfoupdate', {network, ...manager.connectionInformation});
|
||||
}
|
||||
function applyState(state) {
|
||||
power(state.enabled === true);
|
||||
manager.macAddress=state.macAddress || manager.macAddress;
|
||||
if (state.state) {
|
||||
connectionInfo=state.connectionInformation || {};
|
||||
if (state.enabled && (state.state === 'connecting' || (pendingNetwork && state.state === 'disconnected'))) {
|
||||
const target = state.network;
|
||||
const network = target ? {ssid:target.ssid, security:securityTypes(target.security)} : pendingNetwork;
|
||||
if (network) update(network, 'connecting');
|
||||
return;
|
||||
}
|
||||
const network=state.state==='connected' && state.network;
|
||||
update(network ? {
|
||||
...networks.find(n=>n.ssid===network.ssid),ssid:network.ssid,
|
||||
...networks.find(n => network.id ? n.vulpesId === network.id : n.connected && n.ssid === network.ssid),
|
||||
ssid:network.ssid,
|
||||
security:securityTypes(network.security),
|
||||
relSignalStrength:network.signal,savedId:network.savedId,connected:true
|
||||
} : null);
|
||||
|
|
@ -56,7 +63,8 @@
|
|||
networks = result.networks.map(n => ({ssid:n.ssid, relSignalStrength:n.signal,
|
||||
security:securityTypes(n.security),
|
||||
known:n.known === true, connected:n.connected, vulpesId:n.id, savedId:n.savedId}));
|
||||
update(networks.find(n => n.connected) || null);
|
||||
if (result.state) applyState(result);
|
||||
else if (!pendingNetwork) update(networks.find(n => n.connected) || null);
|
||||
return networks;
|
||||
}
|
||||
manager.getNetworks = () => request(scan());
|
||||
|
|
@ -68,8 +76,19 @@
|
|||
manager.associate = network => request((async () => {
|
||||
const security=(network.security || []).filter(Boolean);
|
||||
if (security.length && security[0] !== 'WPA-PSK') throw Error('WIFI_UNSUPPORTED_SECURITY');
|
||||
await call('platform.wifi',network.hidden ? {operation:'connectHidden',ssid:network.ssid,security:security.length?'wpa-psk':'open',password:network.psk || ''} : {operation:'connect',id:network.vulpesId,password:network.psk || ''});
|
||||
await scan(); return network;
|
||||
if (pendingNetwork) throw Error('WIFI_BUSY');
|
||||
pendingNetwork = {ssid:network.ssid, security};
|
||||
update(pendingNetwork, 'connecting');
|
||||
try {
|
||||
await call('platform.wifi',network.hidden ? {operation:'connectHidden',ssid:network.ssid,security:security.length?'wpa-psk':'open',password:network.psk || ''} : {operation:'connect',id:network.vulpesId || network.savedId,password:network.psk || ''});
|
||||
} catch (error) {
|
||||
update(null);
|
||||
throw error;
|
||||
} finally {
|
||||
pendingNetwork = null;
|
||||
}
|
||||
applyState(await call('platform.wifi',{operation:'status'}));
|
||||
return network;
|
||||
})());
|
||||
manager.forget = network => request(call('platform.wifi',{operation:'forget',id:network.savedId}).then(()=>scan()));
|
||||
const unsupported = () => request(Promise.reject(new DOMException('Not supported by this adapter','NotSupportedError')));
|
||||
|
|
@ -161,14 +180,24 @@
|
|||
}
|
||||
window.VulpesWifiSettings={panels:{hotspot:hotspotPanel},dialogs:{'hotspot-wifiSettings':hotspotDialog}};
|
||||
}
|
||||
addEventListener('DOMContentLoaded', async () => {
|
||||
let retryTimer, closed = false;
|
||||
addEventListener('pagehide', () => { closed = true; clearTimeout(retryTimer); }, {once:true});
|
||||
async function initialize() {
|
||||
let state;
|
||||
try {
|
||||
state = await call('platform.wifi',{operation:'status'});
|
||||
} catch (error) {
|
||||
// The WLAN driver may still be starting when Gaia opens.
|
||||
if (!closed) retryTimer = setTimeout(initialize, 5000);
|
||||
return;
|
||||
}
|
||||
if (closed) return;
|
||||
try {
|
||||
const state = await call('platform.wifi',{operation:'status'});
|
||||
applyState(state);
|
||||
if (location.hostname.startsWith('system.')) {
|
||||
let queue=Promise.resolve();
|
||||
navigator.mozSettings.addObserver('wifi.enabled', event => {
|
||||
const enabled=event.settingValue===true;
|
||||
let powerChanges = 0;
|
||||
function requestPower(enabled) {
|
||||
queue=queue.then(async () => {
|
||||
if(manager.enabled===enabled) {power(enabled,true);return;}
|
||||
try {
|
||||
|
|
@ -181,9 +210,18 @@
|
|||
await call('settings.set',{values:{'wifi.enabled':manager.enabled}});
|
||||
console.warn('Wi-Fi radio change failed',error);
|
||||
}
|
||||
});
|
||||
}).catch(error => console.warn('Wi-Fi settings synchronization failed', error));
|
||||
return queue;
|
||||
}
|
||||
navigator.mozSettings.addObserver('wifi.enabled', event => {
|
||||
powerChanges++;
|
||||
requestPower(event.settingValue === true);
|
||||
});
|
||||
await call('settings.set',{values:{'wifi.enabled':state.enabled}});
|
||||
const saved = await call('settings.get',{key:'wifi.enabled'});
|
||||
if (!powerChanges) {
|
||||
if (typeof saved?.value === 'boolean') await requestPower(saved.value);
|
||||
else await call('settings.set',{values:{'wifi.enabled':state.enabled}});
|
||||
}
|
||||
} else {
|
||||
navigator.mozSettings.addObserver('wifi.enabled', () => {
|
||||
call('platform.wifi',{operation:'status'}).then(applyState).catch(console.warn);
|
||||
|
|
@ -204,5 +242,6 @@
|
|||
}
|
||||
if(manager.enabled) await scan();
|
||||
} catch(error) { console.warn('Wi-Fi initialization failed',error); }
|
||||
}, {once:true});
|
||||
}
|
||||
addEventListener('DOMContentLoaded', initialize, {once:true});
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue