mirror of https://github.com/espruino/BangleApps
update the connection button at every connection change
parent
2d702859fa
commit
d18ce375ad
16
comms.js
16
comms.js
|
@ -63,5 +63,21 @@ setTime : () => {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
watchConnectionChange : cb => {
|
||||||
|
var connected = Puck.isConnected();
|
||||||
|
|
||||||
|
//TODO Switch to an event listener when Puck will support it
|
||||||
|
var interval = setInterval(() => {
|
||||||
|
if (connected === Puck.isConnected()) return;
|
||||||
|
|
||||||
|
connected = Puck.isConnected();
|
||||||
|
cb(connected);
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
//stop watching
|
||||||
|
return () => {
|
||||||
|
clearInterval(interval);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
<!-- <a href="#" class="btn btn-link">...</a> -->
|
<!-- <a href="#" class="btn btn-link">...</a> -->
|
||||||
</section>
|
</section>
|
||||||
<section class="navbar-section">
|
<section class="navbar-section">
|
||||||
<button class="btn" id="connectmydevice" style="text-align: right;">Connect</button>
|
<button class="btn" id="connectmydevice">Connect</button>
|
||||||
</section>
|
</section>
|
||||||
<!--<section class="navbar-section">
|
<!--<section class="navbar-section">
|
||||||
<div class="input-group input-inline">
|
<div class="input-group input-inline">
|
||||||
|
|
11
index.js
11
index.js
|
@ -247,14 +247,12 @@ function refreshMyApps() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var connectMyDeviceBtn = document.getElementById("connectmydevice");
|
|
||||||
|
|
||||||
function getInstalledApps() {
|
function getInstalledApps() {
|
||||||
showLoadingIndicator();
|
showLoadingIndicator();
|
||||||
// Get apps
|
// Get apps
|
||||||
Comms.getInstalledApps().then(appIDs => {
|
Comms.getInstalledApps().then(appIDs => {
|
||||||
appsInstalled = appIDs;
|
appsInstalled = appIDs;
|
||||||
connectMyDeviceBtn.style.display = 'none';
|
handleConnectionChange(true);
|
||||||
refreshMyApps();
|
refreshMyApps();
|
||||||
refreshLibrary();
|
refreshLibrary();
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
|
@ -262,8 +260,15 @@ function getInstalledApps() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var connectMyDeviceBtn = document.getElementById("connectmydevice");
|
||||||
|
|
||||||
|
function handleConnectionChange(connected) {
|
||||||
|
connectMyDeviceBtn.style.display = connected ? 'none' : '';
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById("myappsrefresh").addEventListener("click", getInstalledApps);
|
document.getElementById("myappsrefresh").addEventListener("click", getInstalledApps);
|
||||||
connectMyDeviceBtn.addEventListener("click", getInstalledApps);
|
connectMyDeviceBtn.addEventListener("click", getInstalledApps);
|
||||||
|
Comms.watchConnectionChange(handleConnectionChange);
|
||||||
|
|
||||||
// =========================================== About
|
// =========================================== About
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue