Centralized browser detection
This commit is contained in:
parent
1cc3ddb03c
commit
0feae3ba18
3 changed files with 34 additions and 11 deletions
|
|
@ -22,7 +22,7 @@ $(function() {
|
|||
|
||||
return function() {
|
||||
var newArgs;
|
||||
if (format) {
|
||||
if (format && (OctoPrint.coreui.browser.chrome || OctoPrint.coreui.browser.firefox)) {
|
||||
newArgs = ["%c[" + level + "]", format];
|
||||
} else {
|
||||
newArgs = ["[" + level + "]"];
|
||||
|
|
@ -67,7 +67,18 @@ $(function() {
|
|||
browserTabVisibility: undefined,
|
||||
selectedTab: undefined,
|
||||
settingsOpen: false,
|
||||
wizardOpen: false
|
||||
wizardOpen: false,
|
||||
browser: {
|
||||
chrome: false,
|
||||
firefox: false,
|
||||
safari: false,
|
||||
ie: false,
|
||||
edge: false,
|
||||
opera: false,
|
||||
|
||||
mobile: false,
|
||||
desktop: false
|
||||
}
|
||||
};
|
||||
|
||||
var browserVisibilityCallbacks = [];
|
||||
|
|
@ -117,6 +128,22 @@ $(function() {
|
|||
updateBrowserVisibility();
|
||||
}
|
||||
|
||||
// determine browser - loosely based on is.js
|
||||
|
||||
var navigator = window.navigator;
|
||||
var userAgent = (navigator && navigator.userAgent || "").toLowerCase();
|
||||
var vendor = (navigator && navigator.vendor || "").toLowerCase();
|
||||
|
||||
exports.browser.opera = userAgent.match(/opera|opr/) != null;
|
||||
exports.browser.chrome = !exports.browser.opera && /google inc/.test(vendor) && userAgent.match(/chrome|crios/) != null;
|
||||
exports.browser.firefox = userAgent.match(/firefox|fxios/) != null;
|
||||
exports.browser.ie = userAgent.match(/msie|trident/) != null;
|
||||
exports.browser.edge = userAgent.match(/edge/) != null;
|
||||
exports.browser.safari = !exports.browser.chrome && !exports.browser.edge && !exports.browser.opera && userAgent.match(/safari/) != null;
|
||||
|
||||
exports.browser.mobile = $.browser.mobile;
|
||||
exports.browser.desktop = !exports.browser.mobile;
|
||||
|
||||
// exports
|
||||
|
||||
exports.isVisible = function() { return !isHidden() };
|
||||
|
|
@ -127,6 +154,8 @@ $(function() {
|
|||
return exports;
|
||||
})();
|
||||
|
||||
log.debug("Browser enviroment:", OctoPrint.coreui.browser);
|
||||
|
||||
//~~ AJAX setup
|
||||
|
||||
// work around a stupid iOS6 bug where ajax requests get cached and only work once, as described at
|
||||
|
|
|
|||
|
|
@ -353,18 +353,12 @@ $(function() {
|
|||
self.requestData();
|
||||
};
|
||||
|
||||
self._isSafari = function() {
|
||||
var is_chrome = navigator.userAgent.indexOf('Chrome') > -1;
|
||||
var is_safari = navigator.userAgent.indexOf("Safari") > -1;
|
||||
return is_safari && !is_chrome;
|
||||
};
|
||||
|
||||
self._disableWebcam = function() {
|
||||
// only disable webcam stream if tab is out of focus for more than 5s, otherwise we might cause
|
||||
// more load by the constant connection creation than by the actual webcam stream
|
||||
|
||||
// safari bug doesn't release the mjpeg stream, so we just disable this for safari.
|
||||
if (self._isSafari()) {
|
||||
if (OctoPrint.coreui.browser.safari) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -388,7 +382,7 @@ $(function() {
|
|||
var currentSrc = webcamImage.attr("src");
|
||||
|
||||
// safari bug doesn't release the mjpeg stream, so we just set it up the once
|
||||
if (self._isSafari() && currentSrc != undefined) {
|
||||
if (OctoPrint.coreui.browser.safari && currentSrc != undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -406,7 +406,7 @@ $(function() {
|
|||
self.selectedFile.date(data.job.file.date);
|
||||
self.selectedFile.size(data.job.file.size);
|
||||
|
||||
if (data.job.file.size > CONFIG_GCODE_SIZE_THRESHOLD || ($.browser.mobile && data.job.file.size > CONFIG_GCODE_MOBILE_SIZE_THRESHOLD)) {
|
||||
if (data.job.file.size > CONFIG_GCODE_SIZE_THRESHOLD || (OctoPrint.coreui.browser.mobile && data.job.file.size > CONFIG_GCODE_MOBILE_SIZE_THRESHOLD)) {
|
||||
self.waitForApproval(true);
|
||||
self.loadedFilepath = undefined;
|
||||
self.loadedFileDate = undefined;
|
||||
|
|
|
|||
Loading…
Reference in a new issue