Disconnect snapshot event handler when tablet "home" button pressed

This commit is contained in:
David Rowe 2017-03-27 17:32:04 +13:00
parent dc3095bfcd
commit e58e3fbbf7

View file

@ -36,30 +36,27 @@ function showFeedWindow() {
DialogsManager.showFeed(); DialogsManager.showFeed();
} }
var SNAPSHOT_REVIEW_URL = Script.resolvePath("html/SnapshotReview.html");
var outstanding; var outstanding;
function confirmShare(data) { var readyData;
tablet.gotoWebScreen(SNAPSHOT_REVIEW_URL); function onMessage(message) {
function onMessage(message) { // Receives message from the html dialog via the qwebchannel EventBridge. This is complicated by the following:
// Receives message from the html dialog via the qwebchannel EventBridge. This is complicated by the following: // 1. Although we can send POJOs, we cannot receive a toplevel object. (Arrays of POJOs are fine, though.)
// 1. Although we can send POJOs, we cannot receive a toplevel object. (Arrays of POJOs are fine, though.) // 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);
message = JSON.parse(message); if (message.type !== "snapshot") {
if (message.type !== "snapshot") { return;
return; }
}
var isLoggedIn; var isLoggedIn;
var needsLogin = false; var needsLogin = false;
switch (message.action) { switch (message.action) {
case 'ready': // Send it. case 'ready': // Send it.
tablet.emitScriptEvent(JSON.stringify({ tablet.emitScriptEvent(JSON.stringify({
type: "snapshot", type: "snapshot",
action: data action: readyData
})); }));
outstanding = 0; outstanding = 0;
break; break;
case 'openSettings': case 'openSettings':
@ -72,7 +69,7 @@ function confirmShare(data) {
Settings.setValue('openFeedAfterShare', true); Settings.setValue('openFeedAfterShare', true);
break; break;
default: default:
tablet.webEventReceived.disconnect(onMessage); //tablet.webEventReceived.disconnect(onMessage); // <<< It's probably this that's missing?!
HMD.closeTablet(); HMD.closeTablet();
tablet.gotoHomeScreen(); tablet.gotoHomeScreen();
isLoggedIn = Account.isLoggedIn(); isLoggedIn = Account.isLoggedIn();
@ -90,15 +87,22 @@ function confirmShare(data) {
} }
}); });
if (!outstanding && shouldOpenFeedAfterShare()) { if (!outstanding && shouldOpenFeedAfterShare()) {
showFeedWindow(); //showFeedWindow();
} }
if (needsLogin) { // after the possible feed, so that the login is on top if (needsLogin) { // after the possible feed, so that the login is on top
Account.checkAndSignalForAccessToken(); Account.checkAndSignalForAccessToken();
} }
}
} }
}
var SNAPSHOT_REVIEW_URL = Script.resolvePath("html/SnapshotReview.html");
var isInSnapshotReview = false;
function confirmShare(data) {
tablet.gotoWebScreen(SNAPSHOT_REVIEW_URL);
readyData = data;
tablet.webEventReceived.connect(onMessage); tablet.webEventReceived.connect(onMessage);
HMD.openTablet(); HMD.openTablet();
isInSnapshotReview = true;
} }
function snapshotShared(errorMessage) { function snapshotShared(errorMessage) {
@ -214,10 +218,18 @@ function processingGif() {
} }
} }
function onTabletScreenChanged(type, url) {
if (isInSnapshotReview) {
tablet.webEventReceived.disconnect(onMessage);
isInSnapshotReview = false;
}
}
button.clicked.connect(onClicked); button.clicked.connect(onClicked);
buttonConnected = true; buttonConnected = true;
Window.snapshotShared.connect(snapshotShared); Window.snapshotShared.connect(snapshotShared);
Window.processingGif.connect(processingGif); Window.processingGif.connect(processingGif);
tablet.screenChanged.connect(onTabletScreenChanged);
Script.scriptEnding.connect(function () { Script.scriptEnding.connect(function () {
if (buttonConnected) { if (buttonConnected) {
@ -229,6 +241,7 @@ Script.scriptEnding.connect(function () {
} }
Window.snapshotShared.disconnect(snapshotShared); Window.snapshotShared.disconnect(snapshotShared);
Window.processingGif.disconnect(processingGif); Window.processingGif.disconnect(processingGif);
tablet.screenChanged.disconnect(onTabletScreenChanged);
}); });
}()); // END LOCAL_SCOPE }()); // END LOCAL_SCOPE