pulls device Fingerprint from Server, if watch does not have one
- adds debug switch, where 'downloads' instead of 'wgt-private' is used so that files prevail after a reinstall - watch saves a device fingerprint on the device itself - some minor code simplification -> future version of server should generate a UID and save to database
This commit is contained in:
122
js/app.js
122
js/app.js
@ -14,8 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
/* 'downloads' for debugging,
|
||||
* 'wgt-private' for any release */
|
||||
var STORAGE_SPACE = "downloads";
|
||||
var events = null;
|
||||
var deviceId = null;
|
||||
var deviceFingerprint = null;
|
||||
var eventsTimeStamp = 0;
|
||||
|
||||
(function() {
|
||||
@ -38,12 +42,18 @@ var eventsTimeStamp = 0;
|
||||
console.log(exc.message)
|
||||
}
|
||||
|
||||
if(dirfile == null)
|
||||
return null;
|
||||
// if file not existed, call callback with null
|
||||
if(dirfile == null) {
|
||||
callback(null)
|
||||
return;
|
||||
} else {
|
||||
|
||||
// if file was found, call callback with json
|
||||
dirfile.openStream("r", function(fs) {
|
||||
callback(JSON.parse(fs.read(dirfile.fileSize)));
|
||||
fs.close();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function onerror(e){
|
||||
@ -51,7 +61,7 @@ var eventsTimeStamp = 0;
|
||||
}
|
||||
|
||||
function onsuccessPermission(){
|
||||
tizen.filesystem.resolve("wgt-private", onsuccess, onerror, "rw");
|
||||
tizen.filesystem.resolve(STORAGE_SPACE, onsuccess, onerror, "rw");
|
||||
}
|
||||
|
||||
function onErrorPermission(e){
|
||||
@ -61,7 +71,7 @@ var eventsTimeStamp = 0;
|
||||
tizen.ppm.requestPermission("http://tizen.org/privilege/mediastorage", onsuccessPermission, onErrorPermission);
|
||||
}
|
||||
|
||||
function readJSON(path) {
|
||||
function readJSON() {
|
||||
/* - requests permission to view media storage
|
||||
* - resolves the file 'calendarevents'
|
||||
* - opens stream and reads entire file as json
|
||||
@ -70,25 +80,88 @@ var eventsTimeStamp = 0;
|
||||
getJsonFile("calendarevents", function(eventlist) {events = eventlist;});
|
||||
console.log(events);
|
||||
}
|
||||
|
||||
function getDeviceID() {
|
||||
// check if device id set already as global, if it is return
|
||||
if(deviceId != null)
|
||||
return;
|
||||
|
||||
// otherwise, check if there is a devicefingerprint file in wft-private
|
||||
getJsonFile("devicefingerprint", function(df) {deviceId = df;})
|
||||
// if there is, open it up and get your device ID from it
|
||||
|
||||
// otherwise, ask the longitude server for a device fingerprint file
|
||||
|
||||
function getNewFingerprintFromServer() {
|
||||
console.log("fingerprintfromserver");
|
||||
getFileFromServer("/devicefingerprint.json", function() {
|
||||
console.log("1");
|
||||
getJsonFile("devicefingerprint", function(df) {devicefingerprint = df; console.log(devicefingerprint)});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getDeviceFingerprint() {
|
||||
console.log("getfingerprint");
|
||||
// check if device id set already as global, if it is return
|
||||
if(deviceFingerprint != null)
|
||||
return;
|
||||
|
||||
// otherwise, check if there is a devicefingerprint file in wgt-private
|
||||
// if there is, open it up and get your device ID from it
|
||||
getJsonFile("devicefingerprint", function(df) {
|
||||
if(df != null) {
|
||||
deviceFingerprint = df;
|
||||
} else {
|
||||
// otherwise, ask the longitude server for a device fingerprint file
|
||||
getNewFingerprintFromServer();
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function getFileFromServer(route, callback) {
|
||||
var server = "https://longitudecalendar.com/"
|
||||
var downloadRequest = new tizen.DownloadRequest(server + route, STORAGE_SPACE);
|
||||
tizen.systeminfo.getPropertyValue('NETWORK', function(networkInfo) {
|
||||
if (networkInfo.networkType === 'NONE') {
|
||||
console.log('Network connection is not available.Download is not possible.');
|
||||
downloadRequest = null;
|
||||
}
|
||||
});
|
||||
|
||||
var listener = {
|
||||
/* When the download progresses (interval is platform-dependent) */
|
||||
onprogress: function(id, receivedSize, totalSize) {
|
||||
console.log('progress for id: ' + id);
|
||||
},
|
||||
|
||||
/* When the user pauses the download */
|
||||
onpaused: function(id) {
|
||||
console.log('Paused with id: ' + id);
|
||||
},
|
||||
|
||||
/* When the user cancels the download */
|
||||
oncanceled: function(id) {
|
||||
console.log('Canceled with id: ' + id);
|
||||
},
|
||||
|
||||
/* When the download is completed */
|
||||
oncompleted: function(id, fullPath) {
|
||||
console.log('Completed with id: ' + id + ', full path: ' + fullPath);
|
||||
callback();
|
||||
},
|
||||
|
||||
/* When the download fails */
|
||||
onfailed: function(id, error) {
|
||||
console.log('Failed with id: ' + id + ', error name: ' + error.name);
|
||||
}
|
||||
};
|
||||
downloadId = tizen.download.start(downloadRequest, listener);
|
||||
}
|
||||
function getJSON() {
|
||||
|
||||
/*if(deviceId == null)
|
||||
return;
|
||||
*/
|
||||
var downloadRequest = new tizen.DownloadRequest('https://longitudecalendar.com/userinfo/107971745944668140075/calendarevents.json', 'wgt-private');
|
||||
if(deviceFingerprint == null) {
|
||||
getDeviceFingerprint();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
console.log(deviceFingerprint);
|
||||
console.log(deviceFingerprint.deviceId);
|
||||
getFileFromServer("userinfo/" + deviceFingerprint.deviceId + "/calendarevents.json", readJSON);
|
||||
return true;
|
||||
|
||||
var downloadRequest = new tizen.DownloadRequest('https://longitudecalendar.com/userinfo/107971745944668140075/calendarevents.json', STORAGE_SPACE);
|
||||
tizen.systeminfo.getPropertyValue('NETWORK', function(networkInfo) {
|
||||
if (networkInfo.networkType === 'NONE') {
|
||||
console.log('Network connection is not available.Download is not possible.');
|
||||
@ -116,7 +189,7 @@ var eventsTimeStamp = 0;
|
||||
/* When the download is completed */
|
||||
oncompleted: function(id, fullPath) {
|
||||
console.log('Completed with id: ' + id + ', full path: ' + fullPath);
|
||||
readJSON(fullPath);
|
||||
readJSON();
|
||||
},
|
||||
|
||||
/* When the download fails */
|
||||
@ -390,7 +463,6 @@ var eventsTimeStamp = 0;
|
||||
// Draw the text for date
|
||||
// renderText(ctxContent, date, center.x, center.y + (watchRadius * 0.5), 25, "#999999");
|
||||
|
||||
console.log(events);
|
||||
if(events == null)
|
||||
return;
|
||||
|
||||
@ -454,8 +526,8 @@ var eventsTimeStamp = 0;
|
||||
var currentTime = d.getTime();
|
||||
if(eventsTimeStamp + offset_ms < currentTime){
|
||||
getJSON();
|
||||
eventsTimeStamp = currentTime;
|
||||
}
|
||||
eventsTimeStamp = currentTime;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -514,7 +586,7 @@ var eventsTimeStamp = 0;
|
||||
// Update the content of the watch every second
|
||||
setInterval(function() {
|
||||
drawWatchContent();
|
||||
updateCalendar(600000);
|
||||
updateCalendar(5000); //60000 -> 10 minutes
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user