Snapshot.js now uses AppUi

This commit is contained in:
Zach Fox 2018-09-11 12:04:39 -07:00
parent 299e9d0d38
commit 1aaa90675c
2 changed files with 61 additions and 97 deletions

View file

@ -54,6 +54,17 @@ function AppUi(properties) {
that.tablet.gotoWebScreen(url, that.inject); that.tablet.gotoWebScreen(url, that.inject);
} }
}; };
that.openOnTop = function openOnTop(url, optionalInject) { // Opens some app on top of the current app
if (that.isQML(url)) {
that.tablet.loadQMLOnTop(url);
} else {
if (optionalInject) {
that.tablet.loadWebScreenOnTop(url, optionalInject);
} else {
that.tablet.loadWebScreenOnTop(url);
}
}
}
that.close = function close() { // How to close the app. that.close = function close() { // How to close the app.
that.currentUrl = ""; that.currentUrl = "";
// for toolbar-mode: go back to home screen, this will close the window. // for toolbar-mode: go back to home screen, this will close the window.
@ -69,7 +80,11 @@ function AppUi(properties) {
activeIcon: isWaiting ? that.activeMessagesButton : that.activeButton activeIcon: isWaiting ? that.activeMessagesButton : that.activeButton
}); });
}; };
that.isQML = function isQML() { // We set type property in onClick. that.isQML = function isQML(optionalUrl) { // We set type property in onClick.
if (optionalUrl) {
var type = /.qml$/.test(optionalUrl) ? 'QML' : 'Web';
return type === 'QML';
}
return that.type === 'QML'; return that.type === 'QML';
}; };
that.eventSignal = function eventSignal() { // What signal to hook onMessage to. that.eventSignal = function eventSignal() { // What signal to hook onMessage to.

View file

@ -12,23 +12,13 @@
(function () { // BEGIN LOCAL_SCOPE (function () { // BEGIN LOCAL_SCOPE
Script.include("/~/system/libraries/accountUtils.js"); Script.include("/~/system/libraries/accountUtils.js");
var AppUi = Script.require('appUi');
var SNAPSHOT_DELAY = 500; // 500ms var SNAPSHOT_DELAY = 500; // 500ms
var FINISH_SOUND_DELAY = 350; var FINISH_SOUND_DELAY = 350;
var resetOverlays; var resetOverlays;
var reticleVisible; var reticleVisible;
var buttonName = "SNAP";
var buttonConnected = false;
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
var button = tablet.addButton({
icon: "icons/tablet-icons/snap-i.svg",
activeIcon: "icons/tablet-icons/snap-a.svg",
text: buttonName,
sortOrder: 5
});
var snapshotOptions = {}; var snapshotOptions = {};
var imageData = []; var imageData = [];
var storyIDsToMaybeDelete = []; var storyIDsToMaybeDelete = [];
@ -52,8 +42,6 @@ try {
print('Failed to resolve request api, error: ' + err); print('Failed to resolve request api, error: ' + err);
} }
function removeFromStoryIDsToMaybeDelete(story_id) { function removeFromStoryIDsToMaybeDelete(story_id) {
storyIDsToMaybeDelete.splice(storyIDsToMaybeDelete.indexOf(story_id), 1); storyIDsToMaybeDelete.splice(storyIDsToMaybeDelete.indexOf(story_id), 1);
print('storyIDsToMaybeDelete[] now:', JSON.stringify(storyIDsToMaybeDelete)); print('storyIDsToMaybeDelete[] now:', JSON.stringify(storyIDsToMaybeDelete));
@ -73,33 +61,32 @@ function onMessage(message) {
// 2. Although we currently use a single image, we would like to take snapshot, a selfie, a 360 etc. all at the // 2. Although we currently use a single image, we would like to take snapshot, a selfie, a 360 etc. all at the
// same time, show the user all of them, and have the user deselect any that they do not want to share. // same time, show the user all of them, and have the user deselect any that they do not want to share.
// So we'll ultimately be receiving a set of objects, perhaps with different post processing for each. // So we'll ultimately be receiving a set of objects, perhaps with different post processing for each.
message = JSON.parse(message);
if (message.type !== "snapshot") { if (message.type !== "snapshot") {
return; return;
} }
switch (message.action) { switch (message.action) {
case 'ready': // DOM is ready and page has loaded case 'ready': // DOM is ready and page has loaded
tablet.emitScriptEvent(JSON.stringify({ ui.sendMessage({
type: "snapshot", type: "snapshot",
action: "captureSettings", action: "captureSettings",
setting: Settings.getValue("alsoTakeAnimatedSnapshot", true) setting: Settings.getValue("alsoTakeAnimatedSnapshot", true)
})); });
if (Snapshot.getSnapshotsLocation() !== "") { if (Snapshot.getSnapshotsLocation() !== "") {
isDomainOpen(Settings.getValue("previousSnapshotDomainID"), function (canShare) { isDomainOpen(Settings.getValue("previousSnapshotDomainID"), function (canShare) {
tablet.emitScriptEvent(JSON.stringify({ ui.sendMessage({
type: "snapshot", type: "snapshot",
action: "showPreviousImages", action: "showPreviousImages",
options: snapshotOptions, options: snapshotOptions,
image_data: imageData, image_data: imageData,
canShare: canShare canShare: canShare
})); });
}); });
} else { } else {
tablet.emitScriptEvent(JSON.stringify({ ui.sendMessage({
type: "snapshot", type: "snapshot",
action: "showSetupInstructions" action: "showSetupInstructions"
})); });
Settings.setValue("previousStillSnapPath", ""); Settings.setValue("previousStillSnapPath", "");
Settings.setValue("previousStillSnapStoryID", ""); Settings.setValue("previousStillSnapStoryID", "");
Settings.setValue("previousStillSnapBlastingDisabled", false); Settings.setValue("previousStillSnapBlastingDisabled", false);
@ -124,7 +111,7 @@ function onMessage(message) {
|| (!HMD.active && Settings.getValue("desktopTabletBecomesToolbar", true))) { || (!HMD.active && Settings.getValue("desktopTabletBecomesToolbar", true))) {
Desktop.show("hifi/dialogs/GeneralPreferencesDialog.qml", "GeneralPreferencesDialog"); Desktop.show("hifi/dialogs/GeneralPreferencesDialog.qml", "GeneralPreferencesDialog");
} else { } else {
tablet.loadQMLOnTop("hifi/tablet/TabletGeneralPreferences.qml"); ui.openOnTop("hifi/tablet/TabletGeneralPreferences.qml");
} }
break; break;
case 'captureStillAndGif': case 'captureStillAndGif':
@ -284,7 +271,6 @@ var POLAROID_RATE_LIMIT_MS = 1000;
var polaroidPrintingIsRateLimited = false; var polaroidPrintingIsRateLimited = false;
function printToPolaroid(image_url) { function printToPolaroid(image_url) {
// Rate-limit printing // Rate-limit printing
if (polaroidPrintingIsRateLimited) { if (polaroidPrintingIsRateLimited) {
return; return;
@ -376,19 +362,6 @@ function fillImageDataFromPrevious() {
} }
} }
var SNAPSHOT_REVIEW_URL = Script.resolvePath("html/SnapshotReview.html");
var isInSnapshotReview = false;
function onButtonClicked() {
if (isInSnapshotReview){
// for toolbar-mode: go back to home screen, this will close the window.
tablet.gotoHomeScreen();
} else {
fillImageDataFromPrevious();
tablet.gotoWebScreen(SNAPSHOT_REVIEW_URL);
HMD.openTablet();
}
}
function snapshotUploaded(isError, reply) { function snapshotUploaded(isError, reply) {
if (!isError) { if (!isError) {
var replyJson = JSON.parse(reply), var replyJson = JSON.parse(reply),
@ -409,12 +382,12 @@ function snapshotUploaded(isError, reply) {
} }
if ((isGif && !ignoreGifSnapshotData) || (!isGif && !ignoreStillSnapshotData)) { if ((isGif && !ignoreGifSnapshotData) || (!isGif && !ignoreStillSnapshotData)) {
print('SUCCESS: Snapshot uploaded! Story with audience:for_url created! ID:', storyID); print('SUCCESS: Snapshot uploaded! Story with audience:for_url created! ID:', storyID);
tablet.emitScriptEvent(JSON.stringify({ ui.sendMessage({
type: "snapshot", type: "snapshot",
action: "snapshotUploadComplete", action: "snapshotUploadComplete",
story_id: storyID, story_id: storyID,
image_url: imageURL, image_url: imageURL,
})); });
if (isGif) { if (isGif) {
Settings.setValue("previousAnimatedSnapStoryID", storyID); Settings.setValue("previousAnimatedSnapStoryID", storyID);
} else { } else {
@ -429,10 +402,10 @@ function snapshotUploaded(isError, reply) {
} }
var href, snapshotDomainID; var href, snapshotDomainID;
function takeSnapshot() { function takeSnapshot() {
tablet.emitScriptEvent(JSON.stringify({ ui.sendMessage({
type: "snapshot", type: "snapshot",
action: "clearPreviousImages" action: "clearPreviousImages"
})); });
Settings.setValue("previousStillSnapPath", ""); Settings.setValue("previousStillSnapPath", "");
Settings.setValue("previousStillSnapStoryID", ""); Settings.setValue("previousStillSnapStoryID", "");
Settings.setValue("previousStillSnapBlastingDisabled", false); Settings.setValue("previousStillSnapBlastingDisabled", false);
@ -471,10 +444,6 @@ function takeSnapshot() {
} else { } else {
Window.stillSnapshotTaken.connect(stillSnapshotTaken); Window.stillSnapshotTaken.connect(stillSnapshotTaken);
} }
if (buttonConnected) {
button.clicked.disconnect(onButtonClicked);
buttonConnected = false;
}
// hide overlays if they are on // hide overlays if they are on
if (resetOverlays) { if (resetOverlays) {
@ -538,10 +507,6 @@ function stillSnapshotTaken(pathStillSnapshot, notify) {
Menu.setIsOptionChecked("Show Overlays", true); Menu.setIsOptionChecked("Show Overlays", true);
} }
Window.stillSnapshotTaken.disconnect(stillSnapshotTaken); Window.stillSnapshotTaken.disconnect(stillSnapshotTaken);
if (!buttonConnected) {
button.clicked.connect(onButtonClicked);
buttonConnected = true;
}
// A Snapshot Review dialog might be left open indefinitely after taking the picture, // A Snapshot Review dialog might be left open indefinitely after taking the picture,
// during which time the user may have moved. So stash that info in the dialog so that // during which time the user may have moved. So stash that info in the dialog so that
@ -559,12 +524,12 @@ function stillSnapshotTaken(pathStillSnapshot, notify) {
isLoggedIn: isLoggedIn isLoggedIn: isLoggedIn
}; };
imageData = [{ localPath: pathStillSnapshot, href: href }]; imageData = [{ localPath: pathStillSnapshot, href: href }];
tablet.emitScriptEvent(JSON.stringify({ ui.sendMessage({
type: "snapshot", type: "snapshot",
action: "addImages", action: "addImages",
options: snapshotOptions, options: snapshotOptions,
image_data: imageData image_data: imageData
})); });
}); });
} }
@ -572,10 +537,10 @@ function snapshotDirChanged(snapshotPath) {
Window.browseDirChanged.disconnect(snapshotDirChanged); Window.browseDirChanged.disconnect(snapshotDirChanged);
if (snapshotPath !== "") { // not cancelled if (snapshotPath !== "") { // not cancelled
Snapshot.setSnapshotsLocation(snapshotPath); Snapshot.setSnapshotsLocation(snapshotPath);
tablet.emitScriptEvent(JSON.stringify({ ui.sendMessage({
type: "snapshot", type: "snapshot",
action: "snapshotLocationChosen" action: "snapshotLocationChosen"
})); });
} }
} }
@ -603,22 +568,18 @@ function processingGifStarted(pathStillSnapshot) {
isLoggedIn: isLoggedIn isLoggedIn: isLoggedIn
}; };
imageData = [{ localPath: pathStillSnapshot, href: href }]; imageData = [{ localPath: pathStillSnapshot, href: href }];
tablet.emitScriptEvent(JSON.stringify({ ui.sendMessage({
type: "snapshot", type: "snapshot",
action: "addImages", action: "addImages",
options: snapshotOptions, options: snapshotOptions,
image_data: imageData image_data: imageData
})); });
}); });
} }
function processingGifCompleted(pathAnimatedSnapshot) { function processingGifCompleted(pathAnimatedSnapshot) {
isLoggedIn = Account.isLoggedIn(); isLoggedIn = Account.isLoggedIn();
Window.processingGifCompleted.disconnect(processingGifCompleted); Window.processingGifCompleted.disconnect(processingGifCompleted);
if (!buttonConnected) {
button.clicked.connect(onButtonClicked);
buttonConnected = true;
}
Settings.setValue("previousAnimatedSnapPath", pathAnimatedSnapshot); Settings.setValue("previousAnimatedSnapPath", pathAnimatedSnapshot);
@ -631,12 +592,12 @@ function processingGifCompleted(pathAnimatedSnapshot) {
canBlast: location.domainID === Settings.getValue("previousSnapshotDomainID"), canBlast: location.domainID === Settings.getValue("previousSnapshotDomainID"),
}; };
imageData = [{ localPath: pathAnimatedSnapshot, href: href }]; imageData = [{ localPath: pathAnimatedSnapshot, href: href }];
tablet.emitScriptEvent(JSON.stringify({ ui.sendMessage({
type: "snapshot", type: "snapshot",
action: "addImages", action: "addImages",
options: snapshotOptions, options: snapshotOptions,
image_data: imageData image_data: imageData
})); });
}); });
} }
function maybeDeleteSnapshotStories() { function maybeDeleteSnapshotStories() {
@ -655,28 +616,16 @@ function maybeDeleteSnapshotStories() {
}); });
storyIDsToMaybeDelete = []; storyIDsToMaybeDelete = [];
} }
function onTabletScreenChanged(type, url) {
var wasInSnapshotReview = isInSnapshotReview;
isInSnapshotReview = (type === "Web" && url === SNAPSHOT_REVIEW_URL);
button.editProperties({ isActive: isInSnapshotReview });
if (isInSnapshotReview !== wasInSnapshotReview) {
if (isInSnapshotReview) {
tablet.webEventReceived.connect(onMessage);
} else {
tablet.webEventReceived.disconnect(onMessage);
}
}
}
function onUsernameChanged() { function onUsernameChanged() {
fillImageDataFromPrevious(); fillImageDataFromPrevious();
isDomainOpen(Settings.getValue("previousSnapshotDomainID"), function (canShare) { isDomainOpen(Settings.getValue("previousSnapshotDomainID"), function (canShare) {
tablet.emitScriptEvent(JSON.stringify({ ui.sendMessage({
type: "snapshot", type: "snapshot",
action: "showPreviousImages", action: "showPreviousImages",
options: snapshotOptions, options: snapshotOptions,
image_data: imageData, image_data: imageData,
canShare: canShare canShare: canShare
})); });
}); });
if (isLoggedIn) { if (isLoggedIn) {
if (shareAfterLogin) { if (shareAfterLogin) {
@ -705,10 +654,10 @@ function onUsernameChanged() {
function snapshotLocationSet(location) { function snapshotLocationSet(location) {
if (location !== "") { if (location !== "") {
tablet.emitScriptEvent(JSON.stringify({ ui.sendMessage({
type: "snapshot", type: "snapshot",
action: "snapshotLocationChosen" action: "snapshotLocationChosen"
})); });
} }
} }
@ -733,36 +682,36 @@ function processRezPermissionChange(canRez) {
action = 'setPrintButtonDisabled'; action = 'setPrintButtonDisabled';
} }
tablet.emitScriptEvent(JSON.stringify({ ui.sendMessage({
type: "snapshot", type: "snapshot",
action : action action : action
})); });
} }
button.clicked.connect(onButtonClicked); function startup() {
buttonConnected = true; ui = new AppUi({
buttonName: "SNAP",
sortOrder: 5,
home: Script.resolvePath("html/SnapshotReview.html"),
onOpened: fillImageDataFromPrevious,
onMessage: onMessage
});
Window.snapshotShared.connect(snapshotUploaded); Entities.canRezChanged.connect(updatePrintPermissions);
tablet.screenChanged.connect(onTabletScreenChanged); Entities.canRezTmpChanged.connect(updatePrintPermissions);
GlobalServices.myUsernameChanged.connect(onUsernameChanged); GlobalServices.myUsernameChanged.connect(onUsernameChanged);
Snapshot.snapshotLocationSet.connect(snapshotLocationSet); Snapshot.snapshotLocationSet.connect(snapshotLocationSet);
Window.snapshotShared.connect(snapshotUploaded);
}
startup();
Entities.canRezChanged.connect(updatePrintPermissions); function shutdown() {
Entities.canRezTmpChanged.connect(updatePrintPermissions);
Script.scriptEnding.connect(function () {
if (buttonConnected) {
button.clicked.disconnect(onButtonClicked);
buttonConnected = false;
}
if (tablet) {
tablet.removeButton(button);
tablet.screenChanged.disconnect(onTabletScreenChanged);
}
Window.snapshotShared.disconnect(snapshotUploaded); Window.snapshotShared.disconnect(snapshotUploaded);
Snapshot.snapshotLocationSet.disconnect(snapshotLocationSet); Snapshot.snapshotLocationSet.disconnect(snapshotLocationSet);
GlobalServices.myUsernameChanged.disconnect(onUsernameChanged);
Entities.canRezChanged.disconnect(updatePrintPermissions); Entities.canRezChanged.disconnect(updatePrintPermissions);
Entities.canRezTmpChanged.disconnect(updatePrintPermissions); Entities.canRezTmpChanged.disconnect(updatePrintPermissions);
}); }
Script.scriptEnding.connect(shutdown);
}()); // END LOCAL_SCOPE }()); // END LOCAL_SCOPE