Added Util.close to allow interfaces to close the window

Fix My Location that couldn't be installed after the most recent update
pull/2297/head
Gordon Williams 2022-11-25 09:42:25 +00:00
parent adcee06813
commit f4a48e62e6
5 changed files with 36 additions and 11 deletions

View File

@ -6,3 +6,4 @@
0.06: renamed source files to match standard
0.07: Move mylocation app into 'Settings -> Apps'
0.08: Allow setting location from webinterface in the AppLoader
0.09: Fix web interface so app can be installed (replaced custom with interface html)

View File

@ -1,8 +1,13 @@
# My Location
*Sets and stores GPS lat and lon of your preferred city*
*Sets and stores GPS lat and lon of your preferred city*
To access, go to `Settings -> Apps -> My Location`
To access, you have two options:
**In the App Loader** once My Location is installed, click on the 'Save' icon
next to it - and you can choose your location on a map.
**On Bangle.js** go to `Settings -> Apps -> My Location`
* Select one of the preset Cities, setup through the GPS or use the webinterface from the AppLoader
* Other Apps can read this information to do calculations based on location

View File

@ -33,10 +33,11 @@
<div id="map">
</div>
<div id="controls">
<span id="select-hint">Click the map to select a location</span>
<button id="select" class="btn btn-primary" style="display:none">Save</button><br/>
</div>
<script src="../../core/lib/customize.js"></script>
<script src="../../core/lib/interface.js"></script>
<script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="../../webtools/heatshrink.js"></script>
@ -68,15 +69,19 @@
let latlon;
var marker;
map.on('click', function(e){
console.log(e);
function setPosition(ll) {
latlon = ll;
if (map.hasLayer(marker)) {
map.removeLayer(marker);
}
latlon = e.latlng;
marker = new L.marker(e.latlng).addTo(map);
marker = new L.marker(latlon).addTo(map);
document.getElementById("select-hint").style.display="none";
document.getElementById("select").style.display="";
}
map.on('click', function(e){
setPosition(e.latlng);
});
document.getElementById("select").addEventListener("click", function() {
@ -87,9 +92,23 @@
Util.showModal("Saving...");
Util.writeStorage("mylocation.json", JSON.stringify(settings), ()=>{
Util.hideModal();
Util.close(); // close this window
});
});
function onInit() {
// read existing location
Util.readStorage("mylocation.json", function(data) {
if (data===undefined) return; // no file
try {
var j = JSON.parse(data);
setPosition(j);
} catch (e) {
console.error(e);
}
});
}
</script>
</body>
</html>

View File

@ -4,12 +4,12 @@
"icon": "app.png",
"type": "settings",
"screenshots": [{"url":"screenshot_1.png"}],
"version":"0.08",
"version":"0.09",
"description": "Sets and stores the latitude and longitude of your preferred City. It can be set from GPS or webinterface. `mylocation.json` can be used by other apps that need your main location. See README for details.",
"readme": "README.md",
"tags": "tool,utility",
"supports": ["BANGLEJS", "BANGLEJS2"],
"custom": "custom.html","custom": "custom.html",
"interface": "interface.html",
"storage": [
{"name":"mylocation.settings.js","url":"settings.js"}
],

2
core

@ -1 +1 @@
Subproject commit db08367e0a2c25040449a4b556eaed459e8f47fc
Subproject commit aba9b6a51fe02dfbde307c303560b8382857916d