2017-06-08_509bba0/509bba0_unpacked_with_node_modules/discord_common/js/lib/DevToolsListener.js
2022-07-26 10:06:20 -07:00

91 lines
No EOL
1.6 KiB
JavaScript
Executable file

import {EventEmitter} from 'events';
const THRESHOLD = 160;
const INTERVAL = 500;
const ORIENTATIONS = {
VERTICAL: 'vertical',
HORIZONTAL: 'horizontal'
};
let devTools = {
open: false,
orientation: null
};
function hasFirebug() {
try {
return window.Firebug.chrome.isInitialized;
}
catch (e) {
return false;
}
}
function widthDifference() {
try {
return window.outerWidth - window.innerWidth;
}
catch (e) {
return 0;
}
}
function heightDifference() {
try {
return window.outerHeight - window.innerHeight;
}
catch (e) {
return 0;
}
}
class DevToolsListener extends EventEmitter {
constructor() {
super();
setInterval(() => this.check(), INTERVAL);
}
get orientations() {
return Object.values(ORIENTATIONS);
}
get state() {
return devTools;
}
check() {
const widthThreshold = widthDifference() > THRESHOLD;
const heightThreshold = heightDifference() > THRESHOLD;
const orientation = widthThreshold ? ORIENTATIONS.VERTICAL : ORIENTATIONS.HORIZONTAL;
if (
!(heightThreshold && widthThreshold) &&
(hasFirebug() || widthThreshold || heightThreshold)
) {
const open = devTools.open;
devTools = {
open: true,
orientation
};
if (!open || devTools.orientation !== orientation) {
this.emit('changed', devTools);
}
}
else if (devTools.open) {
devTools.open = false;
this.emit('changed', devTools);
}
}
}
export default DevToolsListener;
// WEBPACK FOOTER //
// ./discord_common/js/lib/DevToolsListener.js