download timer and camera added

This commit is contained in:
CodePoet80 committed 2021-05-29 13:05:58 -04:00
1 parent 561b54bf97
commit e32fcbbea2
7 files changed
+141 -69

No files matched your search

+4 -5
View File
@@ -24,18 +24,17 @@ AppAssistant.prototype.handleLaunch = function(params) {
Mojo.Log.info("settings now: " + JSON.stringify(appModel.AppSettingsCurrent));
if (!appModel.AppSettingsCurrent["AutoDownloadTime"]) {
appModel.AppSettingsCurrent["AutoDownloadTime"] = "00:60:00";
appModel.AppSettingsCurrent["AutoDownloadTime"] = appModel.AppSettingsDefaults["AutoDownloadTime"];
appModel.SaveSettings();
}
//Reset alarms
systemModel.ClearSystemAlarm("BackgroundDownload");
Mojo.Log.warn("Background setting is: " + appModel.AppSettingsCurrent["UseAutoDownload"]);
if (appModel.AppSettingsCurrent["UseAutoDownload"]) {
Mojo.Log.info("Re-establishing background download alarm");
if (appModel.AppSettingsCurrent["UseAutoDownload"] && appModel.AppSettingsCurrent["Username"] != "" && appModel.AppSettingsCurrent["Credential"]) {
Mojo.Log.info("Re-establishing background download alarm with time: " + appModel.AppSettingsCurrent["AutoDownloadTime"]);
systemModel.SetSystemAlarmRelative("BackgroundDownload", appModel.AppSettingsCurrent["AutoDownloadTime"]);
} else {
Mojo.Log.info("Not setting background download alarm");
Mojo.Log.warn("Not setting background download alarm since conditions weren't met.");
}
if (!params || !params["action"]) {
+18 -7
View File
@@ -60,17 +60,18 @@ DetailAssistant.prototype.setup = function() {
},
{
items: [
{ label: 'Share', command: 'do-share' }
]
},
{
items: [
{ label: 'Save', icon: 'save', command: 'do-save' },
{ label: 'Share', command: 'do-share' },
]
}
]
};
if (!appModel.AppSettingsCurrent["UseAutoDownload"]) //If not auto-download, allow manual download
this.cmdMenuModel.items[2].items.push({ label: 'Save', icon: 'save', command: 'do-save' })
this.controller.setupWidget(Mojo.Menu.commandMenu, this.cmdMenuAttributes, this.cmdMenuModel);
/* add event handlers to listen to events from widgets */
@@ -83,14 +84,12 @@ DetailAssistant.prototype.activate = function(event) {
this.controller.get("divShareTitle").innerHTML = "Shared: " + appModel.LastShareSelected.timestamp;
//Show links
//Calculate links
if (appModel.LastShareSelected.contenttype.indexOf("image") != -1) { //image links
var link = this.makeShareURLs(appModel.LastShareSelected.thumbnail, "image");
appModel.CurrentShareURL = link;
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>";
//TODO: We need to handle tapping of the link with an app launch request
link = this.makeShareURLs(appModel.LastShareSelected.thumbnail, "download");
this.downloadLink = link;
} else { //text links
@@ -100,7 +99,7 @@ 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"]) {
if (appModel.AppSettingsCurrent["DebugMode"]) { //If debugging, show links
this.controller.get("divShareInfo").style.display = "block";
}
@@ -144,6 +143,7 @@ DetailAssistant.prototype.handleCommand = function(event) {
var itemsToShow = [
{ label: 'Open in Browser', command: 'do-browserOpen' },
{ label: 'Email Link', command: 'do-emailLink' },
{ label: 'Message Link', command: 'do-messageLink' },
{ label: 'Copy Link', command: 'do-copyLink' }
]
if (appModel.LastShareSelected.contenttype.indexOf("image") == -1) {
@@ -192,6 +192,17 @@ DetailAssistant.prototype.handlePopupChoose = function(task, command) {
}
});
break;
case "do-messageLink":
this.controller.serviceRequest('palm://com.palm.applicationManager', {
method: 'open',
parameters: {
id: 'com.palm.app.messaging',
params: {
messageText: "Check out this link: " + this.downloadLink
}
}
});
break;
case "do-copyLink":
stageController.setClipboard(this.downloadLink);
Mojo.Controller.getAppController().showBanner({ messageText: 'Link copied!', icon: 'assets/notify.png' }, { source: 'notification' });
+75 -35
View File
@@ -18,6 +18,23 @@ MainAssistant.prototype.setup = function() {
appModel.LoadSettings();
Mojo.Log.info("settings now: " + JSON.stringify(appModel.AppSettingsCurrent));
this.errorCount = 5;
//find out what kind of device this is
if (Mojo.Environment.DeviceInfo.platformVersionMajor >= 3) {
this.DeviceType = "TouchPad";
Mojo.Log.info("Device detected as TouchPad");
} else {
if (window.screen.width == 800 || window.screen.height == 800) {
this.DeviceType = "Pre3";
Mojo.Log.info("Device detected as Pre3");
} else if ((window.screen.width == 480 || window.screen.height == 480) && (window.screen.width == 320 || window.screen.height == 320)) {
this.DeviceType = "Pre";
Mojo.Log.warn("Device detected as Pre or Pre2");
} else {
this.DeviceType = "Tiny";
Mojo.Log.warn("Device detected as Pixi or Veer");
}
}
//Loading spinner - with global members for easy toggling later
this.spinnerAttrs = {
@@ -102,7 +119,8 @@ MainAssistant.prototype.setup = function() {
}
};
MainAssistant.prototype.activate = function(event) {
MainAssistant.prototype.activate = function(data) {
//Set options for service model
serviceModel.ForceHTTP = appModel.AppSettingsCurrent["ForceHTTP"];
serviceModel.UseCustomEndpoint = appModel.AppSettingsCurrent["UseCustomEndpoint"];
@@ -124,22 +142,6 @@ MainAssistant.prototype.activate = function(event) {
thisMenuModel.items[3].label = loggedInLabel;
this.controller.modelChanged(thisMenuModel);
//find out what kind of device this is
if (Mojo.Environment.DeviceInfo.platformVersionMajor >= 3) {
this.DeviceType = "TouchPad";
Mojo.Log.info("Device detected as TouchPad");
} else {
if (window.screen.width == 800 || window.screen.height == 800) {
this.DeviceType = "Pre3";
Mojo.Log.info("Device detected as Pre3");
} else if ((window.screen.width == 480 || window.screen.height == 480) && (window.screen.width == 320 || window.screen.height == 320)) {
this.DeviceType = "Pre";
Mojo.Log.warn("Device detected as Pre or Pre2");
} else {
this.DeviceType = "Tiny";
Mojo.Log.warn("Device detected as Pixi or Veer");
}
}
if (appModel.AppSettingsCurrent["FirstRun"]) {
appModel.AppSettingsCurrent["FirstRun"] = false;
appModel.SaveSettings();
@@ -147,17 +149,11 @@ MainAssistant.prototype.activate = function(event) {
} else {
if (appModel.AppSettingsCurrent["Username"] != "" && appModel.AppSettingsCurrent["Credential"] != "") {
Mojo.Log.info("About to fetch shares...");
this.controller.get('workingSpinner').mojo.start();
this.fetchShares();
if (appModel.AppSettingsCurrent["RefreshTimeout"] && appModel.AppSettingsCurrent["RefreshTimeout"] > 1000) {
Mojo.Log.info("Auto refresh interval: " + appModel.AppSettingsCurrent["RefreshTimeout"]);
clearInterval(refreshInt);
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));
Mojo.Log.info("Main scene loaded with launch query: " + JSON.stringify(appModel.LaunchQuery) + ", data: " + JSON.stringify(data));
if (appModel.LaunchQuery && appModel.LaunchQuery != "") {
//JustType Launch
if (appModel.LaunchQuery.newshare) {
@@ -175,6 +171,11 @@ MainAssistant.prototype.activate = function(event) {
}
appModel.LaunchQuery = "";
}
if (data && data.filename) {
Mojo.Log.info("Creating a new share from Camera sub-launch " + data.filename);
Mojo.Controller.getAppController().showBanner({ messageText: "Sharing camera image...", icon: "assets/notify.png" }, "", "");
this.uploadCameraImage(data.filename);
}
} else {
appModel.LaunchQuery = "";
this.showWelcomePrompt();
@@ -353,8 +354,17 @@ MainAssistant.prototype.handlePopupChoose = function(share, command) {
/* Get Share Stuff */
MainAssistant.prototype.fetchShares = function() {
this.controller.window.clearInterval(refreshInt);
if (appModel.AppSettingsCurrent["RefreshTimeout"] && appModel.AppSettingsCurrent["RefreshTimeout"] > 1000) {
Mojo.Log.info("Auto refresh interval: " + appModel.AppSettingsCurrent["RefreshTimeout"]);
refreshInt = this.controller.window.setInterval(this.fetchShares.bind(this), appModel.AppSettingsCurrent["RefreshTimeout"]);
} else {
Mojo.Log.warn("Using Manual Refresh");
}
serviceModel.DoShareListRequest(appModel.AppSettingsCurrent["Username"], appModel.AppSettingsCurrent["Credential"], function(responseObj){
Mojo.Log.info("ready to process share list: " + JSON.stringify(responseObj));
//Mojo.Log.info("ready to process share list: " + JSON.stringify(responseObj));
if (responseObj != null) {
if (responseObj.shares) {
@@ -378,6 +388,7 @@ MainAssistant.prototype.updateShareListWidget = function(username, results, acce
Mojo.Log.info("Displaying shares for: " + username + " with access level: " + accessLevel);
this.controller.get("spnUsername").innerHTML = username;
this.controller.get('workingSpinner').mojo.stop();
var thisShareList = this.controller.getWidgetSetup("shareList");
thisShareList.model.items = []; //remove the previous list
@@ -399,11 +410,22 @@ MainAssistant.prototype.updateShareListWidget = function(username, results, acce
/* New Share Stuff */
MainAssistant.prototype.showNewShareOptions = function() {
var choices = [
{ label: "Text", value: "text/plain", type: "neutral" },
{ label: "JSON", value: "application/json", type: "neutral" },
{ label: "Image", value: "image", type: "neutral" },
];
if (this.DeviceType != "TouchPad")
choices.push({ label: "Camera", value: "camera", type: "neutral" });
choices.push({ label: "Cancel", value: "cancel", type: "negative" });
this.controller.showAlertDialog({
onChoose: function(value) {
Mojo.Log.info("Choice was: " + value);
if (value == "image") {
this.pickAndUploadImage();
} else if (value == "camera") {
this.getCameraImage();
} else if (value == "text/plain" || value == "application/json") {
appModel.LastShareSelected.contenttype = value;
Mojo.Log.info("LastShareSelected: " + JSON.stringify(appModel.LastShareSelected));
@@ -414,12 +436,7 @@ MainAssistant.prototype.showNewShareOptions = function() {
},
title: "New Share",
message: "What do you want to share?",
choices: [
{ label: "Text", value: "text/plain", type: "neutral" },
{ label: "JSON", value: "application/json", type: "neutral" },
{ label: "Image", value: "image", type: "neutral" },
{ label: "Cancel", value: "cancel", type: "negative" }
]
choices: choices
});
}
@@ -455,6 +472,29 @@ MainAssistant.prototype.pickAndUploadImage = function() {
Mojo.FilePicker.pickFile(params, this.controller.stageController);
}
MainAssistant.prototype.getCameraImage = function() {
this.controller.stageController.pushScene(
{ appId: "com.palm.app.camera", name: "capture" },
{ sublaunch: true, mode: "stil" }
);
}
MainAssistant.prototype.uploadCameraImage = function(file) {
var self = this;
serviceModel.DoShareAddRequestImage(file, appModel.AppSettingsCurrent["Username"], appModel.AppSettingsCurrent["Credential"], "image/jpeg", function(responseObj) {
if (responseObj != null) {
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: "assets/notify.png" }, "", "");
}
}.bind(self), function(errorText) {
Mojo.Log.error(errorText);
Mojo.Controller.getAppController().showBanner({ messageText: "Upload failure: " + errorText, icon: "assets/notify.png" }, "", "");
});
}
MainAssistant.prototype.showNewShareScene = function() {
this.DoingEdit = true;
var stageController = Mojo.Controller.getAppController().getActiveStageController();
@@ -530,7 +570,7 @@ MainAssistant.prototype.showLogin = function() {
MainAssistant.prototype.deactivate = function(event) {
/* remove any event handlers you added in activate and do any other cleanup that should happen before
this scene is popped or another scene is pushed on top */
clearInterval(refreshInt);
this.controller.window.clearInterval(refreshInt);
Mojo.Event.stopListening(this.controller.get("shareList"), Mojo.Event.listDelete, this.handleListDelete);
Mojo.Event.stopListening(this.controller.get("shareList"), Mojo.Event.listTap, this.handleListClick);
Mojo.Event.stopListening(this.controller.get("shareList"), Mojo.Event.listAdd, this.handleListAdd);
@@ -551,8 +591,8 @@ MainAssistant.prototype.errorHandler = function (errorText, callback) {
Mojo.Log.error("error count: " + this.errorCount + ", " + errorText);
if (this.errorCount > 5) {
Mojo.Additions.ShowDialogBox("Sync Error", errorText);
clearInterval(refreshInt);
Mojo.Controller.getAppController().showBanner({ messageText: "Sync offline", icon: "assets/notify.png" }, "", "");
this.controller.window.clearInterval(refreshInt);
Mojo.Controller.getAppController().showBanner({ messageText: "Offline", icon: "assets/notify.png" }, "", "");
}
if (callback) {
callback.bind(this);
+22 -5
View File
@@ -27,8 +27,8 @@ PreferencesAssistant.prototype.setup = function() {
);
//Toggles
var disableDL = true;
if (appModel.FileMgrPresent && appModel.AppSettingsCurrent["UseAutoDownload"])
disableDL = false;
if (appModel.FileMgrPresent)
disableDL = false;
this.controller.setupWidget("toggleAutoDownload",
this.attributes = {
trueValue: true,
@@ -45,12 +45,12 @@ PreferencesAssistant.prototype.setup = function() {
label: $L("Download Time"),
choices: [
{ label: "5 minutes", value: "00:05:00" },
{ label: "1 Hour", value: "00:60:00" },
{ label: "1 Hour", value: "01:00:00" },
{ label: "2 Hours", value: "02:00:00" },
{ label: "3 Hours", value: "03:00:00" },
{ label: "6 Hours", value: "06:00:00" },
{ label: "12 Hours", value: "12:00:00" },
{ label: "24 Hours", value: "24:00:00" }
{ label: "24 Hours", value: "23:59:59" }
]
},
this.model = {
@@ -58,7 +58,7 @@ PreferencesAssistant.prototype.setup = function() {
disabled: disableDL
}
);
if (!disableDL)
if (appModel.FileMgrPresent)
this.controller.get("divDownloadExplain").innerHTML = "Frequent automatic downloads can have significant impact on battery life.";
//More toggles
this.controller.setupWidget("toggleForceHTTP",
@@ -144,6 +144,16 @@ PreferencesAssistant.prototype.setup = function() {
disabled: !appModel.AppSettingsCurrent["UseCustomEndpoint"]
}
);
//Drawer
this.controller.setupWidget("drawerSelfHost",
this.attributes = {
modelProperty: 'open',
unstyled: false
},
this.model = {
open: appModel.AppSettingsCurrent["UseCustomEndpoint"]
}
);
//OK Button
this.controller.setupWidget("btnOK", { type: Mojo.Widget.activityButton }, { label: "Done", disabled: false });
@@ -208,6 +218,9 @@ PreferencesAssistant.prototype.handleValueChange = function(event) {
case "toggleCustomEndPoint":
{
//Toggle enabled on related text boxes
var thisWidgetSetup = this.controller.getWidgetSetup("drawerSelfHost");
thisWidgetSetup.model.open = event.value;
this.controller.modelChanged(thisWidgetSetup.model);
var thisWidgetSetup = this.controller.getWidgetSetup("txtEndpointURL");
thisWidgetSetup.model.disabled = !event.value;
this.controller.modelChanged(thisWidgetSetup.model);
@@ -255,6 +268,10 @@ PreferencesAssistant.prototype.handleCommand = function(event) {
};
PreferencesAssistant.prototype.okClick = function(event) {
if (this.controller.get('txtEndpointURL').mojo.getValue() == "") {
appModel.AppSettingsCurrent["UseCustomEndpoint"] = false;
appModel.SaveSettings();
}
var stageController = Mojo.Controller.getAppController().getActiveStageController();
stageController.popScene();
}
+1 -1
View File
@@ -25,7 +25,7 @@ var AppModel = function() {
SharePhrase: "",
RefreshTimeout: 60000,
UseAutoDownload: false,
AutoDownloadTime: "00:60:00",
AutoDownloadTime: "01:00:00",
ForceHTTP: false,
UseCustomEndpoint: false,
EndpointURL: "",
+1 -1
View File
@@ -12,6 +12,6 @@
</div>
</div>
<div id="divSpinnerContainer" style="width: 130px;margin-left: auto;margin-right: auto; align-items: center;">
<div id="divSpinnerContainer" style="margin-top: 100px; width: 130px;margin-left: auto;margin-right: auto; align-items: center;">
<div x-mojo-element="Spinner" class="spinnerClass" id="workingSpinner" name="workingSpinner"></div>
</div>
+20 -15
View File
@@ -63,33 +63,38 @@
</div>
</div>
<div class="palm-row">
<div class="palm-row last">
<div class="palm-row-wrapper">
<div x-mojo-element="ToggleButton" id="toggleCustomEndPoint" title="UseCustomEndpoint"></div>
<div class="title" style="margin-left: -4px; float:left;"><span class="label">Custom Endpoint URL</span></div>
<div class="title" style="margin-left: -4px; float:left;"><span class="label">Custom Endpoint</span></div>
</div>
</div>
<div class="palm-row">
<div class="palm-row-wrapper" style="margin:14px 22px 4px 12px">
<div id="txtEndpointURL" name="txtEndpointURL" x-mojo-element="TextField" title="EndpointURL"></div>
<div x-mojo-element="Drawer" id="drawerSelfHost" class="drawerClass" name="drawerSelfHost">
<div class="palm-row">
<div class="palm-row-wrapper" style="margin:14px 22px 4px 12px">
<div id="txtEndpointURL" name="txtEndpointURL" x-mojo-element="TextField" title="EndpointURL"></div>
</div>
</div>
</div>
<div class="palm-row">
<div class="palm-row-wrapper" style="margin:14px 22px 4px 12px">
<div id="txtShortURL" name="txtShortURL" x-mojo-element="TextField" title="ShortURL"></div>
<div class="palm-row">
<div class="palm-row-wrapper" style="margin:14px 22px 4px 12px">
<div id="txtShortURL" name="txtShortURL" x-mojo-element="TextField" title="ShortURL"></div>
</div>
</div>
</div>
<div class="palm-row last">
<div class="palm-row-wrapper" style="margin:14px 22px 4px 12px">
<div id="txtCustomCreateKey" name="txtCustomCreateKey" x-mojo-element="TextField" title="CustomCreateKey"></div>
<div class="palm-row last">
<div class="palm-row-wrapper" style="margin:14px 22px 4px 12px">
<div id="txtCustomCreateKey" name="txtCustomCreateKey" x-mojo-element="TextField" title="CustomCreateKey"></div>
</div>
</div>
</div>
</div>
<div class="explanation-text">For more information on self-hosting, please visit <a href="https://github.com/codepoet80/webos-sharespace">https://github.com/codepoet80/webos-sharespace</a></div>
</div>
</div>
<div class="explanation-text">For more information on self-hosting, please visit <a href="https://github.com/codepoet80/webos-sharespace">https://github.com/codepoet80/webos-sharespace</a></div>
<div x-mojo-element="Button" id="btnOK" name="btnOK"></div>