From 5e8722ccf549a1f2b48c93d3dfc8d2c06787e773 Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Thu, 18 Aug 2016 12:58:00 -0700 Subject: [PATCH] persist "open feed after" checkbox setting --- scripts/system/html/ShareSnapshot.html | 7 +++++-- scripts/system/snapshot.js | 27 ++++++++++++++++++-------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/scripts/system/html/ShareSnapshot.html b/scripts/system/html/ShareSnapshot.html index 9098b30121..9b9403cf78 100644 --- a/scripts/system/html/ShareSnapshot.html +++ b/scripts/system/html/ShareSnapshot.html @@ -84,6 +84,9 @@ } function handleShareButtons(shareMsg) { + var openFeed = document.getElementById('openFeed'); + openFeed.checked = shareMsg.openFeedAfterShare; + openFeed.onchange = function () { EventBridge.emitWebEvent(openFeed.checked ? 'setOpenFeedTrue' : 'setOpenFeedFalse'); }; if (!shareMsg.canShare) { // this means you may or may not be logged in, but can't share // because you are not in a public place. @@ -116,10 +119,10 @@ }; // beware of bug: Cannot send objects at top level. (Nested in arrays is fine.) shareSelected = function () { - EventBridge.emitWebEvent(paths.concat({openFeed: document.getElementById("openFeed").checked})); + EventBridge.emitWebEvent(paths); }; doNotShare = function () { - EventBridge.emitWebEvent([{openFeed: document.getElementById("openFeed").checked}]); + EventBridge.emitWebEvent([]); }; snapshotSettings = function () { EventBridge.emitWebEvent("openSettings"); diff --git a/scripts/system/snapshot.js b/scripts/system/snapshot.js index 6c9132194e..8e99783ff6 100644 --- a/scripts/system/snapshot.js +++ b/scripts/system/snapshot.js @@ -20,23 +20,32 @@ var button = toolBar.addButton({ alpha: 0.9, }); +function shouldOpenFeedAfterShare() { + var persisted = Settings.getValue('openFeedAfterShare', true); // might answer true, false, "true", or "false" + return persisted && (persisted !== 'false'); +} function showFeedWindow() { DialogsManager.showFeed(); } -var openFeed, outstanding; +var outstanding; function confirmShare(data) { var dialog = new OverlayWebWindow('Snapshot Review', Script.resolvePath("html/ShareSnapshot.html"), 800, 470); function onMessage(message) { switch (message) { case 'ready': dialog.emitScriptEvent(data); // Send it. - openFeed = false; outstanding = 0; break; case 'openSettings': Desktop.show("hifi/dialogs/GeneralPreferencesDialog.qml", "GeneralPreferencesDialog"); break; + case 'setOpenFeedFalse': + Settings.setValue('openFeedAfterShare', false) + break; + case 'setOpenFeedTrue': + Settings.setValue('openFeedAfterShare', true) + break; default: dialog.webEventReceived.disconnect(onMessage); // I'm not certain that this is necessary. If it is, what do we do on normal close? dialog.close(); @@ -46,11 +55,9 @@ function confirmShare(data) { print('sharing', submessage.localPath); outstanding++; Window.shareSnapshot(submessage.localPath); - } else if (submessage.openFeed) { - openFeed = true; } }); - if (openFeed && !outstanding) { + if (!outstanding && shouldOpenFeedAfterShare()) { showFeedWindow(); } } @@ -67,7 +74,7 @@ function snapshotShared(success) { // for now just print an error. print('snapshot upload/share failed'); } - if ((--outstanding <= 0) && openFeed) { + if ((--outstanding <= 0) && shouldOpenFeedAfterShare()) { showFeedWindow(); } } @@ -114,8 +121,12 @@ function resetButtons(path, notify) { // last element in data array tells dialog whether we can share or not confirmShare([ - { localPath: path }, - { canShare: Boolean(Window.location.placename), isLoggedIn: Account.isLoggedIn() } + { localPath: path }, + { + canShare: Boolean(Window.location.placename), + isLoggedIn: Account.isLoggedIn(), + openFeedAfterShare: shouldOpenFeedAfterShare() + } ]); }