popup picks up current zoom level

This commit is contained in:
Tamius Han 2018-09-21 00:26:08 +02:00
parent 51c1255eed
commit afb595d8c0
8 changed files with 69 additions and 33 deletions

View File

@ -96,6 +96,11 @@ var ExtensionConf = {
arChange: { arChange: {
samenessTreshold: 0.025, // if aspect ratios are within 2.5% within each other, don't resize samenessTreshold: 0.025, // if aspect ratios are within 2.5% within each other, don't resize
}, },
zoom: {
minLogZoom: -1,
maxLogZoom: 3,
announceDebounce: 200 // we wait this long before announcing new zoom
},
miscFullscreenSettings: { miscFullscreenSettings: {
videoFloat: "center", videoFloat: "center",
mousePan: { mousePan: {

View File

@ -57,6 +57,10 @@ class CommsClient {
return; return;
} }
if (message.cmd === 'get-current-zoom') {
this.pageInfo.requestCurrentZoom();
}
if (message.cmd === "set-ar") { if (message.cmd === "set-ar") {
this.pageInfo.setAr(message.ratio); this.pageInfo.setAr(message.ratio);
} else if (message.cmd === 'set-video-float') { } else if (message.cmd === 'set-video-float') {
@ -77,7 +81,7 @@ class CommsClient {
// todo: autoArStatus // todo: autoArStatus
this.pageInfo.resumeProcessing(message.autoArStatus); this.pageInfo.resumeProcessing(message.autoArStatus);
} else if (message.cmd === 'set-zoom') { } else if (message.cmd === 'set-zoom') {
this.pageInfo.setZoom(message.zoom); this.pageInfo.setZoom(message.zoom, true);
} }
} }
@ -132,6 +136,10 @@ class CommsClient {
this.port.postMessage({cmd: "has-video"}); this.port.postMessage({cmd: "has-video"});
} }
announceZoom(scale){
this.port.postMessage({cmd: "announce-zoom", zoom: scale});
}
unregisterVideo(){ unregisterVideo(){
this.port.postMessage({cmd: "noVideo"}); // ayymd this.port.postMessage({cmd: "noVideo"}); // ayymd
} }
@ -245,7 +253,14 @@ class CommsServer {
console.log("[CommsServer.js::processMessage] Received message from background script!", message, "port", port, "\nsettings and server:", this.settings,this.server); console.log("[CommsServer.js::processMessage] Received message from background script!", message, "port", port, "\nsettings and server:", this.settings,this.server);
} }
if(message.cmd === 'get-current-site') { if (message.cmd === 'announce-zoom') {
// forward off to the popup, no use for this here
this.popupPort.postMessage({cmd: 'set-current-zoom', zoom: message.zoom});
} else if (message.cmd === 'get-current-zoom') {
this.sendToActive(message);
}
if (message.cmd === 'get-current-site') {
port.postMessage({cmd: 'set-current-site', site: await this.getCurrentTabHostname()}); port.postMessage({cmd: 'set-current-site', site: await this.getCurrentTabHostname()});
} }

View File

@ -1,6 +1,6 @@
class VideoData { class VideoData {
constructor(video, settings){ constructor(video, settings, pageInfo){
this.arSetupComplete = false; this.arSetupComplete = false;
this.video = video; this.video = video;
this.destroyed = false; this.destroyed = false;
@ -13,6 +13,7 @@ class VideoData {
this.arDetector = new ArDetector(this); // this starts Ar detection. needs optional parameter that prevets ardetdctor from starting this.arDetector = new ArDetector(this); // this starts Ar detection. needs optional parameter that prevets ardetdctor from starting
// player dimensions need to be in: // player dimensions need to be in:
// this.player.dimensions // this.player.dimensions
this.pageInfo = pageInfo;
} }
firstTimeArdInit(){ firstTimeArdInit(){
@ -130,13 +131,15 @@ class VideoData {
this.resizer.setStretchMode(stretchMode); this.resizer.setStretchMode(stretchMode);
} }
setZoom(zoomLevel){ setZoom(zoomLevel, no_announce){
this.resizer.setZoom(zoomLevel); this.resizer.setZoom(zoomLevel, no_announce);
} }
zoomStep(step){ zoomStep(step){
this.resizer.zoomStep(step); this.resizer.zoomStep(step);
} }
announceZoom(scale){
this.pageInfo.announceZoom(scale);
}
} }

View File

@ -21,6 +21,8 @@ class PageInfo {
console.log("registering video") console.log("registering video")
comms.registerVideo(); comms.registerVideo();
} }
this.currentZoomScale = 1;
} }
destroy() { destroy() {
@ -91,7 +93,7 @@ class PageInfo {
if(Debug.debug && Debug.periodic && Debug.videoRescan){ if(Debug.debug && Debug.periodic && Debug.videoRescan){
console.log("[PageInfo::rescan] found new video candidate:", video) console.log("[PageInfo::rescan] found new video candidate:", video)
} }
v = new VideoData(video, this.settings); v = new VideoData(video, this.settings, this);
// console.log("[PageInfo::rescan] v is:", v) // console.log("[PageInfo::rescan] v is:", v)
// debugger; // debugger;
v.initArDetection(); v.initArDetection();
@ -253,9 +255,9 @@ class PageInfo {
} }
} }
setZoom(zoomLevel) { setZoom(zoomLevel, no_announce) {
for(var vd of this.videos) { for(var vd of this.videos) {
vd.setZoom(zoomLevel); vd.setZoom(zoomLevel, no_announce);
} }
} }
@ -264,6 +266,19 @@ class PageInfo {
vd.zoomStep(step); vd.zoomStep(step);
} }
} }
announceZoom(scale) {
if (this.announceZoomTimeout) {
clearTimeout(this.announceZoom);
}
this.currentZoomScale = scale;
const ths = this;
this.announceZoomTimeout = setTimeout(() => ths.comms.announceZoom(scale), this.settings.active.zoom.announceDebounce);
}
requestCurrentZoom() {
this.comms.announceZoom(this.currentZoomScale);
}
} }
var RescanReason = { var RescanReason = {

View File

@ -264,8 +264,8 @@ class Resizer {
this.pan = undefined; this.pan = undefined;
} }
setZoom(zoomLevel) { setZoom(zoomLevel, no_announce) {
this.zoom.setZoom(zoomLevel); this.zoom.setZoom(zoomLevel, no_announce);
} }
zoomStep(step){ zoomStep(step){

View File

@ -19,26 +19,6 @@ class Zoom {
this.scale = 1; this.scale = 1;
} }
zoomIn(){
this.logScale += this.scaleStep;
if (this.logScale >= this.maxScale) {
this.logScale = this.maxScale;
}
this.scale = Math.pow(2, this.logScale);
}
zoomOut(){
this.logScale -= this.scaleStep;
if (this.logScale <= this.minScale) {
this.logScale = this.minScale;
}
this.scale = Math.pow(2, this.logScale);
}
zoomStep(amount){ zoomStep(amount){
this.logScale += amount; this.logScale += amount;
@ -56,9 +36,10 @@ class Zoom {
} }
this.conf.restoreAr(); this.conf.restoreAr();
this.conf.announceZoom(this.scale);
} }
setZoom(scale){ setZoom(scale, no_announce){
// NOTE: SCALE IS NOT LOGARITHMIC // NOTE: SCALE IS NOT LOGARITHMIC
if(scale < Math.pow(this.minScale)) { if(scale < Math.pow(this.minScale)) {
scale = this.minScale; scale = this.minScale;
@ -69,6 +50,9 @@ class Zoom {
this.scale = scale; this.scale = scale;
this.conf.restoreAr(); this.conf.restoreAr();
if (!no_announce) {
this.conf.announceZoom(this.scale);
}
} }
applyZoom(videoDimensions){ applyZoom(videoDimensions){

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Ultrawidify", "name": "Ultrawidify",
"version": "3.2.0-a1", "version": "3.2.0-a2",
"applications": { "applications": {
"gecko": { "gecko": {
"id": "{cf02b1a7-a01a-4e37-a609-516a283f1ed3}" "id": "{cf02b1a7-a01a-4e37-a609-516a283f1ed3}"

View File

@ -123,8 +123,13 @@ async function processReceivedMessage(message, port){
} }
if(message.cmd === 'set-current-site'){ if(message.cmd === 'set-current-site'){
if (site !== message.site) {
port.postMessage({cmd: 'get-current-zoom'});
}
site = message.site; site = message.site;
loadConfig(message.site); loadConfig(message.site);
} else if (message.cmd === 'set-current-zoom') {
setCurrentZoom(message.zoom);
} }
} }
@ -138,6 +143,15 @@ async function updateConfig() {
} }
} }
async function setCurrentZoom(scale) {
if(Debug.debug) {
console.log("[popup.js::setCurrentZoom] we're setting zoom:", scale);
}
VideoPanel.inputs.zoomSlider.value = Math.log2(scale);
VideoPanel.labels.zoomLevel.textContent = (scale * 100).toFixed();
}
function hideWarning(warn){ function hideWarning(warn){
document.getElementById(warn).classList.add("hidden"); document.getElementById(warn).classList.add("hidden");
} }