Skip to content

Commit

Permalink
add 3 second timer shutter function (fixes Lana-chan#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lana-chan committed Oct 31, 2020
1 parent 1b3def0 commit 90730d6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
21 changes: 18 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ const cameraStream = document.querySelector("#camera-stream"),
uiMain = document.querySelector("#ui-main"),
uiCapture = document.querySelector("#ui-capture"),
uiSettings = document.querySelector("#ui-settings"),
uiHidden = document.querySelector("#ui-hidden");
uiHidden = document.querySelector("#ui-hidden"),
uiTimer = document.querySelector("#ui-timer");
var amountOfCameras = 0;
var currentFacingMode = 'user';
var appScale;
Expand Down Expand Up @@ -380,6 +381,12 @@ var buttons = {
y:0,
width:15,
height:15
},
timer: {
x:33,
y:131,
width:13,
height:13
}
};

Expand Down Expand Up @@ -543,6 +550,11 @@ function restartCamera() {
window.onorientationchange = restartCamera;
window.onresize = restartCamera;

function captureImage() {
cameraStream.pause();
currentUI = uiCapture;
}

function initCameraUI() {
initAppScaling();

Expand All @@ -554,8 +566,7 @@ function initCameraUI() {
if(currentUI === uiMain) {
if(isInside(mousePos, buttons.bottomLeft) || isInside(mousePos, buttons.screenHotspot)) {
// shutter
cameraStream.pause();
currentUI = uiCapture;
captureImage();
} else if(isInside(mousePos, buttons.bottomRight)) {
// switch camera
switchCameras();
Expand All @@ -565,6 +576,10 @@ function initCameraUI() {
} else if(isInside(mousePos, buttons.hideUI)) {
// hide UI buttons
currentUI = uiHidden;
} else if(isInside(mousePos, buttons.timer)) {
// change UI to timer and trigger 3s delay to capture
currentUI = uiTimer;
setTimeout(captureImage, 3000);
}
} else if(currentUI === uiCapture) {
if(isInside(mousePos, buttons.bottomLeft)) {
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<img src="ui-settings.png" id="ui-settings" />
<img src="ui-capture.png" id="ui-capture" />
<img src="ui-hidden.png" id="ui-hidden" />
<img src="ui-timer.png" id="ui-timer" />
</div>

<script src="app.js"></script>
Expand Down
5 changes: 3 additions & 2 deletions sw.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const cacheName = 'webgbcam-v1'
const cacheName = 'webgbcam-v2'

self.addEventListener('install', function(e) {
e.waitUntil(
Expand All @@ -13,7 +13,8 @@ self.addEventListener('install', function(e) {
'ui-capture.png',
'ui-settings.png',
'ui-main.png',
'ui-hidden.png'
'ui-hidden.png',
'ui-timer.png'
]);
})
);
Expand Down
Binary file modified ui-main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ui-timer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 90730d6

Please sign in to comment.