From c08b40b95009aec68759926e9212084f58450cae Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Fri, 21 Apr 2017 10:17:49 -0700 Subject: [PATCH] Initial sharing code hooked up --- scripts/system/html/js/SnapshotReview.js | 22 +++++----- scripts/system/snapshot.js | 56 +++++++++--------------- 2 files changed, 32 insertions(+), 46 deletions(-) diff --git a/scripts/system/html/js/SnapshotReview.js b/scripts/system/html/js/SnapshotReview.js index aae1fc5787..8fffd207ff 100644 --- a/scripts/system/html/js/SnapshotReview.js +++ b/scripts/system/html/js/SnapshotReview.js @@ -43,7 +43,7 @@ function addImage(data) { document.getElementById(id).style.height = img.clientHeight; } } - paths.push(data); + paths.push(data.localPath); } function createShareOverlay(parentID, isGif) { var shareOverlayContainer = document.createElement("DIV"); @@ -99,7 +99,7 @@ function createShareOverlay(parentID, isGif) { '
' + '
' + '
' + - '
' + + '
' + '' + '
' + '' + @@ -129,6 +129,15 @@ function selectImageToShare(selectedID) { shareOverlayBackground.style.display = "inline"; shareOverlay.style.display = "inline"; } +function shareWithEveryone(selectedID) { + selectedID = selectedID.id; // Why is this necessary? + + EventBridge.emitWebEvent(JSON.stringify({ + type: "snapshot", + action: "shareSnapshot", + data: paths[parseInt(selectedID.substring(1))] + })); +} function cancelSharing(selectedID) { selectedID = selectedID.id; // Why is this necessary? var shareOverlayContainer = document.getElementById(selectedID + "shareOverlayContainer"); @@ -208,7 +217,7 @@ window.onload = function () { document.getElementById('p0').style.height = p0img.clientHeight; } - paths[0].localPath = gifPath; + paths[0] = gifPath; } } else { imageCount = message.data.length; @@ -232,13 +241,6 @@ window.onload = function () { }); }; -// beware of bug: Cannot send objects at top level. (Nested in arrays is fine.) -function shareSelected() { - EventBridge.emitWebEvent(JSON.stringify({ - type: "snapshot", - action: paths - })); -} function doNotShare() { EventBridge.emitWebEvent(JSON.stringify({ type: "snapshot", diff --git a/scripts/system/snapshot.js b/scripts/system/snapshot.js index 97cd2c542e..7f71336dcf 100644 --- a/scripts/system/snapshot.js +++ b/scripts/system/snapshot.js @@ -96,43 +96,31 @@ function onMessage(message) { // onClicked(); break; - default: - //tablet.webEventReceived.disconnect(onMessage); // <<< It's probably this that's missing?! - HMD.closeTablet(); + case 'shareSnapshot': isLoggedIn = Account.isLoggedIn(); - message.action.forEach(function (submessage) { - if (submessage.share && !isLoggedIn) { - needsLogin = true; - submessage.share = false; - shareAfterLogin = true; - snapshotToShareAfterLogin = {path: submessage.localPath, href: submessage.href || href}; - } - if (submessage.share) { - print('sharing', submessage.localPath); - outstanding = true; - Window.shareSnapshot(submessage.localPath, submessage.href || href); - } else { - print('not sharing', submessage.localPath); - } - - }); - if (outstanding && shouldOpenFeedAfterShare()) { - showFeedWindow(); - outstanding = false; + if (!isLoggedIn) { + needsLogin = true; + shareAfterLogin = true; + snapshotToShareAfterLogin = { path: message.data, href: message.href || href }; + } else { + print('sharing', message.data); + outstanding++; + Window.shareSnapshot(message.data, message.href || href); } - if (needsLogin) { // after the possible feed, so that the login is on top - var isLoggedIn = Account.isLoggedIn(); - if (!isLoggedIn) { - if ((HMD.active && Settings.getValue("hmdTabletBecomesToolbar")) - || (!HMD.active && Settings.getValue("desktopTabletBecomesToolbar"))) { - Menu.triggerOption("Login / Sign Up"); - } else { - tablet.loadQMLOnTop("../../dialogs/TabletLoginDialog.qml"); - HMD.openTablet(); - } + if (needsLogin) { + if ((HMD.active && Settings.getValue("hmdTabletBecomesToolbar")) + || (!HMD.active && Settings.getValue("desktopTabletBecomesToolbar"))) { + Menu.triggerOption("Login / Sign Up"); + } else { + tablet.loadQMLOnTop("../../dialogs/TabletLoginDialog.qml"); + HMD.openTablet(); } } + break; + default: + print('Unknown message action received by snapshot.js!'); + break; } } @@ -298,11 +286,7 @@ function onConnected() { print('sharing', snapshotToShareAfterLogin.path); Window.shareSnapshot(snapshotToShareAfterLogin.path, snapshotToShareAfterLogin.href); shareAfterLogin = false; - if (shouldOpenFeedAfterShare()) { - showFeedWindow(); - } } - } button.clicked.connect(onClicked);