From 179d0c0c7c7df44f7a976349aedd85a4ee1817a5 Mon Sep 17 00:00:00 2001 From: GermanBluefox Date: Sat, 16 Mar 2024 14:38:27 +0800 Subject: [PATCH] * (bluefox) Preparations for a custom loading background --- README.md | 3 +++ io-package.json | 9 ++++++++- main.js | 30 +++++++++++++++++++++++++++++- package.json | 2 +- src/package.json | 12 ++++++------ 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 22b4ec5b..0f156abb 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,9 @@ the path could be provided here (e.g. `/vis/`) so this path will be opened autom --> ## Changelog +### **WORK IN PROGRESS** +* (bluefox) Preparations for a custom loading background + ### 6.2.5 (2024-02-22) * (bluefox) Just some packages were updates diff --git a/io-package.json b/io-package.json index d8753b82..057f61f1 100644 --- a/io-package.json +++ b/io-package.json @@ -169,6 +169,10 @@ "dsn": "https://3acf24332d994549bfa3b86e06062c21@sentry.iobroker.net/16" } }, + "licenseInformation": { + "type": "free", + "link": "https://github.com/ioBroker/ioBroker.web/blob/master/LICENSE" + }, "tier": 3 }, "native": { @@ -199,7 +203,10 @@ "staticAssetCacheMaxAge": 60, "language": "", "startDisabledExtensions": false, - "showFolderIndex": false + "showFolderIndex": false, + "loadingBackgroundColor": "", + "loadingHideLogo": false, + "loadingBackgroundImage": false }, "instanceObjects": [ { diff --git a/main.js b/main.js index 2979acdf..f5564e11 100644 --- a/main.js +++ b/main.js @@ -22,6 +22,7 @@ let passport; // = require('passport'); let LocalStrategy; // = require('passport-local').Strategy; let flash; // = require('connect-flash'); // TODO report error to user let checkTimeout; +let vendorPrefix; let webServer = null; let store = null; @@ -335,6 +336,14 @@ function startAdapter(options) { adapter.log.error('Cannot find object system.config'); } + let uuid = null; + try { + uuid = await adapter.getForeignObjectAsync('system.meta.uuid'); + } catch (e) { + adapter.log.warn(`Cannot read UUID: ${e}`); + } + vendorPrefix = systemConfig?.native?.vendor?.uuidPrefix || (uuid?.native?.uuid?.length > 36 ? uuid.native.uuid.substring(0, 2) : ''); + // information about connected socket.io adapter if (adapter.config.socketio && adapter.config.socketio.match(/^system\.adapter\./)) { socketUrl = await getSocketUrl(); @@ -1744,6 +1753,7 @@ async function initWebServer(settings) { return; } + // If root directory requested if (url === '/' || url === '/index.html') { if (adapter.config.defaultRedirect) { res.redirect(301, adapter.config.defaultRedirect); @@ -1898,9 +1908,27 @@ async function initWebServer(settings) { } else { mimeType = mimeType || mime.lookup(url) || 'text/javascript'; + // replace some important variables in HTML + if (url === 'index.html' || url === 'edit.html') { + buffer = buffer + .toString() + .replaceAll(`'@@vendorPrefix@@'`, vendorPrefix) + .replaceAll(`"@@vendorPrefix@@"`, vendorPrefix) + + .replaceAll(`'@@disableDataReporting@@'`, adapter.common.disableDataReporting ? 'true' : 'false') + .replaceAll(`"@@disableDataReporting@@"`, adapter.common.disableDataReporting ? 'true' : 'false') + + .replaceAll(`@@loadingBackgroundColor@@`, adapter.config.loadingBackgroundColor || '') + + .replaceAll(`@@loadingBackgroundImage@@`, adapter.config.loadingBackgroundImage ? `files/${adapter.namespace}/loading-bg.png` : '') + + .replaceAll(`'@@loadingHideLogo@@'`, adapter.config.loadingHideLogo ? 'true' : 'false') + .replaceAll(`"@@loadingHideLogo@@"`, adapter.config.loadingHideLogo ? 'true' : 'false'); + } + // Store file in cache if (settings.cache) { - cache[`${id}/${url}`] = {buffer, mimeType}; + cache[`${id}/${url}`] = { buffer, mimeType }; } res.contentType(mimeType); diff --git a/package.json b/package.json index 28af2e34..d3820b94 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@alcalzone/release-script-plugin-iobroker": "^3.7.0", "@alcalzone/release-script-plugin-license": "^3.7.0", "@iobroker/legacy-testing": "^1.0.9", - "axios": "^1.6.7", + "axios": "^1.6.8", "chai": "^4.4.1", "eslint": "^8.57.0", "gulp": "^4.0.2", diff --git a/src/package.json b/src/package.json index 57932055..c0aad828 100644 --- a/src/package.json +++ b/src/package.json @@ -4,12 +4,12 @@ "private": true, "dependencies": { "@babel/plugin-proposal-private-property-in-object": "^7.21.11", - "@iobroker/adapter-react-v5": "^4.9.10", - "@mui/icons-material": "^5.15.11", + "@iobroker/adapter-react-v5": "^4.10.2", + "@mui/icons-material": "^5.15.13", "@mui/material": "5.14.14", "@mui/styles": "5.14.14", - "@sentry/browser": "^7.102.1", - "@sentry/integrations": "^7.102.1", + "@sentry/browser": "^7.107.0", + "@sentry/integrations": "^7.107.0", "babel-eslint": "^10.1.0", "eslint": "^8.57.0", "eslint-config-airbnb": "^19.0.4", @@ -17,7 +17,7 @@ "eslint-plugin-import": "^2.29.1", "eslint-plugin-jsx-a11y": "^6.8.0", "eslint-plugin-only-warn": "^1.1.0", - "eslint-plugin-react": "^7.33.2", + "eslint-plugin-react": "^7.34.1", "eslint-plugin-react-hooks": "^4.6.0", "prop-types": "^15.8.1", "react": "^18.2.0", @@ -43,4 +43,4 @@ "not ie <= 11", "not op_mini all" ] -} \ No newline at end of file +}