-
-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Made the DevTools to detect for mobile mode #46
Changes from all commits
47376e3
b46e054
999ddee
0260414
b210ff4
2feca53
c40b61b
c37f497
da963e9
1ba8bac
f2a751f
169dc8a
f35a0c9
0f3a628
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,21 +24,55 @@ MIT License | |
})); | ||
}; | ||
|
||
// Function to check if the given device is a phone or ipad | ||
function isPhone() { | ||
return /android|ipad/i.test(navigator.userAgent); | ||
} | ||
|
||
// Check how long its takes for the given code to execute | ||
// It return a value after execution | ||
// If value is greater than 60 then dev tool is open | ||
// If value is less than 60 then dev tool is not open | ||
// Since the time to execute cosole.log takes longer when dev tool is open | ||
function checkPerformance() { | ||
const start = performance.now(); | ||
for (let i = 0; i < 100; i++) { | ||
console.log(); | ||
console.clear(); | ||
} | ||
|
||
const end = performance.now(); | ||
return (end - start); | ||
} | ||
|
||
const main = ({emitEvents = true} = {}) => { | ||
const widthThreshold = window.outerWidth - window.innerWidth > threshold; | ||
const heightThreshold = window.outerHeight - window.innerHeight > threshold; | ||
const orientation = widthThreshold ? 'vertical' : 'horizontal'; | ||
|
||
if ( | ||
!(heightThreshold && widthThreshold) && | ||
((window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized) || widthThreshold || heightThreshold) | ||
) { | ||
if (!(heightThreshold && widthThreshold) && ((window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized) || widthThreshold || heightThreshold)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't do unrelated changes. |
||
if ((!devtools.isOpen || devtools.orientation !== orientation) && emitEvents) { | ||
emitEvent(true, orientation); | ||
} | ||
|
||
devtools.isOpen = true; | ||
devtools.orientation = orientation; | ||
} else if (isPhone()) { | ||
if (parseInt(checkPerformance(), 0) > 60) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if ((!devtools.isOpen || devtools.orientation !== orientation) && emitEvents) { | ||
emitEvent(true, ''); | ||
} | ||
|
||
devtools.isOpen = true; | ||
devtools.orientation = ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
} else { | ||
if (devtools.isOpen && emitEvents) { | ||
emitEvent(false, undefined); | ||
} | ||
|
||
devtools.isOpen = false; | ||
devtools.orientation = undefined; | ||
} | ||
} else { | ||
if (devtools.isOpen && emitEvents) { | ||
emitEvent(false, undefined); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds very fragile. Is this really reliable enough? The performance difference between devices can be huge. For example, maybe the new M1 Macbook's manage to do this in less than 60 even when DevTools is open.