mirror of https://github.com/espruino/BangleApps
added the disconnect button
parent
d18ce375ad
commit
6ddf112b01
7
comms.js
7
comms.js
|
@ -64,6 +64,13 @@ setTime : () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
disconnectDevice: () => {
|
||||||
|
var connection = Puck.getConnection();
|
||||||
|
|
||||||
|
if (!connection) return;
|
||||||
|
|
||||||
|
connection.close();
|
||||||
|
},
|
||||||
watchConnectionChange : cb => {
|
watchConnectionChange : cb => {
|
||||||
var connected = Puck.isConnected();
|
var connected = Puck.isConnected();
|
||||||
|
|
||||||
|
|
23
index.js
23
index.js
|
@ -250,24 +250,35 @@ function refreshMyApps() {
|
||||||
function getInstalledApps() {
|
function getInstalledApps() {
|
||||||
showLoadingIndicator();
|
showLoadingIndicator();
|
||||||
// Get apps
|
// Get apps
|
||||||
Comms.getInstalledApps().then(appIDs => {
|
return Comms.getInstalledApps().then(appIDs => {
|
||||||
appsInstalled = appIDs;
|
appsInstalled = appIDs;
|
||||||
handleConnectionChange(true);
|
handleConnectionChange(true);
|
||||||
refreshMyApps();
|
refreshMyApps();
|
||||||
refreshLibrary();
|
refreshLibrary();
|
||||||
}).catch(err => {
|
|
||||||
showToast("Getting app list failed, "+err,"error");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var connectMyDeviceBtn = document.getElementById("connectmydevice");
|
var connectMyDeviceBtn = document.getElementById("connectmydevice");
|
||||||
|
|
||||||
function handleConnectionChange(connected) {
|
function handleConnectionChange(connected) {
|
||||||
connectMyDeviceBtn.style.display = connected ? 'none' : '';
|
connectMyDeviceBtn.textContent = connected ? 'Disconnect' : 'Connect';
|
||||||
|
connectMyDeviceBtn.classList.toggle('is-connected', connected);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("myappsrefresh").addEventListener("click", getInstalledApps);
|
document.getElementById("myappsrefresh").addEventListener("click", () => {
|
||||||
connectMyDeviceBtn.addEventListener("click", getInstalledApps);
|
getInstalledApps().catch(err => {
|
||||||
|
showToast("Getting app list failed, "+err,"error");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
connectMyDeviceBtn.addEventListener("click", () => {
|
||||||
|
if (connectMyDeviceBtn.classList.contains('is-connected')) {
|
||||||
|
Comms.disconnectDevice();
|
||||||
|
} else {
|
||||||
|
getInstalledApps().catch(err => {
|
||||||
|
showToast("Device connection failed, "+err,"error");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
Comms.watchConnectionChange(handleConnectionChange);
|
Comms.watchConnectionChange(handleConnectionChange);
|
||||||
|
|
||||||
// =========================================== About
|
// =========================================== About
|
||||||
|
|
Loading…
Reference in New Issue