added the disconnect button

pull/27/head
gdorsi 2019-11-12 15:41:03 +01:00
parent d18ce375ad
commit 6ddf112b01
2 changed files with 24 additions and 6 deletions

View File

@ -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();

View File

@ -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