From bd303388e3d4dae90c2266d183395db8321c11de Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Sat, 27 Mar 2021 10:37:22 +0100 Subject: Cleanup ie and old edge properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- core/src/Polyfill/closest.js | 41 ------ core/src/Polyfill/console.js | 34 ----- core/src/Polyfill/index.js | 3 - core/src/Polyfill/windows-phone.js | 31 ----- core/src/components/MainMenu.js | 1 - core/src/init.js | 12 +- core/src/main.js | 17 ++- core/src/services/BrowserStorageService.js | 28 ++++ core/src/services/BrowsersListService.js | 30 ++++ core/src/services/LoggerService.js | 28 ++++ core/src/unsupported-browser.js | 39 ++++++ core/src/utils/RedirectUnsupportedBrowsers.js | 54 ++++++++ core/src/views/UnsupportedBrowser.vue | 191 ++++++++++++++++++++++++++ 13 files changed, 387 insertions(+), 122 deletions(-) delete mode 100644 core/src/Polyfill/closest.js delete mode 100644 core/src/Polyfill/console.js delete mode 100644 core/src/Polyfill/windows-phone.js create mode 100644 core/src/services/BrowserStorageService.js create mode 100644 core/src/services/BrowsersListService.js create mode 100644 core/src/services/LoggerService.js create mode 100644 core/src/unsupported-browser.js create mode 100644 core/src/utils/RedirectUnsupportedBrowsers.js create mode 100644 core/src/views/UnsupportedBrowser.vue (limited to 'core/src') diff --git a/core/src/Polyfill/closest.js b/core/src/Polyfill/closest.js deleted file mode 100644 index 68751fad38c..00000000000 --- a/core/src/Polyfill/closest.js +++ /dev/null @@ -1,41 +0,0 @@ -/** - * @copyright Copyright (c) 2016 John Molakvoæ - * - * @author John Molakvoæ - * - * @license AGPL-3.0-or-later - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -// https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill - -if (!Element.prototype.matches) { - Element.prototype.matches - = Element.prototype.msMatchesSelector - || Element.prototype.webkitMatchesSelector -} - -if (!Element.prototype.closest) { - Element.prototype.closest = function(s) { - let el = this - - do { - if (el.matches(s)) return el - el = el.parentElement || el.parentNode - } while (el !== null && el.nodeType === 1) - return null - } -} diff --git a/core/src/Polyfill/console.js b/core/src/Polyfill/console.js deleted file mode 100644 index be3aca1a9b3..00000000000 --- a/core/src/Polyfill/console.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * @copyright 2019 Christoph Wurst - * - * @author Christoph Wurst - * @author John Molakvoæ - * - * @license AGPL-3.0-or-later - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -/* eslint-disable no-console */ -if (typeof console === 'undefined' || typeof console.log === 'undefined') { - if (!window.console) { - window.console = {} - } - const noOp = () => {} - const methods = ['log', 'debug', 'warn', 'info', 'error', 'assert', 'time', 'timeEnd'] - for (let i = 0; i < methods.length; i++) { - console[methods[i]] = noOp - } -} diff --git a/core/src/Polyfill/index.js b/core/src/Polyfill/index.js index 5a190318327..610619217d2 100644 --- a/core/src/Polyfill/index.js +++ b/core/src/Polyfill/index.js @@ -21,7 +21,4 @@ * */ -import './console' -import './closest' -import './windows-phone' import 'focus-visible' diff --git a/core/src/Polyfill/windows-phone.js b/core/src/Polyfill/windows-phone.js deleted file mode 100644 index 27b45d701c6..00000000000 --- a/core/src/Polyfill/windows-phone.js +++ /dev/null @@ -1,31 +0,0 @@ -/** - * @copyright 2019 Christoph Wurst - * - * @author Christoph Wurst - * @author John Molakvoæ - * - * @license AGPL-3.0-or-later - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -// fix device width on windows phone -if ('-ms-user-select' in document.documentElement.style && navigator.userAgent.match(/IEMobile\/10\.0/)) { - const msViewportStyle = document.createElement('style') - msViewportStyle.appendChild( - document.createTextNode('@-ms-viewport{width:auto!important}') - ) - document.getElementsByTagName('head')[0].appendChild(msViewportStyle) -} diff --git a/core/src/components/MainMenu.js b/core/src/components/MainMenu.js index 267a3d9a361..be27e752237 100644 --- a/core/src/components/MainMenu.js +++ b/core/src/components/MainMenu.js @@ -28,7 +28,6 @@ import Vue from 'vue' import AppMenu from './AppMenu.vue' export const setUp = () => { - Vue.mixin({ methods: { t, diff --git a/core/src/init.js b/core/src/init.js index ae8db0abf49..867ba94483f 100644 --- a/core/src/init.js +++ b/core/src/init.js @@ -29,12 +29,12 @@ import _ from 'underscore' import $ from 'jquery' import moment from 'moment' -import { initSessionHeartBeat } from './session-heartbeat' -import OC from './OC/index' -import { setUp as setUpContactsMenu } from './components/ContactsMenu' -import { setUp as setUpMainMenu } from './components/MainMenu' -import { setUp as setUpUserMenu } from './components/UserMenu' -import PasswordConfirmation from './OC/password-confirmation' +import { initSessionHeartBeat } from './session-heartbeat.js' +import OC from './OC/index.js' +import { setUp as setUpContactsMenu } from './components/ContactsMenu.js' +import { setUp as setUpMainMenu } from './components/MainMenu.js' +import { setUp as setUpUserMenu } from './components/UserMenu.js' +import PasswordConfirmation from './OC/password-confirmation.js' // keep in sync with core/css/variables.scss const breakpointMobileWidth = 1024 diff --git a/core/src/main.js b/core/src/main.js index f9d89327a6a..959110e86a4 100644 --- a/core/src/main.js +++ b/core/src/main.js @@ -26,16 +26,21 @@ import $ from 'jquery' import 'core-js/stable' import 'regenerator-runtime/runtime' -import './Polyfill/index' +import './Polyfill/index.js' // If you remove the line below, tests won't pass // eslint-disable-next-line no-unused-vars -import OC from './OC/index' +import OC from './OC/index.js' -import './globals' -import './jquery/index' -import { initCore } from './init' -import { registerAppsSlideToggle } from './OC/apps' +import './globals.js' +import './jquery/index.js' +import { initCore } from './init.js' +import { registerAppsSlideToggle } from './OC/apps.js' +import { testSupportedBrowser } from './utils/RedirectUnsupportedBrowsers.js' + +if (window.TESTING === undefined) { + testSupportedBrowser() +} window.addEventListener('DOMContentLoaded', function() { initCore() diff --git a/core/src/services/BrowserStorageService.js b/core/src/services/BrowserStorageService.js new file mode 100644 index 00000000000..d383e1caaaf --- /dev/null +++ b/core/src/services/BrowserStorageService.js @@ -0,0 +1,28 @@ +/** + * @copyright 2021 John Molakvoæ + * + * @author John Molakvoæ + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +import { getBuilder } from '@nextcloud/browser-storage' + +export default getBuilder('nextcloud') + .clearOnLogout() + .persist() + .build() diff --git a/core/src/services/BrowsersListService.js b/core/src/services/BrowsersListService.js new file mode 100644 index 00000000000..c5d546665dc --- /dev/null +++ b/core/src/services/BrowsersListService.js @@ -0,0 +1,30 @@ +/** + * @copyright 2021 John Molakvoæ + * + * @author John Molakvoæ + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +import { getUserAgentRegExp } from 'browserslist-useragent-regexp' +// eslint-disable-next-line node/no-extraneous-import +import browserslist from 'browserslist' +import browserslistConfig from '@nextcloud/browserslist-config' + +// Generate a regex that matches user agents to detect incompatible browsers +export const supportedBrowsersRegExp = getUserAgentRegExp({ allowHigherVersions: true, browsers: browserslistConfig }) +export const supportedBrowsers = browserslist(browserslistConfig) diff --git a/core/src/services/LoggerService.js b/core/src/services/LoggerService.js new file mode 100644 index 00000000000..f0b8fc9e61d --- /dev/null +++ b/core/src/services/LoggerService.js @@ -0,0 +1,28 @@ +/** + * @copyright 2021 John Molakvoæ + * + * @author John Molakvoæ + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +import { getLoggerBuilder } from '@nextcloud/logger' + +export default getLoggerBuilder() + .setApp('core') + .detectUser() + .build() diff --git a/core/src/unsupported-browser.js b/core/src/unsupported-browser.js new file mode 100644 index 00000000000..cac5f145a7b --- /dev/null +++ b/core/src/unsupported-browser.js @@ -0,0 +1,39 @@ +/** + * @copyright 2021 John Molakvoæ + * + * @author John Molakvoæ + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import { generateUrl } from '@nextcloud/router' +import Vue from 'vue' + +import { browserStorageKey } from './utils/RedirectUnsupportedBrowsers.js' +import browserStorage from './services/BrowserStorageService.js' +import UnsupportedBrowser from './views/UnsupportedBrowser.vue' + +// If the ignore token is set, redirect +if (browserStorage.getItem(browserStorageKey) === 'true') { + window.location = generateUrl('/') +} + +export default new Vue({ + el: '#unsupported-browser', + // eslint-disable-next-line vue/match-component-file-name + name: 'UnsupportedBrowserRoot', + render: h => h(UnsupportedBrowser), +}) diff --git a/core/src/utils/RedirectUnsupportedBrowsers.js b/core/src/utils/RedirectUnsupportedBrowsers.js new file mode 100644 index 00000000000..74074cec558 --- /dev/null +++ b/core/src/utils/RedirectUnsupportedBrowsers.js @@ -0,0 +1,54 @@ +/** + * @copyright 2021 John Molakvoæ + * + * @author John Molakvoæ + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import { generateUrl } from '@nextcloud/router' + +import { supportedBrowsersRegExp } from '../services/BrowsersListService.js' +import browserStorage from '../services/BrowserStorageService.js' +import logger from '../services/LoggerService.js' + +const redirectPath = '/unsupported' +export const browserStorageKey = 'unsupported-browser-ignore' + +const isBrowserOverridden = browserStorage.getItem(browserStorageKey) === 'true' + +/** + * Test the current browser user agent against our official browserslist config + * and redirect if unsupported + */ +export const testSupportedBrowser = function() { + if (supportedBrowsersRegExp.test(navigator.userAgent)) { + logger.debug('this browser is officially supported ! 🚀') + return + } + + // If incompatible BUT ignored, let's keep going + if (isBrowserOverridden) { + logger.debug('this browser is NOT supported but has been manually overridden ! ⚠️') + return + } + + // If incompatible, NOT overridden AND NOT already on the warning page, + // redirect to the unsupported warning page + if (window.location.pathname.indexOf(redirectPath) === -1) { + window.location = generateUrl(redirectPath) + } +} diff --git a/core/src/views/UnsupportedBrowser.vue b/core/src/views/UnsupportedBrowser.vue new file mode 100644 index 00000000000..ef2a33ca213 --- /dev/null +++ b/core/src/views/UnsupportedBrowser.vue @@ -0,0 +1,191 @@ + + + + + + -- cgit v1.2.3