background sycn and dashboard

This commit is contained in:
CodePoet80 committed 2021-05-28 18:18:43 -04:00
1 parent ea2c54fcf4
commit cbb507b4cb
22 files changed
+459 -118

No files matched your search

+37 -38
View File
@@ -5,6 +5,7 @@ var appModel = null;
var updaterModel = null;
var serviceModel = null;
var MainStageName = "main";
var InDockMode = false;
function AppAssistant() {
appModel = new AppModel();
@@ -22,17 +23,15 @@ AppAssistant.prototype.handleLaunch = function(params) {
appModel.LoadSettings();
Mojo.Log.info("settings now: " + JSON.stringify(appModel.AppSettingsCurrent));
/*
if (!appModel.AppSettingsCurrent["BackgroundUpdate"]) {
appModel.AppSettingsCurrent["BackgroundUpdate"] = "00:30:00";
appModel.AppSettingsCurrent["BackgroundUpdate"] = "00:05:00";
appModel.SaveSettings();
}
//Reset alarms
systemModel.ClearSystemAlarm("ShareSpace");
systemModel.ClearSystemAlarm("BackgroundDownload");
if (appModel.AppSettingsCurrent["BackgroundUpdate"] && appModel.AppSettingsCurrent["BackgroundUpdate"] != "" && appModel.AppSettingsCurrent["BackgroundUpdate"] != -1)
systemModel.SetSystemAlarmRelative("ShareSpace", appModel.AppSettingsCurrent["BackgroundUpdate"]);
*/
systemModel.SetSystemAlarmRelative("BackgroundDownload", appModel.AppSettingsCurrent["BackgroundUpdate"]);
if (!params || !params["action"]) {
var mainStage = this.controller.getStageProxy("main"); //get the proxy for the stage if it already exists (eg: app is currently open)
@@ -59,49 +58,49 @@ AppAssistant.prototype.handleLaunch = function(params) {
}.bind(this));
}
} else {
//this is an alarm launch
//TODO: Add Dashboard scene
this.handleParameterLaunch(params);
}
};
AppAssistant.prototype.handleParameterLaunch = function(params, stageController) {
AppAssistant.prototype.handleParameterLaunch = function(params) {
Mojo.Log.info("Launch params: " + JSON.stringify(params));
//Touch2Share Launch (goes to main)
if (params["sendDataToShare"]) {
Mojo.Log.info("Launch with Touch2Share request!");
systemModel.SendDataForTouch2Share(appModel.CurrentShareURL);
} else {
Mojo.Log.info("Launch with item request to be handled by Main scene...");
//Make sure the main scene is there
appModel.LaunchQuery = params;
stageController.swapScene({ transition: Mojo.Transition.crossFade, name: "main" });
}
}
/*
//This function will handle relaunching the app when an alarm goes off(see the device/alarm scene)
AppAssistant.prototype.handleLaunch = function(params) {
//Alarm Launch (goes to dashboard)
else if (params.action && params.action == "BackgroundDownload"){
Mojo.Log.info("Alarm launch for background sync...");
//TODO: Check if in Dock Mode (and remember)
systemModel.GetDisplayState(function(response) {
Mojo.Log.info("Called back from GetDisplayState with response: " + JSON.stringify(response));
InDockMode = false;
if (response && response.state == "on" && response.active == false) {
InDockMode = true;
systemModel.SetDisplayState("unlock");
systemModel.SetDisplayState("on");
}
appModel.ShowDownloaderStage();
}.bind(this));
}
//get the proxy for the stage in the event it already exists (eg: app is currently open)
var mainStage = this.controller.getStageProxy("");
Mojo.Log.info("Share space is Launching! Launch params: " + JSON.stringify(params));
//JustType or other (goes to main)
else {
Mojo.Log.info("Launch with item request to be handled by Main scene...");
appModel.LaunchQuery = params;
//if there was a search query, load with that
Mojo.Log.info("Launch params: " + JSON.stringify(params));
if (params) {
if (params["sendDataToShare"]) {
Mojo.Log.info("Launch with Touch2Share request!");
systemModel.SendDataForTouch2Share(appModel.CurrentShareURL);
} else {
Mojo.Log.info("Launch with item request to be handled by Main scene...");
appModel.LaunchQuery = params;
var mainStage = this.controller.getStageProxy(MainStageName);
if (mainStage) {
var stageController = this.controller.getStageController(MainStageName);
stageController.swapScene({ transition: Mojo.Transition.crossFade, name: MainStageName });
}
else {
var stageArguments = { name: MainStageName, lightweight: true };
this.controller.createStageWithCallback(stageArguments, function(stageController) {
stageController.pushScene(MainStageName);
}.bind(this));
}
}
//if the stage already exists then just bring it into focus
if (mainStage) {
var stageController = this.controller.getStageController("");
stageController.activate();
}
return;
};
*/
}
+8 -5
View File
@@ -100,6 +100,9 @@ DetailAssistant.prototype.activate = function(event) {
this.controller.get("divShareLinks").innerHTML = "• <a href='" + link + "'>View in Browser</a>";
this.controller.get("divShareLinks").innerHTML += " &nbsp;(<a href='javascript:this.doCopy(\"" + link + "\")'>Copy Link</a>)<br>";
}
if (appModel.AppSettingsCurrent["DebugMode"]) {
this.controller.get("divShareInfo").style.display = "block";
}
//Show actual content
if (appModel.LastShareSelected.contenttype == "application/json") {
@@ -110,14 +113,14 @@ DetailAssistant.prototype.activate = function(event) {
this.controller.get("divImageContent").innerHTML = "<img src='" + appModel.LastShareSelected.content + "' style='max-width:90%;'>";
}
Mojo.Controller.getAppController().showBanner({ messageText: 'Touch2Share Ready!', icon: 'images/notify.png' }, { source: 'notification' });
Mojo.Controller.getAppController().showBanner({ messageText: 'Touch2Share Ready!', icon: 'assets/notify.png' }, { source: 'notification' });
};
doCopy = function(link) {
Mojo.Log.info("Copy tapped for link " + link);
var stageController = Mojo.Controller.getAppController().getActiveStageController()
stageController.setClipboard(link);
Mojo.Controller.getAppController().showBanner({ messageText: 'Link copied!', icon: 'images/notify.png' }, { source: 'notification' });
Mojo.Controller.getAppController().showBanner({ messageText: 'Link copied!', icon: 'assets/notify.png' }, { source: 'notification' });
}
DetailAssistant.prototype.makeShareURLs = function(thumbUrl, type) {
@@ -156,7 +159,7 @@ DetailAssistant.prototype.handleCommand = function(event) {
var usePath = "sharespace/" + appModel.AppSettingsCurrent["Username"];
if (appModel.AppSettingsCurrent["UseCustomDownloadPath"] && appModel.AppSettingsCurrent["CustomDownloadPath"] != "")
usePath = appModel.AppSettingsCurrent["CustomDownloadPath"];
systemModel.DownloadFile(this.downloadLink, appModel.LastShareSelected.contenttype, usePath, appModel.LastShareSelected.guid);
systemModel.DownloadFile(this.downloadLink, appModel.LastShareSelected.contenttype, usePath, appModel.LastShareSelected.guid, true);
break;
}
}
@@ -191,11 +194,11 @@ DetailAssistant.prototype.handlePopupChoose = function(task, command) {
break;
case "do-copyLink":
stageController.setClipboard(this.downloadLink);
Mojo.Controller.getAppController().showBanner({ messageText: 'Link copied!', icon: 'images/notify.png' }, { source: 'notification' });
Mojo.Controller.getAppController().showBanner({ messageText: 'Link copied!', icon: 'assets/notify.png' }, { source: 'notification' });
break;
case "do-copyContent":
stageController.setClipboard(appModel.LastShareSelected.content);
Mojo.Controller.getAppController().showBanner({ messageText: 'Content copied!', icon: 'images/notify.png' }, { source: 'notification' });
Mojo.Controller.getAppController().showBanner({ messageText: 'Content copied!', icon: 'assets/notify.png' }, { source: 'notification' });
break;
}
}
+201
View File
@@ -0,0 +1,201 @@
/*
This alarm scene is used for Touchpads, which will only pretend to change settings if running in the background
Launching this scene forces the Touchpad to wake up to deal with presenting it, and when it does we have a good
chance of successfully changing the settings. We can then close this window. All the smarts for this are in stage assistant.
*/
var downloadMgrInt = null;
function DownloadAssistant(argFromPusher) {
this.passedArguments = argFromPusher;
this.downloadList = [];
}
DownloadAssistant.prototype.setup = function() {
Mojo.Log.info("Dashboard notification stage setup at " + new Date());
this.displayDashboard(Mojo.Controller.appInfo.title, "Checking for new shares...");
//Event handlers
Mojo.Event.listen(this.controller.get("dashboardinfo"), Mojo.Event.tap, this.handleTap.bind(this));
}
DownloadAssistant.prototype.activate = function(event) {
Mojo.Log.info("Dashboard activating!");
this.fetchShares();
}
DownloadAssistant.prototype.displayDashboard = function(title, message, count) {
var infoElement = this.controller.get("dashboardinfo");
var info = { title: title, message: message };
if (count) {
info.count = count;
info.showCount = "inline";
} else {
info.showCount = "none";
}
var renderedInfo = Mojo.View.render({ object: info, template: "download/item-info" });
infoElement.innerHTML = renderedInfo;
this.controller.getSceneScroller().mojo.revealTop(true);
}
DownloadAssistant.prototype.fetchShares = function() {
serviceModel.DoShareListRequest(appModel.AppSettingsCurrent["Username"], appModel.AppSettingsCurrent["Credential"], function(responseObj){
if (responseObj != null) {
if (responseObj.shares) {
//If we got a good looking response, find out what to download
Mojo.Log.info("Download dashboard ready to process share list: " + JSON.stringify(responseObj));
this.checkIfDownloadNeeded(appModel.AppSettingsCurrent["Username"], responseObj.shares, responseObj.accesslevel);
} else {
Mojo.Log.warn("Share list was empty in Download dashboard. Either there was no matching result, or there were server or connectivity problems.");
appModel.CloseNotificationStage();
}
} else {
Mojo.Log.error("No usable response from server while Download dashboard loading shares: " + response);
appModel.CloseNotificationStage();
}
}.bind(this), this.errorHandler.bind(this));
}
DownloadAssistant.prototype.checkIfDownloadNeeded = function(username, results, accessLevel) {
Mojo.Log.info("Determining which shares need to be downloaded...");
this.downloadList = [];
this.getFileListForUser(username, function(fileList) {
for (var i = 0; i < results.length; i++) {
if (results[i].guid) {
//Figure out what mimetype to use
if (results[i].contenttype == "image/jpeg")
ext = ".jpg";
else if (results[i].contenttype == "text/plain")
ext = ".txt";
else if (results[i].contenttype == "text/json")
ext = ".json";
else {
var ext = results[i].contenttype.split("/");
ext = ext[ext.length - 1];
ext = "." + ext;
}
var fileToCheck = results[i].guid + ext;
var found = false;
if (fileList.items) {
for (var f = 0;f < fileList.items.length;f ++){
if (fileList.items[f].name == fileToCheck) {
Mojo.Log.info("Already downloaded: " + fileToCheck);
found = true;
}
}
}
if (!found) {
var newURL = results[i].thumbnail;
newURL = newURL.replace("tthumb", "t");
newURL = newURL.replace("ithumb", "download");
Mojo.Log.info("Need to download: " + newURL);
this.downloadList.push(newURL);
var usePath = "sharespace/" + username;
if (appModel.AppSettingsCurrent["UseCustomDownloadPath"] && appModel.AppSettingsCurrent["CustomDownloadPath"] != "")
usePath = appModel.AppSettingsCurrent["CustomDownloadPath"];
systemModel.DownloadFile(newURL, results[i].contenttype, usePath, results[i].guid);
}
}
}
Mojo.Log.info("Files in download list: " + this.downloadList.length);
if (this.downloadList.length > 0) {
this.displayDashboard(Mojo.Controller.appInfo.title, "Downloading " + this.downloadList.length + " shares...");
} else {
this.displayDashboard(Mojo.Controller.appInfo.title, "No new shares to download.");
}
downloadMgrInt = this.controller.window.setInterval(function() {
this.checkDownloadManagerStatus();
}.bind(this), 1500);
}.bind(this));
}
DownloadAssistant.prototype.getFileListForUser = function(username, callback) {
if (callback)
callback.bind(this);
Mojo.Log.info("Asking FileMgr service for list of files");
this.controller.serviceRequest('palm://ca.canucksoftware.filemgr', {
method: 'listFiles',
parameters: {
path: "/media/internal/sharespace/" + username + "/",
},
onSuccess: callback,
onFailure: callback
});
}
DownloadAssistant.prototype.checkDownloadManagerStatus = function() {
if (this.downloadList.length > 0) {
Mojo.Log.warn("checking if download manager is done...");
this.controller.serviceRequest('palm://com.palm.downloadmanager/', {
method: 'listPending',
parameters: {},
onSuccess : function (response){
//Mojo.Log.info("List Pending success, results="+JSON.stringify(response));
if (response) {
if (response.count && response.count > 0) {
Mojo.Log.info("Remaining downloads: " + response.count);
this.displayDashboard(Mojo.Controller.appInfo.title, "Downloading " + response.count + " shares...");
} else {
Mojo.Log.info("Download Manager completed all downloads!");
this.controller.window.clearInterval(downloadMgrInt);
if (InDockMode)
systemModel.SetDisplayState("dock");
appModel.CloseDashboardStageByName("download");
}
} else {
Mojo.Log.error("List response failure");
this.controller.window.clearInterval(downloadMgrInt);
appModel.CloseDashboardStageByName("download");
}
}.bind(this),
onFailure : function (e){
Mojo.Log.error("List Pending failure, results="+JSON.stringify(e));
this.controller.window.clearInterval(downloadMgrInt);
appModel.CloseDashboardStageByName("download");
}.bind(this)
});
} else {
if (InDockMode)
systemModel.SetDisplayState("dock");
appModel.CloseDashboardStageByName("download");
}
}
DownloadAssistant.prototype.handleTap = function(event) {
Mojo.Log.info("Dashboard tapped!");
var appController = Mojo.Controller.getAppController();
var mainStage = appController.getStageProxy("main");
if (!mainStage) {
systemModel.LaunchApp(Mojo.Controller.appInfo.id);
appController.closeAllStages();
} else {
mainStage.activate();
appController.closeStage("dashboard")
}
}
DownloadAssistant.prototype.handleDrag = function(event) {
var infoElement = this.controller.get("dashboardinfo");
infoElement.style.opacity = "0.5"; //TODO: this only seems to effect the icon
}
DownloadAssistant.prototype.handleDragEnd = function(event) {
Mojo.Log.info("Dashboard drag end!");
this.controller.window.clearInterval(downloadMgrInt);
appModel.CloseDashboardStageByName("download");
}
DownloadAssistant.prototype.errorHandler = function (errorText, callback) {
Mojo.Log.error("Error in Dashboard scene: " + errorText);
}
DownloadAssistant.prototype.deactivate = function(event) {
Mojo.Event.stopListening(this.controller.get("dashboardinfo"), Mojo.Event.tap, this.handleTap);
}
// Cleanup anything we did in setup function
DownloadAssistant.prototype.cleanup = function() {
Mojo.Log.info("Dashboard notification stage closing at " + new Date());
//Event handlers
Mojo.Event.stopListening(this.controller.get("dashboardinfo"), Mojo.Event.tap, this.handleTap);
appModel.SaveSettings();
}
+1 -1
View File
@@ -138,6 +138,6 @@ LoginAssistant.prototype.errorHandler = function (errorText, callback) {
callback.bind(this);
callback({"error": errorText});
} else {
Mojo.Controller.getAppController().showBanner({ messageText: errorText, icon: "images/notify.png" }, "", "");
Mojo.Controller.getAppController().showBanner({ messageText: errorText, icon: "assets/notify.png" }, "", "");
}
}
+80 -43
View File
@@ -16,7 +16,7 @@ MainAssistant.prototype.setup = function() {
//Load preferences
appModel.LoadSettings();
Mojo.Log.info("settings now: " + JSON.stringify(appModel.AppSettingsCurrent));
this.errorCount = 0;
this.errorCount = 5;
//Loading spinner - with global members for easy toggling later
this.spinnerAttrs = {
@@ -52,32 +52,37 @@ MainAssistant.prototype.setup = function() {
{ label: "Preferences", command: 'do-Preferences' },
{ label: "Handle URLs", chosen: false, command: 'do-HandleURLs' },
{ label: "Log In", command: 'do-LogInOut' },
{ label: "About", command: 'do-myAbout' }
{ label: "About", command: 'do-myAbout' },
{ label: "Debug Mode", chosen: appModel.AppSettingsCurrent["DebugMode"], command: 'do-debugMode' } //TODO: Remove Debug Menu
]
};
if(appModel.AppSettingsCurrent["SharePhrase"] && appModel.AppSettingsCurrent["SharePhrase"] != "") {
this.appMenuModel.items.push({ label: "Show Share Phrase", command: 'do-mySharePhrase' });
}
this.controller.setupWidget(Mojo.Menu.appMenu, this.appMenuAttributes, this.appMenuModel);
//Command Buttons
this.cmdMenuAttributes = {
spacerHeight: 40,
//menuClass: 'no-fade'
},
this.cmdMenuModel = {
visible: false,
items: [{
items: [
{ label: 'Refresh', icon: 'refresh', command: 'do-refresh' }
]
},
{
items: [
{ label: 'New', icon: 'new', command: 'do-new' }
]
}
]
};
spacerHeight: 40,
//menuClass: 'no-fade'
},
this.cmdMenuModel = {
visible: false,
items: [{
items: [
{ label: 'Refresh', icon: 'refresh', command: 'do-refresh' }
]
},
{
items: [
{ label: 'New', icon: 'new', command: 'do-new' }
]
}
]
};
if (appModel.AppSettingsCurrent["DebugMode"]) {
this.cmdMenuModel.items[0].items.push({ label: "Download", command: 'do-download' });
}
this.controller.setupWidget(Mojo.Menu.commandMenu, this.cmdMenuAttributes, this.cmdMenuModel);
/* Always on Event handlers */
Mojo.Event.listen(this.controller.get("shareList"), Mojo.Event.listDelete, this.handleListDelete.bind(this));
@@ -143,26 +148,29 @@ MainAssistant.prototype.activate = function(event) {
if (appModel.AppSettingsCurrent["RefreshTimeout"] && appModel.AppSettingsCurrent["RefreshTimeout"] > 1000) {
Mojo.Log.info("Auto refresh interval: " + appModel.AppSettingsCurrent["RefreshTimeout"]);
clearInterval(this.refreshInt);
this.refreshInt = window.setInterval(this.fetchShares.bind(this), appModel.AppSettingsCurrent["RefreshTimeout"]);
this.refreshInt = this.controller.window.setInterval(this.fetchShares.bind(this), appModel.AppSettingsCurrent["RefreshTimeout"]);
} else {
Mojo.Log.warn("Using Manual Refresh");
}
//handle launch with query
Mojo.Log.info("Main scene loaded with launch query: " + JSON.stringify(appModel.LaunchQuery));
if (appModel.LaunchQuery && appModel.LaunchQuery != "") {
//JustType Launch
if (appModel.LaunchQuery.newshare) {
Mojo.Log.warn("Creating new text Share from Just Type");
appModel.LastShareSelected = { guid: "new", contenttype: "text/plain", content: appModel.LaunchQuery };
Mojo.Log.info("Creating new text Share from Just Type");
appModel.LastShareSelected = { guid: "new", contenttype: "text/plain", content: appModel.LaunchQuery.newshare };
this.showNewShareScene();
} else if (appModel.LaunchQuery.target && appModel.LaunchQuery.target != "") {
Mojo.Log.warn("Handling URL launch of: " + appModel.LaunchQuery.target);
var newURL = appModel.LaunchQuery.target;
newURL = newURL.replace("image.php", "q.php");
newURL = newURL.replace("t.php", "q.php");
Mojo.Log.warn("Querying share item with URL: " + newURL);
} else {
}
//URL Launch
else if (appModel.LaunchQuery.target && appModel.LaunchQuery.target != "") {
this.handleURLInvocation(appModel.LaunchQuery.target);
}
//Some other kind of query launch
else {
Mojo.Log.warn("Unknown launch query received");
}
appModel.LaunchQuery = "";
}
} else {
appModel.LaunchQuery = "";
@@ -199,6 +207,27 @@ MainAssistant.prototype.handleUpdateResponse = function(responseObj) {
}
}
MainAssistant.prototype.handleURLInvocation = function(query) {
Mojo.Log.warn("Handling URL launch of: " + appModel.LaunchQuery.target);
serviceModel.QueryShareData(query, function(data) {
Mojo.Log.warn("Item query response payload was: " + data);
if (data) {
try {
var itemData = JSON.parse(data);
if (itemData.guid) {
appModel.LastShareSelected = itemData;
var stageController = Mojo.Controller.getAppController().getActiveStageController();
stageController.pushScene({ transition: Mojo.Transition.crossFade, name: "detail" });
} else {
throw("expected item data missing");
}
} catch (ex) {
Mojo.Log.warn("Got bad item query response payload: " + ex);
}
}
});
}
/* UI Event Handlers */
//Handles the enter key
@@ -241,6 +270,20 @@ MainAssistant.prototype.handleCommand = function(event) {
case 'do-mySharePhrase':
Mojo.Additions.ShowDialogBox("Your Share Phrase", "<b>" + appModel.AppSettingsCurrent["SharePhrase"] + "</b><br><br>Remember that anyone who has your Share Space name and Share Phrase can share with you.");
break;
case 'do-debugMode':
if (appModel.AppSettingsCurrent["DebugMode"]) {
appModel.AppSettingsCurrent["DebugMode"] = false;
} else {
appModel.AppSettingsCurrent["DebugMode"] = true;
}
appModel.SaveSettings();
var stageController = Mojo.Controller.getAppController().getActiveStageController();
stageController.swapScene({ transition: Mojo.Transition.crossFade, name: "main" });
break;
case 'do-download':
Mojo.Log.info("Trying to download in background");
appModel.ShowDownloaderStage();
break;
case 'do-new':
appModel.LastShareSelected = { guid: "new" };
this.showNewShareOptions();
@@ -261,7 +304,7 @@ MainAssistant.prototype.handleListClick = function(event) {
Mojo.Log.info("Item tapped with element class " + event.originalEvent.target.className);
Mojo.Log.info("Item details: " + JSON.stringify(event.item));
appModel.LastShareSelected = event.item;
appModel.LastShareSelected = event.item;
var stageController = Mojo.Controller.getAppController().getActiveStageController();
stageController.pushScene({ transition: Mojo.Transition.crossFade, name: "detail" });
@@ -360,7 +403,7 @@ MainAssistant.prototype.pickAndUploadImage = function() {
var params = { kind: 'image', actionName: 'Share Photo',
onSelect: function(file){
Mojo.Log.info("selected file was: " + JSON.stringify(file));
Mojo.Controller.getAppController().showBanner({ messageText: 'Sharing image...', icon: 'images/notify.png' }, { source: 'notification' });
Mojo.Controller.getAppController().showBanner({ messageText: 'Sharing image...', icon: 'assets/notify.png' }, { source: 'notification' });
//Figure out what mimetype to use
var ext = file.fullPath.split(".");
@@ -372,15 +415,15 @@ MainAssistant.prototype.pickAndUploadImage = function() {
serviceModel.DoShareAddRequestImage(file.fullPath, appModel.AppSettingsCurrent["Username"], appModel.AppSettingsCurrent["Credential"], mimetype, function(responseObj) {
if (responseObj != null) {
Mojo.Controller.getAppController().showBanner({ messageText: "Image shared!", icon: "images/notify.png" }, "", "");
Mojo.Controller.getAppController().showBanner({ messageText: "Image shared!", icon: "assets/notify.png" }, "", "");
self.fetchShares();
} else {
Mojo.Log.error("No usable response from server while uploading share");
Mojo.Controller.getAppController().showBanner({ messageText: "Bad response uploading image", icon: "images/notify.png" }, "", "");
Mojo.Controller.getAppController().showBanner({ messageText: "Bad response uploading image", icon: "assets/notify.png" }, "", "");
}
}.bind(self), function(errorText) {
Mojo.Log.error(errorText);
Mojo.Controller.getAppController().showBanner({ messageText: "Upload failure: " + errorText, icon: "images/notify.png" }, "", "");
Mojo.Controller.getAppController().showBanner({ messageText: "Upload failure: " + errorText, icon: "assets/notify.png" }, "", "");
});
}
}
@@ -390,6 +433,8 @@ MainAssistant.prototype.pickAndUploadImage = function() {
MainAssistant.prototype.showNewShareScene = function() {
this.DoingEdit = true;
var stageController = Mojo.Controller.getAppController().getActiveStageController();
if (!stageController)
stageController = Mojo.Controller.getAppController().getStageController(MainStageName);
stageController.pushScene({ transition: Mojo.Transition.crossFade, name: "newshare" });
}
@@ -482,7 +527,7 @@ MainAssistant.prototype.errorHandler = function (errorText, callback) {
if (this.errorCount > 5) {
Mojo.Additions.ShowDialogBox("Sync Error", errorText);
clearInterval(this.refreshInt);
Mojo.Controller.getAppController().showBanner({ messageText: "Sync offline", icon: "images/notify.png" }, "", "");
Mojo.Controller.getAppController().showBanner({ messageText: "Sync offline", icon: "assets/notify.png" }, "", "");
}
if (callback) {
callback.bind(this);
@@ -490,14 +535,6 @@ MainAssistant.prototype.errorHandler = function (errorText, callback) {
}
}
MainAssistant.prototype.playSound = function(soundToPlay) {
if (appModel.AppSettingsCurrent["SoundTheme"] > 0) {
soundToPlay = "sounds/" + soundToPlay + appModel.AppSettingsCurrent["SoundTheme"] + ".mp3";
Mojo.Log.info("Trying to play sound: " + soundToPlay);
Mojo.Controller.getAppController().playSoundNotification("media", soundToPlay, 1200);
}
}
Array.prototype.move = function(from, to) {
this.splice(to, 0, this.splice(from, 1)[0]);
}
+11 -16
View File
@@ -31,9 +31,11 @@ NewshareAssistant.prototype.setup = function(widget) {
textAttrib.autoReplace = false;
textAttrib.textCase = Mojo.Widget.steModeLowerCase;
}
Mojo.Log.warn("**** " + JSON.stringify(appModel.LastShareSelected));
this.controller.setupWidget("txtShareContent",
this.attributes = textAttrib,
this.model = {
value: appModel.LastShareSelected.content,
disabled: false
}
);
@@ -51,7 +53,6 @@ NewshareAssistant.prototype.activate = function(event) {
}
/* add event handlers to listen to events from widgets */
Mojo.Event.listen(this.controller.get("txtShareContent"), Mojo.Event.propertyChange, this.handleValueChange.bind(this));
Mojo.Event.listen(this.controller.get("goButton"), Mojo.Event.tap, this.handleOKPress.bind(this));
Mojo.Event.listen(this.controller.get("cancelButton"), Mojo.Event.tap, this.handleCancelPress.bind(this));
//Resize event
@@ -70,35 +71,29 @@ NewshareAssistant.prototype.calculateControlsPosition = function() {
}
}
NewshareAssistant.prototype.handleValueChange = function(event) {
switch (event.srcElement.title) {
case "ShareContent":
this.ShareContent = event.value;
break;
}
}
NewshareAssistant.prototype.handleCancelPress = function(event) {
var stageController = Mojo.Controller.getAppController().getActiveStageController();
stageController.pushScene({ transition: Mojo.Transition.crossFade, name: "main" });
}
NewshareAssistant.prototype.handleOKPress = function(event) {
if (this.ShareContent && this.ShareContent != "") {
var shareContent = this.controller.get("txtShareContent").mojo.getValue();
if (shareContent && shareContent != "") {
if (appModel.LastShareSelected.contenttype == "application/json") {
try {
var testObj = JSON.parse(this.ShareContent);
var testObj = JSON.parse(shareContent);
} catch (ex) {
Mojo.Controller.getAppController().showBanner({ messageText: 'JSON content not be parsed', icon: 'images/notify.png' }, { source: 'notification' });
Mojo.Controller.getAppController().showBanner({ messageText: 'JSON content not be parsed', icon: 'assets/notify.png' }, { source: 'notification' });
this.controller.get('goButton').mojo.deactivate();
this.controller.window.setTimeout(this.controller.get('txtShareContent').mojo.focus(), 500);
return false;
}
}
appModel.LastShareSelected.content = this.ShareContent;
appModel.LastShareSelected.content = shareContent;
this.tryAddShare();
} else {
this.handleCancelPress(event);
this.controller.get('goButton').mojo.deactivate();
this.controller.get("txtShareContent").mojo.focus();
}
}
@@ -106,7 +101,7 @@ NewshareAssistant.prototype.tryAddShare = function() {
serviceModel.DoShareAddRequestText(appModel.LastShareSelected.content, appModel.AppSettingsCurrent["Username"], appModel.AppSettingsCurrent["Credential"], appModel.LastShareSelected.contenttype, function(responseObj) {
if (responseObj && responseObj.guid && responseObj.guid != "") {
Mojo.Log.info("Add share success!");
Mojo.Controller.getAppController().showBanner({ messageText: 'Content shared!', icon: 'images/notify.png' }, { source: 'notification' });
Mojo.Controller.getAppController().showBanner({ messageText: 'Content shared!', icon: 'assets/notify.png' }, { source: 'notification' });
} else {
this.errorHandler("Share failure: " + JSON.stringify(responseObj))
}
@@ -116,7 +111,7 @@ NewshareAssistant.prototype.tryAddShare = function() {
NewshareAssistant.prototype.errorHandler = function (errorText, callback) {
Mojo.Log.error(errorText);
Mojo.Controller.getAppController().showBanner({ messageText: errorText, icon: "images/notify.png" }, "", "");
Mojo.Controller.getAppController().showBanner({ messageText: errorText, icon: "assets/notify.png" }, "", "");
errorText = errorText.charAt(0).toUpperCase() + errorText.slice(1);
this.controller.get('goButton').mojo.deactivate();
Mojo.Additions.ShowDialogBox("Share Sevice Error", errorText);
+2 -2
View File
@@ -129,7 +129,7 @@ NewuserAssistant.prototype.okClick = function(event) {
stageController.swapScene({ transition: Mojo.Transition.zoomFade, name: "welcome" });
} else {
Mojo.Log.error("No usable response from server while uploading share");
Mojo.Controller.getAppController().showBanner({ messageText: "Bad response uploading image", icon: "images/notify.png" }, "", "");
Mojo.Controller.getAppController().showBanner({ messageText: "Bad response uploading image", icon: "assets/notify.png" }, "", "");
}
this.controller.get('btnOK').mojo.deactivate();
}.bind(this), this.errorHandler.bind(this));
@@ -148,7 +148,7 @@ NewuserAssistant.prototype.cancelClick = function(event) {
NewuserAssistant.prototype.errorHandler = function (errorText, callback) {
Mojo.Log.error(errorText);
Mojo.Controller.getAppController().showBanner({ messageText: errorText, icon: "images/notify.png" }, "", "");
Mojo.Controller.getAppController().showBanner({ messageText: errorText, icon: "assets/notify.png" }, "", "");
errorText = errorText.charAt(0).toUpperCase() + errorText.slice(1);
Mojo.Additions.ShowDialogBox("Share Sevice Error", errorText);
this.controller.get('btnOK').mojo.deactivate();
+1 -1
View File
@@ -10,7 +10,7 @@ Mojo Additions
this.Additions = function() {}
Mojo.Log.info("#### Mojo Additions added");
console.log("#### Mojo Additions added");
Additions.ShowDialogBox = function(title, message) {
var stageController = Mojo.Controller.getAppController().getActiveStageController();
+57 -2
View File
@@ -22,8 +22,8 @@ var AppModel = function() {
Username: "",
Credential: "",
SharePhrase: "",
SoundTheme: 1,
RefreshTimeout: 60000,
BackgroundUpdate: "00:05:00",
ForceHTTP: false,
UseCustomEndpoint: false,
EndpointURL: "",
@@ -33,10 +33,65 @@ var AppModel = function() {
CustomCreateKey: "",
UseCustomDownloadPath: false,
CustomDownloadPath: null,
FirstRun: true
FirstRun: true,
DebugMode: false
};
}
AppModel.prototype.ShowDownloaderStage = function() {
Mojo.Log.info("App Model checking if we should to show Dashboard stage...");
this.serviceEndpointBase = appModel.ServiceEndpointBase;
if (appModel.AppSettingsCurrent["UseCustomEndpoint"] && appModel.AppSettingsCurrent["EndpointURL"]) {
this.serviceEndpointBase = appModel.AppSettingsCurrent["EndpointURL"];
}
//Check for connectivity, then check for messages
systemModel.GetInternetConnectionState(this.checkForMessages.bind(this));
}
AppModel.prototype.checkForMessages = function(connMgrResponse) {
Mojo.Log.info("App Model got response from connection manager: " + JSON.stringify(connMgrResponse));
if (connMgrResponse && connMgrResponse.isInternetConnectionAvailable) {
this.actuallyShowDownloaderStage();
}
}
AppModel.prototype.actuallyShowDownloaderStage = function() {
this.controller = Mojo.Controller.getAppController();
var dashboardStage = this.controller.getStageProxy("download");
var pushDashScene = function(stageController) {
stageController.pushScene('download', "download/download-scene");
}.bind(this);
if (!dashboardStage) {
Mojo.Log.info("Download dashboard not open, creating it...");
this.controller.createStageWithCallback({
name: 'download',
lightweight: true,
height: 100,
soundclass: "assets/silent.mp3"
}, pushDashScene, 'dashboard');
} else {
Mojo.Log.info("Download dashboard already open, activating it...");
var dashboardStageController = this.controller.getStageController("download");
if (dashboardStageController) {
dashboardStageController.activate();
dashboardStageController.delegateToSceneAssistant("activate");
}
}
}
AppModel.prototype.CloseDashboardStageByName = function(stageName) {
this.controller = Mojo.Controller.getAppController();
var dashboardStage = this.controller.getStageProxy(stageName);
if (!dashboardStage) {
Mojo.Log.info(stageName + " dashboard not open, nothing to do");
} else {
Mojo.Log.info(stageName + " dashboard open, closing it...");
this.controller.closeStage(stageName);
}
}
//You probably don't need to change the below functions since they all work against the Cookie defaults you defined above.
// LoadSettings: call when your app starts, or you want to load previously persisted options.
// SaveSettings: call any time you want to persist an option.
+25 -3
View File
@@ -50,9 +50,11 @@ ShareServiceModel.prototype.DoShareListRequest = function(username, credential,
Mojo.Log.warn(errorText);
Mojo.Controller.getAppController().showBanner({ messageText: errorText }, "", "");
}
} else {
errorhandler = errorhandler.bind(this);
}
var useURL = this.buildURL(username, "get-shares");
Mojo.Log.info("calling sharing service at " + useURL + " with key " + this.getCurrentClientKey());
Mojo.Log.info("Calling sharing service at " + useURL + " with key " + this.getCurrentClientKey());
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", useURL);
@@ -246,7 +248,7 @@ ShareServiceModel.prototype.DoShareDeleteRequest = function(itemid, username, cr
}
}
var useURL = this.buildURL(username, "delete-share-item");
Mojo.Log.info("calling sharing service at " + useURL + " for item " + itemid + " with key " + this.getCurrentClientKey());
Mojo.Log.info("Calling sharing service at " + useURL + " for item " + itemid + " with key " + this.getCurrentClientKey());
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", useURL);
@@ -367,7 +369,6 @@ ShareServiceModel.prototype.GetTnC = function(callback) {
//HTTP request to get random share phrase
ShareServiceModel.prototype.GetRandomWords = function(callback) {
this.retVal = "";
if (callback)
callback = callback.bind(this);
@@ -384,6 +385,27 @@ ShareServiceModel.prototype.GetRandomWords = function(callback) {
}.bind(this);
}
//HTTP request to get random share phrase
ShareServiceModel.prototype.QueryShareData = function(query, callback) {
if (callback)
callback = callback.bind(this);
var theQuery = query;
theQuery = theQuery.replace("image.php", "q.php");
theQuery = theQuery.replace("t.php", "q.php");
Mojo.Log.warn("Querying share item with URL: " + theQuery);
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", theQuery);
xmlhttp.send();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == XMLHttpRequest.DONE) {
if (callback)
callback(xmlhttp.responseText);
}
}.bind(this);
}
ShareServiceModel.prototype.getCurrentClientKey = function() {
var retVal = atob(appKeys['shareBoardClientKey']);
if (this.UseCustomEndpoint) {
+8 -4
View File
@@ -252,7 +252,7 @@ SystemModel.prototype.SendDataForTouch2Share = function(url, callback) {
}
//Download a file
SystemModel.prototype.DownloadFile = function (url, mimetype, pathFromInteral, fileName, callback) {
SystemModel.prototype.DownloadFile = function (url, mimetype, pathFromInteral, fileName, subscribe, callback) {
if (!url) {
Mojo.Log.error("Download URL not supplied");
return false;
@@ -268,8 +268,12 @@ SystemModel.prototype.DownloadFile = function (url, mimetype, pathFromInteral, f
var ext = "";
mimetype = mimetype.toLowerCase();
if (mimetype.indexOf("image/") != -1) {
ext = mimetype.split("/");
ext = ext[ext.length - 1];
if (mimetype == "image/jpeg")
ext = "jpg"
else {
ext = mimetype.split("/");
ext = ext[ext.length - 1];
}
} else if (mimetype == "text/plain") {
ext = "txt";
} else if (mimetype == "application/json") {
@@ -290,7 +294,7 @@ SystemModel.prototype.DownloadFile = function (url, mimetype, pathFromInteral, f
targetDir : "/media/internal/" + pathFromInteral,
targetFilename : fileName + ext,
keepFilenameOnRedirect: true,
subscribe: true
subscribe: subscribe
},
onSuccess: function(response) {
Mojo.Log.info("Download Success!", JSON.stringify(response));
+2 -2
View File
@@ -4,10 +4,10 @@
</div>
</div>
<!-- turn on display for debugging -->
<!-- only visible in debug mode -->
<div class="palm-group" id="divShareInfo" style="display:none">
<div class="palm-group-title">
<span x-mojo-loc=''>Share Links</span>
<span x-mojo-loc=''>Debug Links</span>
</div>
<div id="divShareLinks" name="divShareLinks">
</div>
+1
View File
@@ -0,0 +1 @@
<div id="dashboardinfo" class="dashboardinfo"></div>
+15
View File
@@ -0,0 +1,15 @@
<div class="dashboard-notification-module">
<div class="palm-dashboard-icon-container">
<div class="dashboard-newitem" style="display:#{showCount}">
<span>#{count}</span>
</div>
<div id="dashboard-icon" class="palm-dashboard-icon dashboard-icon-download">
</div>
</div>
<div class="palm-dashboard-text-container">
<div class="dashboard-title">
#{title}
</div>
<div id="dashboard-text" class="palm-dashboard-text">#{message}</div>
</div>
</div>
+1 -1
View File
@@ -45,7 +45,7 @@
<div class="palm-row">
<div class="palm-row-wrapper" style="height: 12px">
<div class="title" class="truncating-text" style="float:left; margin-left: 8px; margin-top: 14px;padding:0px"><span class="label ">Share phrase</span></div>
<img id="imgTryagain" src="images/tryagain.png" style="height:24px; width:24px; margin-top: 12px; margin-left: 12px;">
<img id="imgTryagain" src="assets/tryagain.png" style="height:24px; width:24px; margin-top: 12px; margin-left: 12px;">
</div>
</div>
View File
File renamed without changes.
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

File renamed without changes.
BIN
View File
Binary file not shown.
File renamed without changes.
+5
View File
@@ -29,6 +29,11 @@
"scenes": "preferences",
"source": "app/assistants/preferences-assistant.js"
},
{
"scenes": "download",
"source": "app/assistants/download-assistant.js",
"comment": "this is a dashboard"
},
{ "source": "app/models/shareservice-model.js" },
{ "source": "app/models/updater-model.js" },
{ "source": "app/models/app-model.js" },
+4
View File
@@ -77,4 +77,8 @@
h3 {
margin: 8px 12px 12px 12px
}
.dashboard-icon-download {
background: url(../assets/dash-icon.png);
}