mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
Snapshot.js now uses AppUi
This commit is contained in:
parent
299e9d0d38
commit
1aaa90675c
2 changed files with 61 additions and 97 deletions
|
@ -54,6 +54,17 @@ function AppUi(properties) {
|
|||
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.currentUrl = "";
|
||||
// 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
|
||||
});
|
||||
};
|
||||
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';
|
||||
};
|
||||
that.eventSignal = function eventSignal() { // What signal to hook onMessage to.
|
||||
|
|
|
@ -12,23 +12,13 @@
|
|||
|
||||
(function () { // BEGIN LOCAL_SCOPE
|
||||
Script.include("/~/system/libraries/accountUtils.js");
|
||||
var AppUi = Script.require('appUi');
|
||||
|
||||
var SNAPSHOT_DELAY = 500; // 500ms
|
||||
var FINISH_SOUND_DELAY = 350;
|
||||
var resetOverlays;
|
||||
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 imageData = [];
|
||||
var storyIDsToMaybeDelete = [];
|
||||
|
@ -52,8 +42,6 @@ try {
|
|||
print('Failed to resolve request api, error: ' + err);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function removeFromStoryIDsToMaybeDelete(story_id) {
|
||||
storyIDsToMaybeDelete.splice(storyIDsToMaybeDelete.indexOf(story_id), 1);
|
||||
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
|
||||
// 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.
|
||||
message = JSON.parse(message);
|
||||
if (message.type !== "snapshot") {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (message.action) {
|
||||
case 'ready': // DOM is ready and page has loaded
|
||||
tablet.emitScriptEvent(JSON.stringify({
|
||||
ui.sendMessage({
|
||||
type: "snapshot",
|
||||
action: "captureSettings",
|
||||
setting: Settings.getValue("alsoTakeAnimatedSnapshot", true)
|
||||
}));
|
||||
});
|
||||
if (Snapshot.getSnapshotsLocation() !== "") {
|
||||
isDomainOpen(Settings.getValue("previousSnapshotDomainID"), function (canShare) {
|
||||
tablet.emitScriptEvent(JSON.stringify({
|
||||
ui.sendMessage({
|
||||
type: "snapshot",
|
||||
action: "showPreviousImages",
|
||||
options: snapshotOptions,
|
||||
image_data: imageData,
|
||||
canShare: canShare
|
||||
}));
|
||||
});
|
||||
});
|
||||
} else {
|
||||
tablet.emitScriptEvent(JSON.stringify({
|
||||
ui.sendMessage({
|
||||
type: "snapshot",
|
||||
action: "showSetupInstructions"
|
||||
}));
|
||||
});
|
||||
Settings.setValue("previousStillSnapPath", "");
|
||||
Settings.setValue("previousStillSnapStoryID", "");
|
||||
Settings.setValue("previousStillSnapBlastingDisabled", false);
|
||||
|
@ -124,7 +111,7 @@ function onMessage(message) {
|
|||
|| (!HMD.active && Settings.getValue("desktopTabletBecomesToolbar", true))) {
|
||||
Desktop.show("hifi/dialogs/GeneralPreferencesDialog.qml", "GeneralPreferencesDialog");
|
||||
} else {
|
||||
tablet.loadQMLOnTop("hifi/tablet/TabletGeneralPreferences.qml");
|
||||
ui.openOnTop("hifi/tablet/TabletGeneralPreferences.qml");
|
||||
}
|
||||
break;
|
||||
case 'captureStillAndGif':
|
||||
|
@ -284,7 +271,6 @@ var POLAROID_RATE_LIMIT_MS = 1000;
|
|||
var polaroidPrintingIsRateLimited = false;
|
||||
|
||||
function printToPolaroid(image_url) {
|
||||
|
||||
// Rate-limit printing
|
||||
if (polaroidPrintingIsRateLimited) {
|
||||
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) {
|
||||
if (!isError) {
|
||||
var replyJson = JSON.parse(reply),
|
||||
|
@ -409,12 +382,12 @@ function snapshotUploaded(isError, reply) {
|
|||
}
|
||||
if ((isGif && !ignoreGifSnapshotData) || (!isGif && !ignoreStillSnapshotData)) {
|
||||
print('SUCCESS: Snapshot uploaded! Story with audience:for_url created! ID:', storyID);
|
||||
tablet.emitScriptEvent(JSON.stringify({
|
||||
ui.sendMessage({
|
||||
type: "snapshot",
|
||||
action: "snapshotUploadComplete",
|
||||
story_id: storyID,
|
||||
image_url: imageURL,
|
||||
}));
|
||||
});
|
||||
if (isGif) {
|
||||
Settings.setValue("previousAnimatedSnapStoryID", storyID);
|
||||
} else {
|
||||
|
@ -429,10 +402,10 @@ function snapshotUploaded(isError, reply) {
|
|||
}
|
||||
var href, snapshotDomainID;
|
||||
function takeSnapshot() {
|
||||
tablet.emitScriptEvent(JSON.stringify({
|
||||
ui.sendMessage({
|
||||
type: "snapshot",
|
||||
action: "clearPreviousImages"
|
||||
}));
|
||||
});
|
||||
Settings.setValue("previousStillSnapPath", "");
|
||||
Settings.setValue("previousStillSnapStoryID", "");
|
||||
Settings.setValue("previousStillSnapBlastingDisabled", false);
|
||||
|
@ -471,10 +444,6 @@ function takeSnapshot() {
|
|||
} else {
|
||||
Window.stillSnapshotTaken.connect(stillSnapshotTaken);
|
||||
}
|
||||
if (buttonConnected) {
|
||||
button.clicked.disconnect(onButtonClicked);
|
||||
buttonConnected = false;
|
||||
}
|
||||
|
||||
// hide overlays if they are on
|
||||
if (resetOverlays) {
|
||||
|
@ -538,10 +507,6 @@ function stillSnapshotTaken(pathStillSnapshot, notify) {
|
|||
Menu.setIsOptionChecked("Show Overlays", true);
|
||||
}
|
||||
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,
|
||||
// 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
|
||||
};
|
||||
imageData = [{ localPath: pathStillSnapshot, href: href }];
|
||||
tablet.emitScriptEvent(JSON.stringify({
|
||||
ui.sendMessage({
|
||||
type: "snapshot",
|
||||
action: "addImages",
|
||||
options: snapshotOptions,
|
||||
image_data: imageData
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -572,10 +537,10 @@ function snapshotDirChanged(snapshotPath) {
|
|||
Window.browseDirChanged.disconnect(snapshotDirChanged);
|
||||
if (snapshotPath !== "") { // not cancelled
|
||||
Snapshot.setSnapshotsLocation(snapshotPath);
|
||||
tablet.emitScriptEvent(JSON.stringify({
|
||||
ui.sendMessage({
|
||||
type: "snapshot",
|
||||
action: "snapshotLocationChosen"
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -603,22 +568,18 @@ function processingGifStarted(pathStillSnapshot) {
|
|||
isLoggedIn: isLoggedIn
|
||||
};
|
||||
imageData = [{ localPath: pathStillSnapshot, href: href }];
|
||||
tablet.emitScriptEvent(JSON.stringify({
|
||||
ui.sendMessage({
|
||||
type: "snapshot",
|
||||
action: "addImages",
|
||||
options: snapshotOptions,
|
||||
image_data: imageData
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function processingGifCompleted(pathAnimatedSnapshot) {
|
||||
isLoggedIn = Account.isLoggedIn();
|
||||
Window.processingGifCompleted.disconnect(processingGifCompleted);
|
||||
if (!buttonConnected) {
|
||||
button.clicked.connect(onButtonClicked);
|
||||
buttonConnected = true;
|
||||
}
|
||||
|
||||
Settings.setValue("previousAnimatedSnapPath", pathAnimatedSnapshot);
|
||||
|
||||
|
@ -631,12 +592,12 @@ function processingGifCompleted(pathAnimatedSnapshot) {
|
|||
canBlast: location.domainID === Settings.getValue("previousSnapshotDomainID"),
|
||||
};
|
||||
imageData = [{ localPath: pathAnimatedSnapshot, href: href }];
|
||||
tablet.emitScriptEvent(JSON.stringify({
|
||||
ui.sendMessage({
|
||||
type: "snapshot",
|
||||
action: "addImages",
|
||||
options: snapshotOptions,
|
||||
image_data: imageData
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
function maybeDeleteSnapshotStories() {
|
||||
|
@ -655,28 +616,16 @@ function maybeDeleteSnapshotStories() {
|
|||
});
|
||||
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() {
|
||||
fillImageDataFromPrevious();
|
||||
isDomainOpen(Settings.getValue("previousSnapshotDomainID"), function (canShare) {
|
||||
tablet.emitScriptEvent(JSON.stringify({
|
||||
ui.sendMessage({
|
||||
type: "snapshot",
|
||||
action: "showPreviousImages",
|
||||
options: snapshotOptions,
|
||||
image_data: imageData,
|
||||
canShare: canShare
|
||||
}));
|
||||
});
|
||||
});
|
||||
if (isLoggedIn) {
|
||||
if (shareAfterLogin) {
|
||||
|
@ -705,10 +654,10 @@ function onUsernameChanged() {
|
|||
|
||||
function snapshotLocationSet(location) {
|
||||
if (location !== "") {
|
||||
tablet.emitScriptEvent(JSON.stringify({
|
||||
ui.sendMessage({
|
||||
type: "snapshot",
|
||||
action: "snapshotLocationChosen"
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -733,36 +682,36 @@ function processRezPermissionChange(canRez) {
|
|||
action = 'setPrintButtonDisabled';
|
||||
}
|
||||
|
||||
tablet.emitScriptEvent(JSON.stringify({
|
||||
ui.sendMessage({
|
||||
type: "snapshot",
|
||||
action : action
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
button.clicked.connect(onButtonClicked);
|
||||
buttonConnected = true;
|
||||
function startup() {
|
||||
ui = new AppUi({
|
||||
buttonName: "SNAP",
|
||||
sortOrder: 5,
|
||||
home: Script.resolvePath("html/SnapshotReview.html"),
|
||||
onOpened: fillImageDataFromPrevious,
|
||||
onMessage: onMessage
|
||||
});
|
||||
|
||||
Window.snapshotShared.connect(snapshotUploaded);
|
||||
tablet.screenChanged.connect(onTabletScreenChanged);
|
||||
GlobalServices.myUsernameChanged.connect(onUsernameChanged);
|
||||
Snapshot.snapshotLocationSet.connect(snapshotLocationSet);
|
||||
Entities.canRezChanged.connect(updatePrintPermissions);
|
||||
Entities.canRezTmpChanged.connect(updatePrintPermissions);
|
||||
GlobalServices.myUsernameChanged.connect(onUsernameChanged);
|
||||
Snapshot.snapshotLocationSet.connect(snapshotLocationSet);
|
||||
Window.snapshotShared.connect(snapshotUploaded);
|
||||
}
|
||||
startup();
|
||||
|
||||
Entities.canRezChanged.connect(updatePrintPermissions);
|
||||
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);
|
||||
}
|
||||
function shutdown() {
|
||||
Window.snapshotShared.disconnect(snapshotUploaded);
|
||||
Snapshot.snapshotLocationSet.disconnect(snapshotLocationSet);
|
||||
GlobalServices.myUsernameChanged.disconnect(onUsernameChanged);
|
||||
Entities.canRezChanged.disconnect(updatePrintPermissions);
|
||||
Entities.canRezTmpChanged.disconnect(updatePrintPermissions);
|
||||
});
|
||||
}
|
||||
Script.scriptEnding.connect(shutdown);
|
||||
|
||||
}()); // END LOCAL_SCOPE
|
||||
|
|
Loading…
Reference in a new issue