-
-
Notifications
You must be signed in to change notification settings - Fork 220
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
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
47376e3
Made the devDevTools detect for mobile mode
b46e054
Update index.js
marvlyngkhoi 999ddee
Update index.js
marvlyngkhoi 0260414
Update index.js
marvlyngkhoi b210ff4
Update index.js
marvlyngkhoi 2feca53
Update index.js
marvlyngkhoi c40b61b
Update index.js
marvlyngkhoi c37f497
Update index.js
marvlyngkhoi da963e9
Update index.js
marvlyngkhoi 1ba8bac
Update index.js
marvlyngkhoi f2a751f
Update index.js
marvlyngkhoi 169dc8a
Update index.js
marvlyngkhoi f35a0c9
Update index.js
marvlyngkhoi 0f3a628
Update index.js
marvlyngkhoi File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.