1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-11 09:11:50 +00:00

Remove some legacy browser support code

Includes prefixed document.hidden property with respective
visibilitychanged event and redundant support for navigator.language /
lack of navigator.languages check.
This commit is contained in:
Даниїл Григор'єв 2024-07-26 16:24:20 +03:00
parent a3d82cc46a
commit 89ca498613
No known key found for this signature in database
GPG Key ID: B890DF16341D8C1D
2 changed files with 7 additions and 30 deletions

View File

@ -36,22 +36,6 @@ import { SettingsState } from "./states/settings";
const logger = createLogger("application");
// Set the name of the hidden property and the change event for visibility
let pageHiddenPropName, pageVisibilityEventName;
if (typeof document.hidden !== "undefined") {
// Opera 12.10 and Firefox 18 and later support
pageHiddenPropName = "hidden";
pageVisibilityEventName = "visibilitychange";
// @ts-ignore
} else if (typeof document.msHidden !== "undefined") {
pageHiddenPropName = "msHidden";
pageVisibilityEventName = "msvisibilitychange";
// @ts-ignore
} else if (typeof document.webkitHidden !== "undefined") {
pageHiddenPropName = "webkitHidden";
pageVisibilityEventName = "webkitvisibilitychange";
}
export class Application {
/**
* Boots the application
@ -176,7 +160,7 @@ export class Application {
// Unload events
window.addEventListener("beforeunload", this.onBeforeUnload.bind(this), true);
document.addEventListener(pageVisibilityEventName, this.handleVisibilityChange.bind(this), false);
document.addEventListener("visibilitychange", this.handleVisibilityChange.bind(this), false);
// Track touches so we can update the focus appropriately
document.addEventListener("touchstart", this.updateFocusAfterUserInteraction.bind(this), true);
@ -217,7 +201,7 @@ export class Application {
*/
handleVisibilityChange(event) {
window.focus();
const pageVisible = !document[pageHiddenPropName];
const pageVisible = !document.hidden;
if (pageVisible !== this.pageVisible) {
this.pageVisible = pageVisible;
logger.log("Visibility changed:", this.pageVisible);

View File

@ -7,7 +7,7 @@ const logger = createLogger("translations");
// @ts-ignore
import baseTranslations from "./built-temp/base-en.json";
export let T = baseTranslations;
export const T = baseTranslations;
if (G_IS_DEV && globalConfig.debug.testTranslations) {
// Replaces all translations by fake translations to see whats translated and what not
@ -67,18 +67,11 @@ function mapLanguageCodeToId(languageKey) {
* @returns {string}
*/
export function autoDetectLanguageId() {
let languages = [];
if (navigator.languages) {
languages = navigator.languages.slice();
} else if (navigator.language) {
languages = [navigator.language];
} else {
logger.warn("Navigator has no languages prop");
}
const languages = navigator.languages;
for (let i = 0; i < languages.length; ++i) {
logger.log("Trying to find language target for", languages[i]);
const trans = mapLanguageCodeToId(languages[i]);
for (const language of languages) {
logger.log("Trying to find language target for", language);
const trans = mapLanguageCodeToId(language);
if (trans) {
return trans;
}