From b508d6882f3339b696bc67ceafb9b426202a0ce8 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 13 Apr 2017 17:59:28 +1200 Subject: [PATCH] Add checkbox that stops countdown/finishes recording when reopen dialog --- scripts/system/html/js/record.js | 41 ++++++++++++++++++++++---- scripts/system/html/record.html | 4 +++ scripts/system/record.js | 50 +++++++++++++++++++++++++------- 3 files changed, 79 insertions(+), 16 deletions(-) diff --git a/scripts/system/html/js/record.js b/scripts/system/html/js/record.js index 393d4c246f..7ed44e6d9c 100644 --- a/scripts/system/html/js/record.js +++ b/scripts/system/html/js/record.js @@ -23,14 +23,18 @@ var isUsingToolbar = false, elShowInfoButton, elLoadButton, elRecordButton, + elFinishOnOpen, + elFinishOnOpenLabel, EVENT_BRIDGE_TYPE = "record", BODY_LOADED_ACTION = "bodyLoaded", + USING_TOOLBAR_ACTION = "usingToolbar", RECORDINGS_BEING_PLAYED_ACTION = "recordingsBeingPlayed", NUMBER_OF_PLAYERS_ACTION = "numberOfPlayers", STOP_PLAYING_RECORDING_ACTION = "stopPlayingRecording", LOAD_RECORDING_ACTION = "loadRecording", START_RECORDING_ACTION = "startRecording", - STOP_RECORDING_ACTION = "stopRecording"; + STOP_RECORDING_ACTION = "stopRecording", + FINISH_ON_OPEN_ACTION = "finishOnOpen"; function stopPlayingRecording(event) { var playerID = event.target.getElementsByTagName("input")[0].value; @@ -41,14 +45,14 @@ function stopPlayingRecording(event) { })); } -function orderRecording(a, b) { - return a.filename > b.filename ? 1 : -1; -} - function updatePlayersUnused() { elPlayersUnused.innerHTML = numberOfPlayers - recordingsBeingPlayed.length; } +function orderRecording(a, b) { + return a.filename > b.filename ? 1 : -1; +} + function updateRecordings() { var tbody, tr, @@ -132,10 +136,24 @@ function updateLoadButton() { } } +function updateFinishOnOpenLabel() { + var WINDOW_FINISH_ON_OPEN_LABEL = "Finish recording when open dialog", + TABLET_FINISH_ON_OPEN_LABEL = "Finish recording when open tablet"; + + elFinishOnOpenLabel.innerHTML = isUsingToolbar ? WINDOW_FINISH_ON_OPEN_LABEL : TABLET_FINISH_ON_OPEN_LABEL; +} + function onScriptEventReceived(data) { var message = JSON.parse(data); if (message.type === EVENT_BRIDGE_TYPE) { switch (message.action) { + case USING_TOOLBAR_ACTION: + isUsingToolbar = message.value; + updateFinishOnOpenLabel(); + break; + case FINISH_ON_OPEN_ACTION: + elFinishOnOpen.checked = message.value; + break; case RECORDINGS_BEING_PLAYED_ACTION: recordingsBeingPlayed = JSON.parse(message.value); updateRecordings(); @@ -179,6 +197,14 @@ function onRecordButtonClicked() { } } +function onFinishOnOpenClicked() { + EventBridge.emitWebEvent(JSON.stringify({ + type: EVENT_BRIDGE_TYPE, + action: FINISH_ON_OPEN_ACTION, + value: elFinishOnOpen.checked + })); +} + function signalBodyLoaded() { EventBridge.emitWebEvent(JSON.stringify({ type: EVENT_BRIDGE_TYPE, @@ -206,5 +232,10 @@ function onBodyLoaded() { elRecordButton = document.getElementById("record-button"); elRecordButton.onclick = onRecordButtonClicked; + elFinishOnOpen = document.getElementById("finish-on-open"); + elFinishOnOpen.onclick = onFinishOnOpenClicked; + + elFinishOnOpenLabel = document.getElementById("finish-on-open-label"); + signalBodyLoaded(); } diff --git a/scripts/system/html/record.html b/scripts/system/html/record.html index 8a09564d0f..5eb18de491 100644 --- a/scripts/system/html/record.html +++ b/scripts/system/html/record.html @@ -61,6 +61,10 @@
+
+ + +
diff --git a/scripts/system/record.js b/scripts/system/record.js index 0290f1e083..a3ceda32b3 100644 --- a/scripts/system/record.js +++ b/scripts/system/record.js @@ -385,14 +385,22 @@ }()); Dialog = (function () { - var EVENT_BRIDGE_TYPE = "record", + var isFinishOnOpen = false, + EVENT_BRIDGE_TYPE = "record", BODY_LOADED_ACTION = "bodyLoaded", + USING_TOOLBAR_ACTION = "usingToolbar", RECORDINGS_BEING_PLAYED_ACTION = "recordingsBeingPlayed", NUMBER_OF_PLAYERS_ACTION = "numberOfPlayers", STOP_PLAYING_RECORDING_ACTION = "stopPlayingRecording", LOAD_RECORDING_ACTION = "loadRecording", START_RECORDING_ACTION = "startRecording", - STOP_RECORDING_ACTION = "stopRecording"; + STOP_RECORDING_ACTION = "stopRecording", + FINISH_ON_OPEN_ACTION = "finishOnOpen"; + + function isUsingToolbar() { + return ((HMD.active && Settings.getValue("hmdTabletBecomesToolbar")) + || (!HMD.active && Settings.getValue("desktopTabletBecomesToolbar"))); + } function onWebEventReceived(data) { var message = JSON.parse(data); @@ -400,6 +408,16 @@ switch (message.action) { case BODY_LOADED_ACTION: // Dialog's ready; initialize its state. + tablet.emitScriptEvent(JSON.stringify({ + type: EVENT_BRIDGE_TYPE, + action: USING_TOOLBAR_ACTION, + value: isUsingToolbar() + })); + tablet.emitScriptEvent(JSON.stringify({ + type: EVENT_BRIDGE_TYPE, + action: FINISH_ON_OPEN_ACTION, + value: isFinishOnOpen + })); tablet.emitScriptEvent(JSON.stringify({ type: EVENT_BRIDGE_TYPE, action: NUMBER_OF_PLAYERS_ACTION, @@ -428,6 +446,10 @@ Recorder.finishRecording(); } break; + case FINISH_ON_OPEN_ACTION: + // Set behavior on dialog open. + isFinishOnOpen = message.value; + break; } } } @@ -458,6 +480,10 @@ })); } + function finishOnOpen() { + return isFinishOnOpen; + } + function setUp() { tablet.webEventReceived.connect(onWebEventReceived); } @@ -468,21 +494,24 @@ return { updatePlayerDetails: updatePlayerDetails, + finishOnOpen: finishOnOpen, setUp: setUp, tearDown: tearDown }; }()); function onTabletScreenChanged(type, url) { - // Open/close dialog in tablet or window. + // Opened/closed dialog in tablet or window. var RECORD_URL = "/scripts/system/html/record.html"; if (type === "Web" && url.slice(-RECORD_URL.length) === RECORD_URL) { - // Cancel countdown or finish recording. - if (Recorder.isCountingDown()) { - Recorder.cancelCountdown(); - } else if (Recorder.isRecording()) { - Recorder.finishRecording(); + if (Dialog.finishOnOpen()) { + // Cancel countdown or finish recording. + if (Recorder.isCountingDown()) { + Recorder.cancelCountdown(); + } else if (Recorder.isRecording()) { + Recorder.finishRecording(); + } } isDialogDisplayed = true; } else { @@ -492,9 +521,8 @@ } function onTabletShownChanged() { - // Open/close tablet. - - if (tablet.tabletShown) { + // Opened/closed tablet. + if (tablet.tabletShown && Dialog.finishOnOpen()) { // Cancel countdown or finish recording. if (Recorder.isCountingDown()) { Recorder.cancelCountdown();