Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ The base class from which addons are inherited. If you use the function interfac
| `changingActiveImage` | Notification before changing the current image. |
| | *Argument*: currentImageIndex, fadeTime (ms) |
| `changedActiveImage` | Notification that the current image has been changed. |
| | *Argument*: currentImageIndex (ms) |
| | *Argument*: currentImageIndex |

</details>

Expand Down
6 changes: 6 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ h1 {
color: white;
}

.touch-bar:hover,
.touchBarElement:hover {
cursor: pointer;
}


.disabled-icon {
color: #333;
}
Expand Down
13 changes: 13 additions & 0 deletions js/defaultConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ var defaultConfig = {
]
},

gestures: {
// enable gesture support
enabled: true,
// swipe image out duration
swipeAnimationDuration: 400,
// fade in duration for the loading image
swipeFadeInImgDuration: 800,
// percent per event for pinch/zoom gestures
zoomPercentPerEvent: 1.5,
// maximum factor for zoom/shrink operations
maxScaleFactor: 5
},

// options for the addonHandler class
addonInterface: {
// configure which types should be logged
Expand Down
16 changes: 15 additions & 1 deletion js/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const velocity = require("velocity-animate");
const logger = remote.getGlobal("rendererLogger");
const config = remote.getGlobal("config");
const {TouchBar, TouchBarElement} = require("./js/touchBar.js")
const initGestures = require('./js/touchGestures.js');

// Inform that Renderer started
logger.info("Renderer started ...");
Expand Down Expand Up @@ -52,6 +53,17 @@ if (config.playSoundOnRecieve !== false) {

if (config.touchBar) {
touchBar = new TouchBar(touchBarElements, config.touchBar)
// initialize swipe/pinch gestures
if (config.gestures.enabled) {
initGestures(config, {
pauseCallback: () => {
if (!isPaused) {
pause();
}
},
loadImage: loadImage
});
}
} else {
// handle touch events for navigation and voice reply
$("body").on('touchstart', function() {
Expand Down Expand Up @@ -727,10 +739,12 @@ function loadImage(isNext, fadeTime, goToLatest = false) {
cleanUp();
} else {
$assetDiv.velocity("fadeIn", {
duration: fadeTime
duration: fadeTime,
queue: false
});
$currentAsset.velocity("fadeOut", {
duration: fadeTime,
queue: false,
complete: function() {
$(this).remove();
cleanUp();
Expand Down
4 changes: 2 additions & 2 deletions js/touchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TouchBar {
el.classList = name + " touchBarElement";
el.style.lineHeight = self.height;
el.style.fontSize = ($('#touch-bar-container').height()*0.8) + 'px';
$(el).on('touchend', function(event) {
$(el).on('click', function(event) {
// don't bubble up events to prevent disappearing sweetalert messages
event.preventDefault();
clearTimeout(self.autoHideTimerId);
Expand All @@ -47,7 +47,7 @@ class TouchBar {

touchBarContainer.appendChild(touchBarBlur);
touchBarContainer.appendChild(touchBar);
$("#touch-container").on('touchend', function(event) {
$("#touch-container").on('click', function(event) {
self.toggle()
});
}
Expand Down
61 changes: 61 additions & 0 deletions js/touchGestures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const Hammer = require('hammerjs');

/**
* Initialize touch gesture handling
* @param {object} config TeleFrame configuration object
* @param {object} options object providing callbacks for loadImage and pause
* {
* loadImage: function loadImage(next, fadeTime) {...},
* pause: function pause() {...}
* }
* @return {undefined}
*/
const initGestures = (config, options) => {
// initialize swipe/pinch gestures
new Hammer.Manager(document.getElementById('touch-container'), {
recognizers: [
[Hammer.Swipe, { direction: Hammer.DIRECTION_HORIZONTAL }],
[Hammer.Pinch]
]
})
// Subscribe to the desired events
.on('swipe pinch', function(event) {
switch(event.type) {
case 'swipe':
if (typeof options.loadImage !== 'function') {
$('.imgcontainer').animate({ left: (event.offsetDirection === Hammer.DIRECTION_LEFT ? '-=' : '+=') + '100%'}, 50,
() => $(event.offsetDirection === Hammer.DIRECTION_LEFT ? '.nextImage' : '.previousImage').trigger('click')
);
} else {
$('.imgcontainer').animate({ left: (event.offsetDirection === Hammer.DIRECTION_LEFT ? '-=' : '+=') + '110%'}, config.gestures.swipeAnimationDuration);
options.loadImage(event.offsetDirection === Hammer.DIRECTION_LEFT, config.gestures.swipeFadeInImgDuration);
}
break;
case 'pinch':
if (event.scale) {
const MAX_SCALE_FACTOR = config.gestures.maxScaleFactor;
const ZOOM_PERCENT = config.gestures.zoomPercentPerEvent;
const $assetContainer = $container.find('.imgcontainer');
if (typeof options.pauseCallback === 'function') {
options.pauseCallback();
}
if ($assetContainer.length > 0) {
let attrib = 'height';
// get the current zomm (starts with '100%')
let currentZoom = $assetContainer[0].style.width;
if (currentZoom) {
attrib = 'width';
} else {
currentZoom = $assetContainer[0].style.height;
}
currentZoom = parseInt(currentZoom.replace('%', '')) || 100;
$assetContainer.css(`max-${attrib}`, '');
$assetContainer[attrib](Math.min((100 * MAX_SCALE_FACTOR), Math.max((100 / MAX_SCALE_FACTOR), currentZoom + (event.scale > 1.0 ? ZOOM_PERCENT : -ZOOM_PERCENT))) + '%');
}
}
break;
}
});
}

module.exports = initGestures;
2 changes: 2 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ if(config.switchLedsOff){
}

app.commandLine.appendSwitch("autoplay-policy", "no-user-gesture-required");
// avoid deprecation warning from electron 8
app.allowRendererProcessReuse = true;
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win;
Expand Down
43 changes: 20 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@
},
"homepage": "https://github.com/LukeSkywalker92/teleframe#readme",
"dependencies": {
"@fortawesome/fontawesome-free": "^5.12.0",
"@fortawesome/fontawesome-free": "^5.12.1",
"chroma-js": "^2.1.0",
"dotenv": "^8.2.0",
"electron": "^7.2.4",
"electron": "^8.1.0",
"hammerjs": "^2.0.8",
"image-downloader": "^3.5.0",
"jquery": "^3.5.0",
"moment": "^2.24.0",
"node-audiorecorder": "^1.4.2",
"node-schedule": "^1.3.2",
"randomcolor": "^0.5.4",
"sweetalert": "^2.1.2",
"sweetalert2": "^9.5.4",
"telegraf": "^3.35.0",
"sweetalert2": "^9.10.1",
"telegraf": "^3.36.0",
"velocity-animate": "^1.5.2",
"winston": "^3.2.1"
}
Expand Down