Skip to content
Permalink
Browse files

Merge pull request #652 from lusbenjamin/bugfix-overlay-misc

Overlay Bugfixes
  • Loading branch information...
Manuel-777 committed Oct 22, 2019
2 parents ee65f2c + 7a28fc0 commit d52ae864b37beb2ad6f7b7e7d551492ed4a1456c
Showing with 52 additions and 35 deletions.
  1. +1 −0 .prettierignore
  2. +28 −29 src/main.js
  3. +22 −5 src/shared/card-hover.js
  4. +1 −1 src/window_overlay_v3/overlay.js
@@ -19,3 +19,4 @@ coverage
# production
build
dist
lib
@@ -40,10 +40,10 @@ var tray = null;

const ipc = electron.ipcMain;

var mainLoaded = false;
var backLoaded = false;
let mainLoaded = false;
let backLoaded = false;
let overlayLoaded = false;
let arenaState = ARENA_MODE_IDLE;
let overlayShow = false;

const singleLock = app.requestSingleInstanceLock();

@@ -134,28 +134,34 @@ function startApp() {
mainWindow = createMainWindow();
background = createBackgroundWindow();

setTimeout(() => {
overlay = createOverlayWindow();
}, 500);
const startBackgroundWhenReady = () => {
if (mainLoaded && backLoaded && overlayLoaded) {
background.webContents.send("start_background");
}
};

globalShortcut.register("Alt+Shift+D", openDevTools);

appStarted = true;

mainWindow.webContents.once("dom-ready", () => {
mainLoaded = true;
if (backLoaded == true) {
background.webContents.send("start_background");
}
startBackgroundWhenReady();
});

background.webContents.once("dom-ready", () => {
backLoaded = true;
if (mainLoaded == true) {
background.webContents.send("start_background");
}
startBackgroundWhenReady();
});

setTimeout(() => {
overlay = createOverlayWindow();
overlay.webContents.once("dom-ready", () => {
overlayLoaded = true;
startBackgroundWhenReady();
});
}, 500);

// If we destroy updater before creating another renderer
// Electron shuts down the whole app.
if (updaterWindow) {
@@ -201,12 +207,12 @@ function startApp() {
if (arenaState === ARENA_MODE_IDLE) {
mainWindow.webContents.send("player_data_refresh");
}
if (overlay) overlay.webContents.send("player_data_refresh");
overlay.webContents.send("player_data_refresh");
break;

case "set_db":
mainWindow.webContents.send("set_db", arg);
if (overlay) overlay.webContents.send("set_db", arg);
overlay.webContents.send("set_db", arg);
break;

case "popup":
@@ -314,7 +320,7 @@ function startApp() {
default:
if (to == 0) background.webContents.send(method, arg);
if (to == 1) mainWindow.webContents.send(method, arg);
if (to === 2 && overlay) overlay.webContents.send(method, arg);
if (to === 2) overlay.webContents.send(method, arg);
break;
}
});
@@ -432,7 +438,6 @@ function updateOverlayVisibility() {
}

function isEntireOverlayVisible() {
if (!overlay) return false;
return overlay.isVisible();
}

@@ -564,24 +569,18 @@ function createOverlayWindow() {
resizable: false,
skipTaskbar: true,
focusable: false,
title: "MTG Arena Tool",
title: "Overlay",
webPreferences: {
nodeIntegration: true
}
});
overlay.loadURL(`file://${__dirname}/window_overlay_v3/index.html`);
//overlay.setIgnoreMouseEvents(true, { forward: true });

overlay.webContents.once("dom-ready", function() {
//We need to wait for the overlay to be initialized before we interact with it
//const display = electron.screen.getPrimaryDisplay();
// display.workArea does not include the taskbar
//overlay.setBounds(display.bounds);
overlay.webContents.send("settings_updated");
// only show overlay after its ready
// TODO does this work with Linux transparency???
//setTimeout(() => overlay.show(), 1000);
});

if (process.platform !== "linux") {
// https://electronjs.org/docs/api/browser-window#winsetignoremouseeventsignore-options
// does not currently support Linux
overlay.setIgnoreMouseEvents(true, { forward: true });
}

return overlay;
}
@@ -5,15 +5,28 @@ import { createDiv, queryElements as $$ } from "./dom-fns";
import { getCardImage } from "./util";
import { DRAFT_RANKS, FACE_DFC_BACK, FACE_DFC_FRONT } from "./constants.js";

// controls when to auto-hide hover display
// workaround for edge case bugs that cause hover to "get stuck"
const MAX_HOVER_TIME = 10000; // 10 seconds

let renderer = 0;

export const setRenderer = value => {
renderer = value;
};

let lastHoverStart = null;

export function addCardHover(element, card) {
if (!card || !card.images || card.type == "Special") return;

const hideHover = () => {
$$(
".hover_card_quantity, .main_hover, .main_hover_ratings, .main_hover_dfc, .loader, .loader_dfc"
).forEach(element => (element.style.opacity = 0));
lastHoverStart = null;
};

element.addEventListener("mouseover", () => {
$$(".loader, .main_hover").forEach(element => (element.style.opacity = 1));

@@ -57,13 +70,17 @@ export function addCardHover(element, card) {
element => (element.style.display = "none")
);
}
});

element.addEventListener("mouseleave", () => {
$$(
".hover_card_quantity, .main_hover, .main_hover_ratings, .main_hover_dfc, .loader, .loader_dfc"
).forEach(element => (element.style.opacity = 0));
lastHoverStart = Date.now();

setTimeout(() => {
if (lastHoverStart && Date.now() - lastHoverStart > MAX_HOVER_TIME) {
hideHover();
}
}, MAX_HOVER_TIME + 1);
});

element.addEventListener("mouseleave", hideHover);
}

function show(element, mode) {
@@ -1130,7 +1130,7 @@ ready(function() {
<div class="outer_wrapper elements_wrapper">
<div class="overlay_deckname"></div>
<div class="overlay_deckcolors"></div>
<div class="overlay_decklist"></div>
<div class="overlay_decklist click-on"></div>
<div class="overlay_clock_container">
<div class="clock_prev click-on"></div>
<div class="clock_turn"></div>

0 comments on commit d52ae86

Please sign in to comment.
You can’t perform that action at this time.