mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-10-22 04:13:59 +00:00
Compare commits
214 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ea8a3469a | ||
|
|
118e21238c | ||
|
|
8c0e7db494 | ||
|
|
d20d9a7ef8 | ||
|
|
b8e0e2a791 | ||
|
|
a927eb20d9 | ||
|
|
aad3eefc62 | ||
|
|
ee1960ced0 | ||
|
|
0b70274a1a | ||
|
|
4e7b68a69d | ||
|
|
786ea86e0e | ||
|
|
d397568062 | ||
|
|
a7af76b619 | ||
|
|
319a921f75 | ||
|
|
d5406f4900 | ||
|
|
55cd03576f | ||
|
|
9d97724401 | ||
|
|
74854387cd | ||
|
|
e77f10b86d | ||
|
|
6ffdc7b55b | ||
|
|
7098f1e41f | ||
|
|
679a413788 | ||
|
|
247115d2e4 | ||
|
|
70ddd80632 | ||
|
|
203e8647d4 | ||
|
|
3fe5ad4b3d | ||
|
|
b300191609 | ||
|
|
296df06c21 | ||
|
|
fe882bf92a | ||
|
|
2a6e2aacdc | ||
|
|
3a01acd389 | ||
|
|
a8d06ae74e | ||
|
|
04f0df269a | ||
|
|
f80889d953 | ||
|
|
6815dfa02b | ||
|
|
bbc27f5ae2 | ||
|
|
f46b226940 | ||
|
|
764ca3ac5c | ||
|
|
0e2da630d5 | ||
|
|
a0b444d6c4 | ||
|
|
5d2ddbd3dd | ||
|
|
b067711ede | ||
|
|
66b29ec26e | ||
|
|
343e7de7bd | ||
|
|
6ea94e4512 | ||
|
|
290b350856 | ||
|
|
9566d6c9a0 | ||
|
|
6b204cda25 | ||
|
|
e530c783f8 | ||
|
|
a3c2e7b816 | ||
|
|
ad665a7a33 | ||
|
|
95ec3096e0 | ||
|
|
a67a0b677c | ||
|
|
8b1c279c07 | ||
|
|
4eccce3f77 | ||
|
|
af0fe37f70 | ||
|
|
e5adbea49c | ||
|
|
7127979c6f | ||
|
|
fa7c7fc8cf | ||
|
|
91fd931a58 | ||
|
|
7a1591b2d6 | ||
|
|
f2957f90df | ||
|
|
ffdf321e23 | ||
|
|
79e99e18ea | ||
|
|
a92b3d3f71 | ||
|
|
5cbdd28db3 | ||
|
|
9d49196e69 | ||
|
|
ef20fe2d11 | ||
|
|
c0a5f35a00 | ||
|
|
2ad463b6c7 | ||
|
|
200db181d5 | ||
|
|
7ba96aeb98 | ||
|
|
7c64d8fce6 | ||
|
|
7dcea98e99 | ||
|
|
59e9d765e2 | ||
|
|
156db32c76 | ||
|
|
58cdfa3cb1 | ||
|
|
49c72d8dfc | ||
|
|
1bd146f52e | ||
|
|
948910d304 | ||
|
|
0b97639341 | ||
|
|
f802c85a38 | ||
|
|
62eb23ba6a | ||
|
|
4b0e0aa48f | ||
|
|
e9f1bd9d7a | ||
|
|
e87f50e64a | ||
|
|
46bca1bc6d | ||
|
|
2b6720e6e5 | ||
|
|
ea818bf899 | ||
|
|
0e00e64493 | ||
|
|
3c35d346ee | ||
|
|
675e4d4f67 | ||
|
|
c1850f2577 | ||
|
|
e985e99036 | ||
|
|
b7371538bc | ||
|
|
a56b92990d | ||
|
|
c7405b76b3 | ||
|
|
eceec8285d | ||
|
|
0573d6e772 | ||
|
|
babd22b04f | ||
|
|
432d900ecd | ||
|
|
83315f1fed | ||
|
|
e09d60d1d1 | ||
|
|
d832d795df | ||
|
|
a41aa48dd1 | ||
|
|
b80485b52f | ||
|
|
7e58b38ddf | ||
|
|
979f4ec664 | ||
|
|
4e3369062e | ||
|
|
77f9c86774 | ||
|
|
dee3cd3da7 | ||
|
|
09f117c3d9 | ||
|
|
32192d1698 | ||
|
|
2c7beeaaaf | ||
|
|
0d3ad9812c | ||
|
|
b7eb21e48f | ||
|
|
9703226c73 | ||
|
|
cc11b77f24 | ||
|
|
c5a8b85f4e | ||
|
|
fa40a3e8e8 | ||
|
|
6223584392 | ||
|
|
b5a22bc09b | ||
|
|
4ef030af5f | ||
|
|
5f38c53260 | ||
|
|
d5395ee3f8 | ||
|
|
ab0876f07a | ||
|
|
d276a7ddb9 | ||
|
|
8f8945d418 | ||
|
|
6d779235cf | ||
|
|
beea754514 | ||
|
|
c6db22524a | ||
|
|
23ee155ded | ||
|
|
1b2785cc56 | ||
|
|
b5b61246e6 | ||
|
|
498b440174 | ||
|
|
fe0b915a5d | ||
|
|
2b792cdbb8 | ||
|
|
a23769156e | ||
|
|
6d86ffade4 | ||
|
|
390e5d6490 | ||
|
|
b08a4737af | ||
|
|
bf28e63709 | ||
|
|
fb22a76796 | ||
|
|
81244d961e | ||
|
|
65aa1b0ddc | ||
|
|
88c7e42368 | ||
|
|
e24dfa6b1a | ||
|
|
a65ee86501 | ||
|
|
4b478a5a5e | ||
|
|
1dc0a0d5b5 | ||
|
|
bf279d9a57 | ||
|
|
42d42ef452 | ||
|
|
ed90f0546f | ||
|
|
a8dc563a31 | ||
|
|
58b9ddcd9f | ||
|
|
7198ae5eae | ||
|
|
f6dcfb5ca3 | ||
|
|
157e74ce7c | ||
|
|
67e4dbaacd | ||
|
|
2e2962d492 | ||
|
|
cd4ba428da | ||
|
|
ee8695637b | ||
|
|
4244c05764 | ||
|
|
c714399b4d | ||
|
|
8d9f132666 | ||
|
|
d2327d3d6f | ||
|
|
29e3ec06cb | ||
|
|
877f8ad380 | ||
|
|
6e80e5a295 | ||
|
|
7bc91a742f | ||
|
|
fc303146a5 | ||
|
|
2908c15ea6 | ||
|
|
a975b44fbb | ||
|
|
4fc38bd5bb | ||
|
|
c99f660d98 | ||
|
|
cd739b6912 | ||
|
|
0ebedd0fb8 | ||
|
|
e9be668d1b | ||
|
|
76d9042e60 | ||
|
|
2fec314ff5 | ||
|
|
3124b0a9c5 | ||
|
|
a2624442cc | ||
|
|
eee289aee8 | ||
|
|
abbae90a8f | ||
|
|
bd0b3c00ad | ||
|
|
b9b7d2c95d | ||
|
|
0b01e9dbe0 | ||
|
|
4fecffc3df | ||
|
|
4d47c0837f | ||
|
|
3879949f58 | ||
|
|
f25abfd2f8 | ||
|
|
7058fc5fd8 | ||
|
|
00bc6eb28c | ||
|
|
f79d3f007d | ||
|
|
c191ff0032 | ||
|
|
dde88601a6 | ||
|
|
2d3940a4ff | ||
|
|
64ed5a54cb | ||
|
|
7bd944391e | ||
|
|
ad4dbd786a | ||
|
|
fc59ed20e3 | ||
|
|
835c893205 | ||
|
|
7bbf8c19db | ||
|
|
1eb2965b2b | ||
|
|
85a9f14178 | ||
|
|
a328ce537f | ||
|
|
21ae79b386 | ||
|
|
d5e855dd6d | ||
|
|
a86e27a12c | ||
|
|
f434be3d44 | ||
|
|
ce4906d13b | ||
|
|
8212d30c4c | ||
|
|
f04d578704 | ||
|
|
7694d6fa86 |
@@ -1 +1,2 @@
|
|||||||
modules/default/calendar/vendor/*
|
modules/*
|
||||||
|
!modules/default/
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"extends": ["eslint:recommended", "plugin:prettier/recommended", "plugin:jsdoc/recommended"],
|
"extends": ["eslint:recommended", "plugin:@stylistic/all-extends", "plugin:import/recommended", "plugin:jest/recommended", "plugin:jsdoc/recommended"],
|
||||||
"plugins": ["prettier", "import", "jsdoc", "jest"],
|
"plugins": ["unicorn"],
|
||||||
"env": {
|
"env": {
|
||||||
"browser": true,
|
"browser": true,
|
||||||
"es2022": true,
|
"es2024": true,
|
||||||
"jest/globals": true,
|
"jest/globals": true,
|
||||||
"node": true
|
"node": true
|
||||||
},
|
},
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
},
|
},
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"sourceType": "module",
|
"sourceType": "module",
|
||||||
"ecmaVersion": 2022,
|
"ecmaVersion": "latest",
|
||||||
"ecmaFeatures": {
|
"ecmaFeatures": {
|
||||||
"globalReturn": true
|
"globalReturn": true
|
||||||
}
|
}
|
||||||
@@ -24,10 +24,70 @@
|
|||||||
"rules": {
|
"rules": {
|
||||||
"eqeqeq": "error",
|
"eqeqeq": "error",
|
||||||
"import/order": "error",
|
"import/order": "error",
|
||||||
|
"import/extensions": "error",
|
||||||
|
"import/newline-after-import": "error",
|
||||||
|
"jest/consistent-test-it": "warn",
|
||||||
|
"jest/expect-expect": "warn",
|
||||||
|
"jest/no-done-callback": "warn",
|
||||||
|
"jest/prefer-expect-resolves": "warn",
|
||||||
|
"jest/prefer-mock-promise-shorthand": "warn",
|
||||||
|
"jest/prefer-to-be": "warn",
|
||||||
|
"jest/prefer-to-have-length": "warn",
|
||||||
|
"no-param-reassign": "error",
|
||||||
"no-prototype-builtins": "off",
|
"no-prototype-builtins": "off",
|
||||||
"no-throw-literal": "error",
|
"no-throw-literal": "error",
|
||||||
"no-unused-vars": "off",
|
"no-unused-vars": "off",
|
||||||
"no-useless-return": "error",
|
"no-useless-return": "error",
|
||||||
"prefer-template": "error"
|
"object-shorthand": ["error", "methods"],
|
||||||
}
|
"prefer-template": "error",
|
||||||
|
"@stylistic/array-element-newline": ["error", "consistent"],
|
||||||
|
"@stylistic/arrow-parens": ["error", "always"],
|
||||||
|
"@stylistic/brace-style": "off",
|
||||||
|
"@stylistic/comma-dangle": ["error", "never"],
|
||||||
|
"@stylistic/dot-location": ["error", "property"],
|
||||||
|
"@stylistic/function-call-argument-newline": ["error", "consistent"],
|
||||||
|
"@stylistic/function-paren-newline": ["error", "consistent"],
|
||||||
|
"@stylistic/implicit-arrow-linebreak": ["error", "beside"],
|
||||||
|
"@stylistic/max-statements-per-line": ["error", { "max": 2 }],
|
||||||
|
"@stylistic/multiline-ternary": ["error", "always-multiline"],
|
||||||
|
"@stylistic/newline-per-chained-call": ["error", { "ignoreChainWithDepth": 4 }],
|
||||||
|
"@stylistic/no-extra-parens": "off",
|
||||||
|
"@stylistic/no-tabs": "off",
|
||||||
|
"@stylistic/object-curly-spacing": ["error", "always"],
|
||||||
|
"@stylistic/object-property-newline": ["error", { "allowAllPropertiesOnSameLine": true }],
|
||||||
|
"@stylistic/operator-linebreak": ["error", "before"],
|
||||||
|
"@stylistic/padded-blocks": "off",
|
||||||
|
"@stylistic/quote-props": ["error", "as-needed"],
|
||||||
|
"@stylistic/quotes": ["error", "double"],
|
||||||
|
"@stylistic/indent": ["error", "tab"],
|
||||||
|
"@stylistic/semi": ["error", "always"],
|
||||||
|
"@stylistic/space-before-function-paren": ["error", "always"],
|
||||||
|
"@stylistic/spaced-comment": "off",
|
||||||
|
"unicorn/prefer-node-protocol": "error"
|
||||||
|
},
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": ["config/config.js*"],
|
||||||
|
"rules": {
|
||||||
|
"@stylistic/comma-dangle": "off",
|
||||||
|
"@stylistic/indent": "off",
|
||||||
|
"@stylistic/no-multi-spaces": "off"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"files": ["tests/configs/modules/weather/*.js"],
|
||||||
|
"rules": {
|
||||||
|
"@stylistic/quotes": "off"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"extends": ["plugin:package-json/recommended"],
|
||||||
|
"files": ["package.json"],
|
||||||
|
"parser": "jsonc-eslint-parser",
|
||||||
|
"plugins": ["package-json"],
|
||||||
|
"rules": {
|
||||||
|
"package-json/sort-collections": ["error", ["devDependencies", "dependencies", "peerDependencies", "config"]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
56
.gitattributes
vendored
Normal file
56
.gitattributes
vendored
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
# .gitattributes snippet to force users to use same line endings for project.
|
||||||
|
#
|
||||||
|
# Handle line endings automatically for files detected as text
|
||||||
|
# and leave all files detected as binary untouched.
|
||||||
|
* text=auto
|
||||||
|
|
||||||
|
#
|
||||||
|
# The above will handle all files NOT found below
|
||||||
|
# https://help.github.com/articles/dealing-with-line-endings/
|
||||||
|
# https://github.com/Danimoth/gitattributes/blob/master/Web.gitattributes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# These files are text and should be normalized (Convert crlf => lf)
|
||||||
|
*.php text
|
||||||
|
*.css text
|
||||||
|
*.scss text
|
||||||
|
*.js text
|
||||||
|
*.json text
|
||||||
|
*.htm text
|
||||||
|
*.html text
|
||||||
|
*.xml text
|
||||||
|
*.txt text
|
||||||
|
*.ini text
|
||||||
|
*.inc text
|
||||||
|
*.pl text
|
||||||
|
*.rb text
|
||||||
|
*.py text
|
||||||
|
*.scm text
|
||||||
|
*.sql text
|
||||||
|
.htaccess text
|
||||||
|
*.sh text
|
||||||
|
Dockerfile* text
|
||||||
|
*.yml text
|
||||||
|
*.yaml text
|
||||||
|
*.md text
|
||||||
|
*.markdown text
|
||||||
|
|
||||||
|
# These files are binary and should be left untouched
|
||||||
|
# (binary is a macro for -text -diff)
|
||||||
|
*.png binary
|
||||||
|
*.jpg binary
|
||||||
|
*.jpeg binary
|
||||||
|
*.gif binary
|
||||||
|
*.ico binary
|
||||||
|
*.mov binary
|
||||||
|
*.mp4 binary
|
||||||
|
*.mp3 binary
|
||||||
|
*.flv binary
|
||||||
|
*.fla binary
|
||||||
|
*.swf binary
|
||||||
|
*.gz binary
|
||||||
|
*.zip binary
|
||||||
|
*.7z binary
|
||||||
|
*.ttf binary
|
||||||
|
*.pyc binary
|
||||||
2
.github/CONTRIBUTING.md
vendored
2
.github/CONTRIBUTING.md
vendored
@@ -43,7 +43,7 @@ When submitting a new issue, please supply the following information:
|
|||||||
|
|
||||||
**Platform**: Place your platform here... give us your web browser/Electron version _and_ your hardware (Raspberry Pi 2/3/4, Windows, Mac, Linux, System V UNIX).
|
**Platform**: Place your platform here... give us your web browser/Electron version _and_ your hardware (Raspberry Pi 2/3/4, Windows, Mac, Linux, System V UNIX).
|
||||||
|
|
||||||
**Node Version**: Make sure it's version 14 or later (recommended is 16).
|
**Node Version**: Make sure it's version 18 or later (recommended is 20).
|
||||||
|
|
||||||
**MagicMirror² Version**: Please let us know which version of MagicMirror² you are running. It can be found in the `package.json` file.
|
**MagicMirror² Version**: Please let us know which version of MagicMirror² you are running. It can be found in the `package.json` file.
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Hello and thank you for opening an issue.
|
Hello and thank you for opening an issue.
|
||||||
|
|
||||||
**Please make sure that you have read the following lines before submitting your Issue:**
|
**⚠️ Please make sure that you have read the following lines before submitting your Issue:**
|
||||||
|
|
||||||
## I'm not sure if this is a bug
|
## I'm not sure if this is a bug
|
||||||
|
|
||||||
@@ -22,6 +22,10 @@ If you are facing an issue or found a bug while trying to install MagicMirror²
|
|||||||
If you are facing an issue or found a bug while running MagicMirror² inside a Docker container please create an issue in the corresponding repository:
|
If you are facing an issue or found a bug while running MagicMirror² inside a Docker container please create an issue in the corresponding repository:
|
||||||
[https://gitlab.com/khassel/magicmirror](https://gitlab.com/khassel/magicmirror)
|
[https://gitlab.com/khassel/magicmirror](https://gitlab.com/khassel/magicmirror)
|
||||||
|
|
||||||
|
## I'm having troubles installing or configuring foreign modules
|
||||||
|
|
||||||
|
Please open an issue in the module repository or ask for help in the [forum](https://forum.magicmirror.builders/)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## I found a bug in MagicMirror
|
## I found a bug in MagicMirror
|
||||||
@@ -31,7 +35,7 @@ When submitting a new issue, please supply the following information:
|
|||||||
|
|
||||||
**Platform**: Place your platform here... give us your web browser/Electron version _and_ your hardware (Raspberry Pi 2/3/4, Windows, Mac, Linux, System V UNIX).
|
**Platform**: Place your platform here... give us your web browser/Electron version _and_ your hardware (Raspberry Pi 2/3/4, Windows, Mac, Linux, System V UNIX).
|
||||||
|
|
||||||
**Node Version**: Make sure it's version 14 or later (recommended is 16).
|
**Node Version**: Make sure it's version 18 or later (recommended is 20).
|
||||||
|
|
||||||
**MagicMirror² Version**: Please let us know which version of MagicMirror² you are running. It can be found in the `package.json` file.
|
**MagicMirror² Version**: Please let us know which version of MagicMirror² you are running. It can be found in the `package.json` file.
|
||||||
|
|
||||||
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -3,7 +3,6 @@ Hello and thank you for wanting to contribute to the MagicMirror² project
|
|||||||
**Please make sure that you have followed these 4 rules before submitting your Pull Request:**
|
**Please make sure that you have followed these 4 rules before submitting your Pull Request:**
|
||||||
|
|
||||||
> 1. Base your pull requests against the `develop` branch.
|
> 1. Base your pull requests against the `develop` branch.
|
||||||
>
|
|
||||||
> 2. Include these infos in the description:
|
> 2. Include these infos in the description:
|
||||||
>
|
>
|
||||||
> - Does the pull request solve a **related** issue?
|
> - Does the pull request solve a **related** issue?
|
||||||
@@ -13,7 +12,6 @@ Hello and thank you for wanting to contribute to the MagicMirror² project
|
|||||||
>
|
>
|
||||||
> 3. Please run `npm run lint:prettier` before submitting so that
|
> 3. Please run `npm run lint:prettier` before submitting so that
|
||||||
> style issues are fixed.
|
> style issues are fixed.
|
||||||
>
|
|
||||||
> 4. Don't forget to add an entry about your changes to
|
> 4. Don't forget to add an entry about your changes to
|
||||||
> the CHANGELOG.md file.
|
> the CHANGELOG.md file.
|
||||||
|
|
||||||
|
|||||||
10
.github/codecov.yaml
vendored
10
.github/codecov.yaml
vendored
@@ -1,10 +0,0 @@
|
|||||||
coverage:
|
|
||||||
status:
|
|
||||||
project:
|
|
||||||
default:
|
|
||||||
# advanced settings
|
|
||||||
informational: true
|
|
||||||
patch:
|
|
||||||
default:
|
|
||||||
threshold: 0%
|
|
||||||
target: 0
|
|
||||||
33
.github/dependabot.yaml
vendored
33
.github/dependabot.yaml
vendored
@@ -5,3 +5,36 @@ updates:
|
|||||||
schedule:
|
schedule:
|
||||||
interval: "weekly"
|
interval: "weekly"
|
||||||
target-branch: "develop"
|
target-branch: "develop"
|
||||||
|
labels:
|
||||||
|
- "Skip Changelog"
|
||||||
|
- "dependencies"
|
||||||
|
|
||||||
|
- package-ecosystem: "npm"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "monthly"
|
||||||
|
target-branch: "develop"
|
||||||
|
labels:
|
||||||
|
- "Skip Changelog"
|
||||||
|
- "dependencies"
|
||||||
|
- "javascript"
|
||||||
|
|
||||||
|
- package-ecosystem: "npm"
|
||||||
|
directory: "/vendor"
|
||||||
|
schedule:
|
||||||
|
interval: "monthly"
|
||||||
|
target-branch: "develop"
|
||||||
|
labels:
|
||||||
|
- "Skip Changelog"
|
||||||
|
- "dependencies"
|
||||||
|
- "javascript"
|
||||||
|
|
||||||
|
- package-ecosystem: "npm"
|
||||||
|
directory: "/fonts"
|
||||||
|
schedule:
|
||||||
|
interval: "monthly"
|
||||||
|
target-branch: "develop"
|
||||||
|
labels:
|
||||||
|
- "Skip Changelog"
|
||||||
|
- "dependencies"
|
||||||
|
- "javascript"
|
||||||
|
|||||||
12
.github/workflows/automated-tests.yaml
vendored
12
.github/workflows/automated-tests.yaml
vendored
@@ -18,20 +18,22 @@ jobs:
|
|||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [14.x, 16.x, 18.x]
|
node-version: [18.x, 20.x, 21.x]
|
||||||
steps:
|
steps:
|
||||||
- name: "Checkout code"
|
- name: "Checkout code"
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: "Use Node.js ${{ matrix.node-version }}"
|
- name: "Use Node.js ${{ matrix.node-version }}"
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
cache: "npm"
|
cache: "npm"
|
||||||
- name: "Install dependencies and run tests"
|
- name: "Install dependencies"
|
||||||
|
run: |
|
||||||
|
npm run install-mm:dev
|
||||||
|
- name: "Run tests"
|
||||||
run: |
|
run: |
|
||||||
Xvfb :99 -screen 0 1024x768x16 &
|
Xvfb :99 -screen 0 1024x768x16 &
|
||||||
export DISPLAY=:99
|
export DISPLAY=:99
|
||||||
npm run install-mm:dev
|
|
||||||
touch css/custom.css
|
touch css/custom.css
|
||||||
npm run test:prettier
|
npm run test:prettier
|
||||||
npm run test:js
|
npm run test:js
|
||||||
|
|||||||
33
.github/workflows/codecov-test-suites.yaml
vendored
33
.github/workflows/codecov-test-suites.yaml
vendored
@@ -1,33 +0,0 @@
|
|||||||
# This workflow runs the automated test and uploads the coverage results to codecov.io
|
|
||||||
# For more information see: https://github.com/codecov/codecov-action
|
|
||||||
|
|
||||||
name: "Run Codecov Tests"
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [master, develop]
|
|
||||||
pull_request:
|
|
||||||
branches: [master, develop]
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
run-and-upload-coverage-report:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
timeout-minutes: 30
|
|
||||||
steps:
|
|
||||||
- name: "Checkout code"
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: "Install dependencies and run coverage"
|
|
||||||
run: |
|
|
||||||
Xvfb :99 -screen 0 1024x768x16 &
|
|
||||||
export DISPLAY=:99
|
|
||||||
npm ci
|
|
||||||
touch css/custom.css
|
|
||||||
npm run test:coverage
|
|
||||||
- name: "Upload coverage results to codecov"
|
|
||||||
uses: codecov/codecov-action@v3
|
|
||||||
with:
|
|
||||||
files: ./coverage/lcov.info
|
|
||||||
fail_ci_if_error: true
|
|
||||||
4
.github/workflows/depsreview.yaml
vendored
4
.github/workflows/depsreview.yaml
vendored
@@ -13,6 +13,6 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: "Checkout code"
|
- name: "Checkout code"
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: "Dependency Review"
|
- name: "Dependency Review"
|
||||||
uses: actions/dependency-review-action@v3
|
uses: actions/dependency-review-action@v4
|
||||||
|
|||||||
20
.github/workflows/electronRebuild.yaml
vendored
Normal file
20
.github/workflows/electronRebuild.yaml
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
name: "Electron Rebuild Testing"
|
||||||
|
|
||||||
|
on: [pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
rebuild:
|
||||||
|
name: Run electron-rebuild
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Install MagicMirror
|
||||||
|
run: npm run install-mm
|
||||||
|
- name: Install @electron/rebuild
|
||||||
|
run: npm install @electron/rebuild
|
||||||
|
- name: Install some test library to be rebuilded
|
||||||
|
run: npm install onoff node-pty drivelist
|
||||||
|
- name: Run electron-rebuild
|
||||||
|
run: npx electron-rebuild
|
||||||
|
continue-on-error: false
|
||||||
@@ -19,7 +19,7 @@ jobs:
|
|||||||
changeLogPath: "CHANGELOG.md"
|
changeLogPath: "CHANGELOG.md"
|
||||||
skipLabels: "Skip Changelog"
|
skipLabels: "Skip Changelog"
|
||||||
- name: "Enforce develop branch"
|
- name: "Enforce develop branch"
|
||||||
if: ${{ github.base_ref == 'master' && !contains(github.event.pull_request.labels.*.name, 'mastermerge') }}
|
if: ${{ github.event.pull_request.base.ref == 'master' && !contains(github.event.pull_request.labels.*.name, 'mastermerge') }}
|
||||||
run: |
|
run: |
|
||||||
echo "This PR is based against the master branch and not a release or hotfix."
|
echo "This PR is based against the master branch and not a release or hotfix."
|
||||||
echo "Please don't do this. Switch the branch to 'develop'."
|
echo "Please don't do this. Switch the branch to 'develop'."
|
||||||
|
|||||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -63,8 +63,10 @@ Temporary Items
|
|||||||
!/modules/default/**
|
!/modules/default/**
|
||||||
!/modules/README.md**
|
!/modules/README.md**
|
||||||
|
|
||||||
# Ignore changes to the custom css files.
|
# Ignore changes to the custom css files but keep the sample and main.
|
||||||
/css/custom.css
|
/css/*
|
||||||
|
!/css/custom.css.sample
|
||||||
|
!/css/main.css
|
||||||
|
|
||||||
# Ignore users config file but keep the sample.
|
# Ignore users config file but keep the sample.
|
||||||
/config/*
|
/config/*
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
[ -f "$(dirname "$0")/_/husky.sh" ] && . "$(dirname "$0")/_/husky.sh"
|
|
||||||
|
|
||||||
if command -v npm &> /dev/null; then
|
if command -v npm &> /dev/null; then
|
||||||
npm run lint:staged
|
npm run lint:staged
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
*.js
|
||||||
|
.eslintignore
|
||||||
|
.husky/pre-commit
|
||||||
|
.prettierignore
|
||||||
/config
|
/config
|
||||||
/coverage
|
/coverage
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
**.ics
|
||||||
|
|||||||
370
CHANGELOG.md
370
CHANGELOG.md
@@ -3,7 +3,211 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
This project adheres to [Semantic Versioning](https://semver.org/).
|
This project adheres to [Semantic Versioning](https://semver.org/).
|
||||||
|
|
||||||
❤️ **Donate:** Enjoying MagicMirror²? [Please consider a donation!](https://magicmirror.builders/donate) With your help we can continue to improve the MagicMirror².
|
❤️ **Donate:** Enjoying MagicMirror²? [Please consider a donation!](https://magicmirror.builders/#donate) With your help we can continue to improve the MagicMirror².
|
||||||
|
|
||||||
|
## [2.27.0] - 2024-04-01
|
||||||
|
|
||||||
|
Thanks to: @bugsounet, @crazyscot, @illimarkangur, @jkriegshauser, @khassel, @KristjanESPERANTO, @Paranoid93, @rejas, @sdetweil and @vppencilsharpener.
|
||||||
|
|
||||||
|
This release marks the first release without Michael Teeuw (@michmich). A very special thanks to him for creating MagicMirror and leading the project for so many years.
|
||||||
|
|
||||||
|
For more info, please read the following post: [A New Chapter for MagicMirror: The Community Takes the Lead](https://forum.magicmirror.builders/topic/18329/a-new-chapter-for-magicmirror-the-community-takes-the-lead).
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Output of system information to the console for troubleshooting (#3328 and #3337), ignore errors under aarch64 (#3349)
|
||||||
|
- [chore] Add `eslint-plugin-package-json` to lint the `package.json` files (#3368)
|
||||||
|
- [weather] `showHumidity` config is now a string describing where to show this element. Supported values: "wind", "temp", "feelslike", "below", "none". (#3330)
|
||||||
|
- electron-rebuild test suite for electron and 3rd party modules compatibility (#3392)
|
||||||
|
- Create MM² icon and attach it to electron process (#3407)
|
||||||
|
|
||||||
|
### Updated
|
||||||
|
|
||||||
|
- Update updatenotification (update_helper.js): Recode with pm2 library (#3332)
|
||||||
|
- Removing lodash dependency by replacing merge by spread operator (#3339)
|
||||||
|
- Use node prefix for build-in modules (#3340)
|
||||||
|
- Rework logging colors (#3350)
|
||||||
|
- Update pm2 to v5.3.1 with no allow-ghsas (#3364)
|
||||||
|
- [chore] Update husky and let lint-staged fix ESLint issues
|
||||||
|
- [chore] Update dependencies including electron to v29 (#3357) and node-ical
|
||||||
|
- Update translations for estonian (#3371)
|
||||||
|
- Update electron to v29 and update other dependencies
|
||||||
|
- [calendar] fullDay events over several days now show the left days from the first day on and 'today' on the last day
|
||||||
|
- Update layout of current weather indoor values
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Correct apibase of weathergov weatherprovider to match documentation (#2926)
|
||||||
|
- Worked around several issues in the RRULE library that were causing deleted calender events to still show, some
|
||||||
|
initial and recurring events to not show, and some event times to be off an hour. (#3291)
|
||||||
|
- Skip changelog requirement when running tests for dependency updates (#3320)
|
||||||
|
- Display precipitation probability when it is 0% instead of blank/empty (#3345)
|
||||||
|
- [newsfeed] Suppress unsightly animation cases when there are 0 or 1 active news items (#3336)
|
||||||
|
- [newsfeed] Always compute the feed item URL using the same helper function (#3336)
|
||||||
|
- Ignore all custom css files (#3359)
|
||||||
|
- [newsfeed] Fix newsfeed stall issue introduced by #3336 (#3361)
|
||||||
|
- Changed `log.debug` to `log.log` in `app.js` where logLevel is not set because config is not loaded at this time (#3353)
|
||||||
|
- [calendar] deny fetch interval < 60000 and set 60000 in this case (prevent fetch loop failed) (#3382)
|
||||||
|
- added message in case where config.js is missing the module.export line PR #3383
|
||||||
|
- Fixed an issue where recurring events could extend past their recurrence end date (#3393)
|
||||||
|
- Don't display any `npm WARN <....>` on install (#3399)
|
||||||
|
- Fixed move suncalc dependency to production from dev, as it is used by clock module
|
||||||
|
- [compliments] Fix mirror not responding anymore when no compliments are to be shown (#3385)
|
||||||
|
- [chore] Fixed mastermerge workflow (#3415)
|
||||||
|
|
||||||
|
### Deleted
|
||||||
|
|
||||||
|
- Unneeded file headers (#3358)
|
||||||
|
- Removed codecov.yaml
|
||||||
|
|
||||||
|
## [2.26.0] - 2024-01-01
|
||||||
|
|
||||||
|
Thanks to: @bnitkin, @bugsounet, @dependabot, @jkriegshauser, @kaennchenstruggle, @KristjanESPERANTO and @Ybbet.
|
||||||
|
|
||||||
|
Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not all) of the work on this release as project collaborators. This version would not be there without their effort. Thank you guys! You are awesome!
|
||||||
|
|
||||||
|
This release also marks the latest release by Michael Teeuw. For more info, please read the following post: [A New Chapter for MagicMirror: The Community Takes the Lead](https://forum.magicmirror.builders/topic/18329/a-new-chapter-for-magicmirror-the-community-takes-the-lead).
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added update notification updater (for 3rd party modules)
|
||||||
|
- Added node 21 to the test matrix
|
||||||
|
- Added transform object to calendar:customEvents
|
||||||
|
- Added ESLint rules for jest (including jest/expect-expect and jest/no-done-callback)
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- Removed Codecov workflow (not working anymore, other workflow required) (#3107)
|
||||||
|
- Removed titleReplace from calendar, replaced + extended by customEvents (backward compatibility included) (#3249)
|
||||||
|
- Removed failing unit test (#3254)
|
||||||
|
- Removed some unused variables
|
||||||
|
|
||||||
|
### Updated
|
||||||
|
|
||||||
|
- Update electron to v27 and update other dependencies as well as github actions
|
||||||
|
- Update newsfeed: Use `html-to-text` instead of regex for transform description
|
||||||
|
- Review ESLint config (#3269)
|
||||||
|
- Updated dependencies
|
||||||
|
- Clock module: optionally display current moon phase in addition to rise/set times
|
||||||
|
- electron is now per default started without gpu, if needed it must be enabled with new env var `ELECTRON_ENABLE_GPU=1` on startup (#3226)
|
||||||
|
- Replace prettier by stylistic in ESLint config to lint JavaScript (and disable some rules for `config/config.js*` files)
|
||||||
|
- Update node-ical to v0.17.1 and fix tests
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Avoid fade out/in on updateDom when many calendars are used
|
||||||
|
- Fix the option eventClass on customEvents.
|
||||||
|
- Fix yr API version in locationforecast and sunrise call (#3227)
|
||||||
|
- Fix cloneObject() function to respect RegExp (#3237)
|
||||||
|
- Fix newsfeed module for feeds using "a10:updated" tag (#3238)
|
||||||
|
- Fix issue template (#3167)
|
||||||
|
- Fix #3256 filter out bad results from rrule.between
|
||||||
|
- Fix calendar events sometimes not respecting deleted events (#3250)
|
||||||
|
- Fix electron loadurl locally on Windows when address "0.0.0.0" (#2550)
|
||||||
|
- Fix updatanotification (update_helper.js): catch error if response is not an JSON format (check PM2)
|
||||||
|
- Fix missing typeof in calendar module
|
||||||
|
- Fix style issues after prettier update
|
||||||
|
- Fix calendar test (#3291) by moving "Exdate check" from e2e to electron to run on a Thursday
|
||||||
|
- Fix calendar config params `fetchInterval` and `excludedEvents` were never used from single calendar config (#3297)
|
||||||
|
- Fix MM_PORT variable not used in electron and allow full path for MM_CONFIG_FILE variable (#3302)
|
||||||
|
|
||||||
|
## [2.25.0] - 2023-10-01
|
||||||
|
|
||||||
|
Thanks to: @bugsounet, @dgoth, @dependabot, @kenzal, @Knapoc, @KristjanESPERANTO, @martingron, @NolanKingdon, @Paranoid93, @TeddyStarinvest and @Ybbet.
|
||||||
|
|
||||||
|
Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not all) of the work on this release as project collaborators. This version would not be there without their effort. Thank you guys! You are awesome!
|
||||||
|
|
||||||
|
> ⚠️ This release needs nodejs version >= `v18`, older releases have reached end of life and will not work!
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added UV Index support to OpenWeatherMap
|
||||||
|
- Added 'hideDuplicates' flag to the calendar module
|
||||||
|
- Added `allowOverrideNotification` to weather module to enable sending current weather objects with the `CURRENT_WEATHER_OVERRIDE` notification to supplement/replace the current weather displayed
|
||||||
|
- Added optional AnimateCSS animate for `hide()`, `show()`, `updateDom()`
|
||||||
|
- Added AnimateIn and animateOut in module config definition
|
||||||
|
- Apply AnimateIn rules on the first start
|
||||||
|
- Added automatic client page reload when server was restarted by setting `reloadAfterServerRestart: true` in `config.js`, per default `false` (#3105)
|
||||||
|
- Added eventClass option for customEvents on the default calendar
|
||||||
|
- Added AnimateCSS integration in tests suite (#3206)
|
||||||
|
- Added npm dependabot [Reserved to developer] (#3210)
|
||||||
|
- Added improved logging for calendar (#3110)
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- **Breaking Change**: Removed `digest` authentication method from calendar module (which was already broken since release `2.15.0`)
|
||||||
|
|
||||||
|
### Updated
|
||||||
|
|
||||||
|
- Update roboto fonts to version v5
|
||||||
|
- Update issue template
|
||||||
|
- Update dev/dependencies incl. electron to v26
|
||||||
|
- Replace pretty-quick by lint-staged (<https://github.com/azz/pretty-quick/issues/164>)
|
||||||
|
- Update engine node >=18. v16 reached its end of life. (#3170)
|
||||||
|
- Update typescript definition for modules
|
||||||
|
- Cleaned up nunjuck templates
|
||||||
|
- Replace `node-fetch` with internal fetch (#2649) and remove `digest-fetch`
|
||||||
|
- Update the French translation according to the English file.
|
||||||
|
- Update dependabot incl. vendor/fonts (monthly check)
|
||||||
|
- Renew `package-lock.json` for release
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix engine check on npm install (#3135)
|
||||||
|
- Fix undefined formatTime method in clock module (#3143)
|
||||||
|
- Fix clientonly startup fails after async added (#3151)
|
||||||
|
- Fix electron width/height when using xrandr under bullseye
|
||||||
|
- Fix time issue with certain recurring events in calendar module
|
||||||
|
- Fix ipWhiteList test (#3179)
|
||||||
|
- Fix newsfeed: Convert HTML entities, codes and tag in description (#3191)
|
||||||
|
- Respect width/height (no fullscreen) if set in electronOptions (together with `fullscreen: false`) in `config.js` (#3174)
|
||||||
|
- Fix: AnimateCSS merge hide() and show() animated css class when we do multiple call
|
||||||
|
- Fix `Uncaught SyntaxError: Identifier 'getCorsUrl' has already been declared (at utils.js:1:1)` when using `clock` and `weather` module (#3204)
|
||||||
|
- Fix overriding `config.js` when running tests (#3201)
|
||||||
|
- Fix issue in weathergov provider with probability of precipitation not showing up on hourly or daily forecast
|
||||||
|
- Fix yr weather provider after changes in yr API (#3189)
|
||||||
|
|
||||||
|
## [2.24.0] - 2023-07-01
|
||||||
|
|
||||||
|
Thanks to: @angeldeejay, @bugsounet, @buxxi, @CarJem, @dariom, @DaveChild, @dWoolridge, @eddiehung, @grenagit, @Hirschberger, @ismarslomic, @JakeBinney, @KristjanESPERANTO, @MagMar94, @naveensrinivasan, @nfogal, @oscarb, @OWL4C, @psieg, @rajniszp, @retroflex, @SkySails and @tomzt
|
||||||
|
|
||||||
|
Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not all) of the work on this release as project collaborators. This version would not be there without their effort. Thank you guys! You are awesome!
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added UV Index to hourly and current Weather, with support for Openmeteo
|
||||||
|
- Added tests for serveronly
|
||||||
|
- Set Timezone `Europe/Berlin` in unit tests (needed for new formatTime tests)
|
||||||
|
- Added no-param-reassign eslint rule and fix warnings
|
||||||
|
- [updatenotification] Added `sendUpdatesNotifications` feature. Broadcast update with `UPDATES` notification to other modules
|
||||||
|
- [updatenotification] Allow force scanning with `SCAN_UPDATES` notification from other modules
|
||||||
|
- Added per-calendar fetchInterval
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- Removed unneeded (and unwanted) '.' after the year in calendar repeatingCountTitle (#2896, second attempt ...)
|
||||||
|
|
||||||
|
### Updated
|
||||||
|
|
||||||
|
- Added support for precipitation probability with openmeteo weather-provider
|
||||||
|
- Update electron to v25.2 and other dependencies
|
||||||
|
- Use node v20 in github workflow (replacing v14)
|
||||||
|
- Refactor formatTime into common util function for default modules
|
||||||
|
- Refactor some calendar methods into own class and added tests for them
|
||||||
|
- Split install and run commands in github actions
|
||||||
|
- Changed `fetchInterval` of calendar in `config.js.sample` to 7 days so we not to request example calendar too frequently
|
||||||
|
- Changed default calendar fetchInterval to one hour
|
||||||
|
- Changed calendar url in sample config
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix envcanada hourly forecast time (#3080)
|
||||||
|
- Fix electron not running under windows after async changes (#3083)
|
||||||
|
- Fix style issues after eslint-plugin-jsdoc update
|
||||||
|
- Fix don't filter out ongoing full day events (#3095)
|
||||||
|
- Fix date not shown when clock in analog mode (#3100)
|
||||||
|
- Fix envcanada today percentage-of-precipitation (#3106)
|
||||||
|
- Fix updatenotification where no branch is checked out but e.g. a version tag (#3130)
|
||||||
|
|
||||||
## [2.23.0] - 2023-04-04
|
## [2.23.0] - 2023-04-04
|
||||||
|
|
||||||
@@ -16,17 +220,18 @@ Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not al
|
|||||||
- Added increments for hourly forecasts in weather module (#2996)
|
- Added increments for hourly forecasts in weather module (#2996)
|
||||||
- Added tests for hourly weather forecast
|
- Added tests for hourly weather forecast
|
||||||
- Added possibility to ignore MagicMirror repo in updatenotification module
|
- Added possibility to ignore MagicMirror repo in updatenotification module
|
||||||
- Added Pirate Weather as new weather provider (#3005)
|
- Added Pirate Weather as new weather-provider (#3005)
|
||||||
- Added possibility to use your own templates in Alert module
|
- Added possibility to use your own templates in Alert module
|
||||||
- Added error message if `<modulename>.js` file is missing in module folder to get a hint in the logs (#2403)
|
- Added error message if `<modulename>.js` file is missing in module folder to get a hint in the logs (#2403)
|
||||||
- Added possibility to use environment variables in `config.js` (#1756)
|
- Added possibility to use environment variables in `config.js` (#1756)
|
||||||
- Added option `pastDaysCount` to default calendar module to control of how many days past events should be displayed
|
- Added option `pastDaysCount` to default calendar module to control of how many days past events should be displayed
|
||||||
- Added thai language to alert module
|
- Added thai language to alert module
|
||||||
- Added option `sendNotifications` in clock module (#3056)
|
- Added option `sendNotifications` in clock module (#3056)
|
||||||
|
- Added tests for some weather utils
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
- Removed darksky weather provider
|
- Removed darksky weather-provider
|
||||||
- Removed unneeded (and unwanted) '.' after the year in calendar repeatingCountTitle (#2896)
|
- Removed unneeded (and unwanted) '.' after the year in calendar repeatingCountTitle (#2896)
|
||||||
|
|
||||||
### Updated
|
### Updated
|
||||||
@@ -43,6 +248,7 @@ Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not al
|
|||||||
- Update Eslint config, add new rule and handle issue
|
- Update Eslint config, add new rule and handle issue
|
||||||
- Convert lots of callbacks to async/await
|
- Convert lots of callbacks to async/await
|
||||||
- Revise require imports (#3071 and #3072)
|
- Revise require imports (#3071 and #3072)
|
||||||
|
- Use `config.js-old` instead of file with timestamp suffix when backing up config with a `config.template` in use (#3104)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
@@ -73,12 +279,12 @@ Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not al
|
|||||||
|
|
||||||
- Added new calendar options for colored entries and improved styling (#3033)
|
- Added new calendar options for colored entries and improved styling (#3033)
|
||||||
- Added test for remoteFile option in compliments module
|
- Added test for remoteFile option in compliments module
|
||||||
- Added hourlyWeather functionality to Weather.gov weather provider
|
- Added hourlyWeather functionality to Weather.gov weather-provider
|
||||||
- Added css class names "today" and "tomorrow" for default calendar
|
- Added css class names "today" and "tomorrow" for default calendar
|
||||||
- Added Collaboration.md
|
- Added Collaboration.md
|
||||||
- Added new github action for dependency review (#2862)
|
- Added new github action for dependency review (#2862)
|
||||||
- Added a WeatherProvider for Open-Meteo
|
- Added a WeatherProvider for Open-Meteo
|
||||||
- Added Yr as a weather provider
|
- Added Yr as a weather-provider
|
||||||
- Added config options "ignoreXOriginHeader" and "ignoreContentSecurityPolicy"
|
- Added config options "ignoreXOriginHeader" and "ignoreContentSecurityPolicy"
|
||||||
- Added thai language
|
- Added thai language
|
||||||
- Added workflow rule to make sure PRs are based against develop
|
- Added workflow rule to make sure PRs are based against develop
|
||||||
@@ -96,8 +302,8 @@ Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not al
|
|||||||
- Updated da translation
|
- Updated da translation
|
||||||
- Rework weather module
|
- Rework weather module
|
||||||
- Make sure smhi provider api only gets a maximum of 6 digits coordinates (#2955)
|
- Make sure smhi provider api only gets a maximum of 6 digits coordinates (#2955)
|
||||||
- Use fetch instead of XMLHttpRequest in weatherprovider (#2935)
|
- Use fetch instead of XMLHttpRequest in weather-provider (#2935)
|
||||||
- Reworked how weatherproviders handle units (#2849)
|
- Reworked how weather-providers handle units (#2849)
|
||||||
- Use unix() method for parsing times, fix suntimes on the way (#2950)
|
- Use unix() method for parsing times, fix suntimes on the way (#2950)
|
||||||
- Refactor conversion functions into utils class (#2958)
|
- Refactor conversion functions into utils class (#2958)
|
||||||
- The `cors`-method in `server.js` now supports sending and receiving HTTP headers
|
- The `cors`-method in `server.js` now supports sending and receiving HTTP headers
|
||||||
@@ -107,7 +313,7 @@ Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not al
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Correctly show apparent temperature in SMHI weather provider
|
- Correctly show apparent temperature in SMHI weather-provider
|
||||||
- Ensure updatenotification module isn't shown when local is _ahead_ of remote
|
- Ensure updatenotification module isn't shown when local is _ahead_ of remote
|
||||||
- Handle node_helper errors during startup (#2944)
|
- Handle node_helper errors during startup (#2944)
|
||||||
- Possibility to change FontAwesome class in calendar, so icons like `fab fa-facebook-square` works.
|
- Possibility to change FontAwesome class in calendar, so icons like `fab fa-facebook-square` works.
|
||||||
@@ -126,7 +332,7 @@ Special thanks to: @BKeyport, @buxxi, @davide125, @khassel, @kolbyjack, @krukle,
|
|||||||
- Added possibility to fetch calendars through socket notifications.
|
- Added possibility to fetch calendars through socket notifications.
|
||||||
- New scripts `install-mm` (and `install-mm:dev`) for simplifying mm installation (now: `npm run install-mm`) and adding params `--no-audit --no-fund --no-update-notifier` for less noise.
|
- New scripts `install-mm` (and `install-mm:dev`) for simplifying mm installation (now: `npm run install-mm`) and adding params `--no-audit --no-fund --no-update-notifier` for less noise.
|
||||||
- New `showTimeToday` option in calendar module shows time for current-day events even if `timeFormat` is `"relative"`.
|
- New `showTimeToday` option in calendar module shows time for current-day events even if `timeFormat` is `"relative"`.
|
||||||
- Added hourly forecasts, apparent temperature & custom location name to SMHI weather provider.
|
- Added hourly forecasts, apparent temperature & custom location name to SMHI weather-provider.
|
||||||
- Added new electron tests for calendar and moved some compliments tests from `e2e` to `electron` because of date mocking, removed mock stuff from compliments module.
|
- Added new electron tests for calendar and moved some compliments tests from `e2e` to `electron` because of date mocking, removed mock stuff from compliments module.
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
@@ -182,7 +388,7 @@ Special thanks to the following contributors: @10bias, @CFenner, @JHWelch, @k1rd
|
|||||||
- Added test for new weather forecast `absoluteDates` property.
|
- Added test for new weather forecast `absoluteDates` property.
|
||||||
- The modules get a class hidden added/removed if they get hidden/shown which will also toggle pointer-events.
|
- The modules get a class hidden added/removed if they get hidden/shown which will also toggle pointer-events.
|
||||||
- Added new config option `showTitleAsUrl` to newsfeed module. If set, the displayed title is a link to the article which is useful when running in a browser and you want to read this article.
|
- Added new config option `showTitleAsUrl` to newsfeed module. If set, the displayed title is a link to the article which is useful when running in a browser and you want to read this article.
|
||||||
- Added internal cors proxy to get weather providers working without public proxies (fixes #2714). The new url `http(s)://address:port/cors?url=https://whatever-to-proxy` can be used in other modules too.
|
- Added internal cors proxy to get weather-providers working without public proxies (fixes #2714). The new url `http(s)://address:port/cors?url=https://whatever-to-proxy` can be used in other modules too.
|
||||||
- Added a WeatherProvider for Weatherflow.
|
- Added a WeatherProvider for Weatherflow.
|
||||||
- Added new env var `ELECTRON_DISABLE_GPU` which disable gpu under electron if set (fixes #2831).
|
- Added new env var `ELECTRON_DISABLE_GPU` which disable gpu under electron if set (fixes #2831).
|
||||||
- Added missing Czech translations.
|
- Added missing Czech translations.
|
||||||
@@ -276,7 +482,7 @@ Special thanks to the following contributors: @apiontek, @eouia, @jupadin, @khas
|
|||||||
- Updated jsdocs and print warnings during testing too.
|
- Updated jsdocs and print warnings during testing too.
|
||||||
- Updated weathergov provider to try fetching not just current, but also foreacst, when API URLs available.
|
- Updated weathergov provider to try fetching not just current, but also foreacst, when API URLs available.
|
||||||
- Refactored clock layout.
|
- Refactored clock layout.
|
||||||
- Refactored methods from weatherproviders into weatherobject (isDaytime, updateSunTime).
|
- Refactored methods from weather-providers into weatherobject (isDaytime, updateSunTime).
|
||||||
- Use of `logger.js` in jest tests.
|
- Use of `logger.js` in jest tests.
|
||||||
- Run prettier over all relevant files.
|
- Run prettier over all relevant files.
|
||||||
- Move tests needing electron in new category `electron`, use `server only` mode in `e2e` tests.
|
- Move tests needing electron in new category `electron`, use `server only` mode in `e2e` tests.
|
||||||
@@ -374,7 +580,7 @@ Special thanks to the following contributors: @EdgardosReis, @MystaraTheGreat, @
|
|||||||
- Code cleanup for FEELS like and added {DEGREE} placeholder for FEELSLIKE for each language.
|
- Code cleanup for FEELS like and added {DEGREE} placeholder for FEELSLIKE for each language.
|
||||||
- Converted newsfeed module to use templates.
|
- Converted newsfeed module to use templates.
|
||||||
- Updated documentation and help screen about invalid config files.
|
- Updated documentation and help screen about invalid config files.
|
||||||
- Moving weather provider specific code and configuration into each provider and making hourly part of the interface.
|
- Moving weather-provider specific code and configuration into each provider and making hourly part of the interface.
|
||||||
- Bump electron to v11 and enable contextIsolation.
|
- Bump electron to v11 and enable contextIsolation.
|
||||||
- Don't update the DOM when a module is not displayed.
|
- Don't update the DOM when a module is not displayed.
|
||||||
- Cleaned up jsdoc and tests.
|
- Cleaned up jsdoc and tests.
|
||||||
@@ -456,7 +662,7 @@ Special thanks to the following contributors: @Alvinger, @AndyPoms, @ashishtank,
|
|||||||
- Rename Greek translation to correct ISO 639-1 alpha-2 code (gr > el). (#2155)
|
- Rename Greek translation to correct ISO 639-1 alpha-2 code (gr > el). (#2155)
|
||||||
- Add a space after icons of sunrise and sunset. (#2169)
|
- Add a space after icons of sunrise and sunset. (#2169)
|
||||||
- Fix calendar when no DTEND record found in event, startDate overlay when endDate set. (#2177)
|
- Fix calendar when no DTEND record found in event, startDate overlay when endDate set. (#2177)
|
||||||
- Fix windspeed conversion error in ukmetoffice weather provider. (#2189)
|
- Fix windspeed conversion error in ukmetoffice weather-provider. (#2189)
|
||||||
- Fix console.debug not having timestamps. (#2199)
|
- Fix console.debug not having timestamps. (#2199)
|
||||||
- Fix calendar full day event east of UTC start time. (#2200)
|
- Fix calendar full day event east of UTC start time. (#2200)
|
||||||
- Fix non-fullday recurring rule processing. (#2216)
|
- Fix non-fullday recurring rule processing. (#2216)
|
||||||
@@ -501,12 +707,12 @@ Special thanks to the following contributors: @bryanzzhu, @bugsounet, @chamakura
|
|||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fix backward compatibility issues for Safari < 11.
|
- Fix backward compatibility issues for Safari < 11.
|
||||||
- Fix the use of "maxNumberOfDays" in the module "weatherforecast depending on the endpoint (forecast/daily or forecast)". [#2018](https://github.com/MichMich/MagicMirror/issues/2018)
|
- Fix the use of "maxNumberOfDays" in the module "weatherforecast depending on the endpoint (forecast/daily or forecast)". [#2018](https://github.com/MagicMirrorOrg/MagicMirror/issues/2018)
|
||||||
- Fix calendar display. Account for current timezone. [#2068](https://github.com/MichMich/MagicMirror/issues/2068)
|
- Fix calendar display. Account for current timezone. [#2068](https://github.com/MagicMirrorOrg/MagicMirror/issues/2068)
|
||||||
- Fix logLevel being set before loading config.
|
- Fix logLevel being set before loading config.
|
||||||
- Fix incorrect namespace links in svg clockfaces. [#2072](https://github.com/MichMich/MagicMirror/issues/2072)
|
- Fix incorrect namespace links in svg clockfaces. [#2072](https://github.com/MagicMirrorOrg/MagicMirror/issues/2072)
|
||||||
- Fix weather/providers/weathergov for API guidelines. [#2045](https://github.com/MichMich/MagicMirror/issues/2045)
|
- Fix weather/providers/weathergov for API guidelines. [#2045](https://github.com/MagicMirrorOrg/MagicMirror/issues/2045)
|
||||||
- Fix "undefined" in weather modules header. [#1985](https://github.com/MichMich/MagicMirror/issues/1985)
|
- Fix "undefined" in weather modules header. [#1985](https://github.com/MagicMirrorOrg/MagicMirror/issues/1985)
|
||||||
- Fix #2110, #2111, #2118: Recurring full day events should not use timezone adjustment. Just compare month/day.
|
- Fix #2110, #2111, #2118: Recurring full day events should not use timezone adjustment. Just compare month/day.
|
||||||
|
|
||||||
## [2.12.0] - 2020-07-01
|
## [2.12.0] - 2020-07-01
|
||||||
@@ -540,14 +746,14 @@ Special thanks to the following contributors: @AndreKoepke, @andrezibaia, @bryan
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- The broken modules due to Socket.io change from last release. [#1973](https://github.com/MichMich/MagicMirror/issues/1973)
|
- The broken modules due to Socket.io change from last release. [#1973](https://github.com/MagicMirrorOrg/MagicMirror/issues/1973)
|
||||||
- Add backward compatibility for old module code in socketclient.js. [#1973](https://github.com/MichMich/MagicMirror/issues/1973)
|
- Add backward compatibility for old module code in socketclient.js. [#1973](https://github.com/MagicMirrorOrg/MagicMirror/issues/1973)
|
||||||
- Support multiple instances of calendar module with different config. [#1109](https://github.com/MichMich/MagicMirror/issues/1109)
|
- Support multiple instances of calendar module with different config. [#1109](https://github.com/MagicMirrorOrg/MagicMirror/issues/1109)
|
||||||
- Fix the use of "maxNumberOfDays" in the module "weatherforecast". [#2018](https://github.com/MichMich/MagicMirror/issues/2018)
|
- Fix the use of "maxNumberOfDays" in the module "weatherforecast". [#2018](https://github.com/MagicMirrorOrg/MagicMirror/issues/2018)
|
||||||
- Throw error when check_config fails. [#1928](https://github.com/MichMich/MagicMirror/issues/1928)
|
- Throw error when check_config fails. [#1928](https://github.com/MagicMirrorOrg/MagicMirror/issues/1928)
|
||||||
- Bug fix related to 'maxEntries' not displaying Calendar events. [#2050](https://github.com/MichMich/MagicMirror/issues/2050)
|
- Bug fix related to 'maxEntries' not displaying Calendar events. [#2050](https://github.com/MagicMirrorOrg/MagicMirror/issues/2050)
|
||||||
- Updated ical library to the latest version. [#1926](https://github.com/MichMich/MagicMirror/issues/1926)
|
- Updated ical library to the latest version. [#1926](https://github.com/MagicMirrorOrg/MagicMirror/issues/1926)
|
||||||
- Fix config check after merge of prettier [#2109](https://github.com/MichMich/MagicMirror/issues/2109)
|
- Fix config check after merge of prettier [#2109](https://github.com/MagicMirrorOrg/MagicMirror/issues/2109)
|
||||||
|
|
||||||
## [2.11.0] - 2020-04-01
|
## [2.11.0] - 2020-04-01
|
||||||
|
|
||||||
@@ -555,7 +761,7 @@ Special thanks to the following contributors: @AndreKoepke, @andrezibaia, @bryan
|
|||||||
|
|
||||||
In the past years the project has grown a lot. This came with a huge downside: poor maintainability. If I let the project continue the way it was, it would eventually crash and burn. More important: I would completely lose the drive and interest to continue the project. Because of this the decision was made to simplify the core by removing all side features like automatic installers and support for exotic platforms. This release (2.11.0) is the first real release that will reflect (parts) of these changes. As a result of this, some things might break. So before you continue make sure to backup your installation. Your config, your modules or better yet: your full MagicMirror² folder. In other words: update at your own risk.
|
In the past years the project has grown a lot. This came with a huge downside: poor maintainability. If I let the project continue the way it was, it would eventually crash and burn. More important: I would completely lose the drive and interest to continue the project. Because of this the decision was made to simplify the core by removing all side features like automatic installers and support for exotic platforms. This release (2.11.0) is the first real release that will reflect (parts) of these changes. As a result of this, some things might break. So before you continue make sure to backup your installation. Your config, your modules or better yet: your full MagicMirror² folder. In other words: update at your own risk.
|
||||||
|
|
||||||
For more information regarding this major change, please check issue [#1860](https://github.com/MichMich/MagicMirror/issues/1860).
|
For more information regarding this major change, please check issue [#1860](https://github.com/MagicMirrorOrg/MagicMirror/issues/1860).
|
||||||
|
|
||||||
### Deleted
|
### Deleted
|
||||||
|
|
||||||
@@ -585,8 +791,8 @@ For more information regarding this major change, please check issue [#1860](htt
|
|||||||
- Fix calendar time offset for recurring events crossing Daylight Savings Time (ISSUE #1798)
|
- Fix calendar time offset for recurring events crossing Daylight Savings Time (ISSUE #1798)
|
||||||
- Fix regression in currentweather module causing 'undefined' to show up when config.hideTemp is false
|
- Fix regression in currentweather module causing 'undefined' to show up when config.hideTemp is false
|
||||||
- Fix FEELS translation for Croatian
|
- Fix FEELS translation for Croatian
|
||||||
- Fixed weather tests [#1840](https://github.com/MichMich/MagicMirror/issues/1840)
|
- Fixed weather tests [#1840](https://github.com/MagicMirrorOrg/MagicMirror/issues/1840)
|
||||||
- Fixed Socket.io can't be used with Reverse Proxy in serveronly mode [#1934](https://github.com/MichMich/MagicMirror/issues/1934)
|
- Fixed Socket.io can't be used with Reverse Proxy in serveronly mode [#1934](https://github.com/MagicMirrorOrg/MagicMirror/issues/1934)
|
||||||
- Fix update checking skipping 3rd party modules the first time
|
- Fix update checking skipping 3rd party modules the first time
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
@@ -654,14 +860,14 @@ Special thanks to @sdetweil for all his great contributions!
|
|||||||
|
|
||||||
- Updatenotification module: Display update notification for a limited (configurable) time.
|
- Updatenotification module: Display update notification for a limited (configurable) time.
|
||||||
- Enabled e2e/vendor_spec.js tests.
|
- Enabled e2e/vendor_spec.js tests.
|
||||||
- The css/custom.css will be renamed after the next release. We've added into `run-start.sh` an instruction by GIT to ignore with `--skip-worktree` and `rm --cached`. [#1540](https://github.com/MichMich/MagicMirror/issues/1540)
|
- The css/custom.css will be renamed after the next release. We've added into `run-start.sh` an instruction by GIT to ignore with `--skip-worktree` and `rm --cached`. [#1540](https://github.com/MagicMirrorOrg/MagicMirror/issues/1540)
|
||||||
- Disable sending of notification CLOCK_SECOND when displaySeconds is false.
|
- Disable sending of notification CLOCK_SECOND when displaySeconds is false.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Updatenotification module: Properly handle race conditions, prevent crash.
|
- Updatenotification module: Properly handle race conditions, prevent crash.
|
||||||
- Send `NEWS_FEED` notification also for the first news messages which are shown.
|
- Send `NEWS_FEED` notification also for the first news messages which are shown.
|
||||||
- Fixed issue where weather module would not refresh data after a network or API outage. [#1722](https://github.com/MichMich/MagicMirror/issues/1722)
|
- Fixed issue where weather module would not refresh data after a network or API outage. [#1722](https://github.com/MagicMirrorOrg/MagicMirror/issues/1722)
|
||||||
- Fixed weatherforecast module not displaying rain amount on fallback endpoint.
|
- Fixed weatherforecast module not displaying rain amount on fallback endpoint.
|
||||||
- Notifications CLOCK_SECOND & CLOCK_MINUTE being from startup instead of matched against the clock and avoid drifting.
|
- Notifications CLOCK_SECOND & CLOCK_MINUTE being from startup instead of matched against the clock and avoid drifting.
|
||||||
|
|
||||||
@@ -676,7 +882,7 @@ Special thanks to @sdetweil for all his great contributions!
|
|||||||
- Russian translation for “Feels”
|
- Russian translation for “Feels”
|
||||||
- Calendar module: added `nextDaysRelative` config option
|
- Calendar module: added `nextDaysRelative` config option
|
||||||
- Add `broadcastPastEvents` config option for calendars to include events from the past `maximumNumberOfDays` in event broadcasts
|
- Add `broadcastPastEvents` config option for calendars to include events from the past `maximumNumberOfDays` in event broadcasts
|
||||||
- Added feature to broadcast news feed items `NEWS_FEED` and updated news items `NEWS_FEED_UPDATED` in default [newsfeed](https://github.com/MichMich/MagicMirror/tree/develop/modules/default/newsfeed) module (when news is updated) with documented default and `config.js` options in [README.md](https://github.com/MichMich/MagicMirror/blob/develop/modules/default/newsfeed/README.md)
|
- Added feature to broadcast news feed items `NEWS_FEED` and updated news items `NEWS_FEED_UPDATED` in default [newsfeed](https://github.com/MagicMirrorOrg/MagicMirror/tree/develop/modules/default/newsfeed) module (when news is updated) with documented default and `config.js` options in [README.md](https://github.com/MagicMirrorOrg/MagicMirror/blob/develop/modules/default/newsfeed/README.md)
|
||||||
- Added notifications to default `clock` module broadcasting `CLOCK_SECOND` and `CLOCK_MINUTE` for the respective time elapsed.
|
- Added notifications to default `clock` module broadcasting `CLOCK_SECOND` and `CLOCK_MINUTE` for the respective time elapsed.
|
||||||
- Added UK Met Office Datapoint feed as a provider in the default weather module.
|
- Added UK Met Office Datapoint feed as a provider in the default weather module.
|
||||||
- Added new provider class
|
- Added new provider class
|
||||||
@@ -685,7 +891,7 @@ Special thanks to @sdetweil for all his great contributions!
|
|||||||
- Use Feels Like temp from feed if present
|
- Use Feels Like temp from feed if present
|
||||||
- Optionally display probability of precipitation (PoP) in current weather (UK Met Office data)
|
- Optionally display probability of precipitation (PoP) in current weather (UK Met Office data)
|
||||||
- Automatically try to fix eslint errors by passing `--fix` option to it
|
- Automatically try to fix eslint errors by passing `--fix` option to it
|
||||||
- Added sunrise and sunset times to weathergov weather provider [#1705](https://github.com/MichMich/MagicMirror/issues/1705)
|
- Added sunrise and sunset times to weathergov weather-provider [#1705](https://github.com/MagicMirrorOrg/MagicMirror/issues/1705)
|
||||||
- Added "useLocationAsHeader" to display "location" in `config.js` as header when location name is not returned
|
- Added "useLocationAsHeader" to display "location" in `config.js` as header when location name is not returned
|
||||||
- Added to `newsfeed.js`: in order to design the news article better with css, three more class-names were introduced: newsfeed-desc, newsfeed-desc, newsfeed-desc
|
- Added to `newsfeed.js`: in order to design the news article better with css, three more class-names were introduced: newsfeed-desc, newsfeed-desc, newsfeed-desc
|
||||||
|
|
||||||
@@ -694,18 +900,18 @@ Special thanks to @sdetweil for all his great contributions!
|
|||||||
- English translation for "Feels" to "Feels like"
|
- English translation for "Feels" to "Feels like"
|
||||||
- Fixed the example calendar url in `config.js.sample`
|
- Fixed the example calendar url in `config.js.sample`
|
||||||
- Updated `ical.js` to solve various calendar issues.
|
- Updated `ical.js` to solve various calendar issues.
|
||||||
- Updated weather city list url [#1676](https://github.com/MichMich/MagicMirror/issues/1676)
|
- Updated weather city list url [#1676](https://github.com/MagicMirrorOrg/MagicMirror/issues/1676)
|
||||||
- Only update clock once per minute when seconds aren't shown
|
- Only update clock once per minute when seconds aren't shown
|
||||||
- Updated weatherprovider documentation.
|
- Updated weather-provider documentation.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fixed uncaught exception, race condition on module update
|
- Fixed uncaught exception, race condition on module update
|
||||||
- Fixed issue [#1696](https://github.com/MichMich/MagicMirror/issues/1696), some ical files start date to not parse to date type
|
- Fixed issue [#1696](https://github.com/MagicMirrorOrg/MagicMirror/issues/1696), some ical files start date to not parse to date type
|
||||||
- Allowance HTML5 autoplay-policy (policy is changed from Chrome 66 updates)
|
- Allowance HTML5 autoplay-policy (policy is changed from Chrome 66 updates)
|
||||||
- Handle SIGTERM messages
|
- Handle SIGTERM messages
|
||||||
- Fixes sliceMultiDayEvents so it respects maximumNumberOfDays
|
- Fixes sliceMultiDayEvents so it respects maximumNumberOfDays
|
||||||
- Minor types in default NewsFeed [README.md](https://github.com/MichMich/MagicMirror/blob/develop/modules/default/newsfeed/README.md)
|
- Minor types in default NewsFeed [README.md](https://github.com/MagicMirrorOrg/MagicMirror/blob/develop/modules/default/newsfeed/README.md)
|
||||||
- Fix typos and small syntax errors, cleanup dependencies, remove multiple-empty-lines, add semi-rule
|
- Fix typos and small syntax errors, cleanup dependencies, remove multiple-empty-lines, add semi-rule
|
||||||
- Fixed issues with calendar not displaying one-time changes to repeating events
|
- Fixed issues with calendar not displaying one-time changes to repeating events
|
||||||
- Updated the fetchedLocationName variable in currentweather.js so that city shows up in the header
|
- Updated the fetchedLocationName variable in currentweather.js so that city shows up in the header
|
||||||
@@ -743,42 +949,42 @@ Fixed `package.json` version number.
|
|||||||
|
|
||||||
### Updated
|
### Updated
|
||||||
|
|
||||||
- Bumped the Electron dependency to v3.0.13 to support the most recent Raspbian. [#1500](https://github.com/MichMich/MagicMirror/issues/1500)
|
- Bumped the Electron dependency to v3.0.13 to support the most recent Raspbian. [#1500](https://github.com/MagicMirrorOrg/MagicMirror/issues/1500)
|
||||||
- Updated modernizr code in alert module, fixed a small typo there too
|
- Updated modernizr code in alert module, fixed a small typo there too
|
||||||
- More verbose error message on console if the config is malformed
|
- More verbose error message on console if the config is malformed
|
||||||
- Updated installer script to install Node.js version 10.x
|
- Updated installer script to install Node.js version 10.x
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fixed temperature displays in currentweather and weatherforecast modules [#1503](https://github.com/MichMich/MagicMirror/issues/1503), [#1511](https://github.com/MichMich/MagicMirror/issues/1511).
|
- Fixed temperature displays in currentweather and weatherforecast modules [#1503](https://github.com/MagicMirrorOrg/MagicMirror/issues/1503), [#1511](https://github.com/MagicMirrorOrg/MagicMirror/issues/1511).
|
||||||
- Fixed unhandled error on bad git data in updatenotification module [#1285](https://github.com/MichMich/MagicMirror/issues/1285).
|
- Fixed unhandled error on bad git data in updatenotification module [#1285](https://github.com/MagicMirrorOrg/MagicMirror/issues/1285).
|
||||||
- Weather forecast now works with openweathermap in new weather module. Daily data are displayed, see issue [#1504](https://github.com/MichMich/MagicMirror/issues/1504).
|
- Weather forecast now works with openweathermap in new weather module. Daily data are displayed, see issue [#1504](https://github.com/MagicMirrorOrg/MagicMirror/issues/1504).
|
||||||
- Fixed analogue clock border display issue where non-black backgrounds used (previous fix for issue 611)
|
- Fixed analogue clock border display issue where non-black backgrounds used (previous fix for issue 611)
|
||||||
- Fixed compatibility issues caused when modules request different versions of Font Awesome, see issue [#1522](https://github.com/MichMich/MagicMirror/issues/1522). MagicMirror² now uses [Font Awesome 5 with v4 shims included for backwards compatibility](https://fontawesome.com/how-to-use/on-the-web/setup/upgrading-from-version-4#shims).
|
- Fixed compatibility issues caused when modules request different versions of Font Awesome, see issue [#1522](https://github.com/MagicMirrorOrg/MagicMirror/issues/1522). MagicMirror² now uses [Font Awesome 5 with v4 shims included for backwards compatibility](https://fontawesome.com/how-to-use/on-the-web/setup/upgrading-from-version-4#shims).
|
||||||
- Installation script problems with raspbian
|
- Installation script problems with raspbian
|
||||||
- Calendar: only show repeating count if the event is actually repeating [#1534](https://github.com/MichMich/MagicMirror/pull/1534)
|
- Calendar: only show repeating count if the event is actually repeating [#1534](https://github.com/MagicMirrorOrg/MagicMirror/pull/1534)
|
||||||
- Calendar: Fix exdate handling when multiple values are specified (comma separated)
|
- Calendar: Fix exdate handling when multiple values are specified (comma separated)
|
||||||
- Calendar: Fix relative date handling for fulldate events, calculate difference always from start of day [#1572](https://github.com/MichMich/MagicMirror/issues/1572)
|
- Calendar: Fix relative date handling for fulldate events, calculate difference always from start of day [#1572](https://github.com/MagicMirrorOrg/MagicMirror/issues/1572)
|
||||||
- Fix null dereference in moduleNeedsUpdate when the module isn't visible
|
- Fix null dereference in moduleNeedsUpdate when the module isn't visible
|
||||||
- Calendar: Fixed event end times by setting default calendarEndTime to "LT" (Local time format). [#1479]
|
- Calendar: Fixed event end times by setting default calendarEndTime to "LT" (Local time format). [#1479]
|
||||||
- Calendar: Fixed missing calendar fetchers after server process restarts [#1589](https://github.com/MichMich/MagicMirror/issues/1589)
|
- Calendar: Fixed missing calendar fetchers after server process restarts [#1589](https://github.com/MagicMirrorOrg/MagicMirror/issues/1589)
|
||||||
- Notification: fixed background color (was white text on white background)
|
- Notification: fixed background color (was white text on white background)
|
||||||
- Use getHeader instead of data.header when creating the DOM so overwriting the function also propagates into it
|
- Use getHeader instead of data.header when creating the DOM so overwriting the function also propagates into it
|
||||||
- Fix documentation of `useKMPHwind` option in currentweather
|
- Fix documentation of `useKMPHwind` option in currentweather
|
||||||
|
|
||||||
### New weather module
|
### New weather module
|
||||||
|
|
||||||
- Fixed weather forecast table display [#1499](https://github.com/MichMich/MagicMirror/issues/1499).
|
- Fixed weather forecast table display [#1499](https://github.com/MagicMirrorOrg/MagicMirror/issues/1499).
|
||||||
- Dimmed loading indicator for weather forecast.
|
- Dimmed loading indicator for weather forecast.
|
||||||
- Implemented config option `decimalSymbol` [#1499](https://github.com/MichMich/MagicMirror/issues/1499).
|
- Implemented config option `decimalSymbol` [#1499](https://github.com/MagicMirrorOrg/MagicMirror/issues/1499).
|
||||||
- Aligned indoor values in current weather vertical [#1499](https://github.com/MichMich/MagicMirror/issues/1499).
|
- Aligned indoor values in current weather vertical [#1499](https://github.com/MagicMirrorOrg/MagicMirror/issues/1499).
|
||||||
- Added humidity support to nunjuck unit filter.
|
- Added humidity support to nunjuck unit filter.
|
||||||
- Do not display degree symbol for temperature in Kelvin [#1503](https://github.com/MichMich/MagicMirror/issues/1503).
|
- Do not display degree symbol for temperature in Kelvin [#1503](https://github.com/MagicMirrorOrg/MagicMirror/issues/1503).
|
||||||
- Weather forecast now works with openweathermap for both, `/forecast` and `/forecast/daily`, in new weather module. If you use the `/forecast`-weatherEndpoint, the hourly data are converted to daily data, see issues [#1504](https://github.com/MichMich/MagicMirror/issues/1504), [#1513](https://github.com/MichMich/MagicMirror/issues/1513).
|
- Weather forecast now works with openweathermap for both, `/forecast` and `/forecast/daily`, in new weather module. If you use the `/forecast`-weatherEndpoint, the hourly data are converted to daily data, see issues [#1504](https://github.com/MagicMirrorOrg/MagicMirror/issues/1504), [#1513](https://github.com/MagicMirrorOrg/MagicMirror/issues/1513).
|
||||||
- Added fade, fadePoint and maxNumberOfDays properties to the forecast mode [#1516](https://github.com/MichMich/MagicMirror/issues/1516)
|
- Added fade, fadePoint and maxNumberOfDays properties to the forecast mode [#1516](https://github.com/MagicMirrorOrg/MagicMirror/issues/1516)
|
||||||
- Fixed Loading string and decimalSymbol string replace [#1538](https://github.com/MichMich/MagicMirror/issues/1538)
|
- Fixed Loading string and decimalSymbol string replace [#1538](https://github.com/MagicMirrorOrg/MagicMirror/issues/1538)
|
||||||
- Show Snow amounts in new weather module [#1545](https://github.com/MichMich/MagicMirror/issues/1545)
|
- Show Snow amounts in new weather module [#1545](https://github.com/MagicMirrorOrg/MagicMirror/issues/1545)
|
||||||
- Added weather.gov as a new weather provider for US locations
|
- Added weather.gov as a new weather-provider for US locations
|
||||||
|
|
||||||
## [2.6.0] - 2019-01-01
|
## [2.6.0] - 2019-01-01
|
||||||
|
|
||||||
@@ -802,7 +1008,7 @@ A huge, huge, huge thanks to user @fewieden for all his hard work on the new `we
|
|||||||
- Screenshot for the weather forecast module
|
- Screenshot for the weather forecast module
|
||||||
- Portuguese translation for "Feels"
|
- Portuguese translation for "Feels"
|
||||||
- Croatian translation
|
- Croatian translation
|
||||||
- Fading for dateheaders timeFormat in Calendar [#1464](https://github.com/MichMich/MagicMirror/issues/1464)
|
- Fading for dateheaders timeFormat in Calendar [#1464](https://github.com/MagicMirrorOrg/MagicMirror/issues/1464)
|
||||||
- Documentation for the existing `scale` option in the Weather Forecast module.
|
- Documentation for the existing `scale` option in the Weather Forecast module.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
@@ -811,7 +1017,7 @@ A huge, huge, huge thanks to user @fewieden for all his hard work on the new `we
|
|||||||
- Fixed Polish translation for Single Update Info
|
- Fixed Polish translation for Single Update Info
|
||||||
- Ignore entries with unparseable details in the calendar module
|
- Ignore entries with unparseable details in the calendar module
|
||||||
- Bug showing FullDayEvents one day too long in calendar fixed
|
- Bug showing FullDayEvents one day too long in calendar fixed
|
||||||
- Bug in newsfeed when `removeStartTags` is used on the description [#1478](https://github.com/MichMich/MagicMirror/issues/1478)
|
- Bug in newsfeed when `removeStartTags` is used on the description [#1478](https://github.com/MagicMirrorOrg/MagicMirror/issues/1478)
|
||||||
|
|
||||||
### Updated
|
### Updated
|
||||||
|
|
||||||
@@ -844,7 +1050,7 @@ A huge, huge, huge thanks to user @fewieden for all his hard work on the new `we
|
|||||||
- Fixed mixup between german and spanish translation for newsfeed.
|
- Fixed mixup between german and spanish translation for newsfeed.
|
||||||
- Fixed close dates to be absolute, if no configured in the config.js - module Calendar
|
- Fixed close dates to be absolute, if no configured in the config.js - module Calendar
|
||||||
- Fixed the updatenotification module message about new commits in the repository, so they can be correctly localized in singular and plural form.
|
- Fixed the updatenotification module message about new commits in the repository, so they can be correctly localized in singular and plural form.
|
||||||
- Fix for weatherforecast rainfall rounding [#1374](https://github.com/MichMich/MagicMirror/issues/1374)
|
- Fix for weatherforecast rainfall rounding [#1374](https://github.com/MagicMirrorOrg/MagicMirror/issues/1374)
|
||||||
- Fix calendar parsing issue for Midori on RasperryPi Zero w, related to issue #694.
|
- Fix calendar parsing issue for Midori on RasperryPi Zero w, related to issue #694.
|
||||||
- Fix weather city ID link in sample config
|
- Fix weather city ID link in sample config
|
||||||
- Fixed issue with clientonly not updating with IP address and port provided on command line.
|
- Fixed issue with clientonly not updating with IP address and port provided on command line.
|
||||||
@@ -866,7 +1072,7 @@ A huge, huge, huge thanks to user @fewieden for all his hard work on the new `we
|
|||||||
|
|
||||||
## [2.4.0] - 2018-07-01
|
## [2.4.0] - 2018-07-01
|
||||||
|
|
||||||
⚠️ **Warning:** This release includes an updated version of Electron. This requires a Raspberry Pi configuration change to allow the best performance and prevent the CPU from overheating. Please read the information on the [MagicMirror² Wiki](https://github.com/michmich/magicmirror/wiki/configuring-the-raspberry-pi#enable-the-open-gl-driver-to-decrease-electrons-cpu-usage).
|
⚠️ **Warning:** This release includes an updated version of Electron. This requires a Raspberry Pi configuration change to allow the best performance and prevent the CPU from overheating. Please read the information on the [MagicMirror² Wiki](https://github.com/MagicMirrorOrg/MagicMirror/wiki/configuring-the-raspberry-pi#enable-the-open-gl-driver-to-decrease-electrons-cpu-usage).
|
||||||
|
|
||||||
ℹ️ **Note:** This update uses new dependencies. Please update using the following command: `git pull && npm install`
|
ℹ️ **Note:** This update uses new dependencies. Please update using the following command: `git pull && npm install`
|
||||||
|
|
||||||
@@ -888,20 +1094,20 @@ A huge, huge, huge thanks to user @fewieden for all his hard work on the new `we
|
|||||||
|
|
||||||
- Upgrade to Electron 2.0.0.
|
- Upgrade to Electron 2.0.0.
|
||||||
- Remove yarn-or-npm which breaks production builds.
|
- Remove yarn-or-npm which breaks production builds.
|
||||||
- Invoke module suspend even if no dom content. [#1308](https://github.com/MichMich/MagicMirror/issues/1308)
|
- Invoke module suspend even if no dom content. [#1308](https://github.com/MagicMirrorOrg/MagicMirror/issues/1308)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fixed issue where wind chill could not be displayed in Fahrenheit. [#1247](https://github.com/MichMich/MagicMirror/issues/1247)
|
- Fixed issue where wind chill could not be displayed in Fahrenheit. [#1247](https://github.com/MagicMirrorOrg/MagicMirror/issues/1247)
|
||||||
- Fixed issues where a module crashes when it tries to dismiss a non existing alert. [#1240](https://github.com/MichMich/MagicMirror/issues/1240)
|
- Fixed issues where a module crashes when it tries to dismiss a non existing alert. [#1240](https://github.com/MagicMirrorOrg/MagicMirror/issues/1240)
|
||||||
- In default module currentWeather/currentWeather.js line 296, 300, self.config.animationSpeed can not be found because the notificationReceived function does not have "self" variable.
|
- In default module currentWeather/currentWeather.js line 296, 300, self.config.animationSpeed can not be found because the notificationReceived function does not have "self" variable.
|
||||||
- Fixed browser-side code to work on the Midori browser.
|
- Fixed browser-side code to work on the Midori browser.
|
||||||
- Fixed issue where heat index was reporting incorrect values in Celsius and Fahrenheit. [#1263](https://github.com/MichMich/MagicMirror/issues/1263)
|
- Fixed issue where heat index was reporting incorrect values in Celsius and Fahrenheit. [#1263](https://github.com/MagicMirrorOrg/MagicMirror/issues/1263)
|
||||||
- Fixed weatherforecast to use dt_txt field instead of dt to handle timezones better
|
- Fixed weatherforecast to use dt_txt field instead of dt to handle timezones better
|
||||||
- Newsfeed now remembers to show the description when `"ARTICLE_LESS_DETAILS"` is called if the user wants to always show the description. [#1282](https://github.com/MichMich/MagicMirror/issues/1282)
|
- Newsfeed now remembers to show the description when `"ARTICLE_LESS_DETAILS"` is called if the user wants to always show the description. [#1282](https://github.com/MagicMirrorOrg/MagicMirror/issues/1282)
|
||||||
- `clientonly/*.js` is now linted, and one linting error is fixed
|
- `clientonly/*.js` is now linted, and one linting error is fixed
|
||||||
- Fix issue #1196 by changing underscore to hyphen in locale id, in align with momentjs.
|
- Fix issue #1196 by changing underscore to hyphen in locale id, in align with momentjs.
|
||||||
- Fixed issue where heat index and wind chill were reporting incorrect values in Kelvin. [#1263](https://github.com/MichMich/MagicMirror/issues/1263)
|
- Fixed issue where heat index and wind chill were reporting incorrect values in Kelvin. [#1263](https://github.com/MagicMirrorOrg/MagicMirror/issues/1263)
|
||||||
|
|
||||||
### Updated
|
### Updated
|
||||||
|
|
||||||
@@ -913,7 +1119,7 @@ A huge, huge, huge thanks to user @fewieden for all his hard work on the new `we
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Downgrade electron to 1.4.15 to solve the black screen issue.[#1243](https://github.com/MichMich/MagicMirror/issues/1243)
|
- Downgrade electron to 1.4.15 to solve the black screen issue.[#1243](https://github.com/MagicMirrorOrg/MagicMirror/issues/1243)
|
||||||
|
|
||||||
## [2.3.0] - 2018-04-01
|
## [2.3.0] - 2018-04-01
|
||||||
|
|
||||||
@@ -1039,8 +1245,8 @@ A huge, huge, huge thanks to user @fewieden for all his hard work on the new `we
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Revert Docker related changes in favor of [docker-MagicMirror](https://github.com/bastilimbach/docker-MagicMirror). All Docker images are outsourced. ([#856](https://github.com/MichMich/MagicMirror/pull/856))
|
- Revert Docker related changes in favor of [docker-MagicMirror](https://github.com/bastilimbach/docker-MagicMirror). All Docker images are outsourced. ([#856](https://github.com/MagicMirrorOrg/MagicMirror/pull/856))
|
||||||
- Change Docker base image (Debian + Node) to an arm based distro (AlpineARM + Node) ([#846](https://github.com/MichMich/MagicMirror/pull/846))
|
- Change Docker base image (Debian + Node) to an arm based distro (AlpineARM + Node) ([#846](https://github.com/MagicMirrorOrg/MagicMirror/pull/846))
|
||||||
- Fix the dockerfile to have it running from the first time.
|
- Fix the dockerfile to have it running from the first time.
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
@@ -1087,7 +1293,7 @@ A huge, huge, huge thanks to user @fewieden for all his hard work on the new `we
|
|||||||
- Add `anytime` group for Compliments module.
|
- Add `anytime` group for Compliments module.
|
||||||
- Compliments module can use remoteFile without default daytime arrays defined.
|
- Compliments module can use remoteFile without default daytime arrays defined.
|
||||||
- Installer: Use init config.js from config.js.sample.
|
- Installer: Use init config.js from config.js.sample.
|
||||||
- Switched out `rrule` package for `rrule-alt` and fixes in `ical.js` in order to fix calendar issues. ([#565](https://github.com/MichMich/MagicMirror/issues/565))
|
- Switched out `rrule` package for `rrule-alt` and fixes in `ical.js` in order to fix calendar issues. ([#565](https://github.com/MagicMirrorOrg/MagicMirror/issues/565))
|
||||||
- Make mouse events pass through the region fullscreen_above to modules below.
|
- Make mouse events pass through the region fullscreen_above to modules below.
|
||||||
- Scaled the splash screen down to make it a bit more subtle.
|
- Scaled the splash screen down to make it a bit more subtle.
|
||||||
- Replace HTML tables with markdown tables in README files.
|
- Replace HTML tables with markdown tables in README files.
|
||||||
@@ -1100,7 +1306,7 @@ A huge, huge, huge thanks to user @fewieden for all his hard work on the new `we
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Added Docker support (Pull Request [#673](https://github.com/MichMich/MagicMirror/pull/673)).
|
- Added Docker support (Pull Request [#673](https://github.com/MagicMirrorOrg/MagicMirror/pull/673)).
|
||||||
- Calendar-specific support for `maximumEntries`, and `maximumNumberOfDays`.
|
- Calendar-specific support for `maximumEntries`, and `maximumNumberOfDays`.
|
||||||
- Add loaded function to modules, providing an async callback.
|
- Add loaded function to modules, providing an async callback.
|
||||||
- Made default newsfeed module aware of gesture events from [MMM-Gestures](https://github.com/thobach/MMM-Gestures)
|
- Made default newsfeed module aware of gesture events from [MMM-Gestures](https://github.com/thobach/MMM-Gestures)
|
||||||
@@ -1146,7 +1352,7 @@ A huge, huge, huge thanks to user @fewieden for all his hard work on the new `we
|
|||||||
- Updated .gitignore to not ignore default modules folder.
|
- Updated .gitignore to not ignore default modules folder.
|
||||||
- Remove white flash on boot up.
|
- Remove white flash on boot up.
|
||||||
- Added `update` in Raspberry Pi installation script.
|
- Added `update` in Raspberry Pi installation script.
|
||||||
- Fix an issue where the analog clock looked scrambled. ([#611](https://github.com/MichMich/MagicMirror/issues/611))
|
- Fix an issue where the analog clock looked scrambled. ([#611](https://github.com/MagicMirrorOrg/MagicMirror/issues/611))
|
||||||
- If units are set to imperial, the showRainAmount option of weatherforecast will show the correct unit.
|
- If units are set to imperial, the showRainAmount option of weatherforecast will show the correct unit.
|
||||||
- Module currentWeather: check if temperature received from api is defined.
|
- Module currentWeather: check if temperature received from api is defined.
|
||||||
- Fix an issue with module hidden status changing to `true` although lock string prevented showing it.
|
- Fix an issue with module hidden status changing to `true` although lock string prevented showing it.
|
||||||
@@ -1163,18 +1369,18 @@ A huge, huge, huge thanks to user @fewieden for all his hard work on the new `we
|
|||||||
- Finnish translation.
|
- Finnish translation.
|
||||||
- Danish translation.
|
- Danish translation.
|
||||||
- Turkish translation.
|
- Turkish translation.
|
||||||
- Option to limit access to certain IP addresses based on the value of `ipWhitelist` in the `config.js`, default is access from localhost only (Issue [#456](https://github.com/MichMich/MagicMirror/issues/456)).
|
- Option to limit access to certain IP addresses based on the value of `ipWhitelist` in the `config.js`, default is access from localhost only (Issue [#456](https://github.com/MagicMirrorOrg/MagicMirror/issues/456)).
|
||||||
- Added ability to change the point of time when calendar events get relative.
|
- Added ability to change the point of time when calendar events get relative.
|
||||||
- Add Splash screen on boot.
|
- Add Splash screen on boot.
|
||||||
- Add option to show humidity in currentWeather module.
|
- Add option to show humidity in currentWeather module.
|
||||||
- Add VSCode IntelliSense support.
|
- Add VSCode IntelliSense support.
|
||||||
- Module API: Add Visibility locking to module system. [See documentation](https://github.com/MichMich/MagicMirror/tree/develop/modules#visibility-locking) for more information.
|
- Module API: Add Visibility locking to module system. [See documentation](https://github.com/MagicMirrorOrg/MagicMirror/tree/develop/modules#visibility-locking) for more information.
|
||||||
- Module API: Method to overwrite the module's header. [See documentation](https://github.com/MichMich/MagicMirror/tree/develop/modules#getheader) for more information.
|
- Module API: Method to overwrite the module's header. [See documentation](https://github.com/MagicMirrorOrg/MagicMirror/tree/develop/modules#getheader) for more information.
|
||||||
- Module API: Option to define the minimum MagicMirror² version to run a module. [See documentation](https://github.com/MichMich/MagicMirror/tree/develop/modules#requiresversion) for more information.
|
- Module API: Option to define the minimum MagicMirror² version to run a module. [See documentation](https://github.com/MagicMirrorOrg/MagicMirror/tree/develop/modules#requiresversion) for more information.
|
||||||
- Calendar module now broadcasts the event list to all other modules using the notification system. [See documentation](https://github.com/MichMich/MagicMirror/tree/develop/modules/default/calendar) for more information.
|
- Calendar module now broadcasts the event list to all other modules using the notification system. [See documentation](https://github.com/MagicMirrorOrg/MagicMirror/tree/develop/modules/default/calendar) for more information.
|
||||||
- Possibility to use the calendar feed as the source for the weather (currentweather & weatherforecast) location data. [See documentation](https://github.com/MichMich/MagicMirror/tree/develop/modules/default/weatherforecast) for more information.
|
- Possibility to use the calendar feed as the source for the weather (currentweather & weatherforecast) location data. [See documentation](https://github.com/MagicMirrorOrg/MagicMirror/tree/develop/modules/default/weatherforecast) for more information.
|
||||||
- Added option to show rain amount in the weatherforecast default module
|
- Added option to show rain amount in the weatherforecast default module
|
||||||
- Add module `updatenotification` to get an update whenever a new version is available. [See documentation](https://github.com/MichMich/MagicMirror/tree/develop/modules/default/updatenotification) for more information.
|
- Add module `updatenotification` to get an update whenever a new version is available. [See documentation](https://github.com/MagicMirrorOrg/MagicMirror/tree/develop/modules/default/updatenotification) for more information.
|
||||||
- Add the ability to set timezone on the date display in the Clock Module
|
- Add the ability to set timezone on the date display in the Clock Module
|
||||||
- Ability to set date format in calendar module
|
- Ability to set date format in calendar module
|
||||||
- Possibility to use currentweather for the compliments
|
- Possibility to use currentweather for the compliments
|
||||||
@@ -1244,11 +1450,11 @@ A huge, huge, huge thanks to user @fewieden for all his hard work on the new `we
|
|||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Prevent `getModules()` selectors from returning duplicate entries.
|
- Prevent `getModules()` selectors from returning duplicate entries.
|
||||||
- Append endpoints of weather modules with `/` to retrieve the correct data. (Issue [#337](https://github.com/MichMich/MagicMirror/issues/337))
|
- Append endpoints of weather modules with `/` to retrieve the correct data. (Issue [#337](https://github.com/MagicMirrorOrg/MagicMirror/issues/337))
|
||||||
- Corrected grammar in `module.js` from 'suspend' to 'suspended'.
|
- Corrected grammar in `module.js` from 'suspend' to 'suspended'.
|
||||||
- Fixed openweathermap.org URL in config sample.
|
- Fixed openweathermap.org URL in config sample.
|
||||||
- Prevent currentweather module from crashing when received data object is incorrect.
|
- Prevent currentweather module from crashing when received data object is incorrect.
|
||||||
- Fix issue where translation loading prevented the UI start-up when the language was set to 'en'. (Issue [#388](https://github.com/MichMich/MagicMirror/issues/388))
|
- Fix issue where translation loading prevented the UI start-up when the language was set to 'en'. (Issue [#388](https://github.com/MagicMirrorOrg/MagicMirror/issues/388))
|
||||||
|
|
||||||
### Updated
|
### Updated
|
||||||
|
|
||||||
@@ -1268,8 +1474,8 @@ A huge, huge, huge thanks to user @fewieden for all his hard work on the new `we
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Edit Alert Module to display title & message if they are provided in the notification (Issue [#300](https://github.com/MichMich/MagicMirror/issues/300))
|
- Edit Alert Module to display title & message if they are provided in the notification (Issue [#300](https://github.com/MagicMirrorOrg/MagicMirror/issues/300))
|
||||||
- Removed 'null' reference from updateModuleContent(). This fixes recent Edge and Internet Explorer browser displays (Issue [#319](https://github.com/MichMich/MagicMirror/issues/319))
|
- Removed 'null' reference from updateModuleContent(). This fixes recent Edge and Internet Explorer browser displays (Issue [#319](https://github.com/MagicMirrorOrg/MagicMirror/issues/319))
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
@@ -1286,7 +1492,7 @@ A huge, huge, huge thanks to user @fewieden for all his hard work on the new `we
|
|||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Added reference to Italian Translation.
|
- Added reference to Italian Translation.
|
||||||
- Added the missing NE translation to all languages. [#344](https://github.com/MichMich/MagicMirror/issues/344)
|
- Added the missing NE translation to all languages. [#344](https://github.com/MagicMirrorOrg/MagicMirror/issues/344)
|
||||||
- Added proper User-Agent string to calendar call.
|
- Added proper User-Agent string to calendar call.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ This document describes how collaborators of this repository should work togethe
|
|||||||
- never merge your own PR's
|
- never merge your own PR's
|
||||||
- never merge without someone having approved (approving and merging from same person is allowed)
|
- never merge without someone having approved (approving and merging from same person is allowed)
|
||||||
- wait for all approvals requested (or the author decides something different in the comments)
|
- wait for all approvals requested (or the author decides something different in the comments)
|
||||||
- never merge to `master`, except for releases (because of update notification)
|
- merge to `master` only for releases or other urgent issues (update notification is only triggered by tags)
|
||||||
- merges to master should be tagged with the "mastermerge" label so that the test runs through
|
- merges to master should be tagged with the "mastermerge" label so that the test runs through
|
||||||
|
|
||||||
## Issues
|
## Issues
|
||||||
@@ -15,4 +15,24 @@ This document describes how collaborators of this repository should work togethe
|
|||||||
|
|
||||||
## Releases
|
## Releases
|
||||||
|
|
||||||
- are done by @MichMich only
|
Are done by @rejas or @khassel.
|
||||||
|
|
||||||
|
### Deployment steps
|
||||||
|
|
||||||
|
- pull latest `develop` branch
|
||||||
|
- update `package.json` to reflect correct version number
|
||||||
|
- run `npm install` to generate new `package-lock.json`
|
||||||
|
- test `develop` branch
|
||||||
|
- update `CHANGELOG.md` (don't forget to add all contributor names)
|
||||||
|
- commit and push all changes
|
||||||
|
- after successful test run via github actions: create pull request to `master` branch
|
||||||
|
- after PR tests run without issues, merge PR
|
||||||
|
- create new release with corresponding version tag
|
||||||
|
- publish release notes with link to github release on forum in new locked topic
|
||||||
|
|
||||||
|
### Draft new development release
|
||||||
|
|
||||||
|
- checkout `develop` branch
|
||||||
|
- update `package.json` to reflect correct version number `2.xx.0-develop`
|
||||||
|
- draft new section in `CHANGELOG.md`
|
||||||
|
- commit and publish `develop` branch
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# The MIT License (MIT)
|
# The MIT License (MIT)
|
||||||
|
|
||||||
Copyright © 2016-2022 Michael Teeuw
|
Copyright © 2016-2024 Michael Teeuw
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person
|
Permission is hereby granted, free of charge, to any person
|
||||||
obtaining a copy of this software and associated documentation
|
obtaining a copy of this software and associated documentation
|
||||||
|
|||||||
13
README.md
13
README.md
@@ -4,17 +4,14 @@
|
|||||||
<a href="https://choosealicense.com/licenses/mit">
|
<a href="https://choosealicense.com/licenses/mit">
|
||||||
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License">
|
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License">
|
||||||
</a>
|
</a>
|
||||||
<img src="https://img.shields.io/github/actions/workflow/status/michmich/magicmirror/automated-tests.yaml" alt="GitHub Actions">
|
<img src="https://img.shields.io/github/actions/workflow/status/magicmirrororg/magicmirror/automated-tests.yaml" alt="GitHub Actions">
|
||||||
<img src="https://img.shields.io/github/checks-status/michmich/magicmirror/master" alt="Build Status">
|
<img src="https://img.shields.io/github/checks-status/magicmirrororg/magicmirror/master" alt="Build Status">
|
||||||
<a href="https://codecov.io/gh/MichMich/MagicMirror">
|
<a href="https://github.com/MagicMirrorOrg/MagicMirror">
|
||||||
<img src="https://codecov.io/gh/MichMich/MagicMirror/branch/master/graph/badge.svg?token=LEG1KitZR6" alt="CodeCov Status"/>
|
<img src="https://img.shields.io/github/stars/magicmirrororg/magicmirror?style=social">
|
||||||
</a>
|
|
||||||
<a href="https://github.com/MichMich/MagicMirror">
|
|
||||||
<img src="https://img.shields.io/github/stars/michmich/magicmirror?style=social">
|
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
**MagicMirror²** is an open source modular smart mirror platform. With a growing list of installable modules, the **MagicMirror²** allows you to convert your hallway or bathroom mirror into your personal assistant. **MagicMirror²** is built by the creator of [the original MagicMirror](https://michaelteeuw.nl/tagged/magicmirror) with the incredible help of a [growing community of contributors](https://github.com/MichMich/MagicMirror/graphs/contributors).
|
**MagicMirror²** is an open source modular smart mirror platform. With a growing list of installable modules, the **MagicMirror²** allows you to convert your hallway or bathroom mirror into your personal assistant. **MagicMirror²** is built by the creator of [the original MagicMirror](https://michaelteeuw.nl/tagged/magicmirror) with the incredible help of a [growing community of contributors](https://github.com/MagicMirrorOrg/MagicMirror/graphs/contributors).
|
||||||
|
|
||||||
MagicMirror² focuses on a modular plugin system and uses [Electron](https://www.electronjs.org/) as an application wrapper. So no more web server or browser installs necessary!
|
MagicMirror² focuses on a modular plugin system and uses [Electron](https://www.electronjs.org/) as an application wrapper. So no more web server or browser installs necessary!
|
||||||
|
|
||||||
|
|||||||
@@ -7,16 +7,16 @@
|
|||||||
/**
|
/**
|
||||||
* Helper function to get server address/hostname from either the commandline or env
|
* Helper function to get server address/hostname from either the commandline or env
|
||||||
*/
|
*/
|
||||||
function getServerAddress() {
|
function getServerAddress () {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get command line parameters
|
* Get command line parameters
|
||||||
* Assumes that a cmdline parameter is defined with `--key [value]`
|
* Assumes that a cmdline parameter is defined with `--key [value]`
|
||||||
*
|
|
||||||
* @param {string} key key to look for at the command line
|
* @param {string} key key to look for at the command line
|
||||||
* @param {string} defaultValue value if no key is given at the command line
|
* @param {string} defaultValue value if no key is given at the command line
|
||||||
* @returns {string} the value of the parameter
|
* @returns {string} the value of the parameter
|
||||||
*/
|
*/
|
||||||
function getCommandLineParameter(key, defaultValue = undefined) {
|
function getCommandLineParameter (key, defaultValue = undefined) {
|
||||||
const index = process.argv.indexOf(`--${key}`);
|
const index = process.argv.indexOf(`--${key}`);
|
||||||
const value = index > -1 ? process.argv[index + 1] : undefined;
|
const value = index > -1 ? process.argv[index + 1] : undefined;
|
||||||
return value !== undefined ? String(value) : defaultValue;
|
return value !== undefined ? String(value) : defaultValue;
|
||||||
@@ -33,15 +33,14 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the config from the specified server url
|
* Gets the config from the specified server url
|
||||||
*
|
|
||||||
* @param {string} url location where the server is running.
|
* @param {string} url location where the server is running.
|
||||||
* @returns {Promise} the config
|
* @returns {Promise} the config
|
||||||
*/
|
*/
|
||||||
function getServerConfig(url) {
|
function getServerConfig (url) {
|
||||||
// Return new pending promise
|
// Return new pending promise
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// Select http or https module, depending on requested url
|
// Select http or https module, depending on requested url
|
||||||
const lib = url.startsWith("https") ? require("https") : require("http");
|
const lib = url.startsWith("https") ? require("node:https") : require("node:http");
|
||||||
const request = lib.get(url, (response) => {
|
const request = lib.get(url, (response) => {
|
||||||
let configData = "";
|
let configData = "";
|
||||||
|
|
||||||
@@ -63,11 +62,10 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Print a message to the console in case of errors
|
* Print a message to the console in case of errors
|
||||||
*
|
|
||||||
* @param {string} message error message to print
|
* @param {string} message error message to print
|
||||||
* @param {number} code error code for the exit call
|
* @param {number} code error code for the exit call
|
||||||
*/
|
*/
|
||||||
function fail(message, code = 1) {
|
function fail (message, code = 1) {
|
||||||
if (message !== undefined && typeof message === "string") {
|
if (message !== undefined && typeof message === "string") {
|
||||||
console.log(message);
|
console.log(message);
|
||||||
} else {
|
} else {
|
||||||
@@ -87,6 +85,7 @@
|
|||||||
.then(function (configReturn) {
|
.then(function (configReturn) {
|
||||||
// Pass along the server config via an environment variable
|
// Pass along the server config via an environment variable
|
||||||
const env = Object.create(process.env);
|
const env = Object.create(process.env);
|
||||||
|
env.clientonly = true; // set to pass to electron.js
|
||||||
const options = { env: env };
|
const options = { env: env };
|
||||||
configReturn.address = config.address;
|
configReturn.address = config.address;
|
||||||
configReturn.port = config.port;
|
configReturn.port = config.port;
|
||||||
@@ -95,7 +94,7 @@
|
|||||||
|
|
||||||
// Spawn electron application
|
// Spawn electron application
|
||||||
const electron = require("electron");
|
const electron = require("electron");
|
||||||
const child = require("child_process").spawn(electron, ["js/electron.js"], options);
|
const child = require("node:child_process").spawn(electron, ["js/electron.js"], options);
|
||||||
|
|
||||||
// Pipe all child process output to current stdout
|
// Pipe all child process output to current stdout
|
||||||
child.stdout.on("data", function (buf) {
|
child.stdout.on("data", function (buf) {
|
||||||
@@ -123,4 +122,4 @@
|
|||||||
} else {
|
} else {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
})();
|
}());
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
/* MagicMirror² Config Sample
|
/* Config Sample
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*
|
*
|
||||||
* For more information on how you can configure this file
|
* For more information on how you can configure this file
|
||||||
* see https://docs.magicmirror.builders/configuration/introduction.html
|
* see https://docs.magicmirror.builders/configuration/introduction.html
|
||||||
@@ -18,17 +15,17 @@ let config = {
|
|||||||
// - "0.0.0.0", "::" to listen on any interface
|
// - "0.0.0.0", "::" to listen on any interface
|
||||||
// Default, when address config is left out or empty, is "localhost"
|
// Default, when address config is left out or empty, is "localhost"
|
||||||
port: 8080,
|
port: 8080,
|
||||||
basePath: "/", // The URL path where MagicMirror² is hosted. If you are using a Reverse proxy
|
basePath: "/", // The URL path where MagicMirror² is hosted. If you are using a Reverse proxy
|
||||||
// you must set the sub path here. basePath must end with a /
|
// you must set the sub path here. basePath must end with a /
|
||||||
ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], // Set [] to allow all IP addresses
|
ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], // Set [] to allow all IP addresses
|
||||||
// or add a specific IPv4 of 192.168.1.5 :
|
// or add a specific IPv4 of 192.168.1.5 :
|
||||||
// ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.1.5"],
|
// ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.1.5"],
|
||||||
// or IPv4 range of 192.168.3.0 --> 192.168.3.15 use CIDR format :
|
// or IPv4 range of 192.168.3.0 --> 192.168.3.15 use CIDR format :
|
||||||
// ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.3.0/28"],
|
// ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.3.0/28"],
|
||||||
|
|
||||||
useHttps: false, // Support HTTPS or not, default "false" will use HTTP
|
useHttps: false, // Support HTTPS or not, default "false" will use HTTP
|
||||||
httpsPrivateKey: "", // HTTPS private key path, only require when useHttps is true
|
httpsPrivateKey: "", // HTTPS private key path, only require when useHttps is true
|
||||||
httpsCertificate: "", // HTTPS Certificate path, only require when useHttps is true
|
httpsCertificate: "", // HTTPS Certificate path, only require when useHttps is true
|
||||||
|
|
||||||
language: "en",
|
language: "en",
|
||||||
locale: "en-US",
|
locale: "en-US",
|
||||||
@@ -55,8 +52,9 @@ let config = {
|
|||||||
config: {
|
config: {
|
||||||
calendars: [
|
calendars: [
|
||||||
{
|
{
|
||||||
|
fetchInterval: 7 * 24 * 60 * 60 * 1000,
|
||||||
symbol: "calendar-check",
|
symbol: "calendar-check",
|
||||||
url: "webcal://www.calendarlabs.com/ical-calendar/ics/76/US_Holidays.ics"
|
url: "https://ics.calendarlabs.com/76/mm3137/US_Holidays.ics"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -108,4 +106,4 @@ let config = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||||
if (typeof module !== "undefined") {module.exports = config;}
|
if (typeof module !== "undefined") { module.exports = config; }
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
/* MagicMirror² Custom CSS Sample
|
/* Custom CSS Sample
|
||||||
*
|
*
|
||||||
* Change color and fonts here.
|
* Change color and fonts here.
|
||||||
*
|
*
|
||||||
* Beware that properties cannot be unitless, so for example write '--gap-body: 0px;' instead of just '--gap-body: 0;'
|
* Beware that properties cannot be unitless, so for example write '--gap-body: 0px;' instead of just '--gap-body: 0;'
|
||||||
*
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Uncomment and adjust accordingly if you want to import another font from the google-fonts-api: */
|
/* Uncomment and adjust accordingly if you want to import another font from the google-fonts-api: */
|
||||||
@@ -18,7 +16,7 @@
|
|||||||
|
|
||||||
--font-primary: "Roboto Condensed";
|
--font-primary: "Roboto Condensed";
|
||||||
--font-secondary: "Roboto";
|
--font-secondary: "Roboto";
|
||||||
|
|
||||||
--font-size: 20px;
|
--font-size: 20px;
|
||||||
--font-size-small: 0.75rem;
|
--font-size-small: 0.75rem;
|
||||||
|
|
||||||
@@ -26,6 +24,6 @@
|
|||||||
--gap-body-right: 60px;
|
--gap-body-right: 60px;
|
||||||
--gap-body-bottom: 60px;
|
--gap-body-bottom: 60px;
|
||||||
--gap-body-left: 60px;
|
--gap-body-left: 60px;
|
||||||
|
|
||||||
--gap-modules: 30px;
|
--gap-modules: 30px;
|
||||||
}
|
}
|
||||||
|
|||||||
32
fonts/package-lock.json
generated
32
fonts/package-lock.json
generated
@@ -1,37 +1,27 @@
|
|||||||
{
|
{
|
||||||
"name": "magicmirror-fonts",
|
"name": "magicmirror-fonts",
|
||||||
"lockfileVersion": 2,
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "magicmirror-fonts",
|
"name": "magicmirror-fonts",
|
||||||
|
"version": "1.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fontsource/roboto": "^4.5.8",
|
"@fontsource/roboto": "^5.0.12",
|
||||||
"@fontsource/roboto-condensed": "^4.5.9"
|
"@fontsource/roboto-condensed": "^5.0.15"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@fontsource/roboto": {
|
"node_modules/@fontsource/roboto": {
|
||||||
"version": "4.5.8",
|
"version": "5.0.12",
|
||||||
"resolved": "https://registry.npmjs.org/@fontsource/roboto/-/roboto-4.5.8.tgz",
|
"resolved": "https://registry.npmjs.org/@fontsource/roboto/-/roboto-5.0.12.tgz",
|
||||||
"integrity": "sha512-CnD7zLItIzt86q4Sj3kZUiLcBk1dSk81qcqgMGaZe7SQ1P8hFNxhMl5AZthK1zrDM5m74VVhaOpuMGIL4gagaA=="
|
"integrity": "sha512-x0o17jvgoSSbS9OZnUX2+xJmVRvVCfeaYJjkS7w62iN7CuJWtMf5vJj8LqgC7ibqIkitOHVW+XssRjgrcHn62g=="
|
||||||
},
|
},
|
||||||
"node_modules/@fontsource/roboto-condensed": {
|
"node_modules/@fontsource/roboto-condensed": {
|
||||||
"version": "4.5.9",
|
"version": "5.0.15",
|
||||||
"resolved": "https://registry.npmjs.org/@fontsource/roboto-condensed/-/roboto-condensed-4.5.9.tgz",
|
"resolved": "https://registry.npmjs.org/@fontsource/roboto-condensed/-/roboto-condensed-5.0.15.tgz",
|
||||||
"integrity": "sha512-ql4sQq+h8puBVildZ5ssjYf8DWDONYDe3PD3Bu/p1ZW9GnRETRNPPcCTs/q62HIl3QimwwkiKWynn6wZhQaetg=="
|
"integrity": "sha512-0AFvcI/8JQ5+FZE12hdaE1W/1ooJUzd5XP7jD74+SP+PArsswJ+6OV/oKTasgeQeZlvGrcD3chO6yr5K4JGwzA=="
|
||||||
}
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@fontsource/roboto": {
|
|
||||||
"version": "4.5.8",
|
|
||||||
"resolved": "https://registry.npmjs.org/@fontsource/roboto/-/roboto-4.5.8.tgz",
|
|
||||||
"integrity": "sha512-CnD7zLItIzt86q4Sj3kZUiLcBk1dSk81qcqgMGaZe7SQ1P8hFNxhMl5AZthK1zrDM5m74VVhaOpuMGIL4gagaA=="
|
|
||||||
},
|
|
||||||
"@fontsource/roboto-condensed": {
|
|
||||||
"version": "4.5.9",
|
|
||||||
"resolved": "https://registry.npmjs.org/@fontsource/roboto-condensed/-/roboto-condensed-4.5.9.tgz",
|
|
||||||
"integrity": "sha512-ql4sQq+h8puBVildZ5ssjYf8DWDONYDe3PD3Bu/p1ZW9GnRETRNPPcCTs/q62HIl3QimwwkiKWynn6wZhQaetg=="
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "magicmirror-fonts",
|
"name": "magicmirror-fonts",
|
||||||
"description": "Package for fonts use by MagicMirror² Core.",
|
"version": "1.0.0",
|
||||||
|
"description": "Package for fonts use by MagicMirror² core.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/MichMich/MagicMirror.git"
|
"url": "https://github.com/MagicMirrorOrg/MagicMirror"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/MichMich/MagicMirror/issues"
|
"url": "https://github.com/MagicMirrorOrg/MagicMirror/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fontsource/roboto": "^4.5.8",
|
"@fontsource/roboto": "^5.0.12",
|
||||||
"@fontsource/roboto-condensed": "^4.5.9"
|
"@fontsource/roboto-condensed": "^5.0.15"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
662
fonts/roboto.css
662
fonts/roboto.css
@@ -1,55 +1,671 @@
|
|||||||
|
/* roboto-cyrillic-ext-100-normal */
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: Roboto;
|
font-family: Roboto;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
font-weight: 100;
|
font-weight: 100;
|
||||||
src: local("Roboto Thin"), local("Roboto-Thin"), url("node_modules/@fontsource/roboto/files/roboto-all-100-normal.woff") format("woff");
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-ext-100-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-ext-100-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* roboto-cyrillic-100-normal */
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "Roboto Condensed";
|
font-family: Roboto;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 100;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-100-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-100-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-greek-ext-100-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 100;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-ext-100-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-ext-100-normal.woff") format("woff");
|
||||||
|
unicode-range: U+1F00-1FFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-greek-100-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 100;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-100-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-100-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0370-03FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-vietnamese-100-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 100;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-vietnamese-100-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-vietnamese-100-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-latin-ext-100-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 100;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-ext-100-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-ext-100-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0100-02AF, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-latin-100-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 100;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-100-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-100-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-cyrillic-ext-300-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
font-weight: 300;
|
font-weight: 300;
|
||||||
src: local("Roboto Condensed Light"), local("RobotoCondensed-Light"), url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-all-300-normal.woff") format("woff");
|
src:
|
||||||
}
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-ext-300-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-ext-300-normal.woff") format("woff");
|
||||||
@font-face {
|
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
|
||||||
font-family: "Roboto Condensed";
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 400;
|
|
||||||
src: local("Roboto Condensed"), local("RobotoCondensed-Regular"), url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-all-400-normal.woff") format("woff");
|
|
||||||
}
|
|
||||||
|
|
||||||
@font-face {
|
|
||||||
font-family: "Roboto Condensed";
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 700;
|
|
||||||
src: local("Roboto Condensed Bold"), local("RobotoCondensed-Bold"), url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-all-700-normal.woff") format("woff");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* roboto-cyrillic-300-normal */
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: Roboto;
|
font-family: Roboto;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: 400;
|
font-display: var(--fontsource-display, swap);
|
||||||
src: local("Roboto"), local("Roboto-Regular"), url("node_modules/@fontsource/roboto/files/roboto-all-400-normal.woff") format("woff");
|
font-weight: 300;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-300-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-300-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* roboto-greek-ext-300-normal */
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: Roboto;
|
font-family: Roboto;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 300;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-ext-300-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-ext-300-normal.woff") format("woff");
|
||||||
|
unicode-range: U+1F00-1FFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-greek-300-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 300;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-300-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-300-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0370-03FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-vietnamese-300-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 300;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-vietnamese-300-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-vietnamese-300-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-latin-ext-300-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 300;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-ext-300-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-ext-300-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0100-02AF, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-latin-300-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 300;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-300-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-300-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-cyrillic-ext-400-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 400;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-ext-400-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-ext-400-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-cyrillic-400-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 400;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-400-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-400-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-greek-ext-400-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 400;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-ext-400-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-ext-400-normal.woff") format("woff");
|
||||||
|
unicode-range: U+1F00-1FFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-greek-400-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 400;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-400-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-400-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0370-03FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-vietnamese-400-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 400;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-vietnamese-400-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-vietnamese-400-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-latin-ext-400-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 400;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-ext-400-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-ext-400-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0100-02AF, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-latin-400-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 400;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-400-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-400-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-cyrillic-ext-500-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
src: local("Roboto Medium"), local("Roboto-Medium"), url("node_modules/@fontsource/roboto/files/roboto-all-500-normal.woff") format("woff");
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-ext-500-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-ext-500-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* roboto-cyrillic-500-normal */
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: Roboto;
|
font-family: Roboto;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 500;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-500-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-500-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-greek-ext-500-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 500;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-ext-500-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-ext-500-normal.woff") format("woff");
|
||||||
|
unicode-range: U+1F00-1FFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-greek-500-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 500;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-500-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-500-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0370-03FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-vietnamese-500-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 500;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-vietnamese-500-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-vietnamese-500-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-latin-ext-500-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 500;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-ext-500-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-ext-500-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0100-02AF, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-latin-500-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 500;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-500-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-500-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-cyrillic-ext-700-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
src: local("Roboto Bold"), local("Roboto-Bold"), url("node_modules/@fontsource/roboto/files/roboto-all-700-normal.woff") format("woff");
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-ext-700-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-ext-700-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* roboto-cyrillic-700-normal */
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: Roboto;
|
font-family: Roboto;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: 300;
|
font-display: var(--fontsource-display, swap);
|
||||||
src: local("Roboto Light"), local("Roboto-Light"), url("node_modules/@fontsource/roboto/files/roboto-all-300-normal.woff") format("woff");
|
font-weight: 700;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-700-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-cyrillic-700-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-greek-ext-700-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 700;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-ext-700-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-ext-700-normal.woff") format("woff");
|
||||||
|
unicode-range: U+1F00-1FFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-greek-700-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 700;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-700-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-greek-700-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0370-03FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-vietnamese-700-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 700;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-vietnamese-700-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-vietnamese-700-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-latin-ext-700-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 700;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-ext-700-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-ext-700-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0100-02AF, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-latin-700-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: Roboto;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 700;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-700-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto/files/roboto-latin-700-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-cyrillic-ext-300-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 300;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-cyrillic-ext-300-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-cyrillic-ext-300-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-cyrillic-300-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 300;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-cyrillic-300-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-cyrillic-300-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-greek-ext-300-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 300;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-greek-ext-300-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-greek-ext-300-normal.woff") format("woff");
|
||||||
|
unicode-range: U+1F00-1FFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-greek-300-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 300;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-greek-300-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-greek-300-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0370-03FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-vietnamese-300-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 300;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-vietnamese-300-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-vietnamese-300-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-latin-ext-300-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 300;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-latin-ext-300-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-latin-ext-300-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0100-02AF, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-latin-300-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 300;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-latin-300-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-latin-300-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-cyrillic-ext-400-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 400;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-cyrillic-ext-400-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-cyrillic-ext-400-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-cyrillic-400-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 400;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-cyrillic-400-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-cyrillic-400-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-greek-ext-400-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 400;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-greek-ext-400-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-greek-ext-400-normal.woff") format("woff");
|
||||||
|
unicode-range: U+1F00-1FFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-greek-400-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 400;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-greek-400-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-greek-400-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0370-03FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-vietnamese-400-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 400;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-vietnamese-400-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-vietnamese-400-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-latin-ext-400-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 400;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-latin-ext-400-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-latin-ext-400-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0100-02AF, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-latin-400-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 400;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-latin-400-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-latin-400-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-cyrillic-ext-700-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 700;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-cyrillic-ext-700-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-cyrillic-ext-700-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-cyrillic-700-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 700;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-cyrillic-700-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-cyrillic-700-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-greek-ext-700-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 700;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-greek-ext-700-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-greek-ext-700-normal.woff") format("woff");
|
||||||
|
unicode-range: U+1F00-1FFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-greek-700-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 700;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-greek-700-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-greek-700-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0370-03FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-vietnamese-700-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 700;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-vietnamese-700-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-vietnamese-700-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-latin-ext-700-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 700;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-latin-ext-700-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-latin-ext-700-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0100-02AF, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* roboto-condensed-latin-700-normal */
|
||||||
|
@font-face {
|
||||||
|
font-family: "Roboto Condensed";
|
||||||
|
font-style: normal;
|
||||||
|
font-display: var(--fontsource-display, swap);
|
||||||
|
font-weight: 700;
|
||||||
|
src:
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-latin-700-normal.woff2") format("woff2"),
|
||||||
|
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-latin-700-normal.woff") format("woff");
|
||||||
|
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>MagicMirror²</title>
|
<title>MagicMirror²</title>
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
<link rel="icon" href="data:;base64,iVBORw0KGgo=" />
|
<link rel="icon" href="data:;base64,iVBORw0KGgo=" />
|
||||||
<link rel="stylesheet" type="text/css" href="css/main.css" />
|
<link rel="stylesheet" type="text/css" href="css/main.css" />
|
||||||
<link rel="stylesheet" type="text/css" href="fonts/roboto.css" />
|
<link rel="stylesheet" type="text/css" href="fonts/roboto.css" />
|
||||||
|
<link rel="stylesheet" type="text/css" href="vendor/node_modules/animate.css/animate.min.css" />
|
||||||
<!-- custom.css is loaded by the loader.js to make sure it's loaded after the module css files. -->
|
<!-- custom.css is loaded by the loader.js to make sure it's loaded after the module css files. -->
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@@ -45,6 +46,7 @@
|
|||||||
<script type="text/javascript" src="#CONFIG_FILE#"></script>
|
<script type="text/javascript" src="#CONFIG_FILE#"></script>
|
||||||
<script type="text/javascript" src="vendor/vendor.js"></script>
|
<script type="text/javascript" src="vendor/vendor.js"></script>
|
||||||
<script type="text/javascript" src="modules/default/defaultmodules.js"></script>
|
<script type="text/javascript" src="modules/default/defaultmodules.js"></script>
|
||||||
|
<script type="text/javascript" src="modules/default/utils.js"></script>
|
||||||
<script type="text/javascript" src="js/logger.js"></script>
|
<script type="text/javascript" src="js/logger.js"></script>
|
||||||
<script type="text/javascript" src="translations/translations.js"></script>
|
<script type="text/javascript" src="translations/translations.js"></script>
|
||||||
<script type="text/javascript" src="js/translator.js"></script>
|
<script type="text/javascript" src="js/translator.js"></script>
|
||||||
@@ -52,6 +54,7 @@
|
|||||||
<script type="text/javascript" src="js/module.js"></script>
|
<script type="text/javascript" src="js/module.js"></script>
|
||||||
<script type="text/javascript" src="js/loader.js"></script>
|
<script type="text/javascript" src="js/loader.js"></script>
|
||||||
<script type="text/javascript" src="js/socketclient.js"></script>
|
<script type="text/javascript" src="js/socketclient.js"></script>
|
||||||
|
<script type="text/javascript" src="js/animateCSS.js"></script>
|
||||||
<script type="text/javascript" src="js/main.js"></script>
|
<script type="text/javascript" src="js/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -6,23 +6,24 @@ module.exports = async () => {
|
|||||||
projects: [
|
projects: [
|
||||||
{
|
{
|
||||||
displayName: "unit",
|
displayName: "unit",
|
||||||
|
globalSetup: "<rootDir>/tests/unit/helpers/global-setup.js",
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
logger: "<rootDir>/js/logger.js"
|
logger: "<rootDir>/js/logger.js"
|
||||||
},
|
},
|
||||||
testMatch: ["**/tests/unit/**/*.[jt]s?(x)"],
|
testMatch: ["**/tests/unit/**/*.[jt]s?(x)"],
|
||||||
testPathIgnorePatterns: ["<rootDir>/tests/unit/mocks"]
|
testPathIgnorePatterns: ["<rootDir>/tests/unit/mocks", "<rootDir>/tests/unit/helpers"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: "electron",
|
displayName: "electron",
|
||||||
testMatch: ["**/tests/electron/**/*.[jt]s?(x)"],
|
testMatch: ["**/tests/electron/**/*.[jt]s?(x)"],
|
||||||
testPathIgnorePatterns: ["<rootDir>/tests/electron/helpers/"]
|
testPathIgnorePatterns: ["<rootDir>/tests/electron/helpers"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: "e2e",
|
displayName: "e2e",
|
||||||
setupFilesAfterEnv: ["<rootDir>/tests/e2e/helpers/mock-console.js"],
|
setupFilesAfterEnv: ["<rootDir>/tests/e2e/helpers/mock-console.js"],
|
||||||
testMatch: ["**/tests/e2e/**/*.[jt]s?(x)"],
|
testMatch: ["**/tests/e2e/**/*.[jt]s?(x)"],
|
||||||
modulePaths: ["<rootDir>/js/"],
|
modulePaths: ["<rootDir>/js/"],
|
||||||
testPathIgnorePatterns: ["<rootDir>/tests/e2e/helpers/", "<rootDir>/tests/e2e/mocks"]
|
testPathIgnorePatterns: ["<rootDir>/tests/e2e/helpers", "<rootDir>/tests/e2e/mocks"]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
collectCoverageFrom: ["./clientonly/**/*.js", "./js/**/*.js", "./modules/default/**/*.js", "./serveronly/**/*.js"],
|
collectCoverageFrom: ["./clientonly/**/*.js", "./js/**/*.js", "./modules/default/**/*.js", "./serveronly/**/*.js"],
|
||||||
|
|||||||
157
js/animateCSS.js
Normal file
157
js/animateCSS.js
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
/* enumeration of animations in Array **/
|
||||||
|
const AnimateCSSIn = [
|
||||||
|
// Attention seekers
|
||||||
|
"bounce",
|
||||||
|
"flash",
|
||||||
|
"pulse",
|
||||||
|
"rubberBand",
|
||||||
|
"shakeX",
|
||||||
|
"shakeY",
|
||||||
|
"headShake",
|
||||||
|
"swing",
|
||||||
|
"tada",
|
||||||
|
"wobble",
|
||||||
|
"jello",
|
||||||
|
"heartBeat",
|
||||||
|
// Back entrances
|
||||||
|
"backInDown",
|
||||||
|
"backInLeft",
|
||||||
|
"backInRight",
|
||||||
|
"backInUp",
|
||||||
|
// Bouncing entrances
|
||||||
|
"bounceIn",
|
||||||
|
"bounceInDown",
|
||||||
|
"bounceInLeft",
|
||||||
|
"bounceInRight",
|
||||||
|
"bounceInUp",
|
||||||
|
// Fading entrances
|
||||||
|
"fadeIn",
|
||||||
|
"fadeInDown",
|
||||||
|
"fadeInDownBig",
|
||||||
|
"fadeInLeft",
|
||||||
|
"fadeInLeftBig",
|
||||||
|
"fadeInRight",
|
||||||
|
"fadeInRightBig",
|
||||||
|
"fadeInUp",
|
||||||
|
"fadeInUpBig",
|
||||||
|
"fadeInTopLeft",
|
||||||
|
"fadeInTopRight",
|
||||||
|
"fadeInBottomLeft",
|
||||||
|
"fadeInBottomRight",
|
||||||
|
// Flippers
|
||||||
|
"flip",
|
||||||
|
"flipInX",
|
||||||
|
"flipInY",
|
||||||
|
// Lightspeed
|
||||||
|
"lightSpeedInRight",
|
||||||
|
"lightSpeedInLeft",
|
||||||
|
// Rotating entrances
|
||||||
|
"rotateIn",
|
||||||
|
"rotateInDownLeft",
|
||||||
|
"rotateInDownRight",
|
||||||
|
"rotateInUpLeft",
|
||||||
|
"rotateInUpRight",
|
||||||
|
// Specials
|
||||||
|
"jackInTheBox",
|
||||||
|
"rollIn",
|
||||||
|
// Zooming entrances
|
||||||
|
"zoomIn",
|
||||||
|
"zoomInDown",
|
||||||
|
"zoomInLeft",
|
||||||
|
"zoomInRight",
|
||||||
|
"zoomInUp",
|
||||||
|
// Sliding entrances
|
||||||
|
"slideInDown",
|
||||||
|
"slideInLeft",
|
||||||
|
"slideInRight",
|
||||||
|
"slideInUp"
|
||||||
|
];
|
||||||
|
|
||||||
|
const AnimateCSSOut = [
|
||||||
|
// Back exits
|
||||||
|
"backOutDown",
|
||||||
|
"backOutLeft",
|
||||||
|
"backOutRight",
|
||||||
|
"backOutUp",
|
||||||
|
// Bouncing exits
|
||||||
|
"bounceOut",
|
||||||
|
"bounceOutDown",
|
||||||
|
"bounceOutLeft",
|
||||||
|
"bounceOutRight",
|
||||||
|
"bounceOutUp",
|
||||||
|
// Fading exits
|
||||||
|
"fadeOut",
|
||||||
|
"fadeOutDown",
|
||||||
|
"fadeOutDownBig",
|
||||||
|
"fadeOutLeft",
|
||||||
|
"fadeOutLeftBig",
|
||||||
|
"fadeOutRight",
|
||||||
|
"fadeOutRightBig",
|
||||||
|
"fadeOutUp",
|
||||||
|
"fadeOutUpBig",
|
||||||
|
"fadeOutTopLeft",
|
||||||
|
"fadeOutTopRight",
|
||||||
|
"fadeOutBottomRight",
|
||||||
|
"fadeOutBottomLeft",
|
||||||
|
// Flippers
|
||||||
|
"flipOutX",
|
||||||
|
"flipOutY",
|
||||||
|
// Lightspeed
|
||||||
|
"lightSpeedOutRight",
|
||||||
|
"lightSpeedOutLeft",
|
||||||
|
// Rotating exits
|
||||||
|
"rotateOut",
|
||||||
|
"rotateOutDownLeft",
|
||||||
|
"rotateOutDownRight",
|
||||||
|
"rotateOutUpLeft",
|
||||||
|
"rotateOutUpRight",
|
||||||
|
// Specials
|
||||||
|
"hinge",
|
||||||
|
"rollOut",
|
||||||
|
// Zooming exits
|
||||||
|
"zoomOut",
|
||||||
|
"zoomOutDown",
|
||||||
|
"zoomOutLeft",
|
||||||
|
"zoomOutRight",
|
||||||
|
"zoomOutUp",
|
||||||
|
// Sliding exits
|
||||||
|
"slideOutDown",
|
||||||
|
"slideOutLeft",
|
||||||
|
"slideOutRight",
|
||||||
|
"slideOutUp"
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an animation with Animate CSS
|
||||||
|
* @param {string} [element] div element to animate.
|
||||||
|
* @param {string} [animation] animation name.
|
||||||
|
* @param {number} [animationTime] animation duration.
|
||||||
|
*/
|
||||||
|
function addAnimateCSS (element, animation, animationTime) {
|
||||||
|
const animationName = `animate__${animation}`;
|
||||||
|
const node = document.getElementById(element);
|
||||||
|
if (!node) {
|
||||||
|
// don't execute animate: we don't find div
|
||||||
|
Log.warn("addAnimateCSS: node not found for", element);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
node.style.setProperty("--animate-duration", `${animationTime}s`);
|
||||||
|
node.classList.add("animate__animated", animationName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove an animation with Animate CSS
|
||||||
|
* @param {string} [element] div element to animate.
|
||||||
|
* @param {string} [animation] animation name.
|
||||||
|
*/
|
||||||
|
function removeAnimateCSS (element, animation) {
|
||||||
|
const animationName = `animate__${animation}`;
|
||||||
|
const node = document.getElementById(element);
|
||||||
|
if (!node) {
|
||||||
|
// don't execute animate: we don't find div
|
||||||
|
Log.warn("removeAnimateCSS: node not found for", element);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
node.classList.remove("animate__animated", animationName);
|
||||||
|
node.style.removeProperty("--animate-duration");
|
||||||
|
}
|
||||||
95
js/app.js
95
js/app.js
@@ -1,17 +1,11 @@
|
|||||||
/* MagicMirror²
|
|
||||||
* The Core App (Server)
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Alias modules mentioned in package.js under _moduleAliases.
|
// Alias modules mentioned in package.js under _moduleAliases.
|
||||||
require("module-alias/register");
|
require("module-alias/register");
|
||||||
|
|
||||||
const fs = require("fs");
|
const fs = require("node:fs");
|
||||||
const path = require("path");
|
const path = require("node:path");
|
||||||
const envsub = require("envsub");
|
const envsub = require("envsub");
|
||||||
const Log = require("logger");
|
const Log = require("logger");
|
||||||
|
|
||||||
const Server = require(`${__dirname}/server`);
|
const Server = require(`${__dirname}/server`);
|
||||||
const Utils = require(`${__dirname}/utils`);
|
const Utils = require(`${__dirname}/utils`);
|
||||||
const defaultModules = require(`${__dirname}/../modules/default/defaultmodules`);
|
const defaultModules = require(`${__dirname}/../modules/default/defaultmodules`);
|
||||||
@@ -20,15 +14,18 @@ const defaultModules = require(`${__dirname}/../modules/default/defaultmodules`)
|
|||||||
global.version = require(`${__dirname}/../package.json`).version;
|
global.version = require(`${__dirname}/../package.json`).version;
|
||||||
Log.log(`Starting MagicMirror: v${global.version}`);
|
Log.log(`Starting MagicMirror: v${global.version}`);
|
||||||
|
|
||||||
|
// Log system information.
|
||||||
|
Utils.logSystemInformation();
|
||||||
|
|
||||||
// global absolute root path
|
// global absolute root path
|
||||||
global.root_path = path.resolve(`${__dirname}/../`);
|
global.root_path = path.resolve(`${__dirname}/../`);
|
||||||
|
|
||||||
if (process.env.MM_CONFIG_FILE) {
|
if (process.env.MM_CONFIG_FILE) {
|
||||||
global.configuration_file = process.env.MM_CONFIG_FILE;
|
global.configuration_file = process.env.MM_CONFIG_FILE.replace(`${global.root_path}/`, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Hotfix Pull Request
|
// FIXME: Hotfix Pull Request
|
||||||
// https://github.com/MichMich/MagicMirror/pull/673
|
// https://github.com/MagicMirrorOrg/MagicMirror/pull/673
|
||||||
if (process.env.MM_PORT) {
|
if (process.env.MM_PORT) {
|
||||||
global.mmPort = process.env.MM_PORT;
|
global.mmPort = process.env.MM_PORT;
|
||||||
}
|
}
|
||||||
@@ -36,28 +33,29 @@ if (process.env.MM_PORT) {
|
|||||||
// The next part is here to prevent a major exception when there
|
// The next part is here to prevent a major exception when there
|
||||||
// is no internet connection. This could probable be solved better.
|
// is no internet connection. This could probable be solved better.
|
||||||
process.on("uncaughtException", function (err) {
|
process.on("uncaughtException", function (err) {
|
||||||
Log.error("Whoops! There was an uncaught exception...");
|
// ignore strange exceptions under aarch64 coming from systeminformation:
|
||||||
Log.error(err);
|
if (!err.stack.includes("node_modules/systeminformation")) {
|
||||||
Log.error("MagicMirror² will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?");
|
Log.error("Whoops! There was an uncaught exception...");
|
||||||
Log.error("If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues");
|
Log.error(err);
|
||||||
|
Log.error("MagicMirror² will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?");
|
||||||
|
Log.error("If you think this really is an issue, please open an issue on GitHub: https://github.com/MagicMirrorOrg/MagicMirror/issues");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The core app.
|
* The core app.
|
||||||
*
|
|
||||||
* @class
|
* @class
|
||||||
*/
|
*/
|
||||||
function App() {
|
function App () {
|
||||||
let nodeHelpers = [];
|
let nodeHelpers = [];
|
||||||
let httpServer;
|
let httpServer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the config file. Combines it with the defaults and returns the config
|
* Loads the config file. Combines it with the defaults and returns the config
|
||||||
*
|
|
||||||
* @async
|
* @async
|
||||||
* @returns {Promise<object>} the loaded config or the defaults if something goes wrong
|
* @returns {Promise<object>} the loaded config or the defaults if something goes wrong
|
||||||
*/
|
*/
|
||||||
async function loadConfig() {
|
async function loadConfig () {
|
||||||
Log.log("Loading config ...");
|
Log.log("Loading config ...");
|
||||||
const defaults = require(`${__dirname}/defaults`);
|
const defaults = require(`${__dirname}/defaults`);
|
||||||
|
|
||||||
@@ -71,14 +69,14 @@ function App() {
|
|||||||
fs.accessSync(templateFile, fs.F_OK);
|
fs.accessSync(templateFile, fs.F_OK);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
templateFile = null;
|
templateFile = null;
|
||||||
Log.debug("config template file not exists, no envsubst");
|
Log.log("config template file not exists, no envsubst");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (templateFile) {
|
if (templateFile) {
|
||||||
// save current config.js
|
// save current config.js
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(configFilename)) {
|
if (fs.existsSync(configFilename)) {
|
||||||
fs.copyFileSync(configFilename, `${configFilename}_${Date.now()}`);
|
fs.copyFileSync(configFilename, `${configFilename}-old`);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Log.warn(`Could not copy ${configFilename}: ${err.message}`);
|
Log.warn(`Could not copy ${configFilename}: ${err.message}`);
|
||||||
@@ -92,7 +90,7 @@ function App() {
|
|||||||
envFiles.push(configEnvFile);
|
envFiles.push(configEnvFile);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Log.debug(`${configEnvFile} does not exist. ${err.message}`);
|
Log.log(`${configEnvFile} does not exist. ${err.message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let options = {
|
let options = {
|
||||||
@@ -117,15 +115,18 @@ function App() {
|
|||||||
try {
|
try {
|
||||||
fs.accessSync(configFilename, fs.F_OK);
|
fs.accessSync(configFilename, fs.F_OK);
|
||||||
const c = require(configFilename);
|
const c = require(configFilename);
|
||||||
|
if (Object.keys(c).length === 0) {
|
||||||
|
Log.error("WARNING! Config file appears empty, maybe missing module.exports last line?");
|
||||||
|
}
|
||||||
checkDeprecatedOptions(c);
|
checkDeprecatedOptions(c);
|
||||||
return Object.assign(defaults, c);
|
return Object.assign(defaults, c);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.code === "ENOENT") {
|
if (e.code === "ENOENT") {
|
||||||
Log.error(Utils.colors.error("WARNING! Could not find config file. Please create one. Starting with default configuration."));
|
Log.error("WARNING! Could not find config file. Please create one. Starting with default configuration.");
|
||||||
} else if (e instanceof ReferenceError || e instanceof SyntaxError) {
|
} else if (e instanceof ReferenceError || e instanceof SyntaxError) {
|
||||||
Log.error(Utils.colors.error(`WARNING! Could not validate config file. Starting with default configuration. Please correct syntax errors at or above this line: ${e.stack}`));
|
Log.error(`WARNING! Could not validate config file. Starting with default configuration. Please correct syntax errors at or above this line: ${e.stack}`);
|
||||||
} else {
|
} else {
|
||||||
Log.error(Utils.colors.error(`WARNING! Could not load config file. Starting with default configuration. Error found: ${e}`));
|
Log.error(`WARNING! Could not load config file. Starting with default configuration. Error found: ${e}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,25 +136,23 @@ function App() {
|
|||||||
/**
|
/**
|
||||||
* Checks the config for deprecated options and throws a warning in the logs
|
* Checks the config for deprecated options and throws a warning in the logs
|
||||||
* if it encounters one option from the deprecated.js list
|
* if it encounters one option from the deprecated.js list
|
||||||
*
|
|
||||||
* @param {object} userConfig The user config
|
* @param {object} userConfig The user config
|
||||||
*/
|
*/
|
||||||
function checkDeprecatedOptions(userConfig) {
|
function checkDeprecatedOptions (userConfig) {
|
||||||
const deprecated = require(`${global.root_path}/js/deprecated`);
|
const deprecated = require(`${global.root_path}/js/deprecated`);
|
||||||
const deprecatedOptions = deprecated.configs;
|
const deprecatedOptions = deprecated.configs;
|
||||||
|
|
||||||
const usedDeprecated = deprecatedOptions.filter((option) => userConfig.hasOwnProperty(option));
|
const usedDeprecated = deprecatedOptions.filter((option) => userConfig.hasOwnProperty(option));
|
||||||
if (usedDeprecated.length > 0) {
|
if (usedDeprecated.length > 0) {
|
||||||
Log.warn(Utils.colors.warn(`WARNING! Your config is using deprecated options: ${usedDeprecated.join(", ")}. Check README and CHANGELOG for more up-to-date ways of getting the same functionality.`));
|
Log.warn(`WARNING! Your config is using deprecated options: ${usedDeprecated.join(", ")}. Check README and CHANGELOG for more up-to-date ways of getting the same functionality.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a specific module.
|
* Loads a specific module.
|
||||||
*
|
|
||||||
* @param {string} module The name of the module (including subpath).
|
* @param {string} module The name of the module (including subpath).
|
||||||
*/
|
*/
|
||||||
function loadModule(module) {
|
function loadModule (module) {
|
||||||
const elements = module.split("/");
|
const elements = module.split("/");
|
||||||
const moduleName = elements[elements.length - 1];
|
const moduleName = elements[elements.length - 1];
|
||||||
let moduleFolder = `${__dirname}/../modules/${module}`;
|
let moduleFolder = `${__dirname}/../modules/${module}`;
|
||||||
@@ -204,42 +203,27 @@ function App() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all modules.
|
* Loads all modules.
|
||||||
*
|
* @param {Module[]} modules All modules to be loaded
|
||||||
* @param {string[]} modules All modules to be loaded
|
* @returns {Promise} A promise that is resolved when all modules been loaded
|
||||||
*/
|
*/
|
||||||
async function loadModules(modules) {
|
async function loadModules (modules) {
|
||||||
return new Promise((resolve) => {
|
Log.log("Loading module helpers ...");
|
||||||
Log.log("Loading module helpers ...");
|
|
||||||
|
|
||||||
/**
|
for (let module of modules) {
|
||||||
*
|
await loadModule(module);
|
||||||
*/
|
}
|
||||||
function loadNextModule() {
|
|
||||||
if (modules.length > 0) {
|
|
||||||
const nextModule = modules[0];
|
|
||||||
loadModule(nextModule);
|
|
||||||
modules = modules.slice(1);
|
|
||||||
loadNextModule();
|
|
||||||
} else {
|
|
||||||
// All modules are loaded
|
|
||||||
Log.log("All module helpers loaded.");
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loadNextModule();
|
Log.log("All module helpers loaded.");
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare two semantic version numbers and return the difference.
|
* Compare two semantic version numbers and return the difference.
|
||||||
*
|
|
||||||
* @param {string} a Version number a.
|
* @param {string} a Version number a.
|
||||||
* @param {string} b Version number b.
|
* @param {string} b Version number b.
|
||||||
* @returns {number} A positive number if a is larger than b, a negative
|
* @returns {number} A positive number if a is larger than b, a negative
|
||||||
* number if a is smaller and 0 if they are the same
|
* number if a is smaller and 0 if they are the same
|
||||||
*/
|
*/
|
||||||
function cmpVersions(a, b) {
|
function cmpVersions (a, b) {
|
||||||
let i, diff;
|
let i, diff;
|
||||||
const regExStrip0 = /(\.0+)+$/;
|
const regExStrip0 = /(\.0+)+$/;
|
||||||
const segmentsA = a.replace(regExStrip0, "").split(".");
|
const segmentsA = a.replace(regExStrip0, "").split(".");
|
||||||
@@ -259,7 +243,6 @@ function App() {
|
|||||||
* Start the core app.
|
* Start the core app.
|
||||||
*
|
*
|
||||||
* It loads the config, then it loads all modules.
|
* It loads the config, then it loads all modules.
|
||||||
*
|
|
||||||
* @async
|
* @async
|
||||||
* @returns {Promise<object>} the config used
|
* @returns {Promise<object>} the config used
|
||||||
*/
|
*/
|
||||||
@@ -274,6 +257,7 @@ function App() {
|
|||||||
modules.push(module.module);
|
modules.push(module.module);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await loadModules(modules);
|
await loadModules(modules);
|
||||||
|
|
||||||
httpServer = new Server(config);
|
httpServer = new Server(config);
|
||||||
@@ -312,7 +296,6 @@ function App() {
|
|||||||
* exists.
|
* exists.
|
||||||
*
|
*
|
||||||
* Added to fix #1056
|
* Added to fix #1056
|
||||||
*
|
|
||||||
* @returns {Promise} A promise that is resolved when all node_helpers and
|
* @returns {Promise} A promise that is resolved when all node_helpers and
|
||||||
* the http server has been closed
|
* the http server has been closed
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,27 +1,19 @@
|
|||||||
/* MagicMirror²
|
const path = require("node:path");
|
||||||
*
|
const fs = require("node:fs");
|
||||||
* Check the configuration file for errors
|
const colors = require("ansis");
|
||||||
*
|
|
||||||
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
const path = require("path");
|
|
||||||
const fs = require("fs");
|
|
||||||
const { Linter } = require("eslint");
|
const { Linter } = require("eslint");
|
||||||
|
|
||||||
const linter = new Linter();
|
const linter = new Linter();
|
||||||
|
|
||||||
const rootPath = path.resolve(`${__dirname}/../`);
|
const rootPath = path.resolve(`${__dirname}/../`);
|
||||||
const Log = require(`${rootPath}/js/logger.js`);
|
const Log = require(`${rootPath}/js/logger.js`);
|
||||||
const Utils = require(`${rootPath}/js/utils.js`);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a string with path of configuration file.
|
* Returns a string with path of configuration file.
|
||||||
* Check if set by environment variable MM_CONFIG_FILE
|
* Check if set by environment variable MM_CONFIG_FILE
|
||||||
*
|
|
||||||
* @returns {string} path and filename of the config file
|
* @returns {string} path and filename of the config file
|
||||||
*/
|
*/
|
||||||
function getConfigFile() {
|
function getConfigFile () {
|
||||||
// FIXME: This function should be in core. Do you want refactor me ;) ?, be good!
|
// FIXME: This function should be in core. Do you want refactor me ;) ?, be good!
|
||||||
return path.resolve(process.env.MM_CONFIG_FILE || `${rootPath}/config/config.js`);
|
return path.resolve(process.env.MM_CONFIG_FILE || `${rootPath}/config/config.js`);
|
||||||
}
|
}
|
||||||
@@ -29,12 +21,12 @@ function getConfigFile() {
|
|||||||
/**
|
/**
|
||||||
* Checks the config file using eslint.
|
* Checks the config file using eslint.
|
||||||
*/
|
*/
|
||||||
function checkConfigFile() {
|
function checkConfigFile () {
|
||||||
const configFileName = getConfigFile();
|
const configFileName = getConfigFile();
|
||||||
|
|
||||||
// Check if file is present
|
// Check if file is present
|
||||||
if (fs.existsSync(configFileName) === false) {
|
if (fs.existsSync(configFileName) === false) {
|
||||||
Log.error(Utils.colors.error("File not found: "), configFileName);
|
Log.error(`File not found: ${configFileName}`);
|
||||||
throw new Error("No config file present!");
|
throw new Error("No config file present!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,12 +34,12 @@ function checkConfigFile() {
|
|||||||
try {
|
try {
|
||||||
fs.accessSync(configFileName, fs.F_OK);
|
fs.accessSync(configFileName, fs.F_OK);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Log.error(Utils.colors.error(e));
|
Log.error(e);
|
||||||
throw new Error("No permission to access config file!");
|
throw new Error("No permission to access config file!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate syntax of the configuration file.
|
// Validate syntax of the configuration file.
|
||||||
Log.info(Utils.colors.info("Checking file... "), configFileName);
|
Log.info("Checking file... ", configFileName);
|
||||||
|
|
||||||
// I'm not sure if all ever is utf-8
|
// I'm not sure if all ever is utf-8
|
||||||
const configFile = fs.readFileSync(configFileName, "utf-8");
|
const configFile = fs.readFileSync(configFileName, "utf-8");
|
||||||
@@ -60,9 +52,9 @@ function checkConfigFile() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (errors.length === 0) {
|
if (errors.length === 0) {
|
||||||
Log.info(Utils.colors.pass("Your configuration file doesn't contain syntax errors :)"));
|
Log.info(colors.green("Your configuration file doesn't contain syntax errors :)"));
|
||||||
} else {
|
} else {
|
||||||
Log.error(Utils.colors.error("Your configuration file contains syntax errors :("));
|
Log.error(colors.red("Your configuration file contains syntax errors :("));
|
||||||
|
|
||||||
for (const error of errors) {
|
for (const error of errors) {
|
||||||
Log.error(`Line ${error.line} column ${error.column}: ${error.message}`);
|
Log.error(`Line ${error.line} column ${error.column}: ${error.message}`);
|
||||||
|
|||||||
41
js/class.js
41
js/class.js
@@ -9,7 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
(function () {
|
(function () {
|
||||||
let initializing = false;
|
let initializing = false;
|
||||||
const fnTest = /xyz/.test(function () {
|
const fnTest = (/xyz/).test(function () {
|
||||||
xyz;
|
xyz;
|
||||||
})
|
})
|
||||||
? /\b_super\b/
|
? /\b_super\b/
|
||||||
@@ -36,31 +36,31 @@
|
|||||||
// Copy the properties over onto the new prototype
|
// Copy the properties over onto the new prototype
|
||||||
for (const name in prop) {
|
for (const name in prop) {
|
||||||
// Check if we're overwriting an existing function
|
// Check if we're overwriting an existing function
|
||||||
prototype[name] =
|
prototype[name]
|
||||||
typeof prop[name] === "function" && typeof _super[name] === "function" && fnTest.test(prop[name])
|
= typeof prop[name] === "function" && typeof _super[name] === "function" && fnTest.test(prop[name])
|
||||||
? (function (name, fn) {
|
? (function (name, fn) {
|
||||||
return function () {
|
return function () {
|
||||||
const tmp = this._super;
|
const tmp = this._super;
|
||||||
|
|
||||||
// Add a new ._super() method that is the same method
|
// Add a new ._super() method that is the same method
|
||||||
// but on the super-class
|
// but on the super-class
|
||||||
this._super = _super[name];
|
this._super = _super[name];
|
||||||
|
|
||||||
// The method only need to be bound temporarily, so we
|
// The method only need to be bound temporarily, so we
|
||||||
// remove it when we're done executing
|
// remove it when we're done executing
|
||||||
const ret = fn.apply(this, arguments);
|
const ret = fn.apply(this, arguments);
|
||||||
this._super = tmp;
|
this._super = tmp;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
})(name, prop[name])
|
}(name, prop[name]))
|
||||||
: prop[name];
|
: prop[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The dummy class constructor
|
* The dummy class constructor
|
||||||
*/
|
*/
|
||||||
function Class() {
|
function Class () {
|
||||||
// All construction is actually done in the init method
|
// All construction is actually done in the init method
|
||||||
if (!initializing && this.init) {
|
if (!initializing && this.init) {
|
||||||
this.init.apply(this, arguments);
|
this.init.apply(this, arguments);
|
||||||
@@ -78,19 +78,22 @@
|
|||||||
|
|
||||||
return Class;
|
return Class;
|
||||||
};
|
};
|
||||||
})();
|
}());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define the clone method for later use. Helper Method.
|
* Define the clone method for later use. Helper Method.
|
||||||
*
|
|
||||||
* @param {object} obj Object to be cloned
|
* @param {object} obj Object to be cloned
|
||||||
* @returns {object} the cloned object
|
* @returns {object} the cloned object
|
||||||
*/
|
*/
|
||||||
function cloneObject(obj) {
|
function cloneObject (obj) {
|
||||||
if (obj === null || typeof obj !== "object") {
|
if (obj === null || typeof obj !== "object") {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (obj.constructor.name === "RegExp") {
|
||||||
|
return new RegExp(obj);
|
||||||
|
}
|
||||||
|
|
||||||
const temp = obj.constructor(); // give temp the original obj's constructor
|
const temp = obj.constructor(); // give temp the original obj's constructor
|
||||||
for (const key in obj) {
|
for (const key in obj) {
|
||||||
temp[key] = cloneObject(obj[key]);
|
temp[key] = cloneObject(obj[key]);
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
/* global mmPort */
|
/* global mmPort */
|
||||||
|
|
||||||
/* MagicMirror²
|
|
||||||
* Config Defaults
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
const address = "localhost";
|
const address = "localhost";
|
||||||
let port = 8080;
|
let port = 8080;
|
||||||
if (typeof mmPort !== "undefined") {
|
if (typeof mmPort !== "undefined") {
|
||||||
@@ -26,9 +20,14 @@ const defaults = {
|
|||||||
zoom: 1,
|
zoom: 1,
|
||||||
customCss: "css/custom.css",
|
customCss: "css/custom.css",
|
||||||
// httpHeaders used by helmet, see https://helmetjs.github.io/. You can add other/more object values by overriding this in config.js,
|
// httpHeaders used by helmet, see https://helmetjs.github.io/. You can add other/more object values by overriding this in config.js,
|
||||||
// e.g. you need to add `frameguard: false` for embedding MagicMirror in another website, see https://github.com/MichMich/MagicMirror/issues/2847
|
// e.g. you need to add `frameguard: false` for embedding MagicMirror in another website, see https://github.com/MagicMirrorOrg/MagicMirror/issues/2847
|
||||||
httpHeaders: { contentSecurityPolicy: false, crossOriginOpenerPolicy: false, crossOriginEmbedderPolicy: false, crossOriginResourcePolicy: false, originAgentCluster: false },
|
httpHeaders: { contentSecurityPolicy: false, crossOriginOpenerPolicy: false, crossOriginEmbedderPolicy: false, crossOriginResourcePolicy: false, originAgentCluster: false },
|
||||||
|
|
||||||
|
// properties for checking if server is alive and has same startup-timestamp, the check is per default enabled
|
||||||
|
// (interval 30 seconds). If startup-timestamp has changed the client reloads the magicmirror webpage.
|
||||||
|
checkServerInterval: 30 * 1000,
|
||||||
|
reloadAfterServerRestart: false,
|
||||||
|
|
||||||
modules: [
|
modules: [
|
||||||
{
|
{
|
||||||
module: "updatenotification",
|
module: "updatenotification",
|
||||||
|
|||||||
@@ -1,11 +1,3 @@
|
|||||||
/* MagicMirror² Deprecated Config Options List
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*
|
|
||||||
* Olex S. original idea this deprecated option
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
configs: ["kioskmode"]
|
configs: ["kioskmode"]
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,9 +8,10 @@ const Log = require("./logger");
|
|||||||
let config = process.env.config ? JSON.parse(process.env.config) : {};
|
let config = process.env.config ? JSON.parse(process.env.config) : {};
|
||||||
// Module to control application life.
|
// Module to control application life.
|
||||||
const app = electron.app;
|
const app = electron.app;
|
||||||
// If ELECTRON_DISABLE_GPU is set electron is started with --disable-gpu flag.
|
// Per default electron is started with --disable-gpu flag, if you want the gpu enabled,
|
||||||
|
// you must set the env var ELECTRON_ENABLE_GPU=1 on startup.
|
||||||
// See https://www.electronjs.org/docs/latest/tutorial/offscreen-rendering for more info.
|
// See https://www.electronjs.org/docs/latest/tutorial/offscreen-rendering for more info.
|
||||||
if (process.env.ELECTRON_DISABLE_GPU !== undefined) {
|
if (process.env.ELECTRON_ENABLE_GPU !== "1") {
|
||||||
app.disableHardwareAcceleration();
|
app.disableHardwareAcceleration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,12 +25,22 @@ let mainWindow;
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function createWindow() {
|
function createWindow () {
|
||||||
|
// see https://www.electronjs.org/docs/latest/api/screen
|
||||||
|
// Create a window that fills the screen's available work area.
|
||||||
|
let electronSize = (800, 600);
|
||||||
|
try {
|
||||||
|
electronSize = electron.screen.getPrimaryDisplay().workAreaSize;
|
||||||
|
} catch {
|
||||||
|
Log.warn("Could not get display size, using defaults ...");
|
||||||
|
}
|
||||||
|
|
||||||
let electronSwitchesDefaults = ["autoplay-policy", "no-user-gesture-required"];
|
let electronSwitchesDefaults = ["autoplay-policy", "no-user-gesture-required"];
|
||||||
app.commandLine.appendSwitch(...new Set(electronSwitchesDefaults, config.electronSwitches));
|
app.commandLine.appendSwitch(...new Set(electronSwitchesDefaults, config.electronSwitches));
|
||||||
let electronOptionsDefaults = {
|
let electronOptionsDefaults = {
|
||||||
width: 800,
|
width: electronSize.width,
|
||||||
height: 600,
|
height: electronSize.height,
|
||||||
|
icon: "mm2.png",
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
darkTheme: true,
|
darkTheme: true,
|
||||||
@@ -50,6 +61,7 @@ function createWindow() {
|
|||||||
electronOptionsDefaults.frame = false;
|
electronOptionsDefaults.frame = false;
|
||||||
electronOptionsDefaults.transparent = true;
|
electronOptionsDefaults.transparent = true;
|
||||||
electronOptionsDefaults.hasShadow = false;
|
electronOptionsDefaults.hasShadow = false;
|
||||||
|
electronOptionsDefaults.fullscreen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const electronOptions = Object.assign({}, electronOptionsDefaults, config.electronOptions);
|
const electronOptions = Object.assign({}, electronOptionsDefaults, config.electronOptions);
|
||||||
@@ -67,8 +79,9 @@ function createWindow() {
|
|||||||
prefix = "http://";
|
prefix = "http://";
|
||||||
}
|
}
|
||||||
|
|
||||||
let address = (config.address === void 0) | (config.address === "") ? (config.address = "localhost") : config.address;
|
let address = (config.address === void 0) | (config.address === "") | (config.address === "0.0.0.0") ? (config.address = "localhost") : config.address;
|
||||||
mainWindow.loadURL(`${prefix}${address}:${config.port}`);
|
const port = process.env.MM_PORT || config.port;
|
||||||
|
mainWindow.loadURL(`${prefix}${address}:${port}`);
|
||||||
|
|
||||||
// Open the DevTools if run with "npm start dev"
|
// Open the DevTools if run with "npm start dev"
|
||||||
if (process.argv.includes("dev")) {
|
if (process.argv.includes("dev")) {
|
||||||
@@ -110,29 +123,21 @@ function createWindow() {
|
|||||||
mainWindow.webContents.session.webRequest.onHeadersReceived((details, callback) => {
|
mainWindow.webContents.session.webRequest.onHeadersReceived((details, callback) => {
|
||||||
let curHeaders = details.responseHeaders;
|
let curHeaders = details.responseHeaders;
|
||||||
if (config["ignoreXOriginHeader"] || false) {
|
if (config["ignoreXOriginHeader"] || false) {
|
||||||
curHeaders = Object.fromEntries(Object.entries(curHeaders).filter((header) => !/x-frame-options/i.test(header[0])));
|
curHeaders = Object.fromEntries(Object.entries(curHeaders).filter((header) => !(/x-frame-options/i).test(header[0])));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config["ignoreContentSecurityPolicy"] || false) {
|
if (config["ignoreContentSecurityPolicy"] || false) {
|
||||||
curHeaders = Object.fromEntries(Object.entries(curHeaders).filter((header) => !/content-security-policy/i.test(header[0])));
|
curHeaders = Object.fromEntries(Object.entries(curHeaders).filter((header) => !(/content-security-policy/i).test(header[0])));
|
||||||
}
|
}
|
||||||
|
|
||||||
callback({ responseHeaders: curHeaders });
|
callback({ responseHeaders: curHeaders });
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWindow.once("ready-to-show", () => {
|
mainWindow.once("ready-to-show", () => {
|
||||||
mainWindow.setFullScreen(true);
|
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method will be called when Electron has finished
|
|
||||||
// initialization and is ready to create browser windows.
|
|
||||||
app.on("ready", function () {
|
|
||||||
Log.log("Launching application.");
|
|
||||||
createWindow();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Quit when all windows are closed.
|
// Quit when all windows are closed.
|
||||||
app.on("window-all-closed", function () {
|
app.on("window-all-closed", function () {
|
||||||
if (process.env.JEST_WORKER_ID !== undefined) {
|
if (process.env.JEST_WORKER_ID !== undefined) {
|
||||||
@@ -175,8 +180,21 @@ app.on("certificate-error", (event, webContents, url, error, certificate, callba
|
|||||||
callback(true);
|
callback(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (process.env.clientonly) {
|
||||||
|
app.whenReady().then(() => {
|
||||||
|
Log.log("Launching client viewer application.");
|
||||||
|
createWindow();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Start the core application if server is run on localhost
|
// Start the core application if server is run on localhost
|
||||||
// This starts all node helpers and starts the webserver.
|
// This starts all node helpers and starts the webserver.
|
||||||
if (["localhost", "127.0.0.1", "::1", "::ffff:127.0.0.1", undefined].includes(config.address)) {
|
if (["localhost", "127.0.0.1", "::1", "::ffff:127.0.0.1", undefined].includes(config.address)) {
|
||||||
core.start().then((c) => (config = c));
|
core.start().then((c) => {
|
||||||
|
config = c;
|
||||||
|
app.whenReady().then(() => {
|
||||||
|
Log.log("Launching application.");
|
||||||
|
createWindow();
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
28
js/fetch.js
28
js/fetch.js
@@ -1,28 +0,0 @@
|
|||||||
/**
|
|
||||||
* Helper class to provide either third party fetch library or (if node >= 18)
|
|
||||||
* return internal node fetch implementation.
|
|
||||||
*
|
|
||||||
* Attention: After some discussion we always return the third party
|
|
||||||
* implementation until the node implementation is stable and more tested
|
|
||||||
*
|
|
||||||
* @see https://github.com/MichMich/MagicMirror/pull/2952
|
|
||||||
* @see https://github.com/MichMich/MagicMirror/issues/2649
|
|
||||||
* @param {string} url to be fetched
|
|
||||||
* @param {object} options object e.g. for headers
|
|
||||||
* @class
|
|
||||||
*/
|
|
||||||
async function fetch(url, options = {}) {
|
|
||||||
// const nodeVersion = process.version.match(/^v(\d+)\.*/)[1];
|
|
||||||
// if (nodeVersion >= 18) {
|
|
||||||
// // node version >= 18
|
|
||||||
// return global.fetch(url, options);
|
|
||||||
// } else {
|
|
||||||
// // node version < 18
|
|
||||||
// const nodefetch = require("node-fetch");
|
|
||||||
// return nodefetch(url, options);
|
|
||||||
// }
|
|
||||||
const nodefetch = require("node-fetch");
|
|
||||||
return nodefetch(url, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = fetch;
|
|
||||||
22
js/loader.js
22
js/loader.js
@@ -1,12 +1,7 @@
|
|||||||
/* global defaultModules, vendor */
|
/* global defaultModules, vendor */
|
||||||
|
|
||||||
/* MagicMirror²
|
|
||||||
* Module and File loaders.
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
const Loader = (function () {
|
const Loader = (function () {
|
||||||
|
|
||||||
/* Create helper variables */
|
/* Create helper variables */
|
||||||
|
|
||||||
const loadedModuleFiles = [];
|
const loadedModuleFiles = [];
|
||||||
@@ -52,7 +47,6 @@ const Loader = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve list of all modules.
|
* Retrieve list of all modules.
|
||||||
*
|
|
||||||
* @returns {object[]} module data as configured in config
|
* @returns {object[]} module data as configured in config
|
||||||
*/
|
*/
|
||||||
const getAllModules = function () {
|
const getAllModules = function () {
|
||||||
@@ -61,7 +55,6 @@ const Loader = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate array with module information including module paths.
|
* Generate array with module information including module paths.
|
||||||
*
|
|
||||||
* @returns {object[]} Module information.
|
* @returns {object[]} Module information.
|
||||||
*/
|
*/
|
||||||
const getModuleData = function () {
|
const getModuleData = function () {
|
||||||
@@ -90,6 +83,8 @@ const Loader = (function () {
|
|||||||
path: `${moduleFolder}/`,
|
path: `${moduleFolder}/`,
|
||||||
file: `${moduleName}.js`,
|
file: `${moduleName}.js`,
|
||||||
position: moduleData.position,
|
position: moduleData.position,
|
||||||
|
animateIn: moduleData.animateIn,
|
||||||
|
animateOut: moduleData.animateOut,
|
||||||
hiddenOnStartup: moduleData.hiddenOnStartup,
|
hiddenOnStartup: moduleData.hiddenOnStartup,
|
||||||
header: moduleData.header,
|
header: moduleData.header,
|
||||||
configDeepMerge: typeof moduleData.configDeepMerge === "boolean" ? moduleData.configDeepMerge : false,
|
configDeepMerge: typeof moduleData.configDeepMerge === "boolean" ? moduleData.configDeepMerge : false,
|
||||||
@@ -103,7 +98,6 @@ const Loader = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Load modules via ajax request and create module objects.
|
* Load modules via ajax request and create module objects.
|
||||||
*
|
|
||||||
* @param {object} module Information about the module we want to load.
|
* @param {object} module Information about the module we want to load.
|
||||||
* @returns {Promise<void>} resolved when module is loaded
|
* @returns {Promise<void>} resolved when module is loaded
|
||||||
*/
|
*/
|
||||||
@@ -131,7 +125,6 @@ const Loader = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Bootstrap modules by setting the module data and loading the scripts & styles.
|
* Bootstrap modules by setting the module data and loading the scripts & styles.
|
||||||
*
|
|
||||||
* @param {object} module Information about the module we want to load.
|
* @param {object} module Information about the module we want to load.
|
||||||
* @param {Module} mObj Modules instance.
|
* @param {Module} mObj Modules instance.
|
||||||
*/
|
*/
|
||||||
@@ -153,7 +146,6 @@ const Loader = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a script or stylesheet by adding it to the dom.
|
* Load a script or stylesheet by adding it to the dom.
|
||||||
*
|
|
||||||
* @param {string} fileName Path of the file we want to load.
|
* @param {string} fileName Path of the file we want to load.
|
||||||
* @returns {Promise} resolved when the file is loaded
|
* @returns {Promise} resolved when the file is loaded
|
||||||
*/
|
*/
|
||||||
@@ -199,10 +191,11 @@ const Loader = (function () {
|
|||||||
|
|
||||||
/* Public Methods */
|
/* Public Methods */
|
||||||
return {
|
return {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load all modules as defined in the config.
|
* Load all modules as defined in the config.
|
||||||
*/
|
*/
|
||||||
loadModules: async function () {
|
async loadModules () {
|
||||||
let moduleData = getModuleData();
|
let moduleData = getModuleData();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -229,12 +222,11 @@ const Loader = (function () {
|
|||||||
/**
|
/**
|
||||||
* Load a file (script or stylesheet).
|
* Load a file (script or stylesheet).
|
||||||
* Prevent double loading and search for files in the vendor folder.
|
* Prevent double loading and search for files in the vendor folder.
|
||||||
*
|
|
||||||
* @param {string} fileName Path of the file we want to load.
|
* @param {string} fileName Path of the file we want to load.
|
||||||
* @param {Module} module The module that calls the loadFile function.
|
* @param {Module} module The module that calls the loadFile function.
|
||||||
* @returns {Promise} resolved when the file is loaded
|
* @returns {Promise} resolved when the file is loaded
|
||||||
*/
|
*/
|
||||||
loadFileForModule: async function (fileName, module) {
|
async loadFileForModule (fileName, module) {
|
||||||
if (loadedFiles.indexOf(fileName.toLowerCase()) !== -1) {
|
if (loadedFiles.indexOf(fileName.toLowerCase()) !== -1) {
|
||||||
Log.log(`File already loaded: ${fileName}`);
|
Log.log(`File already loaded: ${fileName}`);
|
||||||
return;
|
return;
|
||||||
@@ -260,4 +252,4 @@ const Loader = (function () {
|
|||||||
return loadFile(module.file(fileName));
|
return loadFile(module.file(fileName));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
}());
|
||||||
|
|||||||
71
js/logger.js
71
js/logger.js
@@ -1,19 +1,40 @@
|
|||||||
/* MagicMirror²
|
// This logger is very simple, but needs to be extended.
|
||||||
* Log
|
|
||||||
*
|
|
||||||
* This logger is very simple, but needs to be extended.
|
|
||||||
* This system can eventually be used to push the log messages to an external target.
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
(function (root, factory) {
|
(function (root, factory) {
|
||||||
if (typeof exports === "object") {
|
if (typeof exports === "object") {
|
||||||
if (process.env.JEST_WORKER_ID === undefined) {
|
if (process.env.JEST_WORKER_ID === undefined) {
|
||||||
|
const colors = require("ansis");
|
||||||
|
|
||||||
// add timestamps in front of log messages
|
// add timestamps in front of log messages
|
||||||
require("console-stamp")(console, {
|
require("console-stamp")(console, {
|
||||||
pattern: "yyyy-mm-dd HH:MM:ss.l",
|
format: ":date(yyyy-mm-dd HH:MM:ss.l) :label(7) :msg",
|
||||||
include: ["debug", "log", "info", "warn", "error"]
|
tokens: {
|
||||||
|
label: (arg) => {
|
||||||
|
const { method, defaultTokens } = arg;
|
||||||
|
let label = defaultTokens.label(arg);
|
||||||
|
if (method === "error") {
|
||||||
|
label = colors.red(label);
|
||||||
|
} else if (method === "warn") {
|
||||||
|
label = colors.yellow(label);
|
||||||
|
} else if (method === "debug") {
|
||||||
|
label = colors.bgBlue(label);
|
||||||
|
} else if (method === "info") {
|
||||||
|
label = colors.blue(label);
|
||||||
|
}
|
||||||
|
return label;
|
||||||
|
},
|
||||||
|
msg: (arg) => {
|
||||||
|
const { method, defaultTokens } = arg;
|
||||||
|
let msg = defaultTokens.msg(arg);
|
||||||
|
if (method === "error") {
|
||||||
|
msg = colors.red(msg);
|
||||||
|
} else if (method === "warn") {
|
||||||
|
msg = colors.yellow(msg);
|
||||||
|
} else if (method === "info") {
|
||||||
|
msg = colors.blue(msg);
|
||||||
|
}
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Node, CommonJS-like
|
// Node, CommonJS-like
|
||||||
@@ -22,7 +43,7 @@
|
|||||||
// Browser globals (root is window)
|
// Browser globals (root is window)
|
||||||
root.Log = factory(root.config);
|
root.Log = factory(root.config);
|
||||||
}
|
}
|
||||||
})(this, function (config) {
|
}(this, function (config) {
|
||||||
let logLevel;
|
let logLevel;
|
||||||
let enableLog;
|
let enableLog;
|
||||||
if (typeof exports === "object") {
|
if (typeof exports === "object") {
|
||||||
@@ -50,7 +71,7 @@
|
|||||||
|
|
||||||
logLevel.setLogLevel = function (newLevel) {
|
logLevel.setLogLevel = function (newLevel) {
|
||||||
if (newLevel) {
|
if (newLevel) {
|
||||||
Object.keys(logLevel).forEach(function (key, index) {
|
Object.keys(logLevel).forEach(function (key) {
|
||||||
if (!newLevel.includes(key.toLocaleUpperCase())) {
|
if (!newLevel.includes(key.toLocaleUpperCase())) {
|
||||||
logLevel[key] = function () {};
|
logLevel[key] = function () {};
|
||||||
}
|
}
|
||||||
@@ -59,21 +80,21 @@
|
|||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
logLevel = {
|
logLevel = {
|
||||||
debug: function () {},
|
debug () {},
|
||||||
log: function () {},
|
log () {},
|
||||||
info: function () {},
|
info () {},
|
||||||
warn: function () {},
|
warn () {},
|
||||||
error: function () {},
|
error () {},
|
||||||
group: function () {},
|
group () {},
|
||||||
groupCollapsed: function () {},
|
groupCollapsed () {},
|
||||||
groupEnd: function () {},
|
groupEnd () {},
|
||||||
time: function () {},
|
time () {},
|
||||||
timeEnd: function () {},
|
timeEnd () {},
|
||||||
timeStamp: function () {}
|
timeStamp () {}
|
||||||
};
|
};
|
||||||
|
|
||||||
logLevel.setLogLevel = function () {};
|
logLevel.setLogLevel = function () {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return logLevel;
|
return logLevel;
|
||||||
});
|
}));
|
||||||
|
|||||||
267
js/main.js
267
js/main.js
@@ -1,11 +1,5 @@
|
|||||||
/* global Loader, defaults, Translator */
|
/* global Loader, defaults, Translator, addAnimateCSS, removeAnimateCSS, AnimateCSSIn, AnimateCSSOut */
|
||||||
|
|
||||||
/* MagicMirror²
|
|
||||||
* Main System
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
const MM = (function () {
|
const MM = (function () {
|
||||||
let modules = [];
|
let modules = [];
|
||||||
|
|
||||||
@@ -22,6 +16,10 @@ const MM = (function () {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let haveAnimateIn = null;
|
||||||
|
// check if have valid animateIn in module definition (module.data.animateIn)
|
||||||
|
if (module.data.animateIn && AnimateCSSIn.indexOf(module.data.animateIn) !== -1) haveAnimateIn = module.data.animateIn;
|
||||||
|
|
||||||
const wrapper = selectWrapper(module.data.position);
|
const wrapper = selectWrapper(module.data.position);
|
||||||
|
|
||||||
const dom = document.createElement("div");
|
const dom = document.createElement("div");
|
||||||
@@ -50,7 +48,12 @@ const MM = (function () {
|
|||||||
moduleContent.className = "module-content";
|
moduleContent.className = "module-content";
|
||||||
dom.appendChild(moduleContent);
|
dom.appendChild(moduleContent);
|
||||||
|
|
||||||
const domCreationPromise = updateDom(module, 0);
|
// create the domCreationPromise with AnimateCSS (with animateIn of module definition)
|
||||||
|
// or just display it
|
||||||
|
var domCreationPromise;
|
||||||
|
if (haveAnimateIn) domCreationPromise = updateDom(module, { options: { speed: 1000, animate: { in: haveAnimateIn } } }, true);
|
||||||
|
else domCreationPromise = updateDom(module, 0);
|
||||||
|
|
||||||
domCreationPromises.push(domCreationPromise);
|
domCreationPromises.push(domCreationPromise);
|
||||||
domCreationPromise
|
domCreationPromise
|
||||||
.then(function () {
|
.then(function () {
|
||||||
@@ -68,7 +71,6 @@ const MM = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Select the wrapper dom object for a specific position.
|
* Select the wrapper dom object for a specific position.
|
||||||
*
|
|
||||||
* @param {string} position The name of the position.
|
* @param {string} position The name of the position.
|
||||||
* @returns {HTMLElement | void} the wrapper element
|
* @returns {HTMLElement | void} the wrapper element
|
||||||
*/
|
*/
|
||||||
@@ -85,7 +87,6 @@ const MM = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a notification to all modules.
|
* Send a notification to all modules.
|
||||||
*
|
|
||||||
* @param {string} notification The identifier of the notification.
|
* @param {string} notification The identifier of the notification.
|
||||||
* @param {*} payload The payload of the notification.
|
* @param {*} payload The payload of the notification.
|
||||||
* @param {Module} sender The module that sent the notification.
|
* @param {Module} sender The module that sent the notification.
|
||||||
@@ -102,13 +103,31 @@ const MM = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the dom for a specific module.
|
* Update the dom for a specific module.
|
||||||
*
|
|
||||||
* @param {Module} module The module that needs an update.
|
* @param {Module} module The module that needs an update.
|
||||||
* @param {number} [speed] The (optional) number of microseconds for the animation.
|
* @param {object|number} [updateOptions] The (optional) number of microseconds for the animation or object with updateOptions (speed/animates)
|
||||||
|
* @param {boolean} [createAnimatedDom] for displaying only animateIn (used on first start of MagicMirror)
|
||||||
* @returns {Promise} Resolved when the dom is fully updated.
|
* @returns {Promise} Resolved when the dom is fully updated.
|
||||||
*/
|
*/
|
||||||
const updateDom = function (module, speed) {
|
const updateDom = function (module, updateOptions, createAnimatedDom = false) {
|
||||||
return new Promise(function (resolve) {
|
return new Promise(function (resolve) {
|
||||||
|
let speed = updateOptions;
|
||||||
|
let animateOut = null;
|
||||||
|
let animateIn = null;
|
||||||
|
if (typeof updateOptions === "object") {
|
||||||
|
if (typeof updateOptions.options === "object" && updateOptions.options.speed !== undefined) {
|
||||||
|
speed = updateOptions.options.speed;
|
||||||
|
Log.debug(`updateDom: ${module.identifier} Has speed in object: ${speed}`);
|
||||||
|
if (typeof updateOptions.options.animate === "object") {
|
||||||
|
animateOut = updateOptions.options.animate.out;
|
||||||
|
animateIn = updateOptions.options.animate.in;
|
||||||
|
Log.debug(`updateDom: ${module.identifier} Has animate in object: out->${animateOut}, in->${animateIn}`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.debug(`updateDom: ${module.identifier} Has no speed in object`);
|
||||||
|
speed = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const newHeader = module.getHeader();
|
const newHeader = module.getHeader();
|
||||||
let newContentPromise = module.getDom();
|
let newContentPromise = module.getDom();
|
||||||
|
|
||||||
@@ -119,7 +138,7 @@ const MM = (function () {
|
|||||||
|
|
||||||
newContentPromise
|
newContentPromise
|
||||||
.then(function (newContent) {
|
.then(function (newContent) {
|
||||||
const updatePromise = updateDomWithContent(module, speed, newHeader, newContent);
|
const updatePromise = updateDomWithContent(module, speed, newHeader, newContent, animateOut, animateIn, createAnimatedDom);
|
||||||
|
|
||||||
updatePromise.then(resolve).catch(Log.error);
|
updatePromise.then(resolve).catch(Log.error);
|
||||||
})
|
})
|
||||||
@@ -129,14 +148,16 @@ const MM = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the dom with the specified content
|
* Update the dom with the specified content
|
||||||
*
|
|
||||||
* @param {Module} module The module that needs an update.
|
* @param {Module} module The module that needs an update.
|
||||||
* @param {number} [speed] The (optional) number of microseconds for the animation.
|
* @param {number} [speed] The (optional) number of microseconds for the animation.
|
||||||
* @param {string} newHeader The new header that is generated.
|
* @param {string} newHeader The new header that is generated.
|
||||||
* @param {HTMLElement} newContent The new content that is generated.
|
* @param {HTMLElement} newContent The new content that is generated.
|
||||||
|
* @param {string} [animateOut] AnimateCss animation name before hidden
|
||||||
|
* @param {string} [animateIn] AnimateCss animation name on show
|
||||||
|
* @param {boolean} [createAnimatedDom] for displaying only animateIn (used on first start)
|
||||||
* @returns {Promise} Resolved when the module dom has been updated.
|
* @returns {Promise} Resolved when the module dom has been updated.
|
||||||
*/
|
*/
|
||||||
const updateDomWithContent = function (module, speed, newHeader, newContent) {
|
const updateDomWithContent = function (module, speed, newHeader, newContent, animateOut, animateIn, createAnimatedDom = false) {
|
||||||
return new Promise(function (resolve) {
|
return new Promise(function (resolve) {
|
||||||
if (module.hidden || !speed) {
|
if (module.hidden || !speed) {
|
||||||
updateModuleContent(module, newHeader, newContent);
|
updateModuleContent(module, newHeader, newContent);
|
||||||
@@ -155,19 +176,33 @@ const MM = (function () {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
hideModule(module, speed / 2, function () {
|
if (createAnimatedDom && animateIn !== null) {
|
||||||
|
Log.debug(`${module.identifier} createAnimatedDom (${animateIn})`);
|
||||||
updateModuleContent(module, newHeader, newContent);
|
updateModuleContent(module, newHeader, newContent);
|
||||||
if (!module.hidden) {
|
if (!module.hidden) {
|
||||||
showModule(module, speed / 2);
|
showModule(module, speed, null, { animate: animateIn });
|
||||||
}
|
}
|
||||||
resolve();
|
resolve();
|
||||||
});
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
hideModule(
|
||||||
|
module,
|
||||||
|
speed / 2,
|
||||||
|
function () {
|
||||||
|
updateModuleContent(module, newHeader, newContent);
|
||||||
|
if (!module.hidden) {
|
||||||
|
showModule(module, speed / 2, null, { animate: animateIn });
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
},
|
||||||
|
{ animate: animateOut }
|
||||||
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the content has changed.
|
* Check if the content has changed.
|
||||||
*
|
|
||||||
* @param {Module} module The module to check.
|
* @param {Module} module The module to check.
|
||||||
* @param {string} newHeader The new header that is generated.
|
* @param {string} newHeader The new header that is generated.
|
||||||
* @param {HTMLElement} newContent The new content that is generated.
|
* @param {HTMLElement} newContent The new content that is generated.
|
||||||
@@ -198,7 +233,6 @@ const MM = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the content of a module on screen.
|
* Update the content of a module on screen.
|
||||||
*
|
|
||||||
* @param {Module} module The module to check.
|
* @param {Module} module The module to check.
|
||||||
* @param {string} newHeader The new header that is generated.
|
* @param {string} newHeader The new header that is generated.
|
||||||
* @param {HTMLElement} newContent The new content that is generated.
|
* @param {HTMLElement} newContent The new content that is generated.
|
||||||
@@ -224,15 +258,12 @@ const MM = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Hide the module.
|
* Hide the module.
|
||||||
*
|
|
||||||
* @param {Module} module The module to hide.
|
* @param {Module} module The module to hide.
|
||||||
* @param {number} speed The speed of the hide animation.
|
* @param {number} speed The speed of the hide animation.
|
||||||
* @param {Function} callback Called when the animation is done.
|
* @param {Function} callback Called when the animation is done.
|
||||||
* @param {object} [options] Optional settings for the hide method.
|
* @param {object} [options] Optional settings for the hide method.
|
||||||
*/
|
*/
|
||||||
const hideModule = function (module, speed, callback, options) {
|
const hideModule = function (module, speed, callback, options = {}) {
|
||||||
options = options || {};
|
|
||||||
|
|
||||||
// set lockString if set in options.
|
// set lockString if set in options.
|
||||||
if (options.lockString) {
|
if (options.lockString) {
|
||||||
// Log.log("Has lockstring: " + options.lockString);
|
// Log.log("Has lockstring: " + options.lockString);
|
||||||
@@ -243,24 +274,65 @@ const MM = (function () {
|
|||||||
|
|
||||||
const moduleWrapper = document.getElementById(module.identifier);
|
const moduleWrapper = document.getElementById(module.identifier);
|
||||||
if (moduleWrapper !== null) {
|
if (moduleWrapper !== null) {
|
||||||
moduleWrapper.style.transition = `opacity ${speed / 1000}s`;
|
|
||||||
moduleWrapper.style.opacity = 0;
|
|
||||||
moduleWrapper.classList.add("hidden");
|
|
||||||
|
|
||||||
clearTimeout(module.showHideTimer);
|
clearTimeout(module.showHideTimer);
|
||||||
module.showHideTimer = setTimeout(function () {
|
// reset all animations if needed
|
||||||
// To not take up any space, we just make the position absolute.
|
if (module.hasAnimateOut) {
|
||||||
// since it's fade out anyway, we can see it lay above or
|
removeAnimateCSS(module.identifier, module.hasAnimateOut);
|
||||||
// below other modules. This works way better than adjusting
|
Log.debug(`${module.identifier} Force remove animateOut (in hide): ${module.hasAnimateOut}`);
|
||||||
// the .display property.
|
module.hasAnimateOut = false;
|
||||||
moduleWrapper.style.position = "fixed";
|
}
|
||||||
|
if (module.hasAnimateIn) {
|
||||||
|
removeAnimateCSS(module.identifier, module.hasAnimateIn);
|
||||||
|
Log.debug(`${module.identifier} Force remove animateIn (in hide): ${module.hasAnimateIn}`);
|
||||||
|
module.hasAnimateIn = false;
|
||||||
|
}
|
||||||
|
// haveAnimateName for verify if we are using AninateCSS library
|
||||||
|
// we check AnimateCSSOut Array for validate it
|
||||||
|
// and finaly return the animate name or `null` (for default MM² animation)
|
||||||
|
let haveAnimateName = null;
|
||||||
|
// check if have valid animateOut in module definition (module.data.animateOut)
|
||||||
|
if (module.data.animateOut && AnimateCSSOut.indexOf(module.data.animateOut) !== -1) haveAnimateName = module.data.animateOut;
|
||||||
|
// can't be override with options.animate
|
||||||
|
else if (options.animate && AnimateCSSOut.indexOf(options.animate) !== -1) haveAnimateName = options.animate;
|
||||||
|
|
||||||
updateWrapperStates();
|
if (haveAnimateName) {
|
||||||
|
// with AnimateCSS
|
||||||
|
Log.debug(`${module.identifier} Has animateOut: ${haveAnimateName}`);
|
||||||
|
module.hasAnimateOut = haveAnimateName;
|
||||||
|
addAnimateCSS(module.identifier, haveAnimateName, speed / 1000);
|
||||||
|
module.showHideTimer = setTimeout(function () {
|
||||||
|
removeAnimateCSS(module.identifier, haveAnimateName);
|
||||||
|
Log.debug(`${module.identifier} Remove animateOut: ${module.hasAnimateOut}`);
|
||||||
|
// AnimateCSS is now done
|
||||||
|
moduleWrapper.style.opacity = 0;
|
||||||
|
moduleWrapper.classList.add("hidden");
|
||||||
|
moduleWrapper.style.position = "fixed";
|
||||||
|
module.hasAnimateOut = false;
|
||||||
|
|
||||||
if (typeof callback === "function") {
|
updateWrapperStates();
|
||||||
callback();
|
if (typeof callback === "function") {
|
||||||
}
|
callback();
|
||||||
}, speed);
|
}
|
||||||
|
}, speed);
|
||||||
|
} else {
|
||||||
|
// default MM² Animate
|
||||||
|
moduleWrapper.style.transition = `opacity ${speed / 1000}s`;
|
||||||
|
moduleWrapper.style.opacity = 0;
|
||||||
|
moduleWrapper.classList.add("hidden");
|
||||||
|
module.showHideTimer = setTimeout(function () {
|
||||||
|
// To not take up any space, we just make the position absolute.
|
||||||
|
// since it's fade out anyway, we can see it lay above or
|
||||||
|
// below other modules. This works way better than adjusting
|
||||||
|
// the .display property.
|
||||||
|
moduleWrapper.style.position = "fixed";
|
||||||
|
|
||||||
|
updateWrapperStates();
|
||||||
|
|
||||||
|
if (typeof callback === "function") {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}, speed);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// invoke callback even if no content, issue 1308
|
// invoke callback even if no content, issue 1308
|
||||||
if (typeof callback === "function") {
|
if (typeof callback === "function") {
|
||||||
@@ -271,15 +343,12 @@ const MM = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the module.
|
* Show the module.
|
||||||
*
|
|
||||||
* @param {Module} module The module to show.
|
* @param {Module} module The module to show.
|
||||||
* @param {number} speed The speed of the show animation.
|
* @param {number} speed The speed of the show animation.
|
||||||
* @param {Function} callback Called when the animation is done.
|
* @param {Function} callback Called when the animation is done.
|
||||||
* @param {object} [options] Optional settings for the show method.
|
* @param {object} [options] Optional settings for the show method.
|
||||||
*/
|
*/
|
||||||
const showModule = function (module, speed, callback, options) {
|
const showModule = function (module, speed, callback, options = {}) {
|
||||||
options = options || {};
|
|
||||||
|
|
||||||
// remove lockString if set in options.
|
// remove lockString if set in options.
|
||||||
if (options.lockString) {
|
if (options.lockString) {
|
||||||
const index = module.lockStrings.indexOf(options.lockString);
|
const index = module.lockStrings.indexOf(options.lockString);
|
||||||
@@ -297,6 +366,17 @@ const MM = (function () {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// reset all animations if needed
|
||||||
|
if (module.hasAnimateOut) {
|
||||||
|
removeAnimateCSS(module.identifier, module.hasAnimateOut);
|
||||||
|
Log.debug(`${module.identifier} Force remove animateOut (in show): ${module.hasAnimateOut}`);
|
||||||
|
module.hasAnimateOut = false;
|
||||||
|
}
|
||||||
|
if (module.hasAnimateIn) {
|
||||||
|
removeAnimateCSS(module.identifier, module.hasAnimateIn);
|
||||||
|
Log.debug(`${module.identifier} Force remove animateIn (in show): ${module.hasAnimateIn}`);
|
||||||
|
module.hasAnimateIn = false;
|
||||||
|
}
|
||||||
|
|
||||||
module.hidden = false;
|
module.hidden = false;
|
||||||
|
|
||||||
@@ -308,7 +388,18 @@ const MM = (function () {
|
|||||||
|
|
||||||
const moduleWrapper = document.getElementById(module.identifier);
|
const moduleWrapper = document.getElementById(module.identifier);
|
||||||
if (moduleWrapper !== null) {
|
if (moduleWrapper !== null) {
|
||||||
moduleWrapper.style.transition = `opacity ${speed / 1000}s`;
|
clearTimeout(module.showHideTimer);
|
||||||
|
|
||||||
|
// haveAnimateName for verify if we are using AninateCSS library
|
||||||
|
// we check AnimateCSSIn Array for validate it
|
||||||
|
// and finaly return the animate name or `null` (for default MM² animation)
|
||||||
|
let haveAnimateName = null;
|
||||||
|
// check if have valid animateOut in module definition (module.data.animateIn)
|
||||||
|
if (module.data.animateIn && AnimateCSSIn.indexOf(module.data.animateIn) !== -1) haveAnimateName = module.data.animateIn;
|
||||||
|
// can't be override with options.animate
|
||||||
|
else if (options.animate && AnimateCSSIn.indexOf(options.animate) !== -1) haveAnimateName = options.animate;
|
||||||
|
|
||||||
|
if (!haveAnimateName) moduleWrapper.style.transition = `opacity ${speed / 1000}s`;
|
||||||
// Restore the position. See hideModule() for more info.
|
// Restore the position. See hideModule() for more info.
|
||||||
moduleWrapper.style.position = "static";
|
moduleWrapper.style.position = "static";
|
||||||
moduleWrapper.classList.remove("hidden");
|
moduleWrapper.classList.remove("hidden");
|
||||||
@@ -319,12 +410,27 @@ const MM = (function () {
|
|||||||
const dummy = moduleWrapper.parentElement.parentElement.offsetHeight;
|
const dummy = moduleWrapper.parentElement.parentElement.offsetHeight;
|
||||||
moduleWrapper.style.opacity = 1;
|
moduleWrapper.style.opacity = 1;
|
||||||
|
|
||||||
clearTimeout(module.showHideTimer);
|
if (haveAnimateName) {
|
||||||
module.showHideTimer = setTimeout(function () {
|
// with AnimateCSS
|
||||||
if (typeof callback === "function") {
|
Log.debug(`${module.identifier} Has animateIn: ${haveAnimateName}`);
|
||||||
callback();
|
module.hasAnimateIn = haveAnimateName;
|
||||||
}
|
addAnimateCSS(module.identifier, haveAnimateName, speed / 1000);
|
||||||
}, speed);
|
module.showHideTimer = setTimeout(function () {
|
||||||
|
removeAnimateCSS(module.identifier, haveAnimateName);
|
||||||
|
Log.debug(`${module.identifier} Remove animateIn: ${haveAnimateName}`);
|
||||||
|
module.hasAnimateIn = false;
|
||||||
|
if (typeof callback === "function") {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}, speed);
|
||||||
|
} else {
|
||||||
|
// default MM² Animate
|
||||||
|
module.showHideTimer = setTimeout(function () {
|
||||||
|
if (typeof callback === "function") {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}, speed);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// invoke callback
|
// invoke callback
|
||||||
if (typeof callback === "function") {
|
if (typeof callback === "function") {
|
||||||
@@ -367,7 +473,6 @@ const MM = (function () {
|
|||||||
*/
|
*/
|
||||||
const loadConfig = function () {
|
const loadConfig = function () {
|
||||||
// FIXME: Think about how to pass config around without breaking tests
|
// FIXME: Think about how to pass config around without breaking tests
|
||||||
/* eslint-disable */
|
|
||||||
if (typeof config === "undefined") {
|
if (typeof config === "undefined") {
|
||||||
config = defaults;
|
config = defaults;
|
||||||
Log.error("Config file is missing! Please create a config file.");
|
Log.error("Config file is missing! Please create a config file.");
|
||||||
@@ -375,18 +480,16 @@ const MM = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
config = Object.assign({}, defaults, config);
|
config = Object.assign({}, defaults, config);
|
||||||
/* eslint-enable */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds special selectors on a collection of modules.
|
* Adds special selectors on a collection of modules.
|
||||||
*
|
|
||||||
* @param {Module[]} modules Array of modules.
|
* @param {Module[]} modules Array of modules.
|
||||||
*/
|
*/
|
||||||
const setSelectionMethodsForModules = function (modules) {
|
const setSelectionMethodsForModules = function (modules) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter modules with the specified classes.
|
* Filter modules with the specified classes.
|
||||||
*
|
|
||||||
* @param {string|string[]} className one or multiple classnames (array or space divided).
|
* @param {string|string[]} className one or multiple classnames (array or space divided).
|
||||||
* @returns {Module[]} Filtered collection of modules.
|
* @returns {Module[]} Filtered collection of modules.
|
||||||
*/
|
*/
|
||||||
@@ -396,7 +499,6 @@ const MM = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter modules without the specified classes.
|
* Filter modules without the specified classes.
|
||||||
*
|
|
||||||
* @param {string|string[]} className one or multiple classnames (array or space divided).
|
* @param {string|string[]} className one or multiple classnames (array or space divided).
|
||||||
* @returns {Module[]} Filtered collection of modules.
|
* @returns {Module[]} Filtered collection of modules.
|
||||||
*/
|
*/
|
||||||
@@ -406,7 +508,6 @@ const MM = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters a collection of modules based on classname(s).
|
* Filters a collection of modules based on classname(s).
|
||||||
*
|
|
||||||
* @param {string|string[]} className one or multiple classnames (array or space divided).
|
* @param {string|string[]} className one or multiple classnames (array or space divided).
|
||||||
* @param {boolean} include if the filter should include or exclude the modules with the specific classes.
|
* @param {boolean} include if the filter should include or exclude the modules with the specific classes.
|
||||||
* @returns {Module[]} Filtered collection of modules.
|
* @returns {Module[]} Filtered collection of modules.
|
||||||
@@ -435,7 +536,6 @@ const MM = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a module instance from the collection.
|
* Removes a module instance from the collection.
|
||||||
*
|
|
||||||
* @param {object} module The module instance to remove from the collection.
|
* @param {object} module The module instance to remove from the collection.
|
||||||
* @returns {Module[]} Filtered collection of modules.
|
* @returns {Module[]} Filtered collection of modules.
|
||||||
*/
|
*/
|
||||||
@@ -450,7 +550,6 @@ const MM = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Walks thru a collection of modules and executes the callback with the module as an argument.
|
* Walks thru a collection of modules and executes the callback with the module as an argument.
|
||||||
*
|
|
||||||
* @param {Function} callback The function to execute with the module as an argument.
|
* @param {Function} callback The function to execute with the module as an argument.
|
||||||
*/
|
*/
|
||||||
const enumerate = function (callback) {
|
const enumerate = function (callback) {
|
||||||
@@ -474,12 +573,13 @@ const MM = (function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
||||||
/* Public Methods */
|
/* Public Methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main init method.
|
* Main init method.
|
||||||
*/
|
*/
|
||||||
init: async function () {
|
async init () {
|
||||||
Log.info("Initializing MagicMirror².");
|
Log.info("Initializing MagicMirror².");
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
@@ -491,27 +591,46 @@ const MM = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets called when all modules are started.
|
* Gets called when all modules are started.
|
||||||
*
|
|
||||||
* @param {Module[]} moduleObjects All module instances.
|
* @param {Module[]} moduleObjects All module instances.
|
||||||
*/
|
*/
|
||||||
modulesStarted: function (moduleObjects) {
|
modulesStarted (moduleObjects) {
|
||||||
modules = [];
|
modules = [];
|
||||||
|
let startUp = "";
|
||||||
|
|
||||||
moduleObjects.forEach((module) => modules.push(module));
|
moduleObjects.forEach((module) => modules.push(module));
|
||||||
|
|
||||||
Log.info("All modules started!");
|
Log.info("All modules started!");
|
||||||
sendNotification("ALL_MODULES_STARTED");
|
sendNotification("ALL_MODULES_STARTED");
|
||||||
|
|
||||||
createDomObjects();
|
createDomObjects();
|
||||||
|
|
||||||
|
if (config.reloadAfterServerRestart) {
|
||||||
|
setInterval(async () => {
|
||||||
|
// if server startup time has changed (which means server was restarted)
|
||||||
|
// the client reloads the mm page
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${location.protocol}//${location.host}/startup`);
|
||||||
|
const curr = await res.text();
|
||||||
|
if (startUp === "") startUp = curr;
|
||||||
|
if (startUp !== curr) {
|
||||||
|
startUp = "";
|
||||||
|
window.location.reload(true);
|
||||||
|
console.warn("Refreshing Website because server was restarted");
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
Log.error(`MagicMirror not reachable: ${err}`);
|
||||||
|
}
|
||||||
|
}, config.checkServerInterval);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a notification to all modules.
|
* Send a notification to all modules.
|
||||||
*
|
|
||||||
* @param {string} notification The identifier of the notification.
|
* @param {string} notification The identifier of the notification.
|
||||||
* @param {*} payload The payload of the notification.
|
* @param {*} payload The payload of the notification.
|
||||||
* @param {Module} sender The module that sent the notification.
|
* @param {Module} sender The module that sent the notification.
|
||||||
*/
|
*/
|
||||||
sendNotification: function (notification, payload, sender) {
|
sendNotification (notification, payload, sender) {
|
||||||
if (arguments.length < 3) {
|
if (arguments.length < 3) {
|
||||||
Log.error("sendNotification: Missing arguments.");
|
Log.error("sendNotification: Missing arguments.");
|
||||||
return;
|
return;
|
||||||
@@ -533,11 +652,10 @@ const MM = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the dom for a specific module.
|
* Update the dom for a specific module.
|
||||||
*
|
|
||||||
* @param {Module} module The module that needs an update.
|
* @param {Module} module The module that needs an update.
|
||||||
* @param {number} [speed] The number of microseconds for the animation.
|
* @param {object|number} [updateOptions] The (optional) number of microseconds for the animation or object with updateOptions (speed/animates)
|
||||||
*/
|
*/
|
||||||
updateDom: function (module, speed) {
|
updateDom (module, updateOptions) {
|
||||||
if (!(module instanceof Module)) {
|
if (!(module instanceof Module)) {
|
||||||
Log.error("updateDom: Sender should be a module.");
|
Log.error("updateDom: Sender should be a module.");
|
||||||
return;
|
return;
|
||||||
@@ -549,46 +667,43 @@ const MM = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Further implementation is done in the private method.
|
// Further implementation is done in the private method.
|
||||||
updateDom(module, speed);
|
updateDom(module, updateOptions);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a collection of all modules currently active.
|
* Returns a collection of all modules currently active.
|
||||||
*
|
|
||||||
* @returns {Module[]} A collection of all modules currently active.
|
* @returns {Module[]} A collection of all modules currently active.
|
||||||
*/
|
*/
|
||||||
getModules: function () {
|
getModules () {
|
||||||
setSelectionMethodsForModules(modules);
|
setSelectionMethodsForModules(modules);
|
||||||
return modules;
|
return modules;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hide the module.
|
* Hide the module.
|
||||||
*
|
|
||||||
* @param {Module} module The module to hide.
|
* @param {Module} module The module to hide.
|
||||||
* @param {number} speed The speed of the hide animation.
|
* @param {number} speed The speed of the hide animation.
|
||||||
* @param {Function} callback Called when the animation is done.
|
* @param {Function} callback Called when the animation is done.
|
||||||
* @param {object} [options] Optional settings for the hide method.
|
* @param {object} [options] Optional settings for the hide method.
|
||||||
*/
|
*/
|
||||||
hideModule: function (module, speed, callback, options) {
|
hideModule (module, speed, callback, options) {
|
||||||
module.hidden = true;
|
module.hidden = true;
|
||||||
hideModule(module, speed, callback, options);
|
hideModule(module, speed, callback, options);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the module.
|
* Show the module.
|
||||||
*
|
|
||||||
* @param {Module} module The module to show.
|
* @param {Module} module The module to show.
|
||||||
* @param {number} speed The speed of the show animation.
|
* @param {number} speed The speed of the show animation.
|
||||||
* @param {Function} callback Called when the animation is done.
|
* @param {Function} callback Called when the animation is done.
|
||||||
* @param {object} [options] Optional settings for the show method.
|
* @param {object} [options] Optional settings for the show method.
|
||||||
*/
|
*/
|
||||||
showModule: function (module, speed, callback, options) {
|
showModule (module, speed, callback, options) {
|
||||||
// do not change module.hidden yet, only if we really show it later
|
// do not change module.hidden yet, only if we really show it later
|
||||||
showModule(module, speed, callback, options);
|
showModule(module, speed, callback, options);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
}());
|
||||||
|
|
||||||
// Add polyfill for Object.assign.
|
// Add polyfill for Object.assign.
|
||||||
if (typeof Object.assign !== "function") {
|
if (typeof Object.assign !== "function") {
|
||||||
@@ -611,7 +726,7 @@ if (typeof Object.assign !== "function") {
|
|||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
};
|
};
|
||||||
})();
|
}());
|
||||||
}
|
}
|
||||||
|
|
||||||
MM.init();
|
MM.init();
|
||||||
|
|||||||
137
js/module.js
137
js/module.js
@@ -1,13 +1,10 @@
|
|||||||
/* global Class, cloneObject, Loader, MMSocket, nunjucks, Translator */
|
/* global Class, cloneObject, Loader, MMSocket, nunjucks, Translator */
|
||||||
|
|
||||||
/* MagicMirror²
|
/* Module Blueprint.
|
||||||
* Module Blueprint.
|
|
||||||
* @typedef {Object} Module
|
* @typedef {Object} Module
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
*/
|
||||||
const Module = Class.extend({
|
const Module = Class.extend({
|
||||||
|
|
||||||
/*********************************************************
|
/*********************************************************
|
||||||
* All methods (and properties) below can be subclassed. *
|
* All methods (and properties) below can be subclassed. *
|
||||||
*********************************************************/
|
*********************************************************/
|
||||||
@@ -33,32 +30,30 @@ const Module = Class.extend({
|
|||||||
/**
|
/**
|
||||||
* Called when the module is instantiated.
|
* Called when the module is instantiated.
|
||||||
*/
|
*/
|
||||||
init: function () {
|
init () {
|
||||||
//Log.log(this.defaults);
|
//Log.log(this.defaults);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the module is started.
|
* Called when the module is started.
|
||||||
*/
|
*/
|
||||||
start: async function () {
|
async start () {
|
||||||
Log.info(`Starting module: ${this.name}`);
|
Log.info(`Starting module: ${this.name}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of scripts the module requires to be loaded.
|
* Returns a list of scripts the module requires to be loaded.
|
||||||
*
|
|
||||||
* @returns {string[]} An array with filenames.
|
* @returns {string[]} An array with filenames.
|
||||||
*/
|
*/
|
||||||
getScripts: function () {
|
getScripts () {
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of stylesheets the module requires to be loaded.
|
* Returns a list of stylesheets the module requires to be loaded.
|
||||||
*
|
|
||||||
* @returns {string[]} An array with filenames.
|
* @returns {string[]} An array with filenames.
|
||||||
*/
|
*/
|
||||||
getStyles: function () {
|
getStyles () {
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -66,10 +61,9 @@ const Module = Class.extend({
|
|||||||
* Returns a map of translation files the module requires to be loaded.
|
* Returns a map of translation files the module requires to be loaded.
|
||||||
*
|
*
|
||||||
* return Map<String, String> -
|
* return Map<String, String> -
|
||||||
*
|
|
||||||
* @returns {*} A map with langKeys and filenames.
|
* @returns {*} A map with langKeys and filenames.
|
||||||
*/
|
*/
|
||||||
getTranslations: function () {
|
getTranslations () {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -77,17 +71,16 @@ const Module = Class.extend({
|
|||||||
* Generates the dom which needs to be displayed. This method is called by the MagicMirror² core.
|
* Generates the dom which needs to be displayed. This method is called by the MagicMirror² core.
|
||||||
* This method can to be subclassed if the module wants to display info on the mirror.
|
* This method can to be subclassed if the module wants to display info on the mirror.
|
||||||
* Alternatively, the getTemplate method could be subclassed.
|
* Alternatively, the getTemplate method could be subclassed.
|
||||||
*
|
|
||||||
* @returns {HTMLElement|Promise} The dom or a promise with the dom to display.
|
* @returns {HTMLElement|Promise} The dom or a promise with the dom to display.
|
||||||
*/
|
*/
|
||||||
getDom: function () {
|
getDom () {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
const template = this.getTemplate();
|
const template = this.getTemplate();
|
||||||
const templateData = this.getTemplateData();
|
const templateData = this.getTemplateData();
|
||||||
|
|
||||||
// Check to see if we need to render a template string or a file.
|
// Check to see if we need to render a template string or a file.
|
||||||
if (/^.*((\.html)|(\.njk))$/.test(template)) {
|
if ((/^.*((\.html)|(\.njk))$/).test(template)) {
|
||||||
// the template is a filename
|
// the template is a filename
|
||||||
this.nunjucksEnvironment().render(template, templateData, function (err, res) {
|
this.nunjucksEnvironment().render(template, templateData, function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -111,10 +104,9 @@ const Module = Class.extend({
|
|||||||
* Generates the header string which needs to be displayed if a user has a header configured for this module.
|
* Generates the header string which needs to be displayed if a user has a header configured for this module.
|
||||||
* This method is called by the MagicMirror² core, but only if the user has configured a default header for the module.
|
* This method is called by the MagicMirror² core, but only if the user has configured a default header for the module.
|
||||||
* This method needs to be subclassed if the module wants to display modified headers on the mirror.
|
* This method needs to be subclassed if the module wants to display modified headers on the mirror.
|
||||||
*
|
|
||||||
* @returns {string} The header to display above the header.
|
* @returns {string} The header to display above the header.
|
||||||
*/
|
*/
|
||||||
getHeader: function () {
|
getHeader () {
|
||||||
return this.data.header;
|
return this.data.header;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -123,31 +115,28 @@ const Module = Class.extend({
|
|||||||
* This method needs to be subclassed if the module wants to use a template.
|
* This method needs to be subclassed if the module wants to use a template.
|
||||||
* It can either return a template sting, or a template filename.
|
* It can either return a template sting, or a template filename.
|
||||||
* If the string ends with '.html' it's considered a file from within the module's folder.
|
* If the string ends with '.html' it's considered a file from within the module's folder.
|
||||||
*
|
|
||||||
* @returns {string} The template string of filename.
|
* @returns {string} The template string of filename.
|
||||||
*/
|
*/
|
||||||
getTemplate: function () {
|
getTemplate () {
|
||||||
return `<div class="normal">${this.name}</div><div class="small dimmed">${this.identifier}</div>`;
|
return `<div class="normal">${this.name}</div><div class="small dimmed">${this.identifier}</div>`;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the data to be used in the template.
|
* Returns the data to be used in the template.
|
||||||
* This method needs to be subclassed if the module wants to use a custom data.
|
* This method needs to be subclassed if the module wants to use a custom data.
|
||||||
*
|
|
||||||
* @returns {object} The data for the template
|
* @returns {object} The data for the template
|
||||||
*/
|
*/
|
||||||
getTemplateData: function () {
|
getTemplateData () {
|
||||||
return {};
|
return {};
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the MagicMirror² core when a notification arrives.
|
* Called by the MagicMirror² core when a notification arrives.
|
||||||
*
|
|
||||||
* @param {string} notification The identifier of the notification.
|
* @param {string} notification The identifier of the notification.
|
||||||
* @param {*} payload The payload of the notification.
|
* @param {*} payload The payload of the notification.
|
||||||
* @param {Module} sender The module that sent the notification.
|
* @param {Module} sender The module that sent the notification.
|
||||||
*/
|
*/
|
||||||
notificationReceived: function (notification, payload, sender) {
|
notificationReceived (notification, payload, sender) {
|
||||||
if (sender) {
|
if (sender) {
|
||||||
// Log.log(this.name + " received a module notification: " + notification + " from sender: " + sender.name);
|
// Log.log(this.name + " received a module notification: " + notification + " from sender: " + sender.name);
|
||||||
} else {
|
} else {
|
||||||
@@ -158,10 +147,9 @@ const Module = Class.extend({
|
|||||||
/**
|
/**
|
||||||
* Returns the nunjucks environment for the current module.
|
* Returns the nunjucks environment for the current module.
|
||||||
* The environment is checked in the _nunjucksEnvironment instance variable.
|
* The environment is checked in the _nunjucksEnvironment instance variable.
|
||||||
*
|
|
||||||
* @returns {object} The Nunjucks Environment
|
* @returns {object} The Nunjucks Environment
|
||||||
*/
|
*/
|
||||||
nunjucksEnvironment: function () {
|
nunjucksEnvironment () {
|
||||||
if (this._nunjucksEnvironment !== null) {
|
if (this._nunjucksEnvironment !== null) {
|
||||||
return this._nunjucksEnvironment;
|
return this._nunjucksEnvironment;
|
||||||
}
|
}
|
||||||
@@ -180,63 +168,61 @@ const Module = Class.extend({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a socket notification arrives.
|
* Called when a socket notification arrives.
|
||||||
*
|
|
||||||
* @param {string} notification The identifier of the notification.
|
* @param {string} notification The identifier of the notification.
|
||||||
* @param {*} payload The payload of the notification.
|
* @param {*} payload The payload of the notification.
|
||||||
*/
|
*/
|
||||||
socketNotificationReceived: function (notification, payload) {
|
socketNotificationReceived (notification, payload) {
|
||||||
Log.log(`${this.name} received a socket notification: ${notification} - Payload: ${payload}`);
|
Log.log(`${this.name} received a socket notification: ${notification} - Payload: ${payload}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the module is hidden.
|
* Called when the module is hidden.
|
||||||
*/
|
*/
|
||||||
suspend: function () {
|
suspend () {
|
||||||
Log.log(`${this.name} is suspended.`);
|
Log.log(`${this.name} is suspended.`);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the module is shown.
|
* Called when the module is shown.
|
||||||
*/
|
*/
|
||||||
resume: function () {
|
resume () {
|
||||||
Log.log(`${this.name} is resumed.`);
|
Log.log(`${this.name} is resumed.`);
|
||||||
},
|
},
|
||||||
|
|
||||||
/*********************************************
|
/*********************************************
|
||||||
* The methods below don"t need subclassing. *
|
* The methods below don't need subclassing. *
|
||||||
*********************************************/
|
*********************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the module data.
|
* Set the module data.
|
||||||
*
|
|
||||||
* @param {object} data The module data
|
* @param {object} data The module data
|
||||||
*/
|
*/
|
||||||
setData: function (data) {
|
setData (data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.name = data.name;
|
this.name = data.name;
|
||||||
this.identifier = data.identifier;
|
this.identifier = data.identifier;
|
||||||
this.hidden = false;
|
this.hidden = false;
|
||||||
|
this.hasAnimateIn = false;
|
||||||
|
this.hasAnimateOut = false;
|
||||||
|
|
||||||
this.setConfig(data.config, data.configDeepMerge);
|
this.setConfig(data.config, data.configDeepMerge);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the module config and combine it with the module defaults.
|
* Set the module config and combine it with the module defaults.
|
||||||
*
|
|
||||||
* @param {object} config The combined module config.
|
* @param {object} config The combined module config.
|
||||||
* @param {boolean} deep Merge module config in deep.
|
* @param {boolean} deep Merge module config in deep.
|
||||||
*/
|
*/
|
||||||
setConfig: function (config, deep) {
|
setConfig (config, deep) {
|
||||||
this.config = deep ? configMerge({}, this.defaults, config) : Object.assign({}, this.defaults, config);
|
this.config = deep ? configMerge({}, this.defaults, config) : Object.assign({}, this.defaults, config);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a socket object. If it doesn't exist, it's created.
|
* Returns a socket object. If it doesn't exist, it's created.
|
||||||
* It also registers the notification callback.
|
* It also registers the notification callback.
|
||||||
*
|
|
||||||
* @returns {MMSocket} a socket object
|
* @returns {MMSocket} a socket object
|
||||||
*/
|
*/
|
||||||
socket: function () {
|
socket () {
|
||||||
if (typeof this._socket === "undefined") {
|
if (typeof this._socket === "undefined") {
|
||||||
this._socket = new MMSocket(this.name);
|
this._socket = new MMSocket(this.name);
|
||||||
}
|
}
|
||||||
@@ -250,39 +236,35 @@ const Module = Class.extend({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the path to a module file.
|
* Retrieve the path to a module file.
|
||||||
*
|
|
||||||
* @param {string} file Filename
|
* @param {string} file Filename
|
||||||
* @returns {string} the file path
|
* @returns {string} the file path
|
||||||
*/
|
*/
|
||||||
file: function (file) {
|
file (file) {
|
||||||
return `${this.data.path}/${file}`.replace("//", "/");
|
return `${this.data.path}/${file}`.replace("//", "/");
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load all required stylesheets by requesting the MM object to load the files.
|
* Load all required stylesheets by requesting the MM object to load the files.
|
||||||
*
|
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
loadStyles: function () {
|
loadStyles () {
|
||||||
return this.loadDependencies("getStyles");
|
return this.loadDependencies("getStyles");
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load all required scripts by requesting the MM object to load the files.
|
* Load all required scripts by requesting the MM object to load the files.
|
||||||
*
|
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
loadScripts: function () {
|
loadScripts () {
|
||||||
return this.loadDependencies("getScripts");
|
return this.loadDependencies("getScripts");
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to load all dependencies.
|
* Helper method to load all dependencies.
|
||||||
*
|
|
||||||
* @param {string} funcName Function name to call to get scripts or styles.
|
* @param {string} funcName Function name to call to get scripts or styles.
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
loadDependencies: async function (funcName) {
|
async loadDependencies (funcName) {
|
||||||
let dependencies = this[funcName]();
|
let dependencies = this[funcName]();
|
||||||
|
|
||||||
const loadNextDependency = async () => {
|
const loadNextDependency = async () => {
|
||||||
@@ -301,8 +283,9 @@ const Module = Class.extend({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Load all translations.
|
* Load all translations.
|
||||||
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
loadTranslations: async function () {
|
async loadTranslations () {
|
||||||
const translations = this.getTranslations() || {};
|
const translations = this.getTranslations() || {};
|
||||||
const language = config.language.toLowerCase();
|
const language = config.language.toLowerCase();
|
||||||
|
|
||||||
@@ -329,13 +312,12 @@ const Module = Class.extend({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Request the translation for a given key with optional variables and default value.
|
* Request the translation for a given key with optional variables and default value.
|
||||||
*
|
|
||||||
* @param {string} key The key of the string to translate
|
* @param {string} key The key of the string to translate
|
||||||
* @param {string|object} [defaultValueOrVariables] The default value or variables for translating.
|
* @param {string|object} [defaultValueOrVariables] The default value or variables for translating.
|
||||||
* @param {string} [defaultValue] The default value with variables.
|
* @param {string} [defaultValue] The default value with variables.
|
||||||
* @returns {string} the translated key
|
* @returns {string} the translated key
|
||||||
*/
|
*/
|
||||||
translate: function (key, defaultValueOrVariables, defaultValue) {
|
translate (key, defaultValueOrVariables, defaultValue) {
|
||||||
if (typeof defaultValueOrVariables === "object") {
|
if (typeof defaultValueOrVariables === "object") {
|
||||||
return Translator.translate(this, key, defaultValueOrVariables) || defaultValue || "";
|
return Translator.translate(this, key, defaultValueOrVariables) || defaultValue || "";
|
||||||
}
|
}
|
||||||
@@ -344,84 +326,81 @@ const Module = Class.extend({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Request an (animated) update of the module.
|
* Request an (animated) update of the module.
|
||||||
*
|
* @param {number|object} [updateOptions] The speed of the animation or object with for updateOptions (speed/animates)
|
||||||
* @param {number} [speed] The speed of the animation.
|
|
||||||
*/
|
*/
|
||||||
updateDom: function (speed) {
|
updateDom (updateOptions) {
|
||||||
MM.updateDom(this, speed);
|
MM.updateDom(this, updateOptions);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a notification to all modules.
|
* Send a notification to all modules.
|
||||||
*
|
|
||||||
* @param {string} notification The identifier of the notification.
|
* @param {string} notification The identifier of the notification.
|
||||||
* @param {*} payload The payload of the notification.
|
* @param {*} payload The payload of the notification.
|
||||||
*/
|
*/
|
||||||
sendNotification: function (notification, payload) {
|
sendNotification (notification, payload) {
|
||||||
MM.sendNotification(notification, payload, this);
|
MM.sendNotification(notification, payload, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a socket notification to the node helper.
|
* Send a socket notification to the node helper.
|
||||||
*
|
|
||||||
* @param {string} notification The identifier of the notification.
|
* @param {string} notification The identifier of the notification.
|
||||||
* @param {*} payload The payload of the notification.
|
* @param {*} payload The payload of the notification.
|
||||||
*/
|
*/
|
||||||
sendSocketNotification: function (notification, payload) {
|
sendSocketNotification (notification, payload) {
|
||||||
this.socket().sendNotification(notification, payload);
|
this.socket().sendNotification(notification, payload);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hide this module.
|
* Hide this module.
|
||||||
*
|
|
||||||
* @param {number} speed The speed of the hide animation.
|
* @param {number} speed The speed of the hide animation.
|
||||||
* @param {Function} callback Called when the animation is done.
|
* @param {Function} callback Called when the animation is done.
|
||||||
* @param {object} [options] Optional settings for the hide method.
|
* @param {object} [options] Optional settings for the hide method.
|
||||||
*/
|
*/
|
||||||
hide: function (speed, callback, options) {
|
hide (speed, callback, options = {}) {
|
||||||
if (typeof callback === "object") {
|
let usedCallback = callback || function () {};
|
||||||
options = callback;
|
let usedOptions = options;
|
||||||
callback = function () {};
|
|
||||||
}
|
|
||||||
|
|
||||||
callback = callback || function () {};
|
if (typeof callback === "object") {
|
||||||
options = options || {};
|
Log.error("Parameter mismatch in module.hide: callback is not an optional parameter!");
|
||||||
|
usedOptions = callback;
|
||||||
|
usedCallback = function () {};
|
||||||
|
}
|
||||||
|
|
||||||
MM.hideModule(
|
MM.hideModule(
|
||||||
this,
|
this,
|
||||||
speed,
|
speed,
|
||||||
() => {
|
() => {
|
||||||
this.suspend();
|
this.suspend();
|
||||||
callback();
|
usedCallback();
|
||||||
},
|
},
|
||||||
options
|
usedOptions
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show this module.
|
* Show this module.
|
||||||
*
|
|
||||||
* @param {number} speed The speed of the show animation.
|
* @param {number} speed The speed of the show animation.
|
||||||
* @param {Function} callback Called when the animation is done.
|
* @param {Function} callback Called when the animation is done.
|
||||||
* @param {object} [options] Optional settings for the show method.
|
* @param {object} [options] Optional settings for the show method.
|
||||||
*/
|
*/
|
||||||
show: function (speed, callback, options) {
|
show (speed, callback, options) {
|
||||||
if (typeof callback === "object") {
|
let usedCallback = callback || function () {};
|
||||||
options = callback;
|
let usedOptions = options;
|
||||||
callback = function () {};
|
|
||||||
}
|
|
||||||
|
|
||||||
callback = callback || function () {};
|
if (typeof callback === "object") {
|
||||||
options = options || {};
|
Log.error("Parameter mismatch in module.show: callback is not an optional parameter!");
|
||||||
|
usedOptions = callback;
|
||||||
|
usedCallback = function () {};
|
||||||
|
}
|
||||||
|
|
||||||
MM.showModule(
|
MM.showModule(
|
||||||
this,
|
this,
|
||||||
speed,
|
speed,
|
||||||
() => {
|
() => {
|
||||||
this.resume();
|
this.resume();
|
||||||
callback();
|
usedCallback();
|
||||||
},
|
},
|
||||||
options
|
usedOptions
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -445,11 +424,10 @@ const Module = Class.extend({
|
|||||||
* -------
|
* -------
|
||||||
*
|
*
|
||||||
* Todo: idea of Mich determinate what do you want to merge or not
|
* Todo: idea of Mich determinate what do you want to merge or not
|
||||||
*
|
|
||||||
* @param {object} result the initial object
|
* @param {object} result the initial object
|
||||||
* @returns {object} the merged config
|
* @returns {object} the merged config
|
||||||
*/
|
*/
|
||||||
function configMerge(result) {
|
function configMerge (result) {
|
||||||
const stack = Array.prototype.slice.call(arguments, 1);
|
const stack = Array.prototype.slice.call(arguments, 1);
|
||||||
let item, key;
|
let item, key;
|
||||||
|
|
||||||
@@ -507,13 +485,12 @@ window.Module = Module;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare two semantic version numbers and return the difference.
|
* Compare two semantic version numbers and return the difference.
|
||||||
*
|
|
||||||
* @param {string} a Version number a.
|
* @param {string} a Version number a.
|
||||||
* @param {string} b Version number b.
|
* @param {string} b Version number b.
|
||||||
* @returns {number} A positive number if a is larger than b, a negative
|
* @returns {number} A positive number if a is larger than b, a negative
|
||||||
* number if a is smaller and 0 if they are the same
|
* number if a is smaller and 0 if they are the same
|
||||||
*/
|
*/
|
||||||
function cmpVersions(a, b) {
|
function cmpVersions (a, b) {
|
||||||
const regExStrip0 = /(\.0+)+$/;
|
const regExStrip0 = /(\.0+)+$/;
|
||||||
const segmentsA = a.replace(regExStrip0, "").split(".");
|
const segmentsA = a.replace(regExStrip0, "").split(".");
|
||||||
const segmentsB = b.replace(regExStrip0, "").split(".");
|
const segmentsB = b.replace(regExStrip0, "").split(".");
|
||||||
|
|||||||
@@ -1,23 +1,17 @@
|
|||||||
/* MagicMirror²
|
|
||||||
* Node Helper Superclass
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const Log = require("logger");
|
const Log = require("logger");
|
||||||
const Class = require("./class");
|
const Class = require("./class");
|
||||||
|
|
||||||
const NodeHelper = Class.extend({
|
const NodeHelper = Class.extend({
|
||||||
init() {
|
init () {
|
||||||
Log.log("Initializing new module helper ...");
|
Log.log("Initializing new module helper ...");
|
||||||
},
|
},
|
||||||
|
|
||||||
loaded() {
|
loaded () {
|
||||||
Log.log(`Module helper loaded: ${this.name}`);
|
Log.log(`Module helper loaded: ${this.name}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
start() {
|
start () {
|
||||||
Log.log(`Starting module helper: ${this.name}`);
|
Log.log(`Starting module helper: ${this.name}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -26,35 +20,32 @@ const NodeHelper = Class.extend({
|
|||||||
* Close any open connections, stop any sub-processes and
|
* Close any open connections, stop any sub-processes and
|
||||||
* gracefully exit the module.
|
* gracefully exit the module.
|
||||||
*/
|
*/
|
||||||
stop() {
|
stop () {
|
||||||
Log.log(`Stopping module helper: ${this.name}`);
|
Log.log(`Stopping module helper: ${this.name}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called when a socket notification arrives.
|
* This method is called when a socket notification arrives.
|
||||||
*
|
|
||||||
* @param {string} notification The identifier of the notification.
|
* @param {string} notification The identifier of the notification.
|
||||||
* @param {*} payload The payload of the notification.
|
* @param {*} payload The payload of the notification.
|
||||||
*/
|
*/
|
||||||
socketNotificationReceived(notification, payload) {
|
socketNotificationReceived (notification, payload) {
|
||||||
Log.log(`${this.name} received a socket notification: ${notification} - Payload: ${payload}`);
|
Log.log(`${this.name} received a socket notification: ${notification} - Payload: ${payload}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the module name.
|
* Set the module name.
|
||||||
*
|
|
||||||
* @param {string} name Module name.
|
* @param {string} name Module name.
|
||||||
*/
|
*/
|
||||||
setName(name) {
|
setName (name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the module path.
|
* Set the module path.
|
||||||
*
|
|
||||||
* @param {string} path Module path.
|
* @param {string} path Module path.
|
||||||
*/
|
*/
|
||||||
setPath(path) {
|
setPath (path) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -64,7 +55,7 @@ const NodeHelper = Class.extend({
|
|||||||
* argument notification string - The identifier of the notification.
|
* argument notification string - The identifier of the notification.
|
||||||
* argument payload mixed - The payload of the notification.
|
* argument payload mixed - The payload of the notification.
|
||||||
*/
|
*/
|
||||||
sendSocketNotification(notification, payload) {
|
sendSocketNotification (notification, payload) {
|
||||||
this.io.of(this.name).emit(notification, payload);
|
this.io.of(this.name).emit(notification, payload);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -74,7 +65,7 @@ const NodeHelper = Class.extend({
|
|||||||
*
|
*
|
||||||
* argument app Express app - The Express app object.
|
* argument app Express app - The Express app object.
|
||||||
*/
|
*/
|
||||||
setExpressApp(app) {
|
setExpressApp (app) {
|
||||||
this.expressApp = app;
|
this.expressApp = app;
|
||||||
|
|
||||||
app.use(`/${this.name}`, express.static(`${this.path}/public`));
|
app.use(`/${this.name}`, express.static(`${this.path}/public`));
|
||||||
@@ -86,7 +77,7 @@ const NodeHelper = Class.extend({
|
|||||||
*
|
*
|
||||||
* argument io Socket.io - The Socket io object.
|
* argument io Socket.io - The Socket io object.
|
||||||
*/
|
*/
|
||||||
setSocketIO(io) {
|
setSocketIO (io) {
|
||||||
this.io = io;
|
this.io = io;
|
||||||
|
|
||||||
Log.log(`Connecting socket for: ${this.name}`);
|
Log.log(`Connecting socket for: ${this.name}`);
|
||||||
@@ -123,7 +114,6 @@ NodeHelper.checkFetchStatus = function (response) {
|
|||||||
/**
|
/**
|
||||||
* Look at the specified error and return an appropriate error type, that
|
* Look at the specified error and return an appropriate error type, that
|
||||||
* can be translated to a detailed error message
|
* can be translated to a detailed error message
|
||||||
*
|
|
||||||
* @param {Error} error the error from fetching something
|
* @param {Error} error the error from fetching something
|
||||||
* @returns {string} the string of the detailed error message in the translations
|
* @returns {string} the string of the detailed error message in the translations
|
||||||
*/
|
*/
|
||||||
|
|||||||
25
js/server.js
25
js/server.js
@@ -1,13 +1,7 @@
|
|||||||
/* MagicMirror²
|
const fs = require("node:fs");
|
||||||
* Server
|
const http = require("node:http");
|
||||||
*
|
const https = require("node:https");
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
const path = require("node:path");
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
const fs = require("fs");
|
|
||||||
const http = require("http");
|
|
||||||
const https = require("https");
|
|
||||||
const path = require("path");
|
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const ipfilter = require("express-ipfilter").IpFilter;
|
const ipfilter = require("express-ipfilter").IpFilter;
|
||||||
const helmet = require("helmet");
|
const helmet = require("helmet");
|
||||||
@@ -15,15 +9,14 @@ const socketio = require("socket.io");
|
|||||||
|
|
||||||
const Log = require("logger");
|
const Log = require("logger");
|
||||||
const Utils = require("./utils");
|
const Utils = require("./utils");
|
||||||
const { cors, getConfig, getHtml, getVersion } = require("./server_functions");
|
const { cors, getConfig, getHtml, getVersion, getStartup } = require("./server_functions");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server
|
* Server
|
||||||
*
|
|
||||||
* @param {object} config The MM config
|
* @param {object} config The MM config
|
||||||
* @class
|
* @class
|
||||||
*/
|
*/
|
||||||
function Server(config) {
|
function Server (config) {
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = process.env.MM_PORT || config.port;
|
const port = process.env.MM_PORT || config.port;
|
||||||
const serverSockets = new Set();
|
const serverSockets = new Set();
|
||||||
@@ -31,7 +24,6 @@ function Server(config) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the server for incoming connections
|
* Opens the server for incoming connections
|
||||||
*
|
|
||||||
* @returns {Promise} A promise that is resolved when the server listens to connections
|
* @returns {Promise} A promise that is resolved when the server listens to connections
|
||||||
*/
|
*/
|
||||||
this.open = function () {
|
this.open = function () {
|
||||||
@@ -64,7 +56,7 @@ function Server(config) {
|
|||||||
server.listen(port, config.address || "localhost");
|
server.listen(port, config.address || "localhost");
|
||||||
|
|
||||||
if (config.ipWhitelist instanceof Array && config.ipWhitelist.length === 0) {
|
if (config.ipWhitelist instanceof Array && config.ipWhitelist.length === 0) {
|
||||||
Log.warn(Utils.colors.warn("You're using a full whitelist configuration to allow for all IPs"));
|
Log.warn("You're using a full whitelist configuration to allow for all IPs");
|
||||||
}
|
}
|
||||||
|
|
||||||
app.use(function (req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
@@ -93,6 +85,8 @@ function Server(config) {
|
|||||||
|
|
||||||
app.get("/config", (req, res) => getConfig(req, res));
|
app.get("/config", (req, res) => getConfig(req, res));
|
||||||
|
|
||||||
|
app.get("/startup", (req, res) => getStartup(req, res));
|
||||||
|
|
||||||
app.get("/", (req, res) => getHtml(req, res));
|
app.get("/", (req, res) => getHtml(req, res));
|
||||||
|
|
||||||
server.on("listening", () => {
|
server.on("listening", () => {
|
||||||
@@ -106,7 +100,6 @@ function Server(config) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the server and destroys all lingering connections to it.
|
* Closes the server and destroys all lingering connections to it.
|
||||||
*
|
|
||||||
* @returns {Promise} A promise that resolves when server has successfully shut down
|
* @returns {Promise} A promise that resolves when server has successfully shut down
|
||||||
*/
|
*/
|
||||||
this.close = function () {
|
this.close = function () {
|
||||||
|
|||||||
@@ -1,29 +1,37 @@
|
|||||||
const fs = require("fs");
|
const fs = require("node:fs");
|
||||||
const path = require("path");
|
const path = require("node:path");
|
||||||
const Log = require("logger");
|
const Log = require("logger");
|
||||||
const fetch = require("./fetch");
|
|
||||||
|
const startUp = new Date();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the config.
|
* Gets the config.
|
||||||
*
|
|
||||||
* @param {Request} req - the request
|
* @param {Request} req - the request
|
||||||
* @param {Response} res - the result
|
* @param {Response} res - the result
|
||||||
*/
|
*/
|
||||||
function getConfig(req, res) {
|
function getConfig (req, res) {
|
||||||
res.send(config);
|
res.send(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the startup time.
|
||||||
|
* @param {Request} req - the request
|
||||||
|
* @param {Response} res - the result
|
||||||
|
*/
|
||||||
|
function getStartup (req, res) {
|
||||||
|
res.send(startUp);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A method that forwards HTTP Get-methods to the internet to avoid CORS-errors.
|
* A method that forwards HTTP Get-methods to the internet to avoid CORS-errors.
|
||||||
*
|
*
|
||||||
* Example input request url: /cors?sendheaders=header1:value1,header2:value2&expectedheaders=header1,header2&url=http://www.test.com/path?param1=value1
|
* Example input request url: /cors?sendheaders=header1:value1,header2:value2&expectedheaders=header1,header2&url=http://www.test.com/path?param1=value1
|
||||||
*
|
*
|
||||||
* Only the url-param of the input request url is required. It must be the last parameter.
|
* Only the url-param of the input request url is required. It must be the last parameter.
|
||||||
*
|
|
||||||
* @param {Request} req - the request
|
* @param {Request} req - the request
|
||||||
* @param {Response} res - the result
|
* @param {Response} res - the result
|
||||||
*/
|
*/
|
||||||
async function cors(req, res) {
|
async function cors (req, res) {
|
||||||
try {
|
try {
|
||||||
const urlRegEx = "url=(.+?)$";
|
const urlRegEx = "url=(.+?)$";
|
||||||
let url;
|
let url;
|
||||||
@@ -57,11 +65,10 @@ async function cors(req, res) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets headers and values to attach to the web request.
|
* Gets headers and values to attach to the web request.
|
||||||
*
|
|
||||||
* @param {string} url - The url containing the headers and values to send.
|
* @param {string} url - The url containing the headers and values to send.
|
||||||
* @returns {object} An object specifying name and value of the headers.
|
* @returns {object} An object specifying name and value of the headers.
|
||||||
*/
|
*/
|
||||||
function getHeadersToSend(url) {
|
function getHeadersToSend (url) {
|
||||||
const headersToSend = { "User-Agent": `Mozilla/5.0 MagicMirror/${global.version}` };
|
const headersToSend = { "User-Agent": `Mozilla/5.0 MagicMirror/${global.version}` };
|
||||||
const headersToSendMatch = new RegExp("sendheaders=(.+?)(&|$)", "g").exec(url);
|
const headersToSendMatch = new RegExp("sendheaders=(.+?)(&|$)", "g").exec(url);
|
||||||
if (headersToSendMatch) {
|
if (headersToSendMatch) {
|
||||||
@@ -79,11 +86,10 @@ function getHeadersToSend(url) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the headers expected from the response.
|
* Gets the headers expected from the response.
|
||||||
*
|
|
||||||
* @param {string} url - The url containing the expected headers from the response.
|
* @param {string} url - The url containing the expected headers from the response.
|
||||||
* @returns {string[]} headers - The name of the expected headers.
|
* @returns {string[]} headers - The name of the expected headers.
|
||||||
*/
|
*/
|
||||||
function geExpectedRecievedHeaders(url) {
|
function geExpectedRecievedHeaders (url) {
|
||||||
const expectedRecievedHeaders = ["Content-Type"];
|
const expectedRecievedHeaders = ["Content-Type"];
|
||||||
const expectedRecievedHeadersMatch = new RegExp("expectedheaders=(.+?)(&|$)", "g").exec(url);
|
const expectedRecievedHeadersMatch = new RegExp("expectedheaders=(.+?)(&|$)", "g").exec(url);
|
||||||
if (expectedRecievedHeadersMatch) {
|
if (expectedRecievedHeadersMatch) {
|
||||||
@@ -97,11 +103,10 @@ function geExpectedRecievedHeaders(url) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the HTML to display the magic mirror.
|
* Gets the HTML to display the magic mirror.
|
||||||
*
|
|
||||||
* @param {Request} req - the request
|
* @param {Request} req - the request
|
||||||
* @param {Response} res - the result
|
* @param {Response} res - the result
|
||||||
*/
|
*/
|
||||||
function getHtml(req, res) {
|
function getHtml (req, res) {
|
||||||
let html = fs.readFileSync(path.resolve(`${global.root_path}/index.html`), { encoding: "utf8" });
|
let html = fs.readFileSync(path.resolve(`${global.root_path}/index.html`), { encoding: "utf8" });
|
||||||
html = html.replace("#VERSION#", global.version);
|
html = html.replace("#VERSION#", global.version);
|
||||||
|
|
||||||
@@ -116,12 +121,11 @@ function getHtml(req, res) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the MagicMirror version.
|
* Gets the MagicMirror version.
|
||||||
*
|
|
||||||
* @param {Request} req - the request
|
* @param {Request} req - the request
|
||||||
* @param {Response} res - the result
|
* @param {Response} res - the result
|
||||||
*/
|
*/
|
||||||
function getVersion(req, res) {
|
function getVersion (req, res) {
|
||||||
res.send(global.version);
|
res.send(global.version);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { cors, getConfig, getHtml, getVersion };
|
module.exports = { cors, getConfig, getHtml, getVersion, getStartup };
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
/* global io */
|
/* global io */
|
||||||
|
|
||||||
/* MagicMirror²
|
|
||||||
* TODO add description
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
const MMSocket = function (moduleName) {
|
const MMSocket = function (moduleName) {
|
||||||
if (typeof moduleName !== "string") {
|
if (typeof moduleName !== "string") {
|
||||||
throw new Error("Please set the module name for the MMSocket.");
|
throw new Error("Please set the module name for the MMSocket.");
|
||||||
@@ -44,10 +38,7 @@ const MMSocket = function (moduleName) {
|
|||||||
notificationCallback = callback;
|
notificationCallback = callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.sendNotification = (notification, payload) => {
|
this.sendNotification = (notification, payload = {}) => {
|
||||||
if (typeof payload === "undefined") {
|
|
||||||
payload = {};
|
|
||||||
}
|
|
||||||
this.socket.emit(notification, payload);
|
this.socket.emit(notification, payload);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,21 +1,15 @@
|
|||||||
/* global translations */
|
/* global translations */
|
||||||
|
|
||||||
/* MagicMirror²
|
|
||||||
* Translator (l10n)
|
|
||||||
*
|
|
||||||
* By Christopher Fenner https://github.com/CFenner
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
const Translator = (function () {
|
const Translator = (function () {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a JSON file via XHR.
|
* Load a JSON file via XHR.
|
||||||
*
|
|
||||||
* @param {string} file Path of the file we want to load.
|
* @param {string} file Path of the file we want to load.
|
||||||
* @returns {Promise<object>} the translations in the specified file
|
* @returns {Promise<object>} the translations in the specified file
|
||||||
*/
|
*/
|
||||||
async function loadJSON(file) {
|
async function loadJSON (file) {
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve) {
|
||||||
xhr.overrideMimeType("application/json");
|
xhr.overrideMimeType("application/json");
|
||||||
xhr.open("GET", file, true);
|
xhr.open("GET", file, true);
|
||||||
xhr.onreadystatechange = function () {
|
xhr.onreadystatechange = function () {
|
||||||
@@ -43,33 +37,31 @@ const Translator = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a translation for a given key for a given module.
|
* Load a translation for a given key for a given module.
|
||||||
*
|
|
||||||
* @param {Module} module The module to load the translation for.
|
* @param {Module} module The module to load the translation for.
|
||||||
* @param {string} key The key of the text to translate.
|
* @param {string} key The key of the text to translate.
|
||||||
* @param {object} variables The variables to use within the translation template (optional)
|
* @param {object} variables The variables to use within the translation template (optional)
|
||||||
* @returns {string} the translated key
|
* @returns {string} the translated key
|
||||||
*/
|
*/
|
||||||
translate: function (module, key, variables) {
|
translate (module, key, variables = {}) {
|
||||||
variables = variables || {}; // Empty object by default
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combines template and variables like:
|
* Combines template and variables like:
|
||||||
* template: "Please wait for {timeToWait} before continuing with {work}."
|
* template: "Please wait for {timeToWait} before continuing with {work}."
|
||||||
* variables: {timeToWait: "2 hours", work: "painting"}
|
* variables: {timeToWait: "2 hours", work: "painting"}
|
||||||
* to: "Please wait for 2 hours before continuing with painting."
|
* to: "Please wait for 2 hours before continuing with painting."
|
||||||
*
|
|
||||||
* @param {string} template Text with placeholder
|
* @param {string} template Text with placeholder
|
||||||
* @param {object} variables Variables for the placeholder
|
* @param {object} variables Variables for the placeholder
|
||||||
* @returns {string} the template filled with the variables
|
* @returns {string} the template filled with the variables
|
||||||
*/
|
*/
|
||||||
function createStringFromTemplate(template, variables) {
|
function createStringFromTemplate (template, variables) {
|
||||||
if (Object.prototype.toString.call(template) !== "[object String]") {
|
if (Object.prototype.toString.call(template) !== "[object String]") {
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
let templateToUse = template;
|
||||||
if (variables.fallback && !template.match(new RegExp("{.+}"))) {
|
if (variables.fallback && !template.match(new RegExp("{.+}"))) {
|
||||||
template = variables.fallback;
|
templateToUse = variables.fallback;
|
||||||
}
|
}
|
||||||
return template.replace(new RegExp("{([^}]+)}", "g"), function (_unused, varName) {
|
return templateToUse.replace(new RegExp("{([^}]+)}", "g"), function (_unused, varName) {
|
||||||
return varName in variables ? variables[varName] : `{${varName}}`;
|
return varName in variables ? variables[varName] : `{${varName}}`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -99,12 +91,11 @@ const Translator = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a translation file (json) and remember the data.
|
* Load a translation file (json) and remember the data.
|
||||||
*
|
|
||||||
* @param {Module} module The module to load the translation file for.
|
* @param {Module} module The module to load the translation file for.
|
||||||
* @param {string} file Path of the file we want to load.
|
* @param {string} file Path of the file we want to load.
|
||||||
* @param {boolean} isFallback Flag to indicate fallback translations.
|
* @param {boolean} isFallback Flag to indicate fallback translations.
|
||||||
*/
|
*/
|
||||||
async load(module, file, isFallback) {
|
async load (module, file, isFallback) {
|
||||||
Log.log(`${module.name} - Load translation${isFallback ? " fallback" : ""}: ${file}`);
|
Log.log(`${module.name} - Load translation${isFallback ? " fallback" : ""}: ${file}`);
|
||||||
|
|
||||||
if (this.translationsFallback[module.name]) {
|
if (this.translationsFallback[module.name]) {
|
||||||
@@ -118,10 +109,9 @@ const Translator = (function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the core translations.
|
* Load the core translations.
|
||||||
*
|
|
||||||
* @param {string} lang The language identifier of the core language.
|
* @param {string} lang The language identifier of the core language.
|
||||||
*/
|
*/
|
||||||
loadCoreTranslations: async function (lang) {
|
async loadCoreTranslations (lang) {
|
||||||
if (lang in translations) {
|
if (lang in translations) {
|
||||||
Log.log(`Loading core translation file: ${translations[lang]}`);
|
Log.log(`Loading core translation file: ${translations[lang]}`);
|
||||||
this.coreTranslations = await loadJSON(translations[lang]);
|
this.coreTranslations = await loadJSON(translations[lang]);
|
||||||
@@ -136,7 +126,7 @@ const Translator = (function () {
|
|||||||
* Load the core translations' fallback.
|
* Load the core translations' fallback.
|
||||||
* The first language defined in translations.js will be used.
|
* The first language defined in translations.js will be used.
|
||||||
*/
|
*/
|
||||||
loadCoreTranslationsFallback: async function () {
|
async loadCoreTranslationsFallback () {
|
||||||
let first = Object.keys(translations)[0];
|
let first = Object.keys(translations)[0];
|
||||||
if (first) {
|
if (first) {
|
||||||
Log.log(`Loading core translation fallback file: ${translations[first]}`);
|
Log.log(`Loading core translation fallback file: ${translations[first]}`);
|
||||||
@@ -144,6 +134,6 @@ const Translator = (function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
}());
|
||||||
|
|
||||||
window.Translator = Translator;
|
window.Translator = Translator;
|
||||||
|
|||||||
37
js/utils.js
37
js/utils.js
@@ -1,16 +1,29 @@
|
|||||||
/* MagicMirror²
|
const execSync = require("node:child_process").execSync;
|
||||||
* Utils
|
const Log = require("logger");
|
||||||
*
|
const si = require("systeminformation");
|
||||||
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
const colors = require("colors/safe");
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
colors: {
|
|
||||||
warn: colors.yellow,
|
async logSystemInformation () {
|
||||||
error: colors.red,
|
try {
|
||||||
info: colors.blue,
|
let installedNodeVersion = execSync("node -v", { encoding: "utf-8" }).replace("v", "").replace(/(?:\r\n|\r|\n)/g, "");
|
||||||
pass: colors.green
|
|
||||||
|
const staticData = await si.get({
|
||||||
|
system: "manufacturer, model, raspberry, virtual",
|
||||||
|
osInfo: "platform, distro, release, arch",
|
||||||
|
versions: "kernel, node, npm, pm2"
|
||||||
|
});
|
||||||
|
let systemDataString = "System information:";
|
||||||
|
systemDataString += `\n### SYSTEM: manufacturer: ${staticData["system"]["manufacturer"]}; model: ${staticData["system"]["model"]}; raspberry: ${staticData["system"]["raspberry"]}; virtual: ${staticData["system"]["virtual"]}`;
|
||||||
|
systemDataString += `\n### OS: platform: ${staticData["osInfo"]["platform"]}; distro: ${staticData["osInfo"]["distro"]}; release: ${staticData["osInfo"]["release"]}; arch: ${staticData["osInfo"]["arch"]}; kernel: ${staticData["versions"]["kernel"]}`;
|
||||||
|
systemDataString += `\n### VERSIONS: electron: ${process.versions.electron}; used node: ${staticData["versions"]["node"]}; installed node: ${installedNodeVersion}; npm: ${staticData["versions"]["npm"]}; pm2: ${staticData["versions"]["pm2"]}`;
|
||||||
|
systemDataString += `\n### OTHER: timeZone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}; ELECTRON_ENABLE_GPU: ${process.env.ELECTRON_ENABLE_GPU}`;
|
||||||
|
Log.info(systemDataString);
|
||||||
|
|
||||||
|
// Return is currently only for jest
|
||||||
|
return systemDataString;
|
||||||
|
} catch (e) {
|
||||||
|
Log.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
type ModuleProperties = {
|
type ModuleProperties = {
|
||||||
defaults?: object;
|
defaults?: object;
|
||||||
|
[key: string]: any;
|
||||||
start?(): void;
|
start?(): void;
|
||||||
|
getScripts?(): string[];
|
||||||
|
getStyles?(): string[];
|
||||||
|
getTranslations?(): object;
|
||||||
|
getDom?(): HTMLElement;
|
||||||
getHeader?(): string;
|
getHeader?(): string;
|
||||||
getTemplate?(): string;
|
getTemplate?(): string;
|
||||||
getTemplateData?(): object;
|
getTemplateData?(): object;
|
||||||
notificationReceived?(notification: string, payload: any, sender: object): void;
|
notificationReceived?(notification: string, payload: any, sender: object): void;
|
||||||
|
nunjucksEnvironment?(): void;
|
||||||
socketNotificationReceived?(notification: string, payload: any): void;
|
socketNotificationReceived?(notification: string, payload: any): void;
|
||||||
suspend?(): void;
|
suspend?(): void;
|
||||||
resume?(): void;
|
resume?(): void;
|
||||||
getDom?(): HTMLElement;
|
|
||||||
getStyles?(): string[];
|
|
||||||
[key: string]: any;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export declare const Module: {
|
export declare const Module: {
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
/* global NotificationFx */
|
/* global NotificationFx */
|
||||||
|
|
||||||
/* MagicMirror²
|
|
||||||
* Module: alert
|
|
||||||
*
|
|
||||||
* By Paul-Vincent Roll https://paulvincentroll.com/
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
Module.register("alert", {
|
Module.register("alert", {
|
||||||
alerts: {},
|
alerts: {},
|
||||||
|
|
||||||
@@ -17,15 +11,15 @@ Module.register("alert", {
|
|||||||
welcome_message: false // shown at startup
|
welcome_message: false // shown at startup
|
||||||
},
|
},
|
||||||
|
|
||||||
getScripts() {
|
getScripts () {
|
||||||
return ["notificationFx.js"];
|
return ["notificationFx.js"];
|
||||||
},
|
},
|
||||||
|
|
||||||
getStyles() {
|
getStyles () {
|
||||||
return ["font-awesome.css", this.file(`./styles/notificationFx.css`), this.file(`./styles/${this.config.position}.css`)];
|
return ["font-awesome.css", this.file("./styles/notificationFx.css"), this.file(`./styles/${this.config.position}.css`)];
|
||||||
},
|
},
|
||||||
|
|
||||||
getTranslations() {
|
getTranslations () {
|
||||||
return {
|
return {
|
||||||
bg: "translations/bg.json",
|
bg: "translations/bg.json",
|
||||||
da: "translations/da.json",
|
da: "translations/da.json",
|
||||||
@@ -40,11 +34,11 @@ Module.register("alert", {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
getTemplate(type) {
|
getTemplate (type) {
|
||||||
return `templates/${type}.njk`;
|
return `templates/${type}.njk`;
|
||||||
},
|
},
|
||||||
|
|
||||||
async start() {
|
async start () {
|
||||||
Log.info(`Starting module: ${this.name}`);
|
Log.info(`Starting module: ${this.name}`);
|
||||||
|
|
||||||
if (this.config.effect === "slide") {
|
if (this.config.effect === "slide") {
|
||||||
@@ -57,7 +51,7 @@ Module.register("alert", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
notificationReceived(notification, payload, sender) {
|
notificationReceived (notification, payload, sender) {
|
||||||
if (notification === "SHOW_ALERT") {
|
if (notification === "SHOW_ALERT") {
|
||||||
if (payload.type === "notification") {
|
if (payload.type === "notification") {
|
||||||
this.showNotification(payload);
|
this.showNotification(payload);
|
||||||
@@ -69,7 +63,7 @@ Module.register("alert", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async showNotification(notification) {
|
async showNotification (notification) {
|
||||||
const message = await this.renderMessage(notification.templateName || "notification", notification);
|
const message = await this.renderMessage(notification.templateName || "notification", notification);
|
||||||
|
|
||||||
new NotificationFx({
|
new NotificationFx({
|
||||||
@@ -80,7 +74,7 @@ Module.register("alert", {
|
|||||||
}).show();
|
}).show();
|
||||||
},
|
},
|
||||||
|
|
||||||
async showAlert(alert, sender) {
|
async showAlert (alert, sender) {
|
||||||
// If module already has an open alert close it
|
// If module already has an open alert close it
|
||||||
if (this.alerts[sender.name]) {
|
if (this.alerts[sender.name]) {
|
||||||
this.hideAlert(sender, false);
|
this.hideAlert(sender, false);
|
||||||
@@ -113,7 +107,7 @@ Module.register("alert", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
hideAlert(sender, close = true) {
|
hideAlert (sender, close = true) {
|
||||||
// Dismiss alert and remove from this.alerts
|
// Dismiss alert and remove from this.alerts
|
||||||
if (this.alerts[sender.name]) {
|
if (this.alerts[sender.name]) {
|
||||||
this.alerts[sender.name].dismiss(close);
|
this.alerts[sender.name].dismiss(close);
|
||||||
@@ -125,7 +119,7 @@ Module.register("alert", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
renderMessage(type, data) {
|
renderMessage (type, data) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
this.nunjucksEnvironment().render(this.getTemplate(type), data, function (err, res) {
|
this.nunjucksEnvironment().render(this.getTemplate(type), data, function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -137,7 +131,7 @@ Module.register("alert", {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleBlur(add = false) {
|
toggleBlur (add = false) {
|
||||||
const method = add ? "add" : "remove";
|
const method = add ? "add" : "remove";
|
||||||
const modules = document.querySelectorAll(".module");
|
const modules = document.querySelectorAll(".module");
|
||||||
for (const module of modules) {
|
for (const module of modules) {
|
||||||
|
|||||||
@@ -9,18 +9,17 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2014, Codrops
|
* Copyright 2014, Codrops
|
||||||
* https://tympanus.net/codrops/
|
* https://tympanus.net/codrops/
|
||||||
*
|
|
||||||
* @param {object} window The window object
|
* @param {object} window The window object
|
||||||
*/
|
*/
|
||||||
(function (window) {
|
(function (window) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extend one object with another one
|
* Extend one object with another one
|
||||||
*
|
|
||||||
* @param {object} a The object to extend
|
* @param {object} a The object to extend
|
||||||
* @param {object} b The object which extends the other, overwrites existing keys
|
* @param {object} b The object which extends the other, overwrites existing keys
|
||||||
* @returns {object} The merged object
|
* @returns {object} The merged object
|
||||||
*/
|
*/
|
||||||
function extend(a, b) {
|
function extend (a, b) {
|
||||||
for (let key in b) {
|
for (let key in b) {
|
||||||
if (b.hasOwnProperty(key)) {
|
if (b.hasOwnProperty(key)) {
|
||||||
a[key] = b[key];
|
a[key] = b[key];
|
||||||
@@ -31,11 +30,10 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* NotificationFx constructor
|
* NotificationFx constructor
|
||||||
*
|
|
||||||
* @param {object} options The configuration options
|
* @param {object} options The configuration options
|
||||||
* @class
|
* @class
|
||||||
*/
|
*/
|
||||||
function NotificationFx(options) {
|
function NotificationFx (options) {
|
||||||
this.options = extend({}, this.options);
|
this.options = extend({}, this.options);
|
||||||
extend(this.options, options);
|
extend(this.options, options);
|
||||||
this._init();
|
this._init();
|
||||||
@@ -66,10 +64,10 @@
|
|||||||
ttl: 6000,
|
ttl: 6000,
|
||||||
al_no: "ns-box",
|
al_no: "ns-box",
|
||||||
// callbacks
|
// callbacks
|
||||||
onClose: function () {
|
onClose () {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
onOpen: function () {
|
onOpen () {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -81,7 +79,7 @@
|
|||||||
// create HTML structure
|
// create HTML structure
|
||||||
this.ntf = document.createElement("div");
|
this.ntf = document.createElement("div");
|
||||||
this.ntf.className = `${this.options.al_no} ns-${this.options.layout} ns-effect-${this.options.effect} ns-type-${this.options.type}`;
|
this.ntf.className = `${this.options.al_no} ns-${this.options.layout} ns-effect-${this.options.effect} ns-type-${this.options.type}`;
|
||||||
let strinner = '<div class="ns-box-inner">';
|
let strinner = "<div class=\"ns-box-inner\">";
|
||||||
strinner += this.options.message;
|
strinner += this.options.message;
|
||||||
strinner += "</div>";
|
strinner += "</div>";
|
||||||
this.ntf.innerHTML = strinner;
|
this.ntf.innerHTML = strinner;
|
||||||
@@ -124,7 +122,6 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Dismiss the notification
|
* Dismiss the notification
|
||||||
*
|
|
||||||
* @param {boolean} [close] call the onClose callback at the end
|
* @param {boolean} [close] call the onClose callback at the end
|
||||||
*/
|
*/
|
||||||
NotificationFx.prototype.dismiss = function (close = true) {
|
NotificationFx.prototype.dismiss = function (close = true) {
|
||||||
@@ -157,4 +154,4 @@
|
|||||||
* Add to global namespace
|
* Add to global namespace
|
||||||
*/
|
*/
|
||||||
window.NotificationFx = NotificationFx;
|
window.NotificationFx = NotificationFx;
|
||||||
})(window);
|
}(window));
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
{% if imageUrl or imageFA %}
|
{% if imageUrl or imageFA %}
|
||||||
{% set imageHeight = imageHeight if imageHeight else "80px" %}
|
{% set imageHeight = imageHeight if imageHeight else "80px" %}
|
||||||
{% if imageUrl %}
|
{% if imageUrl %}
|
||||||
<img src="{{ imageUrl }}" height="{{ imageHeight }}" style="margin-bottom: 10px;"/>
|
<img src="{{ imageUrl }}"
|
||||||
{% else %}
|
height="{{ imageHeight }}"
|
||||||
<span class="bright fas fa-{{ imageFA }}" style='margin-bottom: 10px; font-size: {{ imageHeight }};'/></span>
|
style="margin-bottom: 10px" />
|
||||||
{% endif %}
|
{% else %}
|
||||||
<br/>
|
<span class="bright fas fa-{{ imageFA }}"
|
||||||
|
style="margin-bottom: 10px;
|
||||||
|
font-size: {{ imageHeight }}"></span>
|
||||||
|
{% endif %}
|
||||||
|
<br />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if title %}
|
{% if title %}
|
||||||
<span class="thin dimmed medium">{{ title if titleType == 'text' else title | safe }}</span>
|
<span class="thin dimmed medium">{{ title if titleType == 'text' else title | safe }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if message %}
|
{% if message %}
|
||||||
{% if title %}
|
{% if title %}<br />{% endif %}
|
||||||
<br/>
|
<span class="light bright small">{{ message if messageType == 'text' else message | safe }}</span>
|
||||||
{% endif %}
|
|
||||||
<span class="light bright small">{{ message if messageType == 'text' else message | safe }}</span>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
{% if title %}
|
{% if title %}
|
||||||
<span class="thin dimmed medium">{{ title if titleType == 'text' else title | safe }}</span>
|
<span class="thin dimmed medium">{{ title if titleType == 'text' else title | safe }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if message %}
|
{% if message %}
|
||||||
{% if title %}
|
{% if title %}<br />{% endif %}
|
||||||
<br/>
|
<span class="light bright small">{{ message if messageType == 'text' else message | safe }}</span>
|
||||||
{% endif %}
|
|
||||||
<span class="light bright small">{{ message if messageType == 'text' else message | safe }}</span>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
/* global cloneObject */
|
/* global CalendarUtils */
|
||||||
|
|
||||||
/* MagicMirror²
|
|
||||||
* Module: Calendar
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
Module.register("calendar", {
|
Module.register("calendar", {
|
||||||
// Define module defaults
|
// Define module defaults
|
||||||
defaults: {
|
defaults: {
|
||||||
@@ -21,13 +15,14 @@ Module.register("calendar", {
|
|||||||
defaultRepeatingCountTitle: "",
|
defaultRepeatingCountTitle: "",
|
||||||
maxTitleLength: 25,
|
maxTitleLength: 25,
|
||||||
maxLocationTitleLength: 25,
|
maxLocationTitleLength: 25,
|
||||||
wrapEvents: false, // wrap events to multiple lines breaking at maxTitleLength
|
wrapEvents: false, // Wrap events to multiple lines breaking at maxTitleLength
|
||||||
wrapLocationEvents: false,
|
wrapLocationEvents: false,
|
||||||
maxTitleLines: 3,
|
maxTitleLines: 3,
|
||||||
maxEventTitleLines: 3,
|
maxEventTitleLines: 3,
|
||||||
fetchInterval: 5 * 60 * 1000, // Update every 5 minutes.
|
fetchInterval: 60 * 60 * 1000, // Update every hour
|
||||||
animationSpeed: 2000,
|
animationSpeed: 2000,
|
||||||
fade: true,
|
fade: true,
|
||||||
|
fadePoint: 0.25, // Start on 1/4th of the list.
|
||||||
urgency: 7,
|
urgency: 7,
|
||||||
timeFormat: "relative",
|
timeFormat: "relative",
|
||||||
dateFormat: "MMM Do",
|
dateFormat: "MMM Do",
|
||||||
@@ -35,13 +30,13 @@ Module.register("calendar", {
|
|||||||
fullDayEventDateFormat: "MMM Do",
|
fullDayEventDateFormat: "MMM Do",
|
||||||
showEnd: false,
|
showEnd: false,
|
||||||
getRelative: 6,
|
getRelative: 6,
|
||||||
fadePoint: 0.25, // Start on 1/4th of the list.
|
|
||||||
hidePrivate: false,
|
hidePrivate: false,
|
||||||
hideOngoing: false,
|
hideOngoing: false,
|
||||||
hideTime: false,
|
hideTime: false,
|
||||||
|
hideDuplicates: true,
|
||||||
showTimeToday: false,
|
showTimeToday: false,
|
||||||
colored: false,
|
colored: false,
|
||||||
customEvents: [], // Array of {keyword: "", symbol: "", color: ""} where Keyword is a regexp and symbol/color are to be applied for matched
|
forceUseCurrentTime: false,
|
||||||
tableClass: "small",
|
tableClass: "small",
|
||||||
calendars: [
|
calendars: [
|
||||||
{
|
{
|
||||||
@@ -49,10 +44,11 @@ Module.register("calendar", {
|
|||||||
url: "https://www.calendarlabs.com/templates/ical/US-Holidays.ics"
|
url: "https://www.calendarlabs.com/templates/ical/US-Holidays.ics"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
titleReplace: {
|
customEvents: [
|
||||||
"De verjaardag van ": "",
|
// Array of {keyword: "", symbol: "", color: "", eventClass: ""} where Keyword is a regexp and symbol/color/eventClass are to be applied for matched
|
||||||
"'s birthday": ""
|
{ keyword: ".*", transform: { search: "De verjaardag van ", replace: "" } },
|
||||||
},
|
{ keyword: ".*", transform: { search: "'s birthday", replace: "" } }
|
||||||
|
],
|
||||||
locationTitleReplace: {
|
locationTitleReplace: {
|
||||||
"street ": ""
|
"street ": ""
|
||||||
},
|
},
|
||||||
@@ -67,23 +63,24 @@ Module.register("calendar", {
|
|||||||
coloredSymbol: false,
|
coloredSymbol: false,
|
||||||
coloredBackground: false,
|
coloredBackground: false,
|
||||||
limitDaysNeverSkip: false,
|
limitDaysNeverSkip: false,
|
||||||
flipDateHeaderTitle: false
|
flipDateHeaderTitle: false,
|
||||||
|
updateOnFetch: true
|
||||||
},
|
},
|
||||||
|
|
||||||
requiresVersion: "2.1.0",
|
requiresVersion: "2.1.0",
|
||||||
|
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
getStyles: function () {
|
getStyles () {
|
||||||
return ["calendar.css", "font-awesome.css"];
|
return ["calendar.css", "font-awesome.css"];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
getScripts: function () {
|
getScripts () {
|
||||||
return ["moment.js"];
|
return ["calendarutils.js", "moment.js"];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Define required translations.
|
// Define required translations.
|
||||||
getTranslations: function () {
|
getTranslations () {
|
||||||
// The translations for the default modules are defined in the core translation files.
|
// The translations for the default modules are defined in the core translation files.
|
||||||
// Therefore we can just return false. Otherwise we should have returned a dictionary.
|
// Therefore we can just return false. Otherwise we should have returned a dictionary.
|
||||||
// If you're trying to build your own module including translations, check out the documentation.
|
// If you're trying to build your own module including translations, check out the documentation.
|
||||||
@@ -91,24 +88,22 @@ Module.register("calendar", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Override start method.
|
// Override start method.
|
||||||
start: function () {
|
start () {
|
||||||
const ONE_MINUTE = 60 * 1000;
|
|
||||||
|
|
||||||
Log.info(`Starting module: ${this.name}`);
|
Log.info(`Starting module: ${this.name}`);
|
||||||
|
|
||||||
if (this.config.colored) {
|
if (this.config.colored) {
|
||||||
Log.warn("Your are using the deprecated config values 'colored'. Please switch to 'coloredSymbol' & 'coloredText'!");
|
Log.warn("Your are using the deprecated config values 'colored'. Please switch to 'coloredSymbol' & 'coloredText'!");
|
||||||
this.config.coloredText = true;
|
this.config.coloredText = true;
|
||||||
this.config.coloredSymbol = true;
|
this.config.coloredSymbol = true;
|
||||||
}
|
}
|
||||||
if (this.config.coloredSymbolOnly) {
|
if (this.config.coloredSymbolOnly) {
|
||||||
Log.warn("Your are using the deprecated config values 'coloredSymbolOnly'. Please switch to 'coloredSymbol' & 'coloredText'!");
|
Log.warn("Your are using the deprecated config values 'coloredSymbolOnly'. Please switch to 'coloredSymbol' & 'coloredText'!");
|
||||||
this.config.coloredText = false;
|
this.config.coloredText = false;
|
||||||
this.config.coloredSymbol = true;
|
this.config.coloredSymbol = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set locale.
|
// Set locale.
|
||||||
moment.updateLocale(config.language, this.getLocaleSpecification(config.timeFormat));
|
moment.updateLocale(config.language, CalendarUtils.getLocaleSpecification(config.timeFormat));
|
||||||
|
|
||||||
// clear data holder before start
|
// clear data holder before start
|
||||||
this.calendarData = {};
|
this.calendarData = {};
|
||||||
@@ -116,6 +111,9 @@ Module.register("calendar", {
|
|||||||
// indicate no data available yet
|
// indicate no data available yet
|
||||||
this.loaded = false;
|
this.loaded = false;
|
||||||
|
|
||||||
|
// data holder of calendar url. Avoid fade out/in on updateDom (one for each calendar update)
|
||||||
|
this.calendarDisplayer = {};
|
||||||
|
|
||||||
this.config.calendars.forEach((calendar) => {
|
this.config.calendars.forEach((calendar) => {
|
||||||
calendar.url = calendar.url.replace("webcal://", "http://");
|
calendar.url = calendar.url.replace("webcal://", "http://");
|
||||||
|
|
||||||
@@ -124,23 +122,25 @@ Module.register("calendar", {
|
|||||||
maximumNumberOfDays: calendar.maximumNumberOfDays,
|
maximumNumberOfDays: calendar.maximumNumberOfDays,
|
||||||
pastDaysCount: calendar.pastDaysCount,
|
pastDaysCount: calendar.pastDaysCount,
|
||||||
broadcastPastEvents: calendar.broadcastPastEvents,
|
broadcastPastEvents: calendar.broadcastPastEvents,
|
||||||
selfSignedCert: calendar.selfSignedCert
|
selfSignedCert: calendar.selfSignedCert,
|
||||||
|
excludedEvents: calendar.excludedEvents,
|
||||||
|
fetchInterval: calendar.fetchInterval
|
||||||
};
|
};
|
||||||
|
|
||||||
if (calendar.symbolClass === "undefined" || calendar.symbolClass === null) {
|
if (typeof calendar.symbolClass === "undefined" || calendar.symbolClass === null) {
|
||||||
calendarConfig.symbolClass = "";
|
calendarConfig.symbolClass = "";
|
||||||
}
|
}
|
||||||
if (calendar.titleClass === "undefined" || calendar.titleClass === null) {
|
if (typeof calendar.titleClass === "undefined" || calendar.titleClass === null) {
|
||||||
calendarConfig.titleClass = "";
|
calendarConfig.titleClass = "";
|
||||||
}
|
}
|
||||||
if (calendar.timeClass === "undefined" || calendar.timeClass === null) {
|
if (typeof calendar.timeClass === "undefined" || calendar.timeClass === null) {
|
||||||
calendarConfig.timeClass = "";
|
calendarConfig.timeClass = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// we check user and password here for backwards compatibility with old configs
|
// we check user and password here for backwards compatibility with old configs
|
||||||
if (calendar.user && calendar.pass) {
|
if (calendar.user && calendar.pass) {
|
||||||
Log.warn("Deprecation warning: Please update your calendar authentication configuration.");
|
Log.warn("Deprecation warning: Please update your calendar authentication configuration.");
|
||||||
Log.warn("https://github.com/MichMich/MagicMirror/tree/v2.1.2/modules/default/calendar#calendar-authentication-options");
|
Log.warn("https://docs.magicmirror.builders/modules/calendar.html#configuration-options");
|
||||||
calendar.auth = {
|
calendar.auth = {
|
||||||
user: calendar.user,
|
user: calendar.user,
|
||||||
pass: calendar.pass
|
pass: calendar.pass
|
||||||
@@ -152,17 +152,19 @@ Module.register("calendar", {
|
|||||||
this.addCalendar(calendar.url, calendar.auth, calendarConfig);
|
this.addCalendar(calendar.url, calendar.auth, calendarConfig);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Refresh the DOM every minute if needed: When using relative date format for events that start
|
// for backward compatibility titleReplace
|
||||||
// or end in less than an hour, the date shows minute granularity and we want to keep that accurate.
|
if (typeof this.config.titleReplace !== "undefined") {
|
||||||
setTimeout(() => {
|
Log.warn("Deprecation warning: Please consider upgrading your calendar titleReplace configuration to customEvents.");
|
||||||
setInterval(() => {
|
for (const [titlesearchstr, titlereplacestr] of Object.entries(this.config.titleReplace)) {
|
||||||
this.updateDom(1);
|
this.config.customEvents.push({ keyword: ".*", transform: { search: titlesearchstr, replace: titlereplacestr } });
|
||||||
}, ONE_MINUTE);
|
}
|
||||||
}, ONE_MINUTE - (new Date() % ONE_MINUTE));
|
}
|
||||||
|
|
||||||
|
this.selfUpdate();
|
||||||
},
|
},
|
||||||
|
|
||||||
// Override socket notification handler.
|
// Override socket notification handler.
|
||||||
socketNotificationReceived: function (notification, payload) {
|
socketNotificationReceived (notification, payload) {
|
||||||
if (notification === "FETCH_CALENDAR") {
|
if (notification === "FETCH_CALENDAR") {
|
||||||
this.sendSocketNotification(notification, { url: payload.url, id: this.identifier });
|
this.sendSocketNotification(notification, { url: payload.url, id: this.identifier });
|
||||||
}
|
}
|
||||||
@@ -180,6 +182,18 @@ Module.register("calendar", {
|
|||||||
if (this.config.broadcastEvents) {
|
if (this.config.broadcastEvents) {
|
||||||
this.broadcastEvents();
|
this.broadcastEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.config.updateOnFetch) {
|
||||||
|
if (this.calendarDisplayer[payload.url] === undefined) {
|
||||||
|
// calendar will never displayed, so display it
|
||||||
|
this.updateDom(this.config.animationSpeed);
|
||||||
|
// set this calendar as displayed
|
||||||
|
this.calendarDisplayer[payload.url] = true;
|
||||||
|
} else {
|
||||||
|
Log.debug("[Calendar] DOM not updated waiting self update()");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (notification === "CALENDAR_ERROR") {
|
} else if (notification === "CALENDAR_ERROR") {
|
||||||
let error_message = this.translate(payload.error_type);
|
let error_message = this.translate(payload.error_type);
|
||||||
@@ -190,8 +204,13 @@ Module.register("calendar", {
|
|||||||
this.updateDom(this.config.animationSpeed);
|
this.updateDom(this.config.animationSpeed);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
eventEndingWithinNextFullTimeUnit (event, ONE_DAY) {
|
||||||
|
const now = new Date();
|
||||||
|
return event.endDate - now <= ONE_DAY;
|
||||||
|
},
|
||||||
|
|
||||||
// Override dom generator.
|
// Override dom generator.
|
||||||
getDom: function () {
|
getDom () {
|
||||||
const ONE_SECOND = 1000; // 1,000 milliseconds
|
const ONE_SECOND = 1000; // 1,000 milliseconds
|
||||||
const ONE_MINUTE = ONE_SECOND * 60;
|
const ONE_MINUTE = ONE_SECOND * 60;
|
||||||
const ONE_HOUR = ONE_MINUTE * 60;
|
const ONE_HOUR = ONE_MINUTE * 60;
|
||||||
@@ -313,16 +332,21 @@ Module.register("calendar", {
|
|||||||
const thisYear = new Date(parseInt(event.startDate)).getFullYear(),
|
const thisYear = new Date(parseInt(event.startDate)).getFullYear(),
|
||||||
yearDiff = thisYear - event.firstYear;
|
yearDiff = thisYear - event.firstYear;
|
||||||
|
|
||||||
repeatingCountTitle = `, ${yearDiff}. ${repeatingCountTitle}`;
|
repeatingCountTitle = `, ${yearDiff} ${repeatingCountTitle}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Color events if custom color is specified
|
var transformedTitle = event.title;
|
||||||
|
|
||||||
|
// Color events if custom color or eventClass are specified, transform title if required
|
||||||
if (this.config.customEvents.length > 0) {
|
if (this.config.customEvents.length > 0) {
|
||||||
for (let ev in this.config.customEvents) {
|
for (let ev in this.config.customEvents) {
|
||||||
if (typeof this.config.customEvents[ev].color !== "undefined" && this.config.customEvents[ev].color !== "") {
|
let needle = new RegExp(this.config.customEvents[ev].keyword, "gi");
|
||||||
let needle = new RegExp(this.config.customEvents[ev].keyword, "gi");
|
if (needle.test(event.title)) {
|
||||||
if (needle.test(event.title)) {
|
if (typeof this.config.customEvents[ev].transform === "object") {
|
||||||
|
transformedTitle = CalendarUtils.titleTransform(transformedTitle, [this.config.customEvents[ev].transform]);
|
||||||
|
}
|
||||||
|
if (typeof this.config.customEvents[ev].color !== "undefined" && this.config.customEvents[ev].color !== "") {
|
||||||
// Respect parameter ColoredSymbolOnly also for custom events
|
// Respect parameter ColoredSymbolOnly also for custom events
|
||||||
if (this.config.coloredText) {
|
if (this.config.coloredText) {
|
||||||
eventWrapper.style.cssText = `color:${this.config.customEvents[ev].color}`;
|
eventWrapper.style.cssText = `color:${this.config.customEvents[ev].color}`;
|
||||||
@@ -331,13 +355,15 @@ Module.register("calendar", {
|
|||||||
if (this.config.displaySymbol && this.config.coloredSymbol) {
|
if (this.config.displaySymbol && this.config.coloredSymbol) {
|
||||||
symbolWrapper.style.cssText = `color:${this.config.customEvents[ev].color}`;
|
symbolWrapper.style.cssText = `color:${this.config.customEvents[ev].color}`;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
if (typeof this.config.customEvents[ev].eventClass !== "undefined" && this.config.customEvents[ev].eventClass !== "") {
|
||||||
|
eventWrapper.className += ` ${this.config.customEvents[ev].eventClass}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
titleWrapper.innerHTML = this.titleTransform(event.title, this.config.titleReplace, this.config.wrapEvents, this.config.maxTitleLength, this.config.maxTitleLines) + repeatingCountTitle;
|
titleWrapper.innerHTML = CalendarUtils.shorten(transformedTitle, this.config.maxTitleLength, this.config.wrapEvents, this.config.maxTitleLines) + repeatingCountTitle;
|
||||||
|
|
||||||
const titleClass = this.titleClassForUrl(event.url);
|
const titleClass = this.titleClassForUrl(event.url);
|
||||||
|
|
||||||
@@ -362,7 +388,7 @@ Module.register("calendar", {
|
|||||||
|
|
||||||
// Add endDate to dataheaders if showEnd is enabled
|
// Add endDate to dataheaders if showEnd is enabled
|
||||||
if (this.config.showEnd) {
|
if (this.config.showEnd) {
|
||||||
timeWrapper.innerHTML += ` - ${this.capFirst(moment(event.endDate, "x").format("LT"))}`;
|
timeWrapper.innerHTML += ` - ${CalendarUtils.capFirst(moment(event.endDate, "x").format("LT"))}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
eventWrapper.appendChild(timeWrapper);
|
eventWrapper.appendChild(timeWrapper);
|
||||||
@@ -378,20 +404,20 @@ Module.register("calendar", {
|
|||||||
|
|
||||||
if (this.config.timeFormat === "absolute") {
|
if (this.config.timeFormat === "absolute") {
|
||||||
// Use dateFormat
|
// Use dateFormat
|
||||||
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").format(this.config.dateFormat));
|
timeWrapper.innerHTML = CalendarUtils.capFirst(moment(event.startDate, "x").format(this.config.dateFormat));
|
||||||
// Add end time if showEnd
|
// Add end time if showEnd
|
||||||
if (this.config.showEnd) {
|
if (this.config.showEnd) {
|
||||||
timeWrapper.innerHTML += "-";
|
timeWrapper.innerHTML += "-";
|
||||||
timeWrapper.innerHTML += this.capFirst(moment(event.endDate, "x").format(this.config.dateEndFormat));
|
timeWrapper.innerHTML += CalendarUtils.capFirst(moment(event.endDate, "x").format(this.config.dateEndFormat));
|
||||||
}
|
}
|
||||||
// For full day events we use the fullDayEventDateFormat
|
// For full day events we use the fullDayEventDateFormat
|
||||||
if (event.fullDayEvent) {
|
if (event.fullDayEvent) {
|
||||||
//subtract one second so that fullDayEvents end at 23:59:59, and not at 0:00:00 one the next day
|
//subtract one second so that fullDayEvents end at 23:59:59, and not at 0:00:00 one the next day
|
||||||
event.endDate -= ONE_SECOND;
|
event.endDate -= ONE_SECOND;
|
||||||
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").format(this.config.fullDayEventDateFormat));
|
timeWrapper.innerHTML = CalendarUtils.capFirst(moment(event.startDate, "x").format(this.config.fullDayEventDateFormat));
|
||||||
} else if (this.config.getRelative > 0 && event.startDate < now) {
|
} else if (this.config.getRelative > 0 && event.startDate < now) {
|
||||||
// Ongoing and getRelative is set
|
// Ongoing and getRelative is set
|
||||||
timeWrapper.innerHTML = this.capFirst(
|
timeWrapper.innerHTML = CalendarUtils.capFirst(
|
||||||
this.translate("RUNNING", {
|
this.translate("RUNNING", {
|
||||||
fallback: `${this.translate("RUNNING")} {timeUntilEnd}`,
|
fallback: `${this.translate("RUNNING")} {timeUntilEnd}`,
|
||||||
timeUntilEnd: moment(event.endDate, "x").fromNow(true)
|
timeUntilEnd: moment(event.endDate, "x").fromNow(true)
|
||||||
@@ -399,30 +425,30 @@ Module.register("calendar", {
|
|||||||
);
|
);
|
||||||
} else if (this.config.urgency > 0 && event.startDate - now < this.config.urgency * ONE_DAY) {
|
} else if (this.config.urgency > 0 && event.startDate - now < this.config.urgency * ONE_DAY) {
|
||||||
// Within urgency days
|
// Within urgency days
|
||||||
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow());
|
timeWrapper.innerHTML = CalendarUtils.capFirst(moment(event.startDate, "x").fromNow());
|
||||||
}
|
}
|
||||||
if (event.fullDayEvent && this.config.nextDaysRelative) {
|
if (event.fullDayEvent && this.config.nextDaysRelative) {
|
||||||
// Full days events within the next two days
|
// Full days events within the next two days
|
||||||
if (event.today) {
|
if (event.today) {
|
||||||
timeWrapper.innerHTML = this.capFirst(this.translate("TODAY"));
|
timeWrapper.innerHTML = CalendarUtils.capFirst(this.translate("TODAY"));
|
||||||
} else if (event.yesterday) {
|
} else if (event.yesterday) {
|
||||||
timeWrapper.innerHTML = this.capFirst(this.translate("YESTERDAY"));
|
timeWrapper.innerHTML = CalendarUtils.capFirst(this.translate("YESTERDAY"));
|
||||||
} else if (event.startDate - now < ONE_DAY && event.startDate - now > 0) {
|
} else if (event.startDate - now < ONE_DAY && event.startDate - now > 0) {
|
||||||
timeWrapper.innerHTML = this.capFirst(this.translate("TOMORROW"));
|
timeWrapper.innerHTML = CalendarUtils.capFirst(this.translate("TOMORROW"));
|
||||||
} else if (event.startDate - now < 2 * ONE_DAY && event.startDate - now > 0) {
|
} else if (event.startDate - now < 2 * ONE_DAY && event.startDate - now > 0) {
|
||||||
if (this.translate("DAYAFTERTOMORROW") !== "DAYAFTERTOMORROW") {
|
if (this.translate("DAYAFTERTOMORROW") !== "DAYAFTERTOMORROW") {
|
||||||
timeWrapper.innerHTML = this.capFirst(this.translate("DAYAFTERTOMORROW"));
|
timeWrapper.innerHTML = CalendarUtils.capFirst(this.translate("DAYAFTERTOMORROW"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Show relative times
|
// Show relative times
|
||||||
if (event.startDate >= now || (event.fullDayEvent && event.today)) {
|
if (event.startDate >= now || (event.fullDayEvent && this.eventEndingWithinNextFullTimeUnit(event, ONE_DAY))) {
|
||||||
// Use relative time
|
// Use relative time
|
||||||
if (!this.config.hideTime && !event.fullDayEvent) {
|
if (!this.config.hideTime && !event.fullDayEvent) {
|
||||||
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").calendar(null, { sameElse: this.config.dateFormat }));
|
timeWrapper.innerHTML = CalendarUtils.capFirst(moment(event.startDate, "x").calendar(null, { sameElse: this.config.dateFormat }));
|
||||||
} else {
|
} else {
|
||||||
timeWrapper.innerHTML = this.capFirst(
|
timeWrapper.innerHTML = CalendarUtils.capFirst(
|
||||||
moment(event.startDate, "x").calendar(null, {
|
moment(event.startDate, "x").calendar(null, {
|
||||||
sameDay: this.config.showTimeToday ? "LT" : `[${this.translate("TODAY")}]`,
|
sameDay: this.config.showTimeToday ? "LT" : `[${this.translate("TODAY")}]`,
|
||||||
nextDay: `[${this.translate("TOMORROW")}]`,
|
nextDay: `[${this.translate("TOMORROW")}]`,
|
||||||
@@ -433,28 +459,28 @@ Module.register("calendar", {
|
|||||||
}
|
}
|
||||||
if (event.fullDayEvent) {
|
if (event.fullDayEvent) {
|
||||||
// Full days events within the next two days
|
// Full days events within the next two days
|
||||||
if (event.today) {
|
if (event.today || (event.fullDayEvent && this.eventEndingWithinNextFullTimeUnit(event, ONE_DAY))) {
|
||||||
timeWrapper.innerHTML = this.capFirst(this.translate("TODAY"));
|
timeWrapper.innerHTML = CalendarUtils.capFirst(this.translate("TODAY"));
|
||||||
} else if (event.dayBeforeYesterday) {
|
} else if (event.dayBeforeYesterday) {
|
||||||
if (this.translate("DAYBEFOREYESTERDAY") !== "DAYBEFOREYESTERDAY") {
|
if (this.translate("DAYBEFOREYESTERDAY") !== "DAYBEFOREYESTERDAY") {
|
||||||
timeWrapper.innerHTML = this.capFirst(this.translate("DAYBEFOREYESTERDAY"));
|
timeWrapper.innerHTML = CalendarUtils.capFirst(this.translate("DAYBEFOREYESTERDAY"));
|
||||||
}
|
}
|
||||||
} else if (event.yesterday) {
|
} else if (event.yesterday) {
|
||||||
timeWrapper.innerHTML = this.capFirst(this.translate("YESTERDAY"));
|
timeWrapper.innerHTML = CalendarUtils.capFirst(this.translate("YESTERDAY"));
|
||||||
} else if (event.startDate - now < ONE_DAY && event.startDate - now > 0) {
|
} else if (event.startDate - now < ONE_DAY && event.startDate - now > 0) {
|
||||||
timeWrapper.innerHTML = this.capFirst(this.translate("TOMORROW"));
|
timeWrapper.innerHTML = CalendarUtils.capFirst(this.translate("TOMORROW"));
|
||||||
} else if (event.startDate - now < 2 * ONE_DAY && event.startDate - now > 0) {
|
} else if (event.startDate - now < 2 * ONE_DAY && event.startDate - now > 0) {
|
||||||
if (this.translate("DAYAFTERTOMORROW") !== "DAYAFTERTOMORROW") {
|
if (this.translate("DAYAFTERTOMORROW") !== "DAYAFTERTOMORROW") {
|
||||||
timeWrapper.innerHTML = this.capFirst(this.translate("DAYAFTERTOMORROW"));
|
timeWrapper.innerHTML = CalendarUtils.capFirst(this.translate("DAYAFTERTOMORROW"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (event.startDate - now < this.config.getRelative * ONE_HOUR) {
|
} else if (event.startDate - now < this.config.getRelative * ONE_HOUR) {
|
||||||
// If event is within getRelative hours, display 'in xxx' time format or moment.fromNow()
|
// If event is within getRelative hours, display 'in xxx' time format or moment.fromNow()
|
||||||
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow());
|
timeWrapper.innerHTML = CalendarUtils.capFirst(moment(event.startDate, "x").fromNow());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Ongoing event
|
// Ongoing event
|
||||||
timeWrapper.innerHTML = this.capFirst(
|
timeWrapper.innerHTML = CalendarUtils.capFirst(
|
||||||
this.translate("RUNNING", {
|
this.translate("RUNNING", {
|
||||||
fallback: `${this.translate("RUNNING")} {timeUntilEnd}`,
|
fallback: `${this.translate("RUNNING")} {timeUntilEnd}`,
|
||||||
timeUntilEnd: moment(event.endDate, "x").fromNow(true)
|
timeUntilEnd: moment(event.endDate, "x").fromNow(true)
|
||||||
@@ -503,7 +529,9 @@ Module.register("calendar", {
|
|||||||
const descCell = document.createElement("td");
|
const descCell = document.createElement("td");
|
||||||
descCell.className = "location";
|
descCell.className = "location";
|
||||||
descCell.colSpan = "2";
|
descCell.colSpan = "2";
|
||||||
descCell.innerHTML = this.titleTransform(event.location, this.config.locationTitleReplace, this.config.wrapLocationEvents, this.config.maxLocationTitleLength, this.config.maxEventTitleLines);
|
|
||||||
|
const transformedTitle = CalendarUtils.titleTransform(event.location, this.config.locationTitleReplace);
|
||||||
|
descCell.innerHTML = CalendarUtils.shorten(transformedTitle, this.config.maxLocationTitleLength, this.config.wrapLocationEvents, this.config.maxEventTitleLines);
|
||||||
locationRow.appendChild(descCell);
|
locationRow.appendChild(descCell);
|
||||||
|
|
||||||
wrapper.appendChild(locationRow);
|
wrapper.appendChild(locationRow);
|
||||||
@@ -519,35 +547,12 @@ Module.register("calendar", {
|
|||||||
return wrapper;
|
return wrapper;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* This function accepts a number (either 12 or 24) and returns a moment.js LocaleSpecification with the
|
|
||||||
* corresponding timeformat to be used in the calendar display. If no number is given (or otherwise invalid input)
|
|
||||||
* it will a localeSpecification object with the system locale time format.
|
|
||||||
*
|
|
||||||
* @param {number} timeFormat Specifies either 12 or 24 hour time format
|
|
||||||
* @returns {moment.LocaleSpecification} formatted time
|
|
||||||
*/
|
|
||||||
getLocaleSpecification: function (timeFormat) {
|
|
||||||
switch (timeFormat) {
|
|
||||||
case 12: {
|
|
||||||
return { longDateFormat: { LT: "h:mm A" } };
|
|
||||||
}
|
|
||||||
case 24: {
|
|
||||||
return { longDateFormat: { LT: "HH:mm" } };
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
return { longDateFormat: { LT: moment.localeData().longDateFormat("LT") } };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if this config contains the calendar url.
|
* Checks if this config contains the calendar url.
|
||||||
*
|
|
||||||
* @param {string} url The calendar url
|
* @param {string} url The calendar url
|
||||||
* @returns {boolean} True if the calendar config contains the url, False otherwise
|
* @returns {boolean} True if the calendar config contains the url, False otherwise
|
||||||
*/
|
*/
|
||||||
hasCalendarURL: function (url) {
|
hasCalendarURL (url) {
|
||||||
for (const calendar of this.config.calendars) {
|
for (const calendar of this.config.calendars) {
|
||||||
if (calendar.url === url) {
|
if (calendar.url === url) {
|
||||||
return true;
|
return true;
|
||||||
@@ -559,19 +564,25 @@ Module.register("calendar", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the sorted list of all events.
|
* Creates the sorted list of all events.
|
||||||
*
|
|
||||||
* @param {boolean} limitNumberOfEntries Whether to filter returned events for display.
|
* @param {boolean} limitNumberOfEntries Whether to filter returned events for display.
|
||||||
* @returns {object[]} Array with events.
|
* @returns {object[]} Array with events.
|
||||||
*/
|
*/
|
||||||
createEventList: function (limitNumberOfEntries) {
|
createEventList (limitNumberOfEntries) {
|
||||||
const ONE_SECOND = 1000; // 1,000 milliseconds
|
const ONE_SECOND = 1000; // 1,000 milliseconds
|
||||||
const ONE_MINUTE = ONE_SECOND * 60;
|
const ONE_MINUTE = ONE_SECOND * 60;
|
||||||
const ONE_HOUR = ONE_MINUTE * 60;
|
const ONE_HOUR = ONE_MINUTE * 60;
|
||||||
const ONE_DAY = ONE_HOUR * 24;
|
const ONE_DAY = ONE_HOUR * 24;
|
||||||
|
|
||||||
const now = new Date();
|
let now, today, future;
|
||||||
const today = moment().startOf("day");
|
if (this.config.forceUseCurrentTime || this.defaults.forceUseCurrentTime) {
|
||||||
const future = moment().startOf("day").add(this.config.maximumNumberOfDays, "days").toDate();
|
now = new Date();
|
||||||
|
today = moment().startOf("day");
|
||||||
|
future = moment().startOf("day").add(this.config.maximumNumberOfDays, "days").toDate();
|
||||||
|
} else {
|
||||||
|
now = new Date(Date.now()); // Can use overridden time
|
||||||
|
today = moment(now).startOf("day");
|
||||||
|
future = moment(now).startOf("day").add(this.config.maximumNumberOfDays, "days").toDate();
|
||||||
|
}
|
||||||
let events = [];
|
let events = [];
|
||||||
|
|
||||||
for (const calendarUrl in this.calendarData) {
|
for (const calendarUrl in this.calendarData) {
|
||||||
@@ -592,13 +603,14 @@ Module.register("calendar", {
|
|||||||
if (this.config.hideOngoing && event.startDate < now) {
|
if (this.config.hideOngoing && event.startDate < now) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (this.listContainsEvent(events, event)) {
|
if (this.config.hideDuplicates && this.listContainsEvent(events, event)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (--remainingEntries < 0) {
|
if (--remainingEntries < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
event.url = calendarUrl;
|
event.url = calendarUrl;
|
||||||
event.today = event.startDate >= today && event.startDate < today + ONE_DAY;
|
event.today = event.startDate >= today && event.startDate < today + ONE_DAY;
|
||||||
event.dayBeforeYesterday = event.startDate >= today - ONE_DAY * 2 && event.startDate < today - ONE_DAY;
|
event.dayBeforeYesterday = event.startDate >= today - ONE_DAY * 2 && event.startDate < today - ONE_DAY;
|
||||||
@@ -612,7 +624,12 @@ Module.register("calendar", {
|
|||||||
const maxCount = Math.ceil((event.endDate - 1 - moment(event.startDate, "x").endOf("day").format("x")) / ONE_DAY) + 1;
|
const maxCount = Math.ceil((event.endDate - 1 - moment(event.startDate, "x").endOf("day").format("x")) / ONE_DAY) + 1;
|
||||||
if (this.config.sliceMultiDayEvents && maxCount > 1) {
|
if (this.config.sliceMultiDayEvents && maxCount > 1) {
|
||||||
const splitEvents = [];
|
const splitEvents = [];
|
||||||
let midnight = moment(event.startDate, "x").clone().startOf("day").add(1, "day").format("x");
|
let midnight
|
||||||
|
= moment(event.startDate, "x")
|
||||||
|
.clone()
|
||||||
|
.startOf("day")
|
||||||
|
.add(1, "day")
|
||||||
|
.format("x");
|
||||||
let count = 1;
|
let count = 1;
|
||||||
while (event.endDate > midnight) {
|
while (event.endDate > midnight) {
|
||||||
const thisEvent = JSON.parse(JSON.stringify(event)); // clone object
|
const thisEvent = JSON.parse(JSON.stringify(event)); // clone object
|
||||||
@@ -681,9 +698,9 @@ Module.register("calendar", {
|
|||||||
return events.slice(0, this.config.maximumEntries);
|
return events.slice(0, this.config.maximumEntries);
|
||||||
},
|
},
|
||||||
|
|
||||||
listContainsEvent: function (eventList, event) {
|
listContainsEvent (eventList, event) {
|
||||||
for (const evt of eventList) {
|
for (const evt of eventList) {
|
||||||
if (evt.title === event.title && parseInt(evt.startDate) === parseInt(event.startDate)) {
|
if (evt.title === event.title && parseInt(evt.startDate) === parseInt(event.startDate) && parseInt(evt.endDate) === parseInt(event.endDate)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -692,12 +709,11 @@ Module.register("calendar", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests node helper to add calendar url.
|
* Requests node helper to add calendar url.
|
||||||
*
|
|
||||||
* @param {string} url The calendar url to add
|
* @param {string} url The calendar url to add
|
||||||
* @param {object} auth The authentication method and credentials
|
* @param {object} auth The authentication method and credentials
|
||||||
* @param {object} calendarConfig The config of the specific calendar
|
* @param {object} calendarConfig The config of the specific calendar
|
||||||
*/
|
*/
|
||||||
addCalendar: function (url, auth, calendarConfig) {
|
addCalendar (url, auth, calendarConfig) {
|
||||||
this.sendSocketNotification("ADD_CALENDAR", {
|
this.sendSocketNotification("ADD_CALENDAR", {
|
||||||
id: this.identifier,
|
id: this.identifier,
|
||||||
url: url,
|
url: url,
|
||||||
@@ -705,7 +721,7 @@ Module.register("calendar", {
|
|||||||
maximumEntries: calendarConfig.maximumEntries || this.config.maximumEntries,
|
maximumEntries: calendarConfig.maximumEntries || this.config.maximumEntries,
|
||||||
maximumNumberOfDays: calendarConfig.maximumNumberOfDays || this.config.maximumNumberOfDays,
|
maximumNumberOfDays: calendarConfig.maximumNumberOfDays || this.config.maximumNumberOfDays,
|
||||||
pastDaysCount: calendarConfig.pastDaysCount || this.config.pastDaysCount,
|
pastDaysCount: calendarConfig.pastDaysCount || this.config.pastDaysCount,
|
||||||
fetchInterval: this.config.fetchInterval,
|
fetchInterval: calendarConfig.fetchInterval || this.config.fetchInterval,
|
||||||
symbolClass: calendarConfig.symbolClass,
|
symbolClass: calendarConfig.symbolClass,
|
||||||
titleClass: calendarConfig.titleClass,
|
titleClass: calendarConfig.titleClass,
|
||||||
timeClass: calendarConfig.timeClass,
|
timeClass: calendarConfig.timeClass,
|
||||||
@@ -717,11 +733,10 @@ Module.register("calendar", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the symbols for a specific event.
|
* Retrieves the symbols for a specific event.
|
||||||
*
|
|
||||||
* @param {object} event Event to look for.
|
* @param {object} event Event to look for.
|
||||||
* @returns {string[]} The symbols
|
* @returns {string[]} The symbols
|
||||||
*/
|
*/
|
||||||
symbolsForEvent: function (event) {
|
symbolsForEvent (event) {
|
||||||
let symbols = this.getCalendarPropertyAsArray(event.url, "symbol", this.config.defaultSymbol);
|
let symbols = this.getCalendarPropertyAsArray(event.url, "symbol", this.config.defaultSymbol);
|
||||||
|
|
||||||
if (event.recurringEvent === true && this.hasCalendarProperty(event.url, "recurringSymbol")) {
|
if (event.recurringEvent === true && this.hasCalendarProperty(event.url, "recurringSymbol")) {
|
||||||
@@ -748,7 +763,7 @@ Module.register("calendar", {
|
|||||||
return symbols;
|
return symbols;
|
||||||
},
|
},
|
||||||
|
|
||||||
mergeUnique: function (arr1, arr2) {
|
mergeUnique (arr1, arr2) {
|
||||||
return arr1.concat(
|
return arr1.concat(
|
||||||
arr2.filter(function (item) {
|
arr2.filter(function (item) {
|
||||||
return arr1.indexOf(item) === -1;
|
return arr1.indexOf(item) === -1;
|
||||||
@@ -758,94 +773,85 @@ Module.register("calendar", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the symbolClass for a specific calendar url.
|
* Retrieves the symbolClass for a specific calendar url.
|
||||||
*
|
|
||||||
* @param {string} url The calendar url
|
* @param {string} url The calendar url
|
||||||
* @returns {string} The class to be used for the symbols of the calendar
|
* @returns {string} The class to be used for the symbols of the calendar
|
||||||
*/
|
*/
|
||||||
symbolClassForUrl: function (url) {
|
symbolClassForUrl (url) {
|
||||||
return this.getCalendarProperty(url, "symbolClass", "");
|
return this.getCalendarProperty(url, "symbolClass", "");
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the titleClass for a specific calendar url.
|
* Retrieves the titleClass for a specific calendar url.
|
||||||
*
|
|
||||||
* @param {string} url The calendar url
|
* @param {string} url The calendar url
|
||||||
* @returns {string} The class to be used for the title of the calendar
|
* @returns {string} The class to be used for the title of the calendar
|
||||||
*/
|
*/
|
||||||
titleClassForUrl: function (url) {
|
titleClassForUrl (url) {
|
||||||
return this.getCalendarProperty(url, "titleClass", "");
|
return this.getCalendarProperty(url, "titleClass", "");
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the timeClass for a specific calendar url.
|
* Retrieves the timeClass for a specific calendar url.
|
||||||
*
|
|
||||||
* @param {string} url The calendar url
|
* @param {string} url The calendar url
|
||||||
* @returns {string} The class to be used for the time of the calendar
|
* @returns {string} The class to be used for the time of the calendar
|
||||||
*/
|
*/
|
||||||
timeClassForUrl: function (url) {
|
timeClassForUrl (url) {
|
||||||
return this.getCalendarProperty(url, "timeClass", "");
|
return this.getCalendarProperty(url, "timeClass", "");
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the calendar name for a specific calendar url.
|
* Retrieves the calendar name for a specific calendar url.
|
||||||
*
|
|
||||||
* @param {string} url The calendar url
|
* @param {string} url The calendar url
|
||||||
* @returns {string} The name of the calendar
|
* @returns {string} The name of the calendar
|
||||||
*/
|
*/
|
||||||
calendarNameForUrl: function (url) {
|
calendarNameForUrl (url) {
|
||||||
return this.getCalendarProperty(url, "name", "");
|
return this.getCalendarProperty(url, "name", "");
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the color for a specific calendar url.
|
* Retrieves the color for a specific calendar url.
|
||||||
*
|
|
||||||
* @param {string} url The calendar url
|
* @param {string} url The calendar url
|
||||||
* @param {boolean} isBg Determines if we fetch the bgColor or not
|
* @param {boolean} isBg Determines if we fetch the bgColor or not
|
||||||
* @returns {string} The color
|
* @returns {string} The color
|
||||||
*/
|
*/
|
||||||
colorForUrl: function (url, isBg) {
|
colorForUrl (url, isBg) {
|
||||||
return this.getCalendarProperty(url, isBg ? "bgColor" : "color", "#fff");
|
return this.getCalendarProperty(url, isBg ? "bgColor" : "color", "#fff");
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the count title for a specific calendar url.
|
* Retrieves the count title for a specific calendar url.
|
||||||
*
|
|
||||||
* @param {string} url The calendar url
|
* @param {string} url The calendar url
|
||||||
* @returns {string} The title
|
* @returns {string} The title
|
||||||
*/
|
*/
|
||||||
countTitleForUrl: function (url) {
|
countTitleForUrl (url) {
|
||||||
return this.getCalendarProperty(url, "repeatingCountTitle", this.config.defaultRepeatingCountTitle);
|
return this.getCalendarProperty(url, "repeatingCountTitle", this.config.defaultRepeatingCountTitle);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the maximum entry count for a specific calendar url.
|
* Retrieves the maximum entry count for a specific calendar url.
|
||||||
*
|
|
||||||
* @param {string} url The calendar url
|
* @param {string} url The calendar url
|
||||||
* @returns {number} The maximum entry count
|
* @returns {number} The maximum entry count
|
||||||
*/
|
*/
|
||||||
maximumEntriesForUrl: function (url) {
|
maximumEntriesForUrl (url) {
|
||||||
return this.getCalendarProperty(url, "maximumEntries", this.config.maximumEntries);
|
return this.getCalendarProperty(url, "maximumEntries", this.config.maximumEntries);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the maximum count of past days which events of should be displayed for a specific calendar url.
|
* Retrieves the maximum count of past days which events of should be displayed for a specific calendar url.
|
||||||
*
|
|
||||||
* @param {string} url The calendar url
|
* @param {string} url The calendar url
|
||||||
* @returns {number} The maximum past days count
|
* @returns {number} The maximum past days count
|
||||||
*/
|
*/
|
||||||
maximumPastDaysForUrl: function (url) {
|
maximumPastDaysForUrl (url) {
|
||||||
return this.getCalendarProperty(url, "pastDaysCount", this.config.pastDaysCount);
|
return this.getCalendarProperty(url, "pastDaysCount", this.config.pastDaysCount);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to retrieve the property for a specific calendar url.
|
* Helper method to retrieve the property for a specific calendar url.
|
||||||
*
|
|
||||||
* @param {string} url The calendar url
|
* @param {string} url The calendar url
|
||||||
* @param {string} property The property to look for
|
* @param {string} property The property to look for
|
||||||
* @param {string} defaultValue The value if the property is not found
|
* @param {string} defaultValue The value if the property is not found
|
||||||
* @returns {*} The property
|
* @returns {*} The property
|
||||||
*/
|
*/
|
||||||
getCalendarProperty: function (url, property, defaultValue) {
|
getCalendarProperty (url, property, defaultValue) {
|
||||||
for (const calendar of this.config.calendars) {
|
for (const calendar of this.config.calendars) {
|
||||||
if (calendar.url === url && calendar.hasOwnProperty(property)) {
|
if (calendar.url === url && calendar.hasOwnProperty(property)) {
|
||||||
return calendar[property];
|
return calendar[property];
|
||||||
@@ -855,7 +861,7 @@ Module.register("calendar", {
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
},
|
},
|
||||||
|
|
||||||
getCalendarPropertyAsArray: function (url, property, defaultValue) {
|
getCalendarPropertyAsArray (url, property, defaultValue) {
|
||||||
let p = this.getCalendarProperty(url, property, defaultValue);
|
let p = this.getCalendarProperty(url, property, defaultValue);
|
||||||
if (property === "symbol" || property === "recurringSymbol" || property === "fullDaySymbol") {
|
if (property === "symbol" || property === "recurringSymbol" || property === "fullDaySymbol") {
|
||||||
const className = this.getCalendarProperty(url, "symbolClassName", this.config.defaultSymbolClassName);
|
const className = this.getCalendarProperty(url, "symbolClassName", this.config.defaultSymbolClassName);
|
||||||
@@ -866,107 +872,15 @@ Module.register("calendar", {
|
|||||||
return p;
|
return p;
|
||||||
},
|
},
|
||||||
|
|
||||||
hasCalendarProperty: function (url, property) {
|
hasCalendarProperty (url, property) {
|
||||||
return !!this.getCalendarProperty(url, property, undefined);
|
return !!this.getCalendarProperty(url, property, undefined);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Shortens a string if it's longer than maxLength and add a ellipsis to the end
|
|
||||||
*
|
|
||||||
* @param {string} string Text string to shorten
|
|
||||||
* @param {number} maxLength The max length of the string
|
|
||||||
* @param {boolean} wrapEvents Wrap the text after the line has reached maxLength
|
|
||||||
* @param {number} maxTitleLines The max number of vertical lines before cutting event title
|
|
||||||
* @returns {string} The shortened string
|
|
||||||
*/
|
|
||||||
shorten: function (string, maxLength, wrapEvents, maxTitleLines) {
|
|
||||||
if (typeof string !== "string") {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wrapEvents === true) {
|
|
||||||
const words = string.split(" ");
|
|
||||||
let temp = "";
|
|
||||||
let currentLine = "";
|
|
||||||
let line = 0;
|
|
||||||
|
|
||||||
for (let i = 0; i < words.length; i++) {
|
|
||||||
const word = words[i];
|
|
||||||
if (currentLine.length + word.length < (typeof maxLength === "number" ? maxLength : 25) - 1) {
|
|
||||||
// max - 1 to account for a space
|
|
||||||
currentLine += `${word} `;
|
|
||||||
} else {
|
|
||||||
line++;
|
|
||||||
if (line > maxTitleLines - 1) {
|
|
||||||
if (i < words.length) {
|
|
||||||
currentLine += "…";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentLine.length > 0) {
|
|
||||||
temp += `${currentLine}<br>${word} `;
|
|
||||||
} else {
|
|
||||||
temp += `${word}<br>`;
|
|
||||||
}
|
|
||||||
currentLine = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (temp + currentLine).trim();
|
|
||||||
} else {
|
|
||||||
if (maxLength && typeof maxLength === "number" && string.length > maxLength) {
|
|
||||||
return `${string.trim().slice(0, maxLength)}…`;
|
|
||||||
} else {
|
|
||||||
return string.trim();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Capitalize the first letter of a string
|
|
||||||
*
|
|
||||||
* @param {string} string The string to capitalize
|
|
||||||
* @returns {string} The capitalized string
|
|
||||||
*/
|
|
||||||
capFirst: function (string) {
|
|
||||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transforms the title of an event for usage.
|
|
||||||
* Replaces parts of the text as defined in config.titleReplace.
|
|
||||||
* Shortens title based on config.maxTitleLength and config.wrapEvents
|
|
||||||
*
|
|
||||||
* @param {string} title The title to transform.
|
|
||||||
* @param {object} titleReplace Pairs of strings to be replaced in the title
|
|
||||||
* @param {boolean} wrapEvents Wrap the text after the line has reached maxLength
|
|
||||||
* @param {number} maxTitleLength The max length of the string
|
|
||||||
* @param {number} maxTitleLines The max number of vertical lines before cutting event title
|
|
||||||
* @returns {string} The transformed title.
|
|
||||||
*/
|
|
||||||
titleTransform: function (title, titleReplace, wrapEvents, maxTitleLength, maxTitleLines) {
|
|
||||||
for (let needle in titleReplace) {
|
|
||||||
const replacement = titleReplace[needle];
|
|
||||||
|
|
||||||
const regParts = needle.match(/^\/(.+)\/([gim]*)$/);
|
|
||||||
if (regParts) {
|
|
||||||
// the parsed pattern is a regexp.
|
|
||||||
needle = new RegExp(regParts[1], regParts[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
title = title.replace(needle, replacement);
|
|
||||||
}
|
|
||||||
|
|
||||||
title = this.shorten(title, maxTitleLength, wrapEvents, maxTitleLines);
|
|
||||||
return title;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Broadcasts the events to all other modules for reuse.
|
* Broadcasts the events to all other modules for reuse.
|
||||||
* The all events available in one array, sorted on startdate.
|
* The all events available in one array, sorted on startdate.
|
||||||
*/
|
*/
|
||||||
broadcastEvents: function () {
|
broadcastEvents () {
|
||||||
const eventList = this.createEventList(false);
|
const eventList = this.createEventList(false);
|
||||||
for (const event of eventList) {
|
for (const event of eventList) {
|
||||||
event.symbol = this.symbolsForEvent(event);
|
event.symbol = this.symbolsForEvent(event);
|
||||||
@@ -976,5 +890,30 @@ Module.register("calendar", {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.sendNotification("CALENDAR_EVENTS", eventList);
|
this.sendNotification("CALENDAR_EVENTS", eventList);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refresh the DOM every minute if needed: When using relative date format for events that start
|
||||||
|
* or end in less than an hour, the date shows minute granularity and we want to keep that accurate.
|
||||||
|
* --
|
||||||
|
* When updateOnFetch is not set, it will Avoid fade out/in on updateDom when many calendars are used
|
||||||
|
* and it's allow to refresh The DOM every minute with animation speed too
|
||||||
|
* (because updateDom is not set in CALENDAR_EVENTS for this case)
|
||||||
|
*/
|
||||||
|
selfUpdate () {
|
||||||
|
const ONE_MINUTE = 60 * 1000;
|
||||||
|
setTimeout(
|
||||||
|
() => {
|
||||||
|
setInterval(() => {
|
||||||
|
Log.debug("[Calendar] self update");
|
||||||
|
if (this.config.updateOnFetch) {
|
||||||
|
this.updateDom(1);
|
||||||
|
} else {
|
||||||
|
this.updateDom(this.config.animationSpeed);
|
||||||
|
}
|
||||||
|
}, ONE_MINUTE);
|
||||||
|
},
|
||||||
|
ONE_MINUTE - (new Date() % ONE_MINUTE)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,17 +1,8 @@
|
|||||||
/* MagicMirror²
|
const https = require("node:https");
|
||||||
* Node Helper: Calendar - CalendarFetcher
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const https = require("https");
|
|
||||||
const digest = require("digest-fetch");
|
|
||||||
const ical = require("node-ical");
|
const ical = require("node-ical");
|
||||||
const fetch = require("fetch");
|
|
||||||
const Log = require("logger");
|
const Log = require("logger");
|
||||||
const NodeHelper = require("node_helper");
|
const NodeHelper = require("node_helper");
|
||||||
const CalendarUtils = require("./calendarutils");
|
const CalendarFetcherUtils = require("./calendarfetcherutils");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -39,7 +30,6 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
|
|||||||
clearTimeout(reloadTimer);
|
clearTimeout(reloadTimer);
|
||||||
reloadTimer = null;
|
reloadTimer = null;
|
||||||
const nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
|
const nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
|
||||||
let fetcher = null;
|
|
||||||
let httpsAgent = null;
|
let httpsAgent = null;
|
||||||
let headers = {
|
let headers = {
|
||||||
"User-Agent": `Mozilla/5.0 (Node.js ${nodeVersion}) MagicMirror/${global.version}`
|
"User-Agent": `Mozilla/5.0 (Node.js ${nodeVersion}) MagicMirror/${global.version}`
|
||||||
@@ -53,17 +43,12 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
|
|||||||
if (auth) {
|
if (auth) {
|
||||||
if (auth.method === "bearer") {
|
if (auth.method === "bearer") {
|
||||||
headers.Authorization = `Bearer ${auth.pass}`;
|
headers.Authorization = `Bearer ${auth.pass}`;
|
||||||
} else if (auth.method === "digest") {
|
|
||||||
fetcher = new digest(auth.user, auth.pass).fetch(url, { headers: headers, agent: httpsAgent });
|
|
||||||
} else {
|
} else {
|
||||||
headers.Authorization = `Basic ${Buffer.from(`${auth.user}:${auth.pass}`).toString("base64")}`;
|
headers.Authorization = `Basic ${Buffer.from(`${auth.user}:${auth.pass}`).toString("base64")}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fetcher === null) {
|
|
||||||
fetcher = fetch(url, { headers: headers, agent: httpsAgent });
|
|
||||||
}
|
|
||||||
|
|
||||||
fetcher
|
fetch(url, { headers: headers, agent: httpsAgent })
|
||||||
.then(NodeHelper.checkFetchStatus)
|
.then(NodeHelper.checkFetchStatus)
|
||||||
.then((response) => response.text())
|
.then((response) => response.text())
|
||||||
.then((responseData) => {
|
.then((responseData) => {
|
||||||
@@ -72,7 +57,7 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
|
|||||||
try {
|
try {
|
||||||
data = ical.parseICS(responseData);
|
data = ical.parseICS(responseData);
|
||||||
Log.debug(`parsed data=${JSON.stringify(data)}`);
|
Log.debug(`parsed data=${JSON.stringify(data)}`);
|
||||||
events = CalendarUtils.filterEvents(data, {
|
events = CalendarFetcherUtils.filterEvents(data, {
|
||||||
excludedEvents,
|
excludedEvents,
|
||||||
includePastEvents,
|
includePastEvents,
|
||||||
maximumEntries,
|
maximumEntries,
|
||||||
@@ -115,13 +100,12 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
|
|||||||
* Broadcast the existing events.
|
* Broadcast the existing events.
|
||||||
*/
|
*/
|
||||||
this.broadcastEvents = function () {
|
this.broadcastEvents = function () {
|
||||||
Log.info(`Calendar-Fetcher: Broadcasting ${events.length} events.`);
|
Log.info(`Calendar-Fetcher: Broadcasting ${events.length} events from ${url}.`);
|
||||||
eventsReceivedCallback(this);
|
eventsReceivedCallback(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the on success callback
|
* Sets the on success callback
|
||||||
*
|
|
||||||
* @param {Function} callback The on success callback.
|
* @param {Function} callback The on success callback.
|
||||||
*/
|
*/
|
||||||
this.onReceive = function (callback) {
|
this.onReceive = function (callback) {
|
||||||
@@ -130,7 +114,6 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the on error callback
|
* Sets the on error callback
|
||||||
*
|
|
||||||
* @param {Function} callback The on error callback.
|
* @param {Function} callback The on error callback.
|
||||||
*/
|
*/
|
||||||
this.onError = function (callback) {
|
this.onError = function (callback) {
|
||||||
@@ -139,7 +122,6 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the url of this fetcher.
|
* Returns the url of this fetcher.
|
||||||
*
|
|
||||||
* @returns {string} The url of this fetcher.
|
* @returns {string} The url of this fetcher.
|
||||||
*/
|
*/
|
||||||
this.url = function () {
|
this.url = function () {
|
||||||
@@ -148,7 +130,6 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns current available events for this fetcher.
|
* Returns current available events for this fetcher.
|
||||||
*
|
|
||||||
* @returns {object[]} The current available events for this fetcher.
|
* @returns {object[]} The current available events for this fetcher.
|
||||||
*/
|
*/
|
||||||
this.events = function () {
|
this.events = function () {
|
||||||
|
|||||||
585
modules/default/calendar/calendarfetcherutils.js
Normal file
585
modules/default/calendar/calendarfetcherutils.js
Normal file
@@ -0,0 +1,585 @@
|
|||||||
|
/**
|
||||||
|
* @external Moment
|
||||||
|
*/
|
||||||
|
const path = require("node:path");
|
||||||
|
const moment = require("moment");
|
||||||
|
|
||||||
|
const zoneTable = require(path.join(__dirname, "windowsZones.json"));
|
||||||
|
const Log = require("../../../js/logger");
|
||||||
|
|
||||||
|
const CalendarFetcherUtils = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate the time correction, either dst/std or full day in cases where
|
||||||
|
* utc time is day before plus offset
|
||||||
|
* @param {object} event the event which needs adjustment
|
||||||
|
* @param {Date} date the date on which this event happens
|
||||||
|
* @returns {number} the necessary adjustment in hours
|
||||||
|
*/
|
||||||
|
calculateTimezoneAdjustment (event, date) {
|
||||||
|
let adjustHours = 0;
|
||||||
|
// if a timezone was specified
|
||||||
|
if (!event.start.tz) {
|
||||||
|
Log.debug(" if no tz, guess based on now");
|
||||||
|
event.start.tz = moment.tz.guess();
|
||||||
|
}
|
||||||
|
Log.debug(`initial tz=${event.start.tz}`);
|
||||||
|
|
||||||
|
// if there is a start date specified
|
||||||
|
if (event.start.tz) {
|
||||||
|
// if this is a windows timezone
|
||||||
|
if (event.start.tz.includes(" ")) {
|
||||||
|
// use the lookup table to get theIANA name as moment and date don't know MS timezones
|
||||||
|
let tz = CalendarFetcherUtils.getIanaTZFromMS(event.start.tz);
|
||||||
|
Log.debug(`corrected TZ=${tz}`);
|
||||||
|
// watch out for unregistered windows timezone names
|
||||||
|
// if we had a successful lookup
|
||||||
|
if (tz) {
|
||||||
|
// change the timezone to the IANA name
|
||||||
|
event.start.tz = tz;
|
||||||
|
// Log.debug("corrected timezone="+event.start.tz)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log.debug(`corrected tz=${event.start.tz}`);
|
||||||
|
let current_offset = 0; // offset from TZ string or calculated
|
||||||
|
let mm = 0; // date with tz or offset
|
||||||
|
let start_offset = 0; // utc offset of created with tz
|
||||||
|
// if there is still an offset, lookup failed, use it
|
||||||
|
if (event.start.tz.startsWith("(")) {
|
||||||
|
const regex = /[+|-]\d*:\d*/;
|
||||||
|
const start_offsetString = event.start.tz.match(regex).toString().split(":");
|
||||||
|
let start_offset = parseInt(start_offsetString[0]);
|
||||||
|
start_offset *= event.start.tz[1] === "-" ? -1 : 1;
|
||||||
|
adjustHours = start_offset;
|
||||||
|
Log.debug(`defined offset=${start_offset} hours`);
|
||||||
|
current_offset = start_offset;
|
||||||
|
event.start.tz = "";
|
||||||
|
Log.debug(`ical offset=${current_offset} date=${date}`);
|
||||||
|
mm = moment(date);
|
||||||
|
let x = moment(new Date()).utcOffset();
|
||||||
|
Log.debug(`net mins=${current_offset * 60 - x}`);
|
||||||
|
|
||||||
|
mm = mm.add(x - current_offset * 60, "minutes");
|
||||||
|
adjustHours = (current_offset * 60 - x) / 60;
|
||||||
|
event.start = mm.toDate();
|
||||||
|
Log.debug(`adjusted date=${event.start}`);
|
||||||
|
} else {
|
||||||
|
// get the start time in that timezone
|
||||||
|
let es = moment(event.start);
|
||||||
|
// check for start date prior to start of daylight changing date
|
||||||
|
if (es.format("YYYY") < 2007) {
|
||||||
|
es.set("year", 2013); // if so, use a closer date
|
||||||
|
}
|
||||||
|
Log.debug(`start date/time=${es.toDate()}`);
|
||||||
|
start_offset = moment.tz(es, event.start.tz).utcOffset();
|
||||||
|
Log.debug(`start offset=${start_offset}`);
|
||||||
|
|
||||||
|
Log.debug(`start date/time w tz =${moment.tz(moment(event.start), event.start.tz).toDate()}`);
|
||||||
|
|
||||||
|
// get the specified date in that timezone
|
||||||
|
mm = moment.tz(moment(date), event.start.tz);
|
||||||
|
Log.debug(`event date=${mm.toDate()}`);
|
||||||
|
current_offset = mm.utcOffset();
|
||||||
|
}
|
||||||
|
Log.debug(`event offset=${current_offset} hour=${mm.format("H")} event date=${mm.toDate()}`);
|
||||||
|
|
||||||
|
// if the offset is greater than 0, east of london
|
||||||
|
if (current_offset !== start_offset) {
|
||||||
|
// big offset
|
||||||
|
Log.debug("offset");
|
||||||
|
let h = parseInt(mm.format("H"));
|
||||||
|
// check if the event time is less than the offset
|
||||||
|
if (h > 0 && h < Math.abs(current_offset) / 60) {
|
||||||
|
// if so, rrule created a wrong date (utc day, oops, with utc yesterday adjusted time)
|
||||||
|
// we need to fix that
|
||||||
|
//adjustHours = 24;
|
||||||
|
// Log.debug("adjusting date")
|
||||||
|
}
|
||||||
|
//-300 > -240
|
||||||
|
//if (Math.abs(current_offset) > Math.abs(start_offset)){
|
||||||
|
if (current_offset > start_offset) {
|
||||||
|
adjustHours -= 1;
|
||||||
|
Log.debug("adjust down 1 hour dst change");
|
||||||
|
//} else if (Math.abs(current_offset) < Math.abs(start_offset)) {
|
||||||
|
} else if (current_offset < start_offset) {
|
||||||
|
adjustHours += 1;
|
||||||
|
Log.debug("adjust up 1 hour dst change");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log.debug(`adjustHours=${adjustHours}`);
|
||||||
|
return adjustHours;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter the events from ical according to the given config
|
||||||
|
* @param {object} data the calendar data from ical
|
||||||
|
* @param {object} config The configuration object
|
||||||
|
* @returns {string[]} the filtered events
|
||||||
|
*/
|
||||||
|
filterEvents (data, config) {
|
||||||
|
const newEvents = [];
|
||||||
|
|
||||||
|
// limitFunction doesn't do much limiting, see comment re: the dates
|
||||||
|
// array in rrule section below as to why we need to do the filtering
|
||||||
|
// ourselves
|
||||||
|
const limitFunction = function (date, i) {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const eventDate = function (event, time) {
|
||||||
|
return CalendarFetcherUtils.isFullDayEvent(event) ? moment(event[time]).startOf("day") : moment(event[time]);
|
||||||
|
};
|
||||||
|
|
||||||
|
Log.debug(`There are ${Object.entries(data).length} calendar entries.`);
|
||||||
|
|
||||||
|
const now = new Date(Date.now());
|
||||||
|
const todayLocal = moment(now).startOf("day").toDate();
|
||||||
|
const futureLocalDate
|
||||||
|
= moment(now)
|
||||||
|
.startOf("day")
|
||||||
|
.add(config.maximumNumberOfDays, "days")
|
||||||
|
.subtract(1, "seconds") // Subtract 1 second so that events that start on the middle of the night will not repeat.
|
||||||
|
.toDate();
|
||||||
|
|
||||||
|
Object.entries(data).forEach(([key, event]) => {
|
||||||
|
Log.debug("Processing entry...");
|
||||||
|
let pastLocalDate = todayLocal;
|
||||||
|
|
||||||
|
if (config.includePastEvents) {
|
||||||
|
pastLocalDate = moment(now).startOf("day").subtract(config.maximumNumberOfDays, "days").toDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Ugly fix to solve the facebook birthday issue.
|
||||||
|
// Otherwise, the recurring events only show the birthday for next year.
|
||||||
|
let isFacebookBirthday = false;
|
||||||
|
if (typeof event.uid !== "undefined") {
|
||||||
|
if (event.uid.indexOf("@facebook.com") !== -1) {
|
||||||
|
isFacebookBirthday = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.type === "VEVENT") {
|
||||||
|
Log.debug(`Event:\n${JSON.stringify(event)}`);
|
||||||
|
let startMoment = eventDate(event, "start");
|
||||||
|
let endMoment;
|
||||||
|
|
||||||
|
if (typeof event.end !== "undefined") {
|
||||||
|
endMoment = eventDate(event, "end");
|
||||||
|
} else if (typeof event.duration !== "undefined") {
|
||||||
|
endMoment = startMoment.clone().add(moment.duration(event.duration));
|
||||||
|
} else {
|
||||||
|
if (!isFacebookBirthday) {
|
||||||
|
// make copy of start date, separate storage area
|
||||||
|
endMoment = moment(startMoment.valueOf());
|
||||||
|
} else {
|
||||||
|
endMoment = moment(startMoment).add(1, "days");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.debug(`start: ${startMoment.toDate()}`);
|
||||||
|
Log.debug(`end:: ${endMoment.toDate()}`);
|
||||||
|
|
||||||
|
// Calculate the duration of the event for use with recurring events.
|
||||||
|
const durationMs = endMoment.valueOf() - startMoment.valueOf();
|
||||||
|
Log.debug(`duration: ${durationMs}`);
|
||||||
|
|
||||||
|
// FIXME: Since the parsed json object from node-ical comes with time information
|
||||||
|
// this check could be removed (?)
|
||||||
|
if (event.start.length === 8) {
|
||||||
|
startMoment = startMoment.startOf("day");
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = CalendarFetcherUtils.getTitleFromEvent(event);
|
||||||
|
Log.debug(`title: ${title}`);
|
||||||
|
|
||||||
|
let excluded = false,
|
||||||
|
dateFilter = null;
|
||||||
|
|
||||||
|
for (let f in config.excludedEvents) {
|
||||||
|
let filter = config.excludedEvents[f],
|
||||||
|
testTitle = title.toLowerCase(),
|
||||||
|
until = null,
|
||||||
|
useRegex = false,
|
||||||
|
regexFlags = "g";
|
||||||
|
|
||||||
|
if (filter instanceof Object) {
|
||||||
|
if (typeof filter.until !== "undefined") {
|
||||||
|
until = filter.until;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof filter.regex !== "undefined") {
|
||||||
|
useRegex = filter.regex;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If additional advanced filtering is added in, this section
|
||||||
|
// must remain last as we overwrite the filter object with the
|
||||||
|
// filterBy string
|
||||||
|
if (filter.caseSensitive) {
|
||||||
|
filter = filter.filterBy;
|
||||||
|
testTitle = title;
|
||||||
|
} else if (useRegex) {
|
||||||
|
filter = filter.filterBy;
|
||||||
|
testTitle = title;
|
||||||
|
regexFlags += "i";
|
||||||
|
} else {
|
||||||
|
filter = filter.filterBy.toLowerCase();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
filter = filter.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CalendarFetcherUtils.titleFilterApplies(testTitle, filter, useRegex, regexFlags)) {
|
||||||
|
if (until) {
|
||||||
|
dateFilter = until;
|
||||||
|
} else {
|
||||||
|
excluded = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (excluded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const location = event.location || false;
|
||||||
|
const geo = event.geo || false;
|
||||||
|
const description = event.description || false;
|
||||||
|
|
||||||
|
if (event.rrule && typeof event.rrule !== "undefined" && !isFacebookBirthday) {
|
||||||
|
const rule = event.rrule;
|
||||||
|
|
||||||
|
const pastMoment = moment(pastLocalDate);
|
||||||
|
const futureMoment = moment(futureLocalDate);
|
||||||
|
|
||||||
|
// can cause problems with e.g. birthdays before 1900
|
||||||
|
if ((rule.options && rule.origOptions && rule.origOptions.dtstart && rule.origOptions.dtstart.getFullYear() < 1900) || (rule.options && rule.options.dtstart && rule.options.dtstart.getFullYear() < 1900)) {
|
||||||
|
rule.origOptions.dtstart.setYear(1900);
|
||||||
|
rule.options.dtstart.setYear(1900);
|
||||||
|
}
|
||||||
|
|
||||||
|
// For recurring events, get the set of start dates that fall within the range
|
||||||
|
// of dates we're looking for.
|
||||||
|
// kblankenship1989 - to fix issue #1798, converting all dates to locale time first, then converting back to UTC time
|
||||||
|
let pastLocal;
|
||||||
|
let futureLocal;
|
||||||
|
if (CalendarFetcherUtils.isFullDayEvent(event)) {
|
||||||
|
Log.debug("fullday");
|
||||||
|
// if full day event, only use the date part of the ranges
|
||||||
|
pastLocal = pastMoment.toDate();
|
||||||
|
futureLocal = futureMoment.toDate();
|
||||||
|
|
||||||
|
Log.debug(`pastLocal: ${pastLocal}`);
|
||||||
|
Log.debug(`futureLocal: ${futureLocal}`);
|
||||||
|
} else {
|
||||||
|
// if we want past events
|
||||||
|
if (config.includePastEvents) {
|
||||||
|
// use the calculated past time for the between from
|
||||||
|
pastLocal = pastMoment.toDate();
|
||||||
|
} else {
|
||||||
|
// otherwise use NOW.. cause we shouldn't use any before now
|
||||||
|
pastLocal = moment(now).toDate(); //now
|
||||||
|
}
|
||||||
|
futureLocal = futureMoment.toDate(); // future
|
||||||
|
}
|
||||||
|
Log.debug(`Search for recurring events between: ${pastLocal} and ${futureLocal}`);
|
||||||
|
const hasByWeekdayRule = rule.options.byweekday !== undefined && rule.options.byweekday !== null;
|
||||||
|
const oneDayInMs = 24 * 60 * 60 * 1000;
|
||||||
|
Log.debug(`RRule: ${rule.toString()}`);
|
||||||
|
rule.options.tzid = null; // RRule gets *very* confused with timezones
|
||||||
|
let dates = rule.between(new Date(pastLocal.valueOf() - oneDayInMs), new Date(futureLocal.valueOf() + oneDayInMs), true, () => { return true; });
|
||||||
|
Log.debug(`Title: ${event.summary}, with dates: ${JSON.stringify(dates)}`);
|
||||||
|
dates = dates.filter((d) => {
|
||||||
|
if (JSON.stringify(d) === "null") return false;
|
||||||
|
else return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// RRule can generate dates with an incorrect recurrence date. Process the array here and apply date correction.
|
||||||
|
if (hasByWeekdayRule) {
|
||||||
|
Log.debug("Rule has byweekday, checking for correction");
|
||||||
|
dates.forEach((date, index, arr) => {
|
||||||
|
// NOTE: getTimezoneOffset() is negative of the expected value. For America/Los_Angeles under DST (GMT-7),
|
||||||
|
// this value is +420. For Australia/Sydney under DST (GMT+11), this value is -660.
|
||||||
|
const tzOffset = date.getTimezoneOffset() / 60;
|
||||||
|
const hour = date.getHours();
|
||||||
|
if ((tzOffset < 0) && (hour < -tzOffset)) { // east of GMT
|
||||||
|
Log.debug(`East of GMT (tzOffset: ${tzOffset}) and hour=${hour} < ${-tzOffset}, Subtracting 1 day from ${date}`);
|
||||||
|
arr[index] = new Date(date.valueOf() - oneDayInMs);
|
||||||
|
} else if ((tzOffset > 0) && (hour >= (24 - tzOffset))) { // west of GMT
|
||||||
|
Log.debug(`West of GMT (tzOffset: ${tzOffset}) and hour=${hour} >= 24-${tzOffset}, Adding 1 day to ${date}`);
|
||||||
|
arr[index] = new Date(date.valueOf() + oneDayInMs);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Adjusting the dates could push it beyond the 'until' date, so filter those out here.
|
||||||
|
if (rule.options.until !== null) {
|
||||||
|
dates = dates.filter((date) => {
|
||||||
|
return date.valueOf() <= rule.options.until.valueOf();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The dates array from rrule can be confused by DST. If the event was created during DST and we
|
||||||
|
// are querying a date range during non-DST, rrule can have the incorrect time for the date range.
|
||||||
|
// Reprocess the array here computing and applying the time offset.
|
||||||
|
dates.forEach((date, index, arr) => {
|
||||||
|
let adjustHours = CalendarFetcherUtils.calculateTimezoneAdjustment(event, date);
|
||||||
|
if (adjustHours !== 0) {
|
||||||
|
Log.debug(`Applying timezone adjustment hours=${adjustHours} to ${date}`);
|
||||||
|
arr[index] = new Date(date.valueOf() + (adjustHours * 60 * 60 * 1000));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// The "dates" array contains the set of dates within our desired date range range that are valid
|
||||||
|
// for the recurrence rule. *However*, it's possible for us to have a specific recurrence that
|
||||||
|
// had its date changed from outside the range to inside the range. For the time being,
|
||||||
|
// we'll handle this by adding *all* recurrence entries into the set of dates that we check,
|
||||||
|
// because the logic below will filter out any recurrences that don't actually belong within
|
||||||
|
// our display range.
|
||||||
|
// Would be great if there was a better way to handle this.
|
||||||
|
Log.debug(`event.recurrences: ${event.recurrences}`);
|
||||||
|
if (event.recurrences !== undefined) {
|
||||||
|
for (let dateKey in event.recurrences) {
|
||||||
|
// Only add dates that weren't already in the range we added from the rrule so that
|
||||||
|
// we don't double-add those events.
|
||||||
|
let d = new Date(dateKey);
|
||||||
|
if (!moment(d).isBetween(pastMoment, futureMoment)) {
|
||||||
|
dates.push(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lastly, sometimes rrule doesn't include the event.start even if it is in the requested range. Ensure
|
||||||
|
// inclusion here. Unfortunately dates.includes() doesn't find it so we have to do forEach().
|
||||||
|
{
|
||||||
|
let found = false;
|
||||||
|
dates.forEach((d) => { if (d.valueOf() === event.start.valueOf()) found = true; });
|
||||||
|
if (!found) {
|
||||||
|
Log.debug(`event.start=${event.start} was not included in results from rrule; adding`);
|
||||||
|
dates.splice(0, 0, event.start);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through the set of date entries to see which recurrences should be added to our event list.
|
||||||
|
for (let d in dates) {
|
||||||
|
let date = dates[d];
|
||||||
|
let curEvent = event;
|
||||||
|
let curDurationMs = durationMs;
|
||||||
|
let showRecurrence = true;
|
||||||
|
|
||||||
|
startMoment = moment(date);
|
||||||
|
|
||||||
|
// Remove the time information of each date by using its substring, using the following method:
|
||||||
|
// .toISOString().substring(0,10).
|
||||||
|
// since the date is given as ISOString with YYYY-MM-DDTHH:MM:SS.SSSZ
|
||||||
|
// (see https://momentjs.com/docs/#/displaying/as-iso-string/).
|
||||||
|
// This must be done after `date` is adjusted
|
||||||
|
const dateKey = date.toISOString().substring(0, 10);
|
||||||
|
|
||||||
|
// For each date that we're checking, it's possible that there is a recurrence override for that one day.
|
||||||
|
if (curEvent.recurrences !== undefined && curEvent.recurrences[dateKey] !== undefined) {
|
||||||
|
// We found an override, so for this recurrence, use a potentially different title, start date, and duration.
|
||||||
|
curEvent = curEvent.recurrences[dateKey];
|
||||||
|
startMoment = moment(curEvent.start);
|
||||||
|
curDurationMs = curEvent.end.valueOf() - startMoment.valueOf();
|
||||||
|
}
|
||||||
|
// If there's no recurrence override, check for an exception date. Exception dates represent exceptions to the rule.
|
||||||
|
else if (curEvent.exdate !== undefined && curEvent.exdate[dateKey] !== undefined) {
|
||||||
|
// This date is an exception date, which means we should skip it in the recurrence pattern.
|
||||||
|
showRecurrence = false;
|
||||||
|
}
|
||||||
|
Log.debug(`duration: ${curDurationMs}`);
|
||||||
|
|
||||||
|
endMoment = moment(startMoment.valueOf() + curDurationMs);
|
||||||
|
if (startMoment.valueOf() === endMoment.valueOf()) {
|
||||||
|
endMoment = endMoment.endOf("day");
|
||||||
|
}
|
||||||
|
|
||||||
|
const recurrenceTitle = CalendarFetcherUtils.getTitleFromEvent(curEvent);
|
||||||
|
|
||||||
|
// If this recurrence ends before the start of the date range, or starts after the end of the date range, don"t add
|
||||||
|
// it to the event list.
|
||||||
|
if (endMoment.isBefore(pastLocal) || startMoment.isAfter(futureLocal)) {
|
||||||
|
showRecurrence = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CalendarFetcherUtils.timeFilterApplies(now, endMoment, dateFilter)) {
|
||||||
|
showRecurrence = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showRecurrence === true) {
|
||||||
|
Log.debug(`saving event: ${description}`);
|
||||||
|
newEvents.push({
|
||||||
|
title: recurrenceTitle,
|
||||||
|
startDate: startMoment.format("x"),
|
||||||
|
endDate: endMoment.format("x"),
|
||||||
|
fullDayEvent: CalendarFetcherUtils.isFullDayEvent(event),
|
||||||
|
recurringEvent: true,
|
||||||
|
class: event.class,
|
||||||
|
firstYear: event.start.getFullYear(),
|
||||||
|
location: location,
|
||||||
|
geo: geo,
|
||||||
|
description: description
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// End recurring event parsing.
|
||||||
|
} else {
|
||||||
|
// Single event.
|
||||||
|
const fullDayEvent = isFacebookBirthday ? true : CalendarFetcherUtils.isFullDayEvent(event);
|
||||||
|
// Log.debug("full day event")
|
||||||
|
|
||||||
|
// if the start and end are the same, then make end the 'end of day' value (start is at 00:00:00)
|
||||||
|
if (fullDayEvent && startMoment.valueOf() === endMoment.valueOf()) {
|
||||||
|
endMoment = endMoment.endOf("day");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.includePastEvents) {
|
||||||
|
// Past event is too far in the past, so skip.
|
||||||
|
if (endMoment < pastLocalDate) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// It's not a fullday event, and it is in the past, so skip.
|
||||||
|
if (!fullDayEvent && endMoment < now) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// It's a fullday event, and it is before today, So skip.
|
||||||
|
if (fullDayEvent && endMoment <= todayLocal) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// It exceeds the maximumNumberOfDays limit, so skip.
|
||||||
|
if (startMoment > futureLocalDate) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CalendarFetcherUtils.timeFilterApplies(now, endMoment, dateFilter)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get correction for date saving and dst change between now and then
|
||||||
|
let adjustHours = CalendarFetcherUtils.calculateTimezoneAdjustment(event, startMoment.toDate());
|
||||||
|
// This shouldn't happen
|
||||||
|
if (adjustHours) {
|
||||||
|
Log.warn(`Unexpected timezone adjustment of ${adjustHours} hours on non-recurring event`);
|
||||||
|
}
|
||||||
|
// Every thing is good. Add it to the list.
|
||||||
|
newEvents.push({
|
||||||
|
title: title,
|
||||||
|
startDate: startMoment.add(adjustHours, "hours").format("x"),
|
||||||
|
endDate: endMoment.add(adjustHours, "hours").format("x"),
|
||||||
|
fullDayEvent: fullDayEvent,
|
||||||
|
class: event.class,
|
||||||
|
location: location,
|
||||||
|
geo: geo,
|
||||||
|
description: description
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
newEvents.sort(function (a, b) {
|
||||||
|
return a.startDate - b.startDate;
|
||||||
|
});
|
||||||
|
|
||||||
|
return newEvents;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lookup iana tz from windows
|
||||||
|
* @param {string} msTZName the timezone name to lookup
|
||||||
|
* @returns {string|null} the iana name or null of none is found
|
||||||
|
*/
|
||||||
|
getIanaTZFromMS (msTZName) {
|
||||||
|
// Get hash entry
|
||||||
|
const he = zoneTable[msTZName];
|
||||||
|
// If found return iana name, else null
|
||||||
|
return he ? he.iana[0] : null;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the title from the event.
|
||||||
|
* @param {object} event The event object to check.
|
||||||
|
* @returns {string} The title of the event, or "Event" if no title is found.
|
||||||
|
*/
|
||||||
|
getTitleFromEvent (event) {
|
||||||
|
let title = "Event";
|
||||||
|
if (event.summary) {
|
||||||
|
title = typeof event.summary.val !== "undefined" ? event.summary.val : event.summary;
|
||||||
|
} else if (event.description) {
|
||||||
|
title = event.description;
|
||||||
|
}
|
||||||
|
|
||||||
|
return title;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if an event is a fullday event.
|
||||||
|
* @param {object} event The event object to check.
|
||||||
|
* @returns {boolean} True if the event is a fullday event, false otherwise
|
||||||
|
*/
|
||||||
|
isFullDayEvent (event) {
|
||||||
|
if (event.start.length === 8 || event.start.dateOnly || event.datetype === "date") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const start = event.start || 0;
|
||||||
|
const startDate = new Date(start);
|
||||||
|
const end = event.end || 0;
|
||||||
|
if ((end - start) % (24 * 60 * 60 * 1000) === 0 && startDate.getHours() === 0 && startDate.getMinutes() === 0) {
|
||||||
|
// Is 24 hours, and starts on the middle of the night.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if the user defined time filter should apply
|
||||||
|
* @param {Date} now Date object using previously created object for consistency
|
||||||
|
* @param {Moment} endDate Moment object representing the event end date
|
||||||
|
* @param {string} filter The time to subtract from the end date to determine if an event should be shown
|
||||||
|
* @returns {boolean} True if the event should be filtered out, false otherwise
|
||||||
|
*/
|
||||||
|
timeFilterApplies (now, endDate, filter) {
|
||||||
|
if (filter) {
|
||||||
|
const until = filter.split(" "),
|
||||||
|
value = parseInt(until[0]),
|
||||||
|
increment = until[1].slice(-1) === "s" ? until[1] : `${until[1]}s`, // Massage the data for moment js
|
||||||
|
filterUntil = moment(endDate.format()).subtract(value, increment);
|
||||||
|
|
||||||
|
return now < filterUntil.toDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if the user defined title filter should apply
|
||||||
|
* @param {string} title the title of the event
|
||||||
|
* @param {string} filter the string to look for, can be a regex also
|
||||||
|
* @param {boolean} useRegex true if a regex should be used, otherwise it just looks for the filter as a string
|
||||||
|
* @param {string} regexFlags flags that should be applied to the regex
|
||||||
|
* @returns {boolean} True if the title should be filtered out, false otherwise
|
||||||
|
*/
|
||||||
|
titleFilterApplies (title, filter, useRegex, regexFlags) {
|
||||||
|
if (useRegex) {
|
||||||
|
let regexFilter = filter;
|
||||||
|
// Assume if leading slash, there is also trailing slash
|
||||||
|
if (filter[0] === "/") {
|
||||||
|
// Strip leading and trailing slashes
|
||||||
|
regexFilter = filter.substr(1).slice(0, -1);
|
||||||
|
}
|
||||||
|
return new RegExp(regexFilter, regexFlags).test(title);
|
||||||
|
} else {
|
||||||
|
return title.includes(filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof module !== "undefined") {
|
||||||
|
module.exports = CalendarFetcherUtils;
|
||||||
|
}
|
||||||
@@ -1,610 +1,125 @@
|
|||||||
/* MagicMirror²
|
|
||||||
* Calendar Util Methods
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @external Moment
|
|
||||||
*/
|
|
||||||
const path = require("path");
|
|
||||||
const moment = require("moment");
|
|
||||||
const zoneTable = require(path.join(__dirname, "windowsZones.json"));
|
|
||||||
const Log = require("../../../js/logger");
|
|
||||||
|
|
||||||
const CalendarUtils = {
|
const CalendarUtils = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the time correction, either dst/std or full day in cases where
|
* Capitalize the first letter of a string
|
||||||
* utc time is day before plus offset
|
* @param {string} string The string to capitalize
|
||||||
*
|
* @returns {string} The capitalized string
|
||||||
* @param {object} event the event which needs adjustement
|
|
||||||
* @param {Date} date the date on which this event happens
|
|
||||||
* @returns {number} the necessary adjustment in hours
|
|
||||||
*/
|
*/
|
||||||
calculateTimezoneAdjustment: function (event, date) {
|
capFirst (string) {
|
||||||
let adjustHours = 0;
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||||
// if a timezone was specified
|
|
||||||
if (!event.start.tz) {
|
|
||||||
Log.debug(" if no tz, guess based on now");
|
|
||||||
event.start.tz = moment.tz.guess();
|
|
||||||
}
|
|
||||||
Log.debug(`initial tz=${event.start.tz}`);
|
|
||||||
|
|
||||||
// if there is a start date specified
|
|
||||||
if (event.start.tz) {
|
|
||||||
// if this is a windows timezone
|
|
||||||
if (event.start.tz.includes(" ")) {
|
|
||||||
// use the lookup table to get theIANA name as moment and date don't know MS timezones
|
|
||||||
let tz = CalendarUtils.getIanaTZFromMS(event.start.tz);
|
|
||||||
Log.debug(`corrected TZ=${tz}`);
|
|
||||||
// watch out for unregistered windows timezone names
|
|
||||||
// if we had a successful lookup
|
|
||||||
if (tz) {
|
|
||||||
// change the timezone to the IANA name
|
|
||||||
event.start.tz = tz;
|
|
||||||
// Log.debug("corrected timezone="+event.start.tz)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Log.debug(`corrected tz=${event.start.tz}`);
|
|
||||||
let current_offset = 0; // offset from TZ string or calculated
|
|
||||||
let mm = 0; // date with tz or offset
|
|
||||||
let start_offset = 0; // utc offset of created with tz
|
|
||||||
// if there is still an offset, lookup failed, use it
|
|
||||||
if (event.start.tz.startsWith("(")) {
|
|
||||||
const regex = /[+|-]\d*:\d*/;
|
|
||||||
const start_offsetString = event.start.tz.match(regex).toString().split(":");
|
|
||||||
let start_offset = parseInt(start_offsetString[0]);
|
|
||||||
start_offset *= event.start.tz[1] === "-" ? -1 : 1;
|
|
||||||
adjustHours = start_offset;
|
|
||||||
Log.debug(`defined offset=${start_offset} hours`);
|
|
||||||
current_offset = start_offset;
|
|
||||||
event.start.tz = "";
|
|
||||||
Log.debug(`ical offset=${current_offset} date=${date}`);
|
|
||||||
mm = moment(date);
|
|
||||||
let x = parseInt(moment(new Date()).utcOffset());
|
|
||||||
Log.debug(`net mins=${current_offset * 60 - x}`);
|
|
||||||
|
|
||||||
mm = mm.add(x - current_offset * 60, "minutes");
|
|
||||||
adjustHours = (current_offset * 60 - x) / 60;
|
|
||||||
event.start = mm.toDate();
|
|
||||||
Log.debug(`adjusted date=${event.start}`);
|
|
||||||
} else {
|
|
||||||
// get the start time in that timezone
|
|
||||||
let es = moment(event.start);
|
|
||||||
// check for start date prior to start of daylight changing date
|
|
||||||
if (es.format("YYYY") < 2007) {
|
|
||||||
es.set("year", 2013); // if so, use a closer date
|
|
||||||
}
|
|
||||||
Log.debug(`start date/time=${es.toDate()}`);
|
|
||||||
start_offset = moment.tz(es, event.start.tz).utcOffset();
|
|
||||||
Log.debug(`start offset=${start_offset}`);
|
|
||||||
|
|
||||||
Log.debug(`start date/time w tz =${moment.tz(moment(event.start), event.start.tz).toDate()}`);
|
|
||||||
|
|
||||||
// get the specified date in that timezone
|
|
||||||
mm = moment.tz(moment(date), event.start.tz);
|
|
||||||
Log.debug(`event date=${mm.toDate()}`);
|
|
||||||
current_offset = mm.utcOffset();
|
|
||||||
}
|
|
||||||
Log.debug(`event offset=${current_offset} hour=${mm.format("H")} event date=${mm.toDate()}`);
|
|
||||||
|
|
||||||
// if the offset is greater than 0, east of london
|
|
||||||
if (current_offset !== start_offset) {
|
|
||||||
// big offset
|
|
||||||
Log.debug("offset");
|
|
||||||
let h = parseInt(mm.format("H"));
|
|
||||||
// check if the event time is less than the offset
|
|
||||||
if (h > 0 && h < Math.abs(current_offset) / 60) {
|
|
||||||
// if so, rrule created a wrong date (utc day, oops, with utc yesterday adjusted time)
|
|
||||||
// we need to fix that
|
|
||||||
//adjustHours = 24;
|
|
||||||
// Log.debug("adjusting date")
|
|
||||||
}
|
|
||||||
//-300 > -240
|
|
||||||
//if (Math.abs(current_offset) > Math.abs(start_offset)){
|
|
||||||
if (current_offset > start_offset) {
|
|
||||||
adjustHours -= 1;
|
|
||||||
Log.debug("adjust down 1 hour dst change");
|
|
||||||
//} else if (Math.abs(current_offset) < Math.abs(start_offset)) {
|
|
||||||
} else if (current_offset < start_offset) {
|
|
||||||
adjustHours += 1;
|
|
||||||
Log.debug("adjust up 1 hour dst change");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Log.debug(`adjustHours=${adjustHours}`);
|
|
||||||
return adjustHours;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the events from ical according to the given config
|
* This function accepts a number (either 12 or 24) and returns a moment.js LocaleSpecification with the
|
||||||
*
|
* corresponding time-format to be used in the calendar display. If no number is given (or otherwise invalid input)
|
||||||
* @param {object} data the calendar data from ical
|
* it will a localeSpecification object with the system locale time format.
|
||||||
* @param {object} config The configuration object
|
* @param {number} timeFormat Specifies either 12 or 24-hour time format
|
||||||
* @returns {string[]} the filtered events
|
* @returns {moment.LocaleSpecification} formatted time
|
||||||
*/
|
*/
|
||||||
filterEvents: function (data, config) {
|
getLocaleSpecification (timeFormat) {
|
||||||
const newEvents = [];
|
switch (timeFormat) {
|
||||||
|
case 12: {
|
||||||
// limitFunction doesn't do much limiting, see comment re: the dates
|
return { longDateFormat: { LT: "h:mm A" } };
|
||||||
// array in rrule section below as to why we need to do the filtering
|
|
||||||
// ourselves
|
|
||||||
const limitFunction = function (date, i) {
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
const eventDate = function (event, time) {
|
|
||||||
return CalendarUtils.isFullDayEvent(event) ? moment(event[time], "YYYYMMDD") : moment(new Date(event[time]));
|
|
||||||
};
|
|
||||||
|
|
||||||
Log.debug(`There are ${Object.entries(data).length} calendar entries.`);
|
|
||||||
Object.entries(data).forEach(([key, event]) => {
|
|
||||||
Log.debug("Processing entry...");
|
|
||||||
const now = new Date();
|
|
||||||
const today = moment().startOf("day").toDate();
|
|
||||||
const future = moment().startOf("day").add(config.maximumNumberOfDays, "days").subtract(1, "seconds").toDate(); // Subtract 1 second so that events that start on the middle of the night will not repeat.
|
|
||||||
let past = today;
|
|
||||||
|
|
||||||
if (config.includePastEvents) {
|
|
||||||
past = moment().startOf("day").subtract(config.maximumNumberOfDays, "days").toDate();
|
|
||||||
}
|
}
|
||||||
|
case 24: {
|
||||||
// FIXME: Ugly fix to solve the facebook birthday issue.
|
return { longDateFormat: { LT: "HH:mm" } };
|
||||||
// Otherwise, the recurring events only show the birthday for next year.
|
|
||||||
let isFacebookBirthday = false;
|
|
||||||
if (typeof event.uid !== "undefined") {
|
|
||||||
if (event.uid.indexOf("@facebook.com") !== -1) {
|
|
||||||
isFacebookBirthday = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
default: {
|
||||||
|
return { longDateFormat: { LT: moment.localeData().longDateFormat("LT") } };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
if (event.type === "VEVENT") {
|
/**
|
||||||
Log.debug(`Event:\n${JSON.stringify(event)}`);
|
* Shortens a string if it's longer than maxLength and add an ellipsis to the end
|
||||||
let startDate = eventDate(event, "start");
|
* @param {string} string Text string to shorten
|
||||||
let endDate;
|
* @param {number} maxLength The max length of the string
|
||||||
|
* @param {boolean} wrapEvents Wrap the text after the line has reached maxLength
|
||||||
|
* @param {number} maxTitleLines The max number of vertical lines before cutting event title
|
||||||
|
* @returns {string} The shortened string
|
||||||
|
*/
|
||||||
|
shorten (string, maxLength, wrapEvents, maxTitleLines) {
|
||||||
|
if (typeof string !== "string") {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof event.end !== "undefined") {
|
if (wrapEvents === true) {
|
||||||
endDate = eventDate(event, "end");
|
const words = string.split(" ");
|
||||||
} else if (typeof event.duration !== "undefined") {
|
let temp = "";
|
||||||
endDate = startDate.clone().add(moment.duration(event.duration));
|
let currentLine = "";
|
||||||
|
let line = 0;
|
||||||
|
|
||||||
|
for (let i = 0; i < words.length; i++) {
|
||||||
|
const word = words[i];
|
||||||
|
if (currentLine.length + word.length < (typeof maxLength === "number" ? maxLength : 25) - 1) {
|
||||||
|
// max - 1 to account for a space
|
||||||
|
currentLine += `${word} `;
|
||||||
} else {
|
} else {
|
||||||
if (!isFacebookBirthday) {
|
line++;
|
||||||
// make copy of start date, separate storage area
|
if (line > maxTitleLines - 1) {
|
||||||
endDate = moment(startDate.format("x"), "x");
|
if (i < words.length) {
|
||||||
} else {
|
currentLine += "…";
|
||||||
endDate = moment(startDate).add(1, "days");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.debug(`start: ${startDate.toDate()}`);
|
|
||||||
Log.debug(`end:: ${endDate.toDate()}`);
|
|
||||||
|
|
||||||
// Calculate the duration of the event for use with recurring events.
|
|
||||||
let duration = parseInt(endDate.format("x")) - parseInt(startDate.format("x"));
|
|
||||||
Log.debug(`duration: ${duration}`);
|
|
||||||
|
|
||||||
// FIXME: Since the parsed json object from node-ical comes with time information
|
|
||||||
// this check could be removed (?)
|
|
||||||
if (event.start.length === 8) {
|
|
||||||
startDate = startDate.startOf("day");
|
|
||||||
}
|
|
||||||
|
|
||||||
const title = CalendarUtils.getTitleFromEvent(event);
|
|
||||||
Log.debug(`title: ${title}`);
|
|
||||||
|
|
||||||
let excluded = false,
|
|
||||||
dateFilter = null;
|
|
||||||
|
|
||||||
for (let f in config.excludedEvents) {
|
|
||||||
let filter = config.excludedEvents[f],
|
|
||||||
testTitle = title.toLowerCase(),
|
|
||||||
until = null,
|
|
||||||
useRegex = false,
|
|
||||||
regexFlags = "g";
|
|
||||||
|
|
||||||
if (filter instanceof Object) {
|
|
||||||
if (typeof filter.until !== "undefined") {
|
|
||||||
until = filter.until;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof filter.regex !== "undefined") {
|
|
||||||
useRegex = filter.regex;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If additional advanced filtering is added in, this section
|
|
||||||
// must remain last as we overwrite the filter object with the
|
|
||||||
// filterBy string
|
|
||||||
if (filter.caseSensitive) {
|
|
||||||
filter = filter.filterBy;
|
|
||||||
testTitle = title;
|
|
||||||
} else if (useRegex) {
|
|
||||||
filter = filter.filterBy;
|
|
||||||
testTitle = title;
|
|
||||||
regexFlags += "i";
|
|
||||||
} else {
|
|
||||||
filter = filter.filterBy.toLowerCase();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
filter = filter.toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CalendarUtils.titleFilterApplies(testTitle, filter, useRegex, regexFlags)) {
|
|
||||||
if (until) {
|
|
||||||
dateFilter = until;
|
|
||||||
} else {
|
|
||||||
excluded = true;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (excluded) {
|
if (currentLine.length > 0) {
|
||||||
return;
|
temp += `${currentLine}<br>${word} `;
|
||||||
}
|
|
||||||
|
|
||||||
const location = event.location || false;
|
|
||||||
const geo = event.geo || false;
|
|
||||||
const description = event.description || false;
|
|
||||||
|
|
||||||
if (typeof event.rrule !== "undefined" && event.rrule !== null && !isFacebookBirthday) {
|
|
||||||
const rule = event.rrule;
|
|
||||||
let addedEvents = 0;
|
|
||||||
|
|
||||||
const pastMoment = moment(past);
|
|
||||||
const futureMoment = moment(future);
|
|
||||||
|
|
||||||
// can cause problems with e.g. birthdays before 1900
|
|
||||||
if ((rule.options && rule.origOptions && rule.origOptions.dtstart && rule.origOptions.dtstart.getFullYear() < 1900) || (rule.options && rule.options.dtstart && rule.options.dtstart.getFullYear() < 1900)) {
|
|
||||||
rule.origOptions.dtstart.setYear(1900);
|
|
||||||
rule.options.dtstart.setYear(1900);
|
|
||||||
}
|
|
||||||
|
|
||||||
// For recurring events, get the set of start dates that fall within the range
|
|
||||||
// of dates we're looking for.
|
|
||||||
// kblankenship1989 - to fix issue #1798, converting all dates to locale time first, then converting back to UTC time
|
|
||||||
let pastLocal = 0;
|
|
||||||
let futureLocal = 0;
|
|
||||||
if (CalendarUtils.isFullDayEvent(event)) {
|
|
||||||
Log.debug("fullday");
|
|
||||||
// if full day event, only use the date part of the ranges
|
|
||||||
pastLocal = pastMoment.toDate();
|
|
||||||
futureLocal = futureMoment.toDate();
|
|
||||||
|
|
||||||
Log.debug(`pastLocal: ${pastLocal}`);
|
|
||||||
Log.debug(`futureLocal: ${futureLocal}`);
|
|
||||||
} else {
|
} else {
|
||||||
// if we want past events
|
temp += `${word}<br>`;
|
||||||
if (config.includePastEvents) {
|
|
||||||
// use the calculated past time for the between from
|
|
||||||
pastLocal = pastMoment.toDate();
|
|
||||||
} else {
|
|
||||||
// otherwise use NOW.. cause we shouldn't use any before now
|
|
||||||
pastLocal = moment().toDate(); //now
|
|
||||||
}
|
|
||||||
futureLocal = futureMoment.toDate(); // future
|
|
||||||
}
|
}
|
||||||
Log.debug(`Search for recurring events between: ${pastLocal} and ${futureLocal}`);
|
currentLine = "";
|
||||||
const dates = rule.between(pastLocal, futureLocal, true, limitFunction);
|
|
||||||
Log.debug(`Title: ${event.summary}, with dates: ${JSON.stringify(dates)}`);
|
|
||||||
// The "dates" array contains the set of dates within our desired date range range that are valid
|
|
||||||
// for the recurrence rule. *However*, it's possible for us to have a specific recurrence that
|
|
||||||
// had its date changed from outside the range to inside the range. For the time being,
|
|
||||||
// we'll handle this by adding *all* recurrence entries into the set of dates that we check,
|
|
||||||
// because the logic below will filter out any recurrences that don't actually belong within
|
|
||||||
// our display range.
|
|
||||||
// Would be great if there was a better way to handle this.
|
|
||||||
Log.debug(`event.recurrences: ${event.recurrences}`);
|
|
||||||
if (event.recurrences !== undefined) {
|
|
||||||
for (let r in event.recurrences) {
|
|
||||||
// Only add dates that weren't already in the range we added from the rrule so that
|
|
||||||
// we don"t double-add those events.
|
|
||||||
if (moment(new Date(r)).isBetween(pastMoment, futureMoment) !== true) {
|
|
||||||
dates.push(new Date(r));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Loop through the set of date entries to see which recurrences should be added to our event list.
|
|
||||||
for (let d in dates) {
|
|
||||||
let date = dates[d];
|
|
||||||
// Remove the time information of each date by using its substring, using the following method:
|
|
||||||
// .toISOString().substring(0,10).
|
|
||||||
// since the date is given as ISOString with YYYY-MM-DDTHH:MM:SS.SSSZ
|
|
||||||
// (see https://momentjs.com/docs/#/displaying/as-iso-string/).
|
|
||||||
const dateKey = date.toISOString().substring(0, 10);
|
|
||||||
let curEvent = event;
|
|
||||||
let showRecurrence = true;
|
|
||||||
|
|
||||||
// Get the offset of today where we are processing
|
|
||||||
// This will be the correction, we need to apply.
|
|
||||||
let nowOffset = new Date().getTimezoneOffset();
|
|
||||||
// For full day events, the time might be off from RRULE/Luxon problem
|
|
||||||
// Get time zone offset of the rule calculated event
|
|
||||||
let dateoffset = date.getTimezoneOffset();
|
|
||||||
|
|
||||||
// Reduce the time by the following offset.
|
|
||||||
Log.debug(` recurring date is ${date} offset is ${dateoffset}`);
|
|
||||||
|
|
||||||
let dh = moment(date).format("HH");
|
|
||||||
Log.debug(` recurring date is ${date} offset is ${dateoffset / 60} Hour is ${dh}`);
|
|
||||||
|
|
||||||
if (CalendarUtils.isFullDayEvent(event)) {
|
|
||||||
Log.debug("Fullday");
|
|
||||||
// If the offset is negative (east of GMT), where the problem is
|
|
||||||
if (dateoffset < 0) {
|
|
||||||
if (dh < Math.abs(dateoffset / 60)) {
|
|
||||||
// if the rrule byweekday WAS explicitly set , correct it
|
|
||||||
// reduce the time by the offset
|
|
||||||
if (curEvent.rrule.origOptions.byweekday !== undefined) {
|
|
||||||
// Apply the correction to the date/time to get it UTC relative
|
|
||||||
date = new Date(date.getTime() - Math.abs(24 * 60) * 60000);
|
|
||||||
}
|
|
||||||
// the duration was calculated way back at the top before we could correct the start time..
|
|
||||||
// fix it for this event entry
|
|
||||||
//duration = 24 * 60 * 60 * 1000;
|
|
||||||
Log.debug(`new recurring date1 fulldate is ${date}`);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// if the timezones are the same, correct date if needed
|
|
||||||
//if (event.start.tz === moment.tz.guess()) {
|
|
||||||
// if the date hour is less than the offset
|
|
||||||
if (24 - dh <= Math.abs(dateoffset / 60)) {
|
|
||||||
// if the rrule byweekday WAS explicitly set , correct it
|
|
||||||
if (curEvent.rrule.origOptions.byweekday !== undefined) {
|
|
||||||
// apply the correction to the date/time back to right day
|
|
||||||
date = new Date(date.getTime() + Math.abs(24 * 60) * 60000);
|
|
||||||
}
|
|
||||||
// the duration was calculated way back at the top before we could correct the start time..
|
|
||||||
// fix it for this event entry
|
|
||||||
//duration = 24 * 60 * 60 * 1000;
|
|
||||||
Log.debug(`new recurring date2 fulldate is ${date}`);
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// not full day, but luxon can still screw up the date on the rule processing
|
|
||||||
// we need to correct the date to get back to the right event for
|
|
||||||
if (dateoffset < 0) {
|
|
||||||
// if the date hour is less than the offset
|
|
||||||
if (dh <= Math.abs(dateoffset / 60)) {
|
|
||||||
// if the rrule byweekday WAS explicitly set , correct it
|
|
||||||
if (curEvent.rrule.origOptions.byweekday !== undefined) {
|
|
||||||
// Reduce the time by t:
|
|
||||||
// Apply the correction to the date/time to get it UTC relative
|
|
||||||
date = new Date(date.getTime() - Math.abs(24 * 60) * 60000);
|
|
||||||
}
|
|
||||||
// the duration was calculated way back at the top before we could correct the start time..
|
|
||||||
// fix it for this event entry
|
|
||||||
//duration = 24 * 60 * 60 * 1000;
|
|
||||||
Log.debug(`new recurring date1 is ${date}`);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// if the timezones are the same, correct date if needed
|
|
||||||
//if (event.start.tz === moment.tz.guess()) {
|
|
||||||
// if the date hour is less than the offset
|
|
||||||
if (24 - dh <= Math.abs(dateoffset / 60)) {
|
|
||||||
// if the rrule byweekday WAS explicitly set , correct it
|
|
||||||
if (curEvent.rrule.origOptions.byweekday !== undefined) {
|
|
||||||
// apply the correction to the date/time back to right day
|
|
||||||
date = new Date(date.getTime() + Math.abs(24 * 60) * 60000);
|
|
||||||
}
|
|
||||||
// the duration was calculated way back at the top before we could correct the start time..
|
|
||||||
// fix it for this event entry
|
|
||||||
//duration = 24 * 60 * 60 * 1000;
|
|
||||||
Log.debug(`new recurring date2 is ${date}`);
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
startDate = moment(date);
|
|
||||||
Log.debug(`Corrected startDate: ${startDate.toDate()}`);
|
|
||||||
|
|
||||||
let adjustDays = CalendarUtils.calculateTimezoneAdjustment(event, date);
|
|
||||||
|
|
||||||
// For each date that we're checking, it's possible that there is a recurrence override for that one day.
|
|
||||||
if (curEvent.recurrences !== undefined && curEvent.recurrences[dateKey] !== undefined) {
|
|
||||||
// We found an override, so for this recurrence, use a potentially different title, start date, and duration.
|
|
||||||
curEvent = curEvent.recurrences[dateKey];
|
|
||||||
startDate = moment(curEvent.start);
|
|
||||||
duration = parseInt(moment(curEvent.end).format("x")) - parseInt(startDate.format("x"));
|
|
||||||
}
|
|
||||||
// If there's no recurrence override, check for an exception date. Exception dates represent exceptions to the rule.
|
|
||||||
else if (curEvent.exdate !== undefined && curEvent.exdate[dateKey] !== undefined) {
|
|
||||||
// This date is an exception date, which means we should skip it in the recurrence pattern.
|
|
||||||
showRecurrence = false;
|
|
||||||
}
|
|
||||||
Log.debug(`duration: ${duration}`);
|
|
||||||
|
|
||||||
endDate = moment(parseInt(startDate.format("x")) + duration, "x");
|
|
||||||
if (startDate.format("x") === endDate.format("x")) {
|
|
||||||
endDate = endDate.endOf("day");
|
|
||||||
}
|
|
||||||
|
|
||||||
const recurrenceTitle = CalendarUtils.getTitleFromEvent(curEvent);
|
|
||||||
|
|
||||||
// If this recurrence ends before the start of the date range, or starts after the end of the date range, don"t add
|
|
||||||
// it to the event list.
|
|
||||||
if (endDate.isBefore(past) || startDate.isAfter(future)) {
|
|
||||||
showRecurrence = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CalendarUtils.timeFilterApplies(now, endDate, dateFilter)) {
|
|
||||||
showRecurrence = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (showRecurrence === true) {
|
|
||||||
Log.debug(`saving event: ${description}`);
|
|
||||||
addedEvents++;
|
|
||||||
newEvents.push({
|
|
||||||
title: recurrenceTitle,
|
|
||||||
startDate: (adjustDays ? (adjustDays > 0 ? startDate.add(adjustDays, "hours") : startDate.subtract(Math.abs(adjustDays), "hours")) : startDate).format("x"),
|
|
||||||
endDate: (adjustDays ? (adjustDays > 0 ? endDate.add(adjustDays, "hours") : endDate.subtract(Math.abs(adjustDays), "hours")) : endDate).format("x"),
|
|
||||||
fullDayEvent: CalendarUtils.isFullDayEvent(event),
|
|
||||||
recurringEvent: true,
|
|
||||||
class: event.class,
|
|
||||||
firstYear: event.start.getFullYear(),
|
|
||||||
location: location,
|
|
||||||
geo: geo,
|
|
||||||
description: description
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// End recurring event parsing.
|
|
||||||
} else {
|
|
||||||
// Single event.
|
|
||||||
const fullDayEvent = isFacebookBirthday ? true : CalendarUtils.isFullDayEvent(event);
|
|
||||||
// Log.debug("full day event")
|
|
||||||
|
|
||||||
if (config.includePastEvents) {
|
|
||||||
// Past event is too far in the past, so skip.
|
|
||||||
if (endDate < past) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// It's not a fullday event, and it is in the past, so skip.
|
|
||||||
if (!fullDayEvent && endDate < new Date()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// It's a fullday event, and it is before today, So skip.
|
|
||||||
if (fullDayEvent && endDate <= today) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// It exceeds the maximumNumberOfDays limit, so skip.
|
|
||||||
if (startDate > future) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CalendarUtils.timeFilterApplies(now, endDate, dateFilter)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the start and end are the same, then make end the 'end of day' value (start is at 00:00:00)
|
|
||||||
if (fullDayEvent && startDate.format("x") === endDate.format("x")) {
|
|
||||||
endDate = endDate.endOf("day");
|
|
||||||
}
|
|
||||||
// get correction for date saving and dst change between now and then
|
|
||||||
let adjustDays = CalendarUtils.calculateTimezoneAdjustment(event, startDate.toDate());
|
|
||||||
// Every thing is good. Add it to the list.
|
|
||||||
newEvents.push({
|
|
||||||
title: title,
|
|
||||||
startDate: (adjustDays ? (adjustDays > 0 ? startDate.add(adjustDays, "hours") : startDate.subtract(Math.abs(adjustDays), "hours")) : startDate).format("x"),
|
|
||||||
endDate: (adjustDays ? (adjustDays > 0 ? endDate.add(adjustDays, "hours") : endDate.subtract(Math.abs(adjustDays), "hours")) : endDate).format("x"),
|
|
||||||
fullDayEvent: fullDayEvent,
|
|
||||||
class: event.class,
|
|
||||||
location: location,
|
|
||||||
geo: geo,
|
|
||||||
description: description
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
newEvents.sort(function (a, b) {
|
return (temp + currentLine).trim();
|
||||||
return a.startDate - b.startDate;
|
|
||||||
});
|
|
||||||
|
|
||||||
return newEvents;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lookup iana tz from windows
|
|
||||||
*
|
|
||||||
* @param {string} msTZName the timezone name to lookup
|
|
||||||
* @returns {string|null} the iana name or null of none is found
|
|
||||||
*/
|
|
||||||
getIanaTZFromMS: function (msTZName) {
|
|
||||||
// Get hash entry
|
|
||||||
const he = zoneTable[msTZName];
|
|
||||||
// If found return iana name, else null
|
|
||||||
return he ? he.iana[0] : null;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the title from the event.
|
|
||||||
*
|
|
||||||
* @param {object} event The event object to check.
|
|
||||||
* @returns {string} The title of the event, or "Event" if no title is found.
|
|
||||||
*/
|
|
||||||
getTitleFromEvent: function (event) {
|
|
||||||
let title = "Event";
|
|
||||||
if (event.summary) {
|
|
||||||
title = typeof event.summary.val !== "undefined" ? event.summary.val : event.summary;
|
|
||||||
} else if (event.description) {
|
|
||||||
title = event.description;
|
|
||||||
}
|
|
||||||
|
|
||||||
return title;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if an event is a fullday event.
|
|
||||||
*
|
|
||||||
* @param {object} event The event object to check.
|
|
||||||
* @returns {boolean} True if the event is a fullday event, false otherwise
|
|
||||||
*/
|
|
||||||
isFullDayEvent: function (event) {
|
|
||||||
if (event.start.length === 8 || event.start.dateOnly || event.datetype === "date") {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const start = event.start || 0;
|
|
||||||
const startDate = new Date(start);
|
|
||||||
const end = event.end || 0;
|
|
||||||
if ((end - start) % (24 * 60 * 60 * 1000) === 0 && startDate.getHours() === 0 && startDate.getMinutes() === 0) {
|
|
||||||
// Is 24 hours, and starts on the middle of the night.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if the user defined time filter should apply
|
|
||||||
*
|
|
||||||
* @param {Date} now Date object using previously created object for consistency
|
|
||||||
* @param {Moment} endDate Moment object representing the event end date
|
|
||||||
* @param {string} filter The time to subtract from the end date to determine if an event should be shown
|
|
||||||
* @returns {boolean} True if the event should be filtered out, false otherwise
|
|
||||||
*/
|
|
||||||
timeFilterApplies: function (now, endDate, filter) {
|
|
||||||
if (filter) {
|
|
||||||
const until = filter.split(" "),
|
|
||||||
value = parseInt(until[0]),
|
|
||||||
increment = until[1].slice(-1) === "s" ? until[1] : `${until[1]}s`, // Massage the data for moment js
|
|
||||||
filterUntil = moment(endDate.format()).subtract(value, increment);
|
|
||||||
|
|
||||||
return now < filterUntil.format("x");
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if the user defined title filter should apply
|
|
||||||
*
|
|
||||||
* @param {string} title the title of the event
|
|
||||||
* @param {string} filter the string to look for, can be a regex also
|
|
||||||
* @param {boolean} useRegex true if a regex should be used, otherwise it just looks for the filter as a string
|
|
||||||
* @param {string} regexFlags flags that should be applied to the regex
|
|
||||||
* @returns {boolean} True if the title should be filtered out, false otherwise
|
|
||||||
*/
|
|
||||||
titleFilterApplies: function (title, filter, useRegex, regexFlags) {
|
|
||||||
if (useRegex) {
|
|
||||||
// Assume if leading slash, there is also trailing slash
|
|
||||||
if (filter[0] === "/") {
|
|
||||||
// Strip leading and trailing slashes
|
|
||||||
filter = filter.substr(1).slice(0, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
filter = new RegExp(filter, regexFlags);
|
|
||||||
|
|
||||||
return filter.test(title);
|
|
||||||
} else {
|
} else {
|
||||||
return title.includes(filter);
|
if (maxLength && typeof maxLength === "number" && string.length > maxLength) {
|
||||||
|
return `${string.trim().slice(0, maxLength)}…`;
|
||||||
|
} else {
|
||||||
|
return string.trim();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms the title of an event for usage.
|
||||||
|
* Replaces parts of the text as defined in config.titleReplace.
|
||||||
|
* @param {string} title The title to transform.
|
||||||
|
* @param {object} titleReplace object definition of parts to be replaced in the title
|
||||||
|
* object definition:
|
||||||
|
* search: {string,required} RegEx in format //x or simple string to be searched. For (birthday) year calcluation, the element matching the year must be in a RegEx group
|
||||||
|
* replace: {string,required} Replacement string, may contain match group references (latter is required for year calculation)
|
||||||
|
* yearmatchgroup: {number,optional} match group for year element
|
||||||
|
* @returns {string} The transformed title.
|
||||||
|
*/
|
||||||
|
titleTransform (title, titleReplace) {
|
||||||
|
let transformedTitle = title;
|
||||||
|
for (let tr in titleReplace) {
|
||||||
|
let transform = titleReplace[tr];
|
||||||
|
if (typeof transform === "object") {
|
||||||
|
if (typeof transform.search !== "undefined" && transform.search !== "" && typeof transform.replace !== "undefined") {
|
||||||
|
let regParts = transform.search.match(/^\/(.+)\/([gim]*)$/);
|
||||||
|
let needle = new RegExp(transform.search, "g");
|
||||||
|
if (regParts) {
|
||||||
|
// the parsed pattern is a regexp with flags.
|
||||||
|
needle = new RegExp(regParts[1], regParts[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let replacement = transform.replace;
|
||||||
|
if (typeof transform.yearmatchgroup !== "undefined" && transform.yearmatchgroup !== "") {
|
||||||
|
const yearmatch = [...title.matchAll(needle)];
|
||||||
|
if (yearmatch[0].length >= transform.yearmatchgroup + 1 && yearmatch[0][transform.yearmatchgroup] * 1 >= 1900) {
|
||||||
|
let calcage = new Date().getFullYear() - yearmatch[0][transform.yearmatchgroup] * 1;
|
||||||
|
let searchstr = `$${transform.yearmatchgroup}`;
|
||||||
|
replacement = replacement.replace(searchstr, calcage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
transformedTitle = transformedTitle.replace(needle, replacement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return transformedTitle;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
/* CalendarFetcher Tester
|
/* CalendarFetcher Tester
|
||||||
* use this script with `node debug.js` to test the fetcher without the need
|
* use this script with `node debug.js` to test the fetcher without the need
|
||||||
* of starting the MagicMirror² core. Adjust the values below to your desire.
|
* of starting the MagicMirror² core. Adjust the values below to your desire.
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
*/
|
||||||
// Alias modules mentioned in package.js under _moduleAliases.
|
// Alias modules mentioned in package.js under _moduleAliases.
|
||||||
require("module-alias/register");
|
require("module-alias/register");
|
||||||
|
|||||||
@@ -1,22 +1,16 @@
|
|||||||
/* MagicMirror²
|
|
||||||
* Node Helper: Calendar
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
const NodeHelper = require("node_helper");
|
const NodeHelper = require("node_helper");
|
||||||
const Log = require("logger");
|
const Log = require("logger");
|
||||||
const CalendarFetcher = require("./calendarfetcher");
|
const CalendarFetcher = require("./calendarfetcher");
|
||||||
|
|
||||||
module.exports = NodeHelper.create({
|
module.exports = NodeHelper.create({
|
||||||
// Override start method.
|
// Override start method.
|
||||||
start: function () {
|
start () {
|
||||||
Log.log(`Starting node helper for: ${this.name}`);
|
Log.log(`Starting node helper for: ${this.name}`);
|
||||||
this.fetchers = [];
|
this.fetchers = [];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Override socketNotificationReceived method.
|
// Override socketNotificationReceived method.
|
||||||
socketNotificationReceived: function (notification, payload) {
|
socketNotificationReceived (notification, payload) {
|
||||||
if (notification === "ADD_CALENDAR") {
|
if (notification === "ADD_CALENDAR") {
|
||||||
this.createFetcher(payload.url, payload.fetchInterval, payload.excludedEvents, payload.maximumEntries, payload.maximumNumberOfDays, payload.auth, payload.broadcastPastEvents, payload.selfSignedCert, payload.id);
|
this.createFetcher(payload.url, payload.fetchInterval, payload.excludedEvents, payload.maximumEntries, payload.maximumNumberOfDays, payload.auth, payload.broadcastPastEvents, payload.selfSignedCert, payload.id);
|
||||||
} else if (notification === "FETCH_CALENDAR") {
|
} else if (notification === "FETCH_CALENDAR") {
|
||||||
@@ -33,7 +27,6 @@ module.exports = NodeHelper.create({
|
|||||||
/**
|
/**
|
||||||
* Creates a fetcher for a new url if it doesn't exist yet.
|
* Creates a fetcher for a new url if it doesn't exist yet.
|
||||||
* Otherwise it reuses the existing one.
|
* Otherwise it reuses the existing one.
|
||||||
*
|
|
||||||
* @param {string} url The url of the calendar
|
* @param {string} url The url of the calendar
|
||||||
* @param {number} fetchInterval How often does the calendar needs to be fetched in ms
|
* @param {number} fetchInterval How often does the calendar needs to be fetched in ms
|
||||||
* @param {string[]} excludedEvents An array of words / phrases from event titles that will be excluded from being shown.
|
* @param {string[]} excludedEvents An array of words / phrases from event titles that will be excluded from being shown.
|
||||||
@@ -44,7 +37,7 @@ module.exports = NodeHelper.create({
|
|||||||
* @param {boolean} selfSignedCert If true, the server certificate is not verified against the list of supplied CAs.
|
* @param {boolean} selfSignedCert If true, the server certificate is not verified against the list of supplied CAs.
|
||||||
* @param {string} identifier ID of the module
|
* @param {string} identifier ID of the module
|
||||||
*/
|
*/
|
||||||
createFetcher: function (url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents, selfSignedCert, identifier) {
|
createFetcher (url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents, selfSignedCert, identifier) {
|
||||||
try {
|
try {
|
||||||
new URL(url);
|
new URL(url);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -54,9 +47,14 @@ module.exports = NodeHelper.create({
|
|||||||
}
|
}
|
||||||
|
|
||||||
let fetcher;
|
let fetcher;
|
||||||
|
let fetchIntervalCorrected;
|
||||||
if (typeof this.fetchers[identifier + url] === "undefined") {
|
if (typeof this.fetchers[identifier + url] === "undefined") {
|
||||||
Log.log(`Create new calendarfetcher for url: ${url} - Interval: ${fetchInterval}`);
|
if (fetchInterval < 60000) {
|
||||||
fetcher = new CalendarFetcher(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents, selfSignedCert);
|
Log.warn(`fetchInterval for url ${url} must be >= 60000`);
|
||||||
|
fetchIntervalCorrected = 60000;
|
||||||
|
}
|
||||||
|
Log.log(`Create new calendarfetcher for url: ${url} - Interval: ${fetchIntervalCorrected || fetchInterval}`);
|
||||||
|
fetcher = new CalendarFetcher(url, fetchIntervalCorrected || fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents, selfSignedCert);
|
||||||
|
|
||||||
fetcher.onReceive((fetcher) => {
|
fetcher.onReceive((fetcher) => {
|
||||||
this.broadcastEvents(fetcher, identifier);
|
this.broadcastEvents(fetcher, identifier);
|
||||||
@@ -86,7 +84,7 @@ module.exports = NodeHelper.create({
|
|||||||
* @param {object} fetcher the fetcher associated with the calendar
|
* @param {object} fetcher the fetcher associated with the calendar
|
||||||
* @param {string} identifier the identifier of the calendar
|
* @param {string} identifier the identifier of the calendar
|
||||||
*/
|
*/
|
||||||
broadcastEvents: function (fetcher, identifier) {
|
broadcastEvents (fetcher, identifier) {
|
||||||
this.sendSocketNotification("CALENDAR_EVENTS", {
|
this.sendSocketNotification("CALENDAR_EVENTS", {
|
||||||
id: identifier,
|
id: identifier,
|
||||||
url: fetcher.url(),
|
url: fetcher.url(),
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
/* global SunCalc */
|
/* global SunCalc, formatTime */
|
||||||
|
|
||||||
/* MagicMirror²
|
|
||||||
* Module: Clock
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
Module.register("clock", {
|
Module.register("clock", {
|
||||||
// Module config defaults.
|
// Module config defaults.
|
||||||
defaults: {
|
defaults: {
|
||||||
@@ -32,20 +26,20 @@ Module.register("clock", {
|
|||||||
secondsColor: "#888888",
|
secondsColor: "#888888",
|
||||||
|
|
||||||
showSunTimes: false,
|
showSunTimes: false,
|
||||||
showMoonTimes: false,
|
showMoonTimes: false, // options: false, 'times' (rise/set), 'percent' (lit percent), 'phase' (current phase), or 'both' (percent & phase)
|
||||||
lat: 47.630539,
|
lat: 47.630539,
|
||||||
lon: -122.344147
|
lon: -122.344147
|
||||||
},
|
},
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
getScripts: function () {
|
getScripts () {
|
||||||
return ["moment.js", "moment-timezone.js", "suncalc.js"];
|
return ["moment.js", "moment-timezone.js", "suncalc.js"];
|
||||||
},
|
},
|
||||||
// Define styles.
|
// Define styles.
|
||||||
getStyles: function () {
|
getStyles () {
|
||||||
return ["clock_styles.css"];
|
return ["clock_styles.css"];
|
||||||
},
|
},
|
||||||
// Define start sequence.
|
// Define start sequence.
|
||||||
start: function () {
|
start () {
|
||||||
Log.info(`Starting module: ${this.name}`);
|
Log.info(`Starting module: ${this.name}`);
|
||||||
|
|
||||||
// Schedule update interval.
|
// Schedule update interval.
|
||||||
@@ -94,7 +88,7 @@ Module.register("clock", {
|
|||||||
moment.locale(config.language);
|
moment.locale(config.language);
|
||||||
},
|
},
|
||||||
// Override dom generator.
|
// Override dom generator.
|
||||||
getDom: function () {
|
getDom () {
|
||||||
const wrapper = document.createElement("div");
|
const wrapper = document.createElement("div");
|
||||||
wrapper.classList.add("clock-grid");
|
wrapper.classList.add("clock-grid");
|
||||||
|
|
||||||
@@ -105,7 +99,6 @@ Module.register("clock", {
|
|||||||
analogWrapper.className = "clock-circle";
|
analogWrapper.className = "clock-circle";
|
||||||
const digitalWrapper = document.createElement("div");
|
const digitalWrapper = document.createElement("div");
|
||||||
digitalWrapper.className = "digital";
|
digitalWrapper.className = "digital";
|
||||||
digitalWrapper.style.gridArea = "center";
|
|
||||||
|
|
||||||
/************************************
|
/************************************
|
||||||
* Create wrappers for DIGITAL clock
|
* Create wrappers for DIGITAL clock
|
||||||
@@ -129,7 +122,7 @@ Module.register("clock", {
|
|||||||
// Set content of wrappers.
|
// Set content of wrappers.
|
||||||
// The moment().format("h") method has a bug on the Raspberry Pi.
|
// The moment().format("h") method has a bug on the Raspberry Pi.
|
||||||
// So we need to generate the timestring manually.
|
// So we need to generate the timestring manually.
|
||||||
// See issue: https://github.com/MichMich/MagicMirror/issues/181
|
// See issue: https://github.com/MagicMirrorOrg/MagicMirror/issues/181
|
||||||
let timeString;
|
let timeString;
|
||||||
const now = moment();
|
const now = moment();
|
||||||
if (this.config.timezone) {
|
if (this.config.timezone) {
|
||||||
@@ -169,21 +162,6 @@ Module.register("clock", {
|
|||||||
digitalWrapper.appendChild(timeWrapper);
|
digitalWrapper.appendChild(timeWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Format the time according to the config
|
|
||||||
*
|
|
||||||
* @param {object} config The config of the module
|
|
||||||
* @param {object} time time to format
|
|
||||||
* @returns {string} The formatted time string
|
|
||||||
*/
|
|
||||||
function formatTime(config, time) {
|
|
||||||
let formatString = `${hourSymbol}:mm`;
|
|
||||||
if (config.showPeriod && config.timeFormat !== 24) {
|
|
||||||
formatString += config.showPeriodUpper ? "A" : "a";
|
|
||||||
}
|
|
||||||
return moment(time).format(formatString);
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
* Create wrappers for Sun Times, only if specified in config
|
* Create wrappers for Sun Times, only if specified in config
|
||||||
*/
|
*/
|
||||||
@@ -201,10 +179,10 @@ Module.register("clock", {
|
|||||||
}
|
}
|
||||||
const untilNextEvent = moment.duration(moment(nextEvent).diff(now));
|
const untilNextEvent = moment.duration(moment(nextEvent).diff(now));
|
||||||
const untilNextEventString = `${untilNextEvent.hours()}h ${untilNextEvent.minutes()}m`;
|
const untilNextEventString = `${untilNextEvent.hours()}h ${untilNextEvent.minutes()}m`;
|
||||||
sunWrapper.innerHTML =
|
sunWrapper.innerHTML
|
||||||
`<span class="${isVisible ? "bright" : ""}"><i class="fas fa-sun" aria-hidden="true"></i> ${untilNextEventString}</span>` +
|
= `<span class="${isVisible ? "bright" : ""}"><i class="fas fa-sun" aria-hidden="true"></i> ${untilNextEventString}</span>`
|
||||||
`<span><i class="fas fa-arrow-up" aria-hidden="true"></i> ${formatTime(this.config, sunTimes.sunrise)}</span>` +
|
+ `<span><i class="fas fa-arrow-up" aria-hidden="true"></i> ${formatTime(this.config, sunTimes.sunrise)}</span>`
|
||||||
`<span><i class="fas fa-arrow-down" aria-hidden="true"></i> ${formatTime(this.config, sunTimes.sunset)}</span>`;
|
+ `<span><i class="fas fa-arrow-down" aria-hidden="true"></i> ${formatTime(this.config, sunTimes.sunset)}</span>`;
|
||||||
digitalWrapper.appendChild(sunWrapper);
|
digitalWrapper.appendChild(sunWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,11 +201,15 @@ Module.register("clock", {
|
|||||||
moonSet = nextMoonTimes.set;
|
moonSet = nextMoonTimes.set;
|
||||||
}
|
}
|
||||||
const isVisible = now.isBetween(moonRise, moonSet) || moonTimes.alwaysUp === true;
|
const isVisible = now.isBetween(moonRise, moonSet) || moonTimes.alwaysUp === true;
|
||||||
|
const showFraction = ["both", "percent"].includes(this.config.showMoonTimes);
|
||||||
|
const showUnicode = ["both", "phase"].includes(this.config.showMoonTimes);
|
||||||
const illuminatedFractionString = `${Math.round(moonIllumination.fraction * 100)}%`;
|
const illuminatedFractionString = `${Math.round(moonIllumination.fraction * 100)}%`;
|
||||||
moonWrapper.innerHTML =
|
const image = showUnicode ? [..."🌑🌒🌓🌔🌕🌖🌗🌘"][Math.floor(moonIllumination.phase * 8)] : "<i class=\"fas fa-moon\" aria-hidden=\"true\"></i>";
|
||||||
`<span class="${isVisible ? "bright" : ""}"><i class="fas fa-moon" aria-hidden="true"></i> ${illuminatedFractionString}</span>` +
|
|
||||||
`<span><i class="fas fa-arrow-up" aria-hidden="true"></i> ${moonRise ? formatTime(this.config, moonRise) : "..."}</span>` +
|
moonWrapper.innerHTML
|
||||||
`<span><i class="fas fa-arrow-down" aria-hidden="true"></i> ${moonSet ? formatTime(this.config, moonSet) : "..."}</span>`;
|
= `<span class="${isVisible ? "bright" : ""}">${image} ${showFraction ? illuminatedFractionString : ""}</span>`
|
||||||
|
+ `<span><i class="fas fa-arrow-up" aria-hidden="true"></i> ${moonRise ? formatTime(this.config, moonRise) : "..."}</span>`
|
||||||
|
+ `<span><i class="fas fa-arrow-down" aria-hidden="true"></i> ${moonSet ? formatTime(this.config, moonSet) : "..."}</span>`;
|
||||||
digitalWrapper.appendChild(moonWrapper);
|
digitalWrapper.appendChild(moonWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,7 +240,7 @@ Module.register("clock", {
|
|||||||
analogWrapper.style.background = `url(${this.data.path}faces/${this.config.analogFace}.svg)`;
|
analogWrapper.style.background = `url(${this.data.path}faces/${this.config.analogFace}.svg)`;
|
||||||
analogWrapper.style.backgroundSize = "100%";
|
analogWrapper.style.backgroundSize = "100%";
|
||||||
|
|
||||||
// The following line solves issue: https://github.com/MichMich/MagicMirror/issues/611
|
// The following line solves issue: https://github.com/MagicMirrorOrg/MagicMirror/issues/611
|
||||||
// analogWrapper.style.border = "1px solid black";
|
// analogWrapper.style.border = "1px solid black";
|
||||||
analogWrapper.style.border = "rgba(0, 0, 0, 0.1)"; //Updated fix for Issue 611 where non-black backgrounds are used
|
analogWrapper.style.border = "rgba(0, 0, 0, 0.1)"; //Updated fix for Issue 611 where non-black backgrounds are used
|
||||||
} else if (this.config.analogFace !== "none") {
|
} else if (this.config.analogFace !== "none") {
|
||||||
@@ -296,9 +278,14 @@ Module.register("clock", {
|
|||||||
*/
|
*/
|
||||||
if (this.config.displayType === "analog") {
|
if (this.config.displayType === "analog") {
|
||||||
// Display only an analog clock
|
// Display only an analog clock
|
||||||
if (this.config.analogShowDate === "top") {
|
if (this.config.showDate) {
|
||||||
|
// Add date to the analog clock
|
||||||
|
dateWrapper.innerHTML = now.format(this.config.dateFormat);
|
||||||
|
wrapper.appendChild(dateWrapper);
|
||||||
|
}
|
||||||
|
if (this.config.analogShowDate === "bottom") {
|
||||||
wrapper.classList.add("clock-grid-bottom");
|
wrapper.classList.add("clock-grid-bottom");
|
||||||
} else if (this.config.analogShowDate === "bottom") {
|
} else if (this.config.analogShowDate === "top") {
|
||||||
wrapper.classList.add("clock-grid-top");
|
wrapper.classList.add("clock-grid-top");
|
||||||
}
|
}
|
||||||
wrapper.appendChild(analogWrapper);
|
wrapper.appendChild(analogWrapper);
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
/* MagicMirror²
|
|
||||||
* Module: Compliments
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
Module.register("compliments", {
|
Module.register("compliments", {
|
||||||
// Module config defaults.
|
// Module config defaults.
|
||||||
defaults: {
|
defaults: {
|
||||||
@@ -28,12 +22,12 @@ Module.register("compliments", {
|
|||||||
currentWeatherType: "",
|
currentWeatherType: "",
|
||||||
|
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
getScripts: function () {
|
getScripts () {
|
||||||
return ["moment.js"];
|
return ["moment.js"];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Define start sequence.
|
// Define start sequence.
|
||||||
start: async function () {
|
async start () {
|
||||||
Log.info(`Starting module: ${this.name}`);
|
Log.info(`Starting module: ${this.name}`);
|
||||||
|
|
||||||
this.lastComplimentIndex = -1;
|
this.lastComplimentIndex = -1;
|
||||||
@@ -52,12 +46,11 @@ Module.register("compliments", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a random index for a list of compliments.
|
* Generate a random index for a list of compliments.
|
||||||
*
|
|
||||||
* @param {string[]} compliments Array with compliments.
|
* @param {string[]} compliments Array with compliments.
|
||||||
* @returns {number} a random index of given array
|
* @returns {number} a random index of given array
|
||||||
*/
|
*/
|
||||||
randomIndex: function (compliments) {
|
randomIndex (compliments) {
|
||||||
if (compliments.length === 1) {
|
if (compliments.length <= 1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,10 +71,9 @@ Module.register("compliments", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve an array of compliments for the time of the day.
|
* Retrieve an array of compliments for the time of the day.
|
||||||
*
|
|
||||||
* @returns {string[]} array with compliments for the time of the day.
|
* @returns {string[]} array with compliments for the time of the day.
|
||||||
*/
|
*/
|
||||||
complimentArray: function () {
|
complimentArray () {
|
||||||
const hour = moment().hour();
|
const hour = moment().hour();
|
||||||
const date = moment().format("YYYY-MM-DD");
|
const date = moment().format("YYYY-MM-DD");
|
||||||
let compliments = [];
|
let compliments = [];
|
||||||
@@ -115,10 +107,9 @@ Module.register("compliments", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a file from the local filesystem
|
* Retrieve a file from the local filesystem
|
||||||
*
|
|
||||||
* @returns {Promise} Resolved when the file is loaded
|
* @returns {Promise} Resolved when the file is loaded
|
||||||
*/
|
*/
|
||||||
loadComplimentFile: async function () {
|
async loadComplimentFile () {
|
||||||
const isRemote = this.config.remoteFile.indexOf("http://") === 0 || this.config.remoteFile.indexOf("https://") === 0,
|
const isRemote = this.config.remoteFile.indexOf("http://") === 0 || this.config.remoteFile.indexOf("https://") === 0,
|
||||||
url = isRemote ? this.config.remoteFile : this.file(this.config.remoteFile);
|
url = isRemote ? this.config.remoteFile : this.file(this.config.remoteFile);
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
@@ -127,10 +118,9 @@ Module.register("compliments", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a random compliment.
|
* Retrieve a random compliment.
|
||||||
*
|
|
||||||
* @returns {string} a compliment
|
* @returns {string} a compliment
|
||||||
*/
|
*/
|
||||||
getRandomCompliment: function () {
|
getRandomCompliment () {
|
||||||
// get the current time of day compliments list
|
// get the current time of day compliments list
|
||||||
const compliments = this.complimentArray();
|
const compliments = this.complimentArray();
|
||||||
// variable for index to next message to display
|
// variable for index to next message to display
|
||||||
@@ -149,7 +139,7 @@ Module.register("compliments", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Override dom generator.
|
// Override dom generator.
|
||||||
getDom: function () {
|
getDom () {
|
||||||
const wrapper = document.createElement("div");
|
const wrapper = document.createElement("div");
|
||||||
wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright pre-line";
|
wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright pre-line";
|
||||||
// get the compliment text
|
// get the compliment text
|
||||||
@@ -177,7 +167,7 @@ Module.register("compliments", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Override notification handler.
|
// Override notification handler.
|
||||||
notificationReceived: function (notification, payload, sender) {
|
notificationReceived (notification, payload, sender) {
|
||||||
if (notification === "CURRENTWEATHER_TYPE") {
|
if (notification === "CURRENTWEATHER_TYPE") {
|
||||||
this.currentWeatherType = payload.type;
|
this.currentWeatherType = payload.type;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
/* MagicMirror² Default Modules List
|
/* Default Modules List
|
||||||
* Modules listed below can be loaded without the 'default/' prefix. Omitting the default folder name.
|
* Modules listed below can be loaded without the 'default/' prefix. Omitting the default folder name.
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
*/
|
||||||
const defaultModules = ["alert", "calendar", "clock", "compliments", "helloworld", "newsfeed", "updatenotification", "weather"];
|
const defaultModules = ["alert", "calendar", "clock", "compliments", "helloworld", "newsfeed", "updatenotification", "weather"];
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,14 @@
|
|||||||
/* MagicMirror²
|
|
||||||
* Module: HelloWorld
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
Module.register("helloworld", {
|
Module.register("helloworld", {
|
||||||
// Default module config.
|
// Default module config.
|
||||||
defaults: {
|
defaults: {
|
||||||
text: "Hello World!"
|
text: "Hello World!"
|
||||||
},
|
},
|
||||||
|
|
||||||
getTemplate: function () {
|
getTemplate () {
|
||||||
return "helloworld.njk";
|
return "helloworld.njk";
|
||||||
},
|
},
|
||||||
|
|
||||||
getTemplateData: function () {
|
getTemplateData () {
|
||||||
return this.config;
|
return this.config;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
Use ` | safe` to allow html tages within the text string.
|
Use ` | safe` to allow html tages within the text string.
|
||||||
https://mozilla.github.io/nunjucks/templating.html#autoescaping
|
https://mozilla.github.io/nunjucks/templating.html#autoescaping
|
||||||
-->
|
-->
|
||||||
<div>{{text | safe}}</div>
|
<div>{{ text | safe }}</div>
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
<div>
|
<div>
|
||||||
<iframe class="newsfeed-fullarticle" src="{{ url }}"></iframe>
|
<iframe class="newsfeed-fullarticle" src="{{ url }}"></iframe>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
/* MagicMirror²
|
|
||||||
* Module: NewsFeed
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
Module.register("newsfeed", {
|
Module.register("newsfeed", {
|
||||||
// Default module config.
|
// Default module config.
|
||||||
defaults: {
|
defaults: {
|
||||||
@@ -42,7 +36,7 @@ Module.register("newsfeed", {
|
|||||||
dangerouslyDisableAutoEscaping: false
|
dangerouslyDisableAutoEscaping: false
|
||||||
},
|
},
|
||||||
|
|
||||||
getUrlPrefix: function (item) {
|
getUrlPrefix (item) {
|
||||||
if (item.useCorsProxy) {
|
if (item.useCorsProxy) {
|
||||||
return `${location.protocol}//${location.host}/cors?url=`;
|
return `${location.protocol}//${location.host}/cors?url=`;
|
||||||
} else {
|
} else {
|
||||||
@@ -51,17 +45,17 @@ Module.register("newsfeed", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
getScripts: function () {
|
getScripts () {
|
||||||
return ["moment.js"];
|
return ["moment.js"];
|
||||||
},
|
},
|
||||||
|
|
||||||
//Define required styles.
|
//Define required styles.
|
||||||
getStyles: function () {
|
getStyles () {
|
||||||
return ["newsfeed.css"];
|
return ["newsfeed.css"];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Define required translations.
|
// Define required translations.
|
||||||
getTranslations: function () {
|
getTranslations () {
|
||||||
// The translations for the default modules are defined in the core translation files.
|
// The translations for the default modules are defined in the core translation files.
|
||||||
// Therefor we can just return false. Otherwise we should have returned a dictionary.
|
// Therefor we can just return false. Otherwise we should have returned a dictionary.
|
||||||
// If you're trying to build your own module including translations, check out the documentation.
|
// If you're trying to build your own module including translations, check out the documentation.
|
||||||
@@ -69,7 +63,7 @@ Module.register("newsfeed", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Define start sequence.
|
// Define start sequence.
|
||||||
start: function () {
|
start () {
|
||||||
Log.info(`Starting module: ${this.name}`);
|
Log.info(`Starting module: ${this.name}`);
|
||||||
|
|
||||||
// Set locale.
|
// Set locale.
|
||||||
@@ -87,7 +81,7 @@ Module.register("newsfeed", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Override socket notification handler.
|
// Override socket notification handler.
|
||||||
socketNotificationReceived: function (notification, payload) {
|
socketNotificationReceived (notification, payload) {
|
||||||
if (notification === "NEWS_ITEMS") {
|
if (notification === "NEWS_ITEMS") {
|
||||||
this.generateFeed(payload);
|
this.generateFeed(payload);
|
||||||
|
|
||||||
@@ -107,7 +101,7 @@ Module.register("newsfeed", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
//Override fetching of template name
|
//Override fetching of template name
|
||||||
getTemplate: function () {
|
getTemplate () {
|
||||||
if (this.config.feedUrl) {
|
if (this.config.feedUrl) {
|
||||||
return "oldconfig.njk";
|
return "oldconfig.njk";
|
||||||
} else if (this.config.showFullArticle) {
|
} else if (this.config.showFullArticle) {
|
||||||
@@ -117,28 +111,34 @@ Module.register("newsfeed", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
//Override template data and return whats used for the current template
|
//Override template data and return whats used for the current template
|
||||||
getTemplateData: function () {
|
getTemplateData () {
|
||||||
|
if (this.activeItem >= this.newsItems.length) {
|
||||||
|
this.activeItem = 0;
|
||||||
|
}
|
||||||
|
this.activeItemCount = this.newsItems.length;
|
||||||
// this.config.showFullArticle is a run-time configuration, triggered by optional notifications
|
// this.config.showFullArticle is a run-time configuration, triggered by optional notifications
|
||||||
if (this.config.showFullArticle) {
|
if (this.config.showFullArticle) {
|
||||||
|
this.activeItemHash = this.newsItems[this.activeItem]?.hash;
|
||||||
return {
|
return {
|
||||||
url: this.getActiveItemURL()
|
url: this.getActiveItemURL()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (this.error) {
|
if (this.error) {
|
||||||
|
this.activeItemHash = undefined;
|
||||||
return {
|
return {
|
||||||
error: this.error
|
error: this.error
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (this.newsItems.length === 0) {
|
if (this.newsItems.length === 0) {
|
||||||
|
this.activeItemHash = undefined;
|
||||||
return {
|
return {
|
||||||
empty: true
|
empty: true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (this.activeItem >= this.newsItems.length) {
|
|
||||||
this.activeItem = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const item = this.newsItems[this.activeItem];
|
const item = this.newsItems[this.activeItem];
|
||||||
|
this.activeItemHash = item.hash;
|
||||||
|
|
||||||
const items = this.newsItems.map(function (item) {
|
const items = this.newsItems.map(function (item) {
|
||||||
item.publishDate = moment(new Date(item.pubdate)).fromNow();
|
item.publishDate = moment(new Date(item.pubdate)).fromNow();
|
||||||
return item;
|
return item;
|
||||||
@@ -150,13 +150,13 @@ Module.register("newsfeed", {
|
|||||||
sourceTitle: item.sourceTitle,
|
sourceTitle: item.sourceTitle,
|
||||||
publishDate: moment(new Date(item.pubdate)).fromNow(),
|
publishDate: moment(new Date(item.pubdate)).fromNow(),
|
||||||
title: item.title,
|
title: item.title,
|
||||||
url: this.getUrlPrefix(item) + item.url,
|
url: this.getActiveItemURL(),
|
||||||
description: item.description,
|
description: item.description,
|
||||||
items: items
|
items: items
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
getActiveItemURL: function () {
|
getActiveItemURL () {
|
||||||
const item = this.newsItems[this.activeItem];
|
const item = this.newsItems[this.activeItem];
|
||||||
if (item) {
|
if (item) {
|
||||||
return typeof item.url === "string" ? this.getUrlPrefix(item) + item.url : this.getUrlPrefix(item) + item.url.href;
|
return typeof item.url === "string" ? this.getUrlPrefix(item) + item.url : this.getUrlPrefix(item) + item.url.href;
|
||||||
@@ -168,7 +168,7 @@ Module.register("newsfeed", {
|
|||||||
/**
|
/**
|
||||||
* Registers the feeds to be used by the backend.
|
* Registers the feeds to be used by the backend.
|
||||||
*/
|
*/
|
||||||
registerFeeds: function () {
|
registerFeeds () {
|
||||||
for (let feed of this.config.feeds) {
|
for (let feed of this.config.feeds) {
|
||||||
this.sendSocketNotification("ADD_FEED", {
|
this.sendSocketNotification("ADD_FEED", {
|
||||||
feed: feed,
|
feed: feed,
|
||||||
@@ -179,10 +179,9 @@ Module.register("newsfeed", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate an ordered list of items for this configured module.
|
* Generate an ordered list of items for this configured module.
|
||||||
*
|
|
||||||
* @param {object} feeds An object with feeds returned by the node helper.
|
* @param {object} feeds An object with feeds returned by the node helper.
|
||||||
*/
|
*/
|
||||||
generateFeed: function (feeds) {
|
generateFeed (feeds) {
|
||||||
let newsItems = [];
|
let newsItems = [];
|
||||||
for (let feed in feeds) {
|
for (let feed in feeds) {
|
||||||
const feedItems = feeds[feed];
|
const feedItems = feeds[feed];
|
||||||
@@ -272,11 +271,10 @@ Module.register("newsfeed", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if this module is configured to show this feed.
|
* Check if this module is configured to show this feed.
|
||||||
*
|
|
||||||
* @param {string} feedUrl Url of the feed to check.
|
* @param {string} feedUrl Url of the feed to check.
|
||||||
* @returns {boolean} True if it is subscribed, false otherwise
|
* @returns {boolean} True if it is subscribed, false otherwise
|
||||||
*/
|
*/
|
||||||
subscribedToFeed: function (feedUrl) {
|
subscribedToFeed (feedUrl) {
|
||||||
for (let feed of this.config.feeds) {
|
for (let feed of this.config.feeds) {
|
||||||
if (feed.url === feedUrl) {
|
if (feed.url === feedUrl) {
|
||||||
return true;
|
return true;
|
||||||
@@ -287,11 +285,10 @@ Module.register("newsfeed", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns title for the specific feed url.
|
* Returns title for the specific feed url.
|
||||||
*
|
|
||||||
* @param {string} feedUrl Url of the feed
|
* @param {string} feedUrl Url of the feed
|
||||||
* @returns {string} The title of the feed
|
* @returns {string} The title of the feed
|
||||||
*/
|
*/
|
||||||
titleForFeed: function (feedUrl) {
|
titleForFeed (feedUrl) {
|
||||||
for (let feed of this.config.feeds) {
|
for (let feed of this.config.feeds) {
|
||||||
if (feed.url === feedUrl) {
|
if (feed.url === feedUrl) {
|
||||||
return feed.title || "";
|
return feed.title || "";
|
||||||
@@ -303,7 +300,7 @@ Module.register("newsfeed", {
|
|||||||
/**
|
/**
|
||||||
* Schedule visual update.
|
* Schedule visual update.
|
||||||
*/
|
*/
|
||||||
scheduleUpdateInterval: function () {
|
scheduleUpdateInterval () {
|
||||||
this.updateDom(this.config.animationSpeed);
|
this.updateDom(this.config.animationSpeed);
|
||||||
|
|
||||||
// Broadcast NewsFeed if needed
|
// Broadcast NewsFeed if needed
|
||||||
@@ -315,8 +312,27 @@ Module.register("newsfeed", {
|
|||||||
if (this.timer) clearInterval(this.timer);
|
if (this.timer) clearInterval(this.timer);
|
||||||
|
|
||||||
this.timer = setInterval(() => {
|
this.timer = setInterval(() => {
|
||||||
this.activeItem++;
|
|
||||||
this.updateDom(this.config.animationSpeed);
|
/*
|
||||||
|
* When animations are enabled, don't update the DOM unless we are actually changing what we are displaying.
|
||||||
|
* (Animating from a headline to itself is unsightly.)
|
||||||
|
* Cases:
|
||||||
|
*
|
||||||
|
* Number of items | Number of items | Display
|
||||||
|
* at last update | right now | Behaviour
|
||||||
|
* ----------------------------------------------------
|
||||||
|
* 0 | 0 | do not update
|
||||||
|
* 0 | >0 | update
|
||||||
|
* 1 | 0 or >1 | update
|
||||||
|
* 1 | 1 | update only if item details (hash value) changed
|
||||||
|
* >1 | any | update
|
||||||
|
*
|
||||||
|
* (N.B. We set activeItemCount and activeItemHash in getTemplateData().)
|
||||||
|
*/
|
||||||
|
if (this.newsItems.length > 1 || this.newsItems.length !== this.activeItemCount || this.activeItemHash !== this.newsItems[0]?.hash) {
|
||||||
|
this.activeItem++; // this is OK if newsItems.Length==1; getTemplateData will wrap it around
|
||||||
|
this.updateDom(this.config.animationSpeed);
|
||||||
|
}
|
||||||
|
|
||||||
// Broadcast NewsFeed if needed
|
// Broadcast NewsFeed if needed
|
||||||
if (this.config.broadcastNewsFeeds) {
|
if (this.config.broadcastNewsFeeds) {
|
||||||
@@ -325,7 +341,7 @@ Module.register("newsfeed", {
|
|||||||
}, this.config.updateInterval);
|
}, this.config.updateInterval);
|
||||||
},
|
},
|
||||||
|
|
||||||
resetDescrOrFullArticleAndTimer: function () {
|
resetDescrOrFullArticleAndTimer () {
|
||||||
this.isShowingDescription = this.config.showDescription;
|
this.isShowingDescription = this.config.showDescription;
|
||||||
this.config.showFullArticle = false;
|
this.config.showFullArticle = false;
|
||||||
this.scrollPosition = 0;
|
this.scrollPosition = 0;
|
||||||
@@ -336,7 +352,7 @@ Module.register("newsfeed", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
notificationReceived: function (notification, payload, sender) {
|
notificationReceived (notification, payload, sender) {
|
||||||
const before = this.activeItem;
|
const before = this.activeItem;
|
||||||
if (notification === "MODULE_DOM_CREATED" && this.config.hideLoading) {
|
if (notification === "MODULE_DOM_CREATED" && this.config.hideLoading) {
|
||||||
this.hide();
|
this.hide();
|
||||||
@@ -397,7 +413,7 @@ Module.register("newsfeed", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
showFullArticle: function () {
|
showFullArticle () {
|
||||||
this.isShowingDescription = !this.isShowingDescription;
|
this.isShowingDescription = !this.isShowingDescription;
|
||||||
this.config.showFullArticle = !this.isShowingDescription;
|
this.config.showFullArticle = !this.isShowingDescription;
|
||||||
// make bottom bar align to top to allow scrolling
|
// make bottom bar align to top to allow scrolling
|
||||||
|
|||||||
@@ -1,27 +1,31 @@
|
|||||||
{% macro escapeText(text, dangerouslyDisableAutoEscaping=false) %}
|
{% macro escapeText(text, dangerouslyDisableAutoEscaping=false) %}
|
||||||
{% if dangerouslyDisableAutoEscaping %}
|
{% if dangerouslyDisableAutoEscaping -%}
|
||||||
{{ text | safe}}
|
{{ text | safe }}
|
||||||
{% else %}
|
{%- else -%}
|
||||||
{{ text }}
|
{{ text }}
|
||||||
{% endif %}
|
{%- endif %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro escapeTitle(title, url, dangerouslyDisableAutoEscaping=false, showTitleAsUrl=false) %}
|
{% macro escapeTitle(title, url, dangerouslyDisableAutoEscaping=false, showTitleAsUrl=false) %}
|
||||||
{% if dangerouslyDisableAutoEscaping %}
|
{% if dangerouslyDisableAutoEscaping %}
|
||||||
{% if showTitleAsUrl %}
|
{% if showTitleAsUrl %}
|
||||||
<a href="{{ url }}" style="text-decoration:none;color:#ffffff" target="_blank">{{ title | safe }}</a>
|
<a href="{{ url }}"
|
||||||
|
style="text-decoration:none;
|
||||||
|
color:#ffffff"
|
||||||
|
target="_blank">{{ title | safe }}</a>
|
||||||
|
{% else %}
|
||||||
|
{{ title | safe }}
|
||||||
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ title | safe}}
|
{% if showTitleAsUrl %}
|
||||||
|
<a href="{{ url }}"
|
||||||
|
style="text-decoration:none;
|
||||||
|
color:#ffffff"
|
||||||
|
target="_blank">{{ title }}</a>
|
||||||
|
{% else %}
|
||||||
|
{{ title }}
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
|
||||||
{% if showTitleAsUrl %}
|
|
||||||
<a href="{{ url }}" style="text-decoration:none;color:#ffffff" target="_blank">{{ title }}</a>
|
|
||||||
{% else %}
|
|
||||||
{{ title }}
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% if loaded %}
|
{% if loaded %}
|
||||||
{% if config.showAsList %}
|
{% if config.showAsList %}
|
||||||
<ul class="newsfeed-list">
|
<ul class="newsfeed-list">
|
||||||
@@ -30,11 +34,9 @@
|
|||||||
{% if (config.showSourceTitle and item.sourceTitle) or config.showPublishDate %}
|
{% if (config.showSourceTitle and item.sourceTitle) or config.showPublishDate %}
|
||||||
<div class="newsfeed-source light small dimmed">
|
<div class="newsfeed-source light small dimmed">
|
||||||
{% if item.sourceTitle and config.showSourceTitle %}
|
{% if item.sourceTitle and config.showSourceTitle %}
|
||||||
{{ item.sourceTitle }}{% if config.showPublishDate %}, {% else %}: {% endif %}
|
{{ item.sourceTitle }}{% if config.showPublishDate %}, {% else %}:{% endif %}
|
||||||
{% endif %}
|
|
||||||
{% if config.showPublishDate %}
|
|
||||||
{{ item.publishDate }}:
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if config.showPublishDate %}{{ item.publishDate }}:{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="newsfeed-title bright medium light{{ ' no-wrap' if not config.wrapTitle }}">
|
<div class="newsfeed-title bright medium light{{ ' no-wrap' if not config.wrapTitle }}">
|
||||||
@@ -43,7 +45,7 @@
|
|||||||
{% if config.showDescription %}
|
{% if config.showDescription %}
|
||||||
<div class="newsfeed-desc small light{{ ' no-wrap' if not config.wrapDescription }}">
|
<div class="newsfeed-desc small light{{ ' no-wrap' if not config.wrapDescription }}">
|
||||||
{% if config.truncDescription %}
|
{% if config.truncDescription %}
|
||||||
{{ escapeText(item.description | truncate(config.lengthDescription), config.dangerouslyDisableAutoEscaping) }}
|
{{ escapeText(item.description | truncate(config.lengthDescription) , config.dangerouslyDisableAutoEscaping) }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ escapeText(item.description, config.dangerouslyDisableAutoEscaping) }}
|
{{ escapeText(item.description, config.dangerouslyDisableAutoEscaping) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -57,11 +59,9 @@
|
|||||||
{% if (config.showSourceTitle and sourceTitle) or config.showPublishDate %}
|
{% if (config.showSourceTitle and sourceTitle) or config.showPublishDate %}
|
||||||
<div class="newsfeed-source light small dimmed">
|
<div class="newsfeed-source light small dimmed">
|
||||||
{% if sourceTitle and config.showSourceTitle %}
|
{% if sourceTitle and config.showSourceTitle %}
|
||||||
{{ escapeText(sourceTitle, config.dangerouslyDisableAutoEscaping) }}{% if config.showPublishDate %}, {% else %}: {% endif %}
|
{{ escapeText(sourceTitle, config.dangerouslyDisableAutoEscaping) }}{% if config.showPublishDate %}, {% else %}:{% endif %}
|
||||||
{% endif %}
|
|
||||||
{% if config.showPublishDate %}
|
|
||||||
{{ publishDate }}:
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if config.showPublishDate %}{{ publishDate }}:{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="newsfeed-title bright medium light{{ ' no-wrap' if not config.wrapTitle }}">
|
<div class="newsfeed-title bright medium light{{ ' no-wrap' if not config.wrapTitle }}">
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
{% if config.showDescription %}
|
{% if config.showDescription %}
|
||||||
<div class="newsfeed-desc small light{{ ' no-wrap' if not config.wrapDescription }}">
|
<div class="newsfeed-desc small light{{ ' no-wrap' if not config.wrapDescription }}">
|
||||||
{% if config.truncDescription %}
|
{% if config.truncDescription %}
|
||||||
{{ escapeText(description | truncate(config.lengthDescription), config.dangerouslyDisableAutoEscaping) }}
|
{{ escapeText(description | truncate(config.lengthDescription) , config.dangerouslyDisableAutoEscaping) }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ escapeText(description, config.dangerouslyDisableAutoEscaping) }}
|
{{ escapeText(description, config.dangerouslyDisableAutoEscaping) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -79,15 +79,11 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% elseif empty %}
|
{% elseif empty %}
|
||||||
<div class="small dimmed">
|
<div class="small dimmed">{{ "NEWSFEED_NO_ITEMS" | translate | safe }}</div>
|
||||||
{{ "NEWSFEED_NO_ITEMS" | translate | safe }}
|
|
||||||
</div>
|
|
||||||
{% elseif error %}
|
{% elseif error %}
|
||||||
<div class="small dimmed">
|
<div class="small dimmed">
|
||||||
{{ "MODULE_CONFIG_ERROR" | translate({MODULE_NAME: "Newsfeed", ERROR: error}) | safe }}
|
{{ "MODULE_CONFIG_ERROR" | translate({MODULE_NAME: "Newsfeed", ERROR: error}) | safe }}
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="small dimmed">
|
<div class="small dimmed">{{ "LOADING" | translate | safe }}</div>
|
||||||
{{ "LOADING" | translate | safe }}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -1,20 +1,13 @@
|
|||||||
/* MagicMirror²
|
const crypto = require("node:crypto");
|
||||||
* Node Helper: Newsfeed - NewsfeedFetcher
|
const stream = require("node:stream");
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const stream = require("stream");
|
|
||||||
const FeedMe = require("feedme");
|
const FeedMe = require("feedme");
|
||||||
const iconv = require("iconv-lite");
|
const iconv = require("iconv-lite");
|
||||||
const fetch = require("fetch");
|
const { htmlToText } = require("html-to-text");
|
||||||
const Log = require("logger");
|
const Log = require("logger");
|
||||||
const NodeHelper = require("node_helper");
|
const NodeHelper = require("node_helper");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Responsible for requesting an update on the set interval and broadcasting the data.
|
* Responsible for requesting an update on the set interval and broadcasting the data.
|
||||||
*
|
|
||||||
* @param {string} url URL of the news feed.
|
* @param {string} url URL of the news feed.
|
||||||
* @param {number} reloadInterval Reload interval in milliseconds.
|
* @param {number} reloadInterval Reload interval in milliseconds.
|
||||||
* @param {string} encoding Encoding of the feed.
|
* @param {string} encoding Encoding of the feed.
|
||||||
@@ -25,12 +18,13 @@ const NodeHelper = require("node_helper");
|
|||||||
const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings, useCorsProxy) {
|
const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings, useCorsProxy) {
|
||||||
let reloadTimer = null;
|
let reloadTimer = null;
|
||||||
let items = [];
|
let items = [];
|
||||||
|
let reloadIntervalMS = reloadInterval;
|
||||||
|
|
||||||
let fetchFailedCallback = function () {};
|
let fetchFailedCallback = function () {};
|
||||||
let itemsReceivedCallback = function () {};
|
let itemsReceivedCallback = function () {};
|
||||||
|
|
||||||
if (reloadInterval < 1000) {
|
if (reloadIntervalMS < 1000) {
|
||||||
reloadInterval = 1000;
|
reloadIntervalMS = 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* private methods */
|
/* private methods */
|
||||||
@@ -48,19 +42,27 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings
|
|||||||
parser.on("item", (item) => {
|
parser.on("item", (item) => {
|
||||||
const title = item.title;
|
const title = item.title;
|
||||||
let description = item.description || item.summary || item.content || "";
|
let description = item.description || item.summary || item.content || "";
|
||||||
const pubdate = item.pubdate || item.published || item.updated || item["dc:date"];
|
const pubdate = item.pubdate || item.published || item.updated || item["dc:date"] || item["a10:updated"];
|
||||||
const url = item.url || item.link || "";
|
const url = item.url || item.link || "";
|
||||||
|
|
||||||
if (title && pubdate) {
|
if (title && pubdate) {
|
||||||
const regex = /(<([^>]+)>)/gi;
|
// Convert HTML entities, codes and tag
|
||||||
description = description.toString().replace(regex, "");
|
description = htmlToText(description, {
|
||||||
|
wordwrap: false,
|
||||||
|
selectors: [
|
||||||
|
{ selector: "a", options: { ignoreHref: true, noAnchorUrl: true } },
|
||||||
|
{ selector: "br", format: "inlineSurround", options: { prefix: " " } },
|
||||||
|
{ selector: "img", format: "skip" }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
items.push({
|
items.push({
|
||||||
title: title,
|
title: title,
|
||||||
description: description,
|
description: description,
|
||||||
pubdate: pubdate,
|
pubdate: pubdate,
|
||||||
url: url,
|
url: url,
|
||||||
useCorsProxy: useCorsProxy
|
useCorsProxy: useCorsProxy,
|
||||||
|
hash: crypto.createHash("sha256").update(`${pubdate} :: ${title} :: ${url}`).digest("hex")
|
||||||
});
|
});
|
||||||
} else if (logFeedWarnings) {
|
} else if (logFeedWarnings) {
|
||||||
Log.warn("Can't parse feed item:");
|
Log.warn("Can't parse feed item:");
|
||||||
@@ -89,9 +91,9 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings
|
|||||||
try {
|
try {
|
||||||
// 86400000 = 24 hours is mentioned in the docs as maximum value:
|
// 86400000 = 24 hours is mentioned in the docs as maximum value:
|
||||||
const ttlms = Math.min(minutes * 60 * 1000, 86400000);
|
const ttlms = Math.min(minutes * 60 * 1000, 86400000);
|
||||||
if (ttlms > reloadInterval) {
|
if (ttlms > reloadIntervalMS) {
|
||||||
reloadInterval = ttlms;
|
reloadIntervalMS = ttlms;
|
||||||
Log.info(`Newsfeed-Fetcher: reloadInterval set to ttl=${reloadInterval} for url ${url}`);
|
Log.info(`Newsfeed-Fetcher: reloadInterval set to ttl=${reloadIntervalMS} for url ${url}`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Log.warn(`Newsfeed-Fetcher: feed ttl is no valid integer=${minutes} for url ${url}`);
|
Log.warn(`Newsfeed-Fetcher: feed ttl is no valid integer=${minutes} for url ${url}`);
|
||||||
@@ -129,19 +131,18 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings
|
|||||||
clearTimeout(reloadTimer);
|
clearTimeout(reloadTimer);
|
||||||
reloadTimer = setTimeout(function () {
|
reloadTimer = setTimeout(function () {
|
||||||
fetchNews();
|
fetchNews();
|
||||||
}, reloadInterval);
|
}, reloadIntervalMS);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* public methods */
|
/* public methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the reload interval, but only if we need to increase the speed.
|
* Update the reload interval, but only if we need to increase the speed.
|
||||||
*
|
|
||||||
* @param {number} interval Interval for the update in milliseconds.
|
* @param {number} interval Interval for the update in milliseconds.
|
||||||
*/
|
*/
|
||||||
this.setReloadInterval = function (interval) {
|
this.setReloadInterval = function (interval) {
|
||||||
if (interval > 1000 && interval < reloadInterval) {
|
if (interval > 1000 && interval < reloadIntervalMS) {
|
||||||
reloadInterval = interval;
|
reloadIntervalMS = interval;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,16 @@
|
|||||||
/* MagicMirror²
|
|
||||||
* Node Helper: Newsfeed
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const NodeHelper = require("node_helper");
|
const NodeHelper = require("node_helper");
|
||||||
const Log = require("logger");
|
const Log = require("logger");
|
||||||
const NewsfeedFetcher = require("./newsfeedfetcher");
|
const NewsfeedFetcher = require("./newsfeedfetcher");
|
||||||
|
|
||||||
module.exports = NodeHelper.create({
|
module.exports = NodeHelper.create({
|
||||||
// Override start method.
|
// Override start method.
|
||||||
start: function () {
|
start () {
|
||||||
Log.log(`Starting node helper for: ${this.name}`);
|
Log.log(`Starting node helper for: ${this.name}`);
|
||||||
this.fetchers = [];
|
this.fetchers = [];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Override socketNotificationReceived received.
|
// Override socketNotificationReceived received.
|
||||||
socketNotificationReceived: function (notification, payload) {
|
socketNotificationReceived (notification, payload) {
|
||||||
if (notification === "ADD_FEED") {
|
if (notification === "ADD_FEED") {
|
||||||
this.createFetcher(payload.feed, payload.config);
|
this.createFetcher(payload.feed, payload.config);
|
||||||
}
|
}
|
||||||
@@ -26,11 +19,10 @@ module.exports = NodeHelper.create({
|
|||||||
/**
|
/**
|
||||||
* Creates a fetcher for a new feed if it doesn't exist yet.
|
* Creates a fetcher for a new feed if it doesn't exist yet.
|
||||||
* Otherwise it reuses the existing one.
|
* Otherwise it reuses the existing one.
|
||||||
*
|
|
||||||
* @param {object} feed The feed object
|
* @param {object} feed The feed object
|
||||||
* @param {object} config The configuration object
|
* @param {object} config The configuration object
|
||||||
*/
|
*/
|
||||||
createFetcher: function (feed, config) {
|
createFetcher (feed, config) {
|
||||||
const url = feed.url || "";
|
const url = feed.url || "";
|
||||||
const encoding = feed.encoding || "UTF-8";
|
const encoding = feed.encoding || "UTF-8";
|
||||||
const reloadInterval = feed.reloadInterval || config.reloadInterval || 5 * 60 * 1000;
|
const reloadInterval = feed.reloadInterval || config.reloadInterval || 5 * 60 * 1000;
|
||||||
@@ -77,7 +69,7 @@ module.exports = NodeHelper.create({
|
|||||||
* Creates an object with all feed items of the different registered feeds,
|
* Creates an object with all feed items of the different registered feeds,
|
||||||
* and broadcasts these using sendSocketNotification.
|
* and broadcasts these using sendSocketNotification.
|
||||||
*/
|
*/
|
||||||
broadcastFeeds: function () {
|
broadcastFeeds () {
|
||||||
const feeds = {};
|
const feeds = {};
|
||||||
for (let f in this.fetchers) {
|
for (let f in this.fetchers) {
|
||||||
feeds[f] = this.fetchers[f].items();
|
feeds[f] = this.fetchers[f].items();
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
<div class="small bright">
|
<div class="small bright">
|
||||||
{{ "MODULE_CONFIG_CHANGED" | translate({MODULE_NAME: "Newsfeed"}) | safe }}
|
{{ "MODULE_CONFIG_CHANGED" | translate({MODULE_NAME: "Newsfeed"}) | safe }}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,27 +1,28 @@
|
|||||||
const util = require("util");
|
const util = require("node:util");
|
||||||
const exec = util.promisify(require("child_process").exec);
|
const exec = util.promisify(require("node:child_process").exec);
|
||||||
const fs = require("fs");
|
const fs = require("node:fs");
|
||||||
const path = require("path");
|
const path = require("node:path");
|
||||||
const Log = require("logger");
|
const Log = require("logger");
|
||||||
|
|
||||||
const BASE_DIR = path.normalize(`${__dirname}/../../../`);
|
const BASE_DIR = path.normalize(`${__dirname}/../../../`);
|
||||||
|
|
||||||
class GitHelper {
|
class GitHelper {
|
||||||
constructor() {
|
constructor () {
|
||||||
this.gitRepos = [];
|
this.gitRepos = [];
|
||||||
|
this.gitResultList = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
getRefRegex(branch) {
|
getRefRegex (branch) {
|
||||||
return new RegExp(`s*([a-z,0-9]+[.][.][a-z,0-9]+) ${branch}`, "g");
|
return new RegExp(`s*([a-z,0-9]+[.][.][a-z,0-9]+) ${branch}`, "g");
|
||||||
}
|
}
|
||||||
|
|
||||||
async execShell(command) {
|
async execShell (command) {
|
||||||
const { stdout = "", stderr = "" } = await exec(command);
|
const { stdout = "", stderr = "" } = await exec(command);
|
||||||
|
|
||||||
return { stdout, stderr };
|
return { stdout, stderr };
|
||||||
}
|
}
|
||||||
|
|
||||||
async isGitRepo(moduleFolder) {
|
async isGitRepo (moduleFolder) {
|
||||||
const { stderr } = await this.execShell(`cd ${moduleFolder} && git remote -v`);
|
const { stderr } = await this.execShell(`cd ${moduleFolder} && git remote -v`);
|
||||||
|
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
@@ -33,7 +34,7 @@ class GitHelper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async add(moduleName) {
|
async add (moduleName) {
|
||||||
let moduleFolder = BASE_DIR;
|
let moduleFolder = BASE_DIR;
|
||||||
|
|
||||||
if (moduleName !== "MagicMirror") {
|
if (moduleName !== "MagicMirror") {
|
||||||
@@ -58,7 +59,7 @@ class GitHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getStatusInfo(repo) {
|
async getStatusInfo (repo) {
|
||||||
let gitInfo = {
|
let gitInfo = {
|
||||||
module: repo.module,
|
module: repo.module,
|
||||||
behind: 0, // commits behind
|
behind: 0, // commits behind
|
||||||
@@ -93,27 +94,30 @@ class GitHelper {
|
|||||||
// ## develop...origin/develop
|
// ## develop...origin/develop
|
||||||
// ## master...origin/master [behind 8]
|
// ## master...origin/master [behind 8]
|
||||||
// ## master...origin/master [ahead 8, behind 1]
|
// ## master...origin/master [ahead 8, behind 1]
|
||||||
|
// ## HEAD (no branch)
|
||||||
status = status.match(/## (.*)\.\.\.([^ ]*)(?: .*behind (\d+))?/);
|
status = status.match(/## (.*)\.\.\.([^ ]*)(?: .*behind (\d+))?/);
|
||||||
// examples for status:
|
// examples for status:
|
||||||
// [ '## develop...origin/develop', 'develop', 'origin/develop' ]
|
// [ '## develop...origin/develop', 'develop', 'origin/develop' ]
|
||||||
// [ '## master...origin/master [behind 8]', 'master', 'origin/master', '8' ]
|
// [ '## master...origin/master [behind 8]', 'master', 'origin/master', '8' ]
|
||||||
// [ '## master...origin/master [ahead 8, behind 1]', 'master', 'origin/master', '1' ]
|
// [ '## master...origin/master [ahead 8, behind 1]', 'master', 'origin/master', '1' ]
|
||||||
gitInfo.current = status[1];
|
if (status) {
|
||||||
gitInfo.tracking = status[2];
|
gitInfo.current = status[1];
|
||||||
|
gitInfo.tracking = status[2];
|
||||||
|
|
||||||
if (status[3]) {
|
if (status[3]) {
|
||||||
// git fetch was already called before so `git status -sb` delivers already the behind number
|
// git fetch was already called before so `git status -sb` delivers already the behind number
|
||||||
gitInfo.behind = parseInt(status[3]);
|
gitInfo.behind = parseInt(status[3]);
|
||||||
gitInfo.isBehindInStatus = true;
|
gitInfo.isBehindInStatus = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return gitInfo;
|
return gitInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getRepoInfo(repo) {
|
async getRepoInfo (repo) {
|
||||||
const gitInfo = await this.getStatusInfo(repo);
|
const gitInfo = await this.getStatusInfo(repo);
|
||||||
|
|
||||||
if (!gitInfo) {
|
if (!gitInfo || !gitInfo.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +128,7 @@ class GitHelper {
|
|||||||
const { stderr } = await this.execShell(`cd ${repo.folder} && git fetch -n --dry-run`);
|
const { stderr } = await this.execShell(`cd ${repo.folder} && git fetch -n --dry-run`);
|
||||||
|
|
||||||
// example output:
|
// example output:
|
||||||
// From https://github.com/MichMich/MagicMirror
|
// From https://github.com/MagicMirrorOrg/MagicMirror
|
||||||
// e40ddd4..06389e3 develop -> origin/develop
|
// e40ddd4..06389e3 develop -> origin/develop
|
||||||
// here the result is in stderr (this is a git default, don't ask why ...)
|
// here the result is in stderr (this is a git default, don't ask why ...)
|
||||||
const matches = stderr.match(this.getRefRegex(gitInfo.current));
|
const matches = stderr.match(this.getRefRegex(gitInfo.current));
|
||||||
@@ -170,22 +174,39 @@ class GitHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getRepos() {
|
async getRepos () {
|
||||||
const gitResultList = [];
|
this.gitResultList = [];
|
||||||
|
|
||||||
for (const repo of this.gitRepos) {
|
for (const repo of this.gitRepos) {
|
||||||
try {
|
try {
|
||||||
const gitInfo = await this.getRepoInfo(repo);
|
const gitInfo = await this.getRepoInfo(repo);
|
||||||
|
|
||||||
if (gitInfo) {
|
if (gitInfo) {
|
||||||
gitResultList.push(gitInfo);
|
this.gitResultList.push(gitInfo);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Log.error(`Failed to retrieve repo info for ${repo.module}: ${e}`);
|
Log.error(`Failed to retrieve repo info for ${repo.module}: ${e}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return gitResultList;
|
return this.gitResultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
async checkUpdates () {
|
||||||
|
var updates = [];
|
||||||
|
|
||||||
|
const allRepos = await this.gitResultList.map((module) => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
if (module.behind > 0 && module.module !== "MagicMirror") {
|
||||||
|
Log.info(`Update found for module: ${module.module}`);
|
||||||
|
updates.push(module);
|
||||||
|
}
|
||||||
|
resolve(module);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
await Promise.all(allRepos);
|
||||||
|
|
||||||
|
return updates;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const NodeHelper = require("node_helper");
|
const NodeHelper = require("node_helper");
|
||||||
const defaultModules = require("../defaultmodules");
|
const defaultModules = require("../defaultmodules");
|
||||||
const GitHelper = require("./git_helper");
|
const GitHelper = require("./git_helper");
|
||||||
|
const UpdateHelper = require("./update_helper");
|
||||||
|
|
||||||
const ONE_MINUTE = 60 * 1000;
|
const ONE_MINUTE = 60 * 1000;
|
||||||
|
|
||||||
@@ -11,8 +12,9 @@ module.exports = NodeHelper.create({
|
|||||||
updateProcessStarted: false,
|
updateProcessStarted: false,
|
||||||
|
|
||||||
gitHelper: new GitHelper(),
|
gitHelper: new GitHelper(),
|
||||||
|
updateHelper: null,
|
||||||
|
|
||||||
async configureModules(modules) {
|
async configureModules (modules) {
|
||||||
for (const moduleName of modules) {
|
for (const moduleName of modules) {
|
||||||
if (!this.ignoreUpdateChecking(moduleName)) {
|
if (!this.ignoreUpdateChecking(moduleName)) {
|
||||||
await this.gitHelper.add(moduleName);
|
await this.gitHelper.add(moduleName);
|
||||||
@@ -24,38 +26,68 @@ module.exports = NodeHelper.create({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async socketNotificationReceived(notification, payload) {
|
async socketNotificationReceived (notification, payload) {
|
||||||
if (notification === "CONFIG") {
|
switch (notification) {
|
||||||
this.config = payload;
|
case "CONFIG":
|
||||||
} else if (notification === "MODULES") {
|
this.config = payload;
|
||||||
// if this is the 1st time thru the update check process
|
this.updateHelper = new UpdateHelper(this.config);
|
||||||
if (!this.updateProcessStarted) {
|
await this.updateHelper.check_PM2_Process();
|
||||||
this.updateProcessStarted = true;
|
break;
|
||||||
await this.configureModules(payload);
|
case "MODULES":
|
||||||
await this.performFetch();
|
// if this is the 1st time thru the update check process
|
||||||
}
|
if (!this.updateProcessStarted) {
|
||||||
|
this.updateProcessStarted = true;
|
||||||
|
await this.configureModules(payload);
|
||||||
|
await this.performFetch();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "SCAN_UPDATES":
|
||||||
|
// 1st time of check allows to force new scan
|
||||||
|
if (this.updateProcessStarted) {
|
||||||
|
clearTimeout(this.updateTimer);
|
||||||
|
await this.performFetch();
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async performFetch() {
|
async performFetch () {
|
||||||
const repos = await this.gitHelper.getRepos();
|
const repos = await this.gitHelper.getRepos();
|
||||||
|
|
||||||
for (const repo of repos) {
|
for (const repo of repos) {
|
||||||
this.sendSocketNotification("STATUS", repo);
|
this.sendSocketNotification("REPO_STATUS", repo);
|
||||||
|
}
|
||||||
|
|
||||||
|
const updates = await this.gitHelper.checkUpdates();
|
||||||
|
|
||||||
|
if (this.config.sendUpdatesNotifications && updates.length) {
|
||||||
|
this.sendSocketNotification("UPDATES", updates);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updates.length) {
|
||||||
|
const updateResult = await this.updateHelper.parse(updates);
|
||||||
|
for (const update of updateResult) {
|
||||||
|
if (update.inProgress) {
|
||||||
|
this.sendSocketNotification("UPDATE_STATUS", update);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scheduleNextFetch(this.config.updateInterval);
|
this.scheduleNextFetch(this.config.updateInterval);
|
||||||
},
|
},
|
||||||
|
|
||||||
scheduleNextFetch(delay) {
|
scheduleNextFetch (delay) {
|
||||||
clearTimeout(this.updateTimer);
|
clearTimeout(this.updateTimer);
|
||||||
|
|
||||||
this.updateTimer = setTimeout(() => {
|
this.updateTimer = setTimeout(
|
||||||
this.performFetch();
|
() => {
|
||||||
}, Math.max(delay, ONE_MINUTE));
|
this.performFetch();
|
||||||
|
},
|
||||||
|
Math.max(delay, ONE_MINUTE)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
ignoreUpdateChecking(moduleName) {
|
ignoreUpdateChecking (moduleName) {
|
||||||
// Should not check for updates for default modules
|
// Should not check for updates for default modules
|
||||||
if (defaultModules.includes(moduleName)) {
|
if (defaultModules.includes(moduleName)) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
213
modules/default/updatenotification/update_helper.js
Normal file
213
modules/default/updatenotification/update_helper.js
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
const Exec = require("node:child_process").exec;
|
||||||
|
const Spawn = require("node:child_process").spawn;
|
||||||
|
const pm2 = require("pm2");
|
||||||
|
|
||||||
|
const Log = require("logger");
|
||||||
|
|
||||||
|
/* class Updater
|
||||||
|
* Allow to self updating 3rd party modules from command defined in config
|
||||||
|
*
|
||||||
|
* [constructor] read value in config:
|
||||||
|
* updates: [ // array of modules update commands
|
||||||
|
* {
|
||||||
|
* <module name>: <update command>
|
||||||
|
* },
|
||||||
|
* {
|
||||||
|
* ...
|
||||||
|
* }
|
||||||
|
* ],
|
||||||
|
* updateTimeout: 2 * 60 * 1000, // max update duration
|
||||||
|
* updateAutorestart: false // autoRestart MM when update done ?
|
||||||
|
*
|
||||||
|
* [main command]: parse(<Array of modules>):
|
||||||
|
* parse if module update is needed
|
||||||
|
* --> Apply ONLY one update (first of the module list)
|
||||||
|
* --> auto-restart MagicMirror or wait manual restart by user
|
||||||
|
* return array with modules update state information for `updatenotification` module displayer information
|
||||||
|
* [
|
||||||
|
* {
|
||||||
|
* name = <module-name>, // name of the module
|
||||||
|
* updateCommand = <update command>, // update command (if found)
|
||||||
|
* inProgress = <boolean>, // an update if in progress for this module
|
||||||
|
* error = <boolean>, // an error if detected when updating
|
||||||
|
* updated = <boolean>, // updated successfully
|
||||||
|
* needRestart = <boolean> // manual restart of MagicMirror is required by user
|
||||||
|
* },
|
||||||
|
* {
|
||||||
|
* ...
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Updater {
|
||||||
|
constructor (config) {
|
||||||
|
this.updates = config.updates;
|
||||||
|
this.timeout = config.updateTimeout;
|
||||||
|
this.autoRestart = config.updateAutorestart;
|
||||||
|
this.moduleList = {};
|
||||||
|
this.updating = false;
|
||||||
|
this.usePM2 = false;
|
||||||
|
this.PM2 = null;
|
||||||
|
this.version = global.version;
|
||||||
|
this.root_path = global.root_path;
|
||||||
|
Log.info("updatenotification: Updater Class Loaded!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// [main command] parse if module update is needed
|
||||||
|
async parse (modules) {
|
||||||
|
var parser = modules.map(async (module) => {
|
||||||
|
if (this.moduleList[module.module] === undefined) {
|
||||||
|
this.moduleList[module.module] = {};
|
||||||
|
this.moduleList[module.module].name = module.module;
|
||||||
|
this.moduleList[module.module].updateCommand = await this.applyCommand(module.module);
|
||||||
|
this.moduleList[module.module].inProgress = false;
|
||||||
|
this.moduleList[module.module].error = null;
|
||||||
|
this.moduleList[module.module].updated = false;
|
||||||
|
this.moduleList[module.module].needRestart = false;
|
||||||
|
}
|
||||||
|
if (!this.moduleList[module.module].inProgress) {
|
||||||
|
if (!this.updating) {
|
||||||
|
if (!this.moduleList[module.module].updateCommand) {
|
||||||
|
this.updating = false;
|
||||||
|
} else {
|
||||||
|
this.updating = true;
|
||||||
|
this.moduleList[module.module].inProgress = true;
|
||||||
|
Object.assign(this.moduleList[module.module], await this.updateProcess(this.moduleList[module.module]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all(parser);
|
||||||
|
let updater = Object.values(this.moduleList);
|
||||||
|
Log.debug("updatenotification Update Result:", updater);
|
||||||
|
return updater;
|
||||||
|
}
|
||||||
|
|
||||||
|
// module updater with his proper command
|
||||||
|
// return object as result
|
||||||
|
//{
|
||||||
|
// error: <boolean>, // if error detected
|
||||||
|
// updated: <boolean>, // if updated successfully
|
||||||
|
// needRestart: <boolean> // if magicmirror restart required
|
||||||
|
//};
|
||||||
|
updateProcess (module) {
|
||||||
|
let Result = {
|
||||||
|
error: false,
|
||||||
|
updated: false,
|
||||||
|
needRestart: false
|
||||||
|
};
|
||||||
|
let Command = null;
|
||||||
|
const Path = `${this.root_path}/modules/`;
|
||||||
|
const modulePath = Path + module.name;
|
||||||
|
|
||||||
|
if (module.updateCommand) {
|
||||||
|
Command = module.updateCommand;
|
||||||
|
} else {
|
||||||
|
Log.warn(`updatenotification: Update of ${module.name} is not supported.`);
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
Log.info(`updatenotification: Updating ${module.name}...`);
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
Exec(Command, { cwd: modulePath, timeout: this.timeout }, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
Log.error(`updatenotification: exec error: ${error}`);
|
||||||
|
Result.error = true;
|
||||||
|
} else {
|
||||||
|
Log.info(`updatenotification: Update logs of ${module.name}: ${stdout}`);
|
||||||
|
Result.updated = true;
|
||||||
|
if (this.autoRestart) {
|
||||||
|
Log.info("updatenotification: Update done");
|
||||||
|
setTimeout(() => this.restart(), 3000);
|
||||||
|
} else {
|
||||||
|
Log.info("updatenotification: Update done, don't forget to restart MagicMirror!");
|
||||||
|
Result.needRestart = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resolve(Result);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// restart rules (pm2 or npm start)
|
||||||
|
restart () {
|
||||||
|
if (this.usePM2) this.pm2Restart();
|
||||||
|
else this.npmRestart();
|
||||||
|
}
|
||||||
|
|
||||||
|
// restart MagicMiror with "pm2"
|
||||||
|
pm2Restart () {
|
||||||
|
Log.info("updatenotification: PM2 will restarting MagicMirror...");
|
||||||
|
pm2.restart(this.PM2, (err, proc) => {
|
||||||
|
if (err) {
|
||||||
|
Log.error("updatenotification:[PM2] restart Error", err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// restart MagicMiror with "npm start"
|
||||||
|
npmRestart () {
|
||||||
|
Log.info("updatenotification: Restarting MagicMirror...");
|
||||||
|
const out = process.stdout;
|
||||||
|
const err = process.stderr;
|
||||||
|
const subprocess = Spawn("npm start", { cwd: this.root_path, shell: true, detached: true, stdio: ["ignore", out, err] });
|
||||||
|
subprocess.unref();
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check using pm2
|
||||||
|
check_PM2_Process () {
|
||||||
|
Log.info("updatenotification: Checking PM2 using...");
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
pm2.connect((err) => {
|
||||||
|
if (err) {
|
||||||
|
Log.error("updatenotification: [PM2]", err);
|
||||||
|
this.usePM2 = false;
|
||||||
|
resolve(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pm2.list((err, list) => {
|
||||||
|
if (err) {
|
||||||
|
Log.error("updatenotification: [PM2] Can't get process List!");
|
||||||
|
this.usePM2 = false;
|
||||||
|
resolve(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
list.forEach((pm) => {
|
||||||
|
if (pm.pm2_env.version === this.version && pm.pm2_env.status === "online" && pm.pm2_env.pm_cwd.includes(`${this.root_path}/`)) {
|
||||||
|
this.PM2 = pm.name;
|
||||||
|
this.usePM2 = true;
|
||||||
|
Log.info("updatenotification: [PM2] You are using pm2 with", this.PM2);
|
||||||
|
resolve(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
pm2.disconnect();
|
||||||
|
if (!this.PM2) {
|
||||||
|
Log.info("updatenotification: [PM2] You are not using pm2");
|
||||||
|
this.usePM2 = false;
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if module is MagicMirror
|
||||||
|
isMagicMirror (module) {
|
||||||
|
if (module === "MagicMirror") return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// search update module command
|
||||||
|
applyCommand (module) {
|
||||||
|
if (this.isMagicMirror(module.module) || !this.updates.length) return null;
|
||||||
|
let command = null;
|
||||||
|
this.updates.forEach((updater) => {
|
||||||
|
if (updater[module]) command = updater[module];
|
||||||
|
});
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Updater;
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
/* MagicMirror²
|
|
||||||
* Module: UpdateNotification
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
Module.register("updatenotification", {
|
Module.register("updatenotification", {
|
||||||
defaults: {
|
defaults: {
|
||||||
updateInterval: 10 * 60 * 1000, // every 10 minutes
|
updateInterval: 10 * 60 * 1000, // every 10 minutes
|
||||||
refreshInterval: 24 * 60 * 60 * 1000, // one day
|
refreshInterval: 24 * 60 * 60 * 1000, // one day
|
||||||
ignoreModules: []
|
ignoreModules: [],
|
||||||
|
sendUpdatesNotifications: false,
|
||||||
|
updates: [],
|
||||||
|
updateTimeout: 2 * 60 * 1000, // max update duration
|
||||||
|
updateAutorestart: false // autoRestart MM when update done ?
|
||||||
},
|
},
|
||||||
|
|
||||||
suspended: false,
|
suspended: false,
|
||||||
moduleList: {},
|
moduleList: {},
|
||||||
|
needRestart: false,
|
||||||
|
updates: [],
|
||||||
|
|
||||||
start() {
|
start () {
|
||||||
Log.info(`Starting module: ${this.name}`);
|
Log.info(`Starting module: ${this.name}`);
|
||||||
this.addFilters();
|
this.addFilters();
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
@@ -23,41 +23,54 @@ Module.register("updatenotification", {
|
|||||||
}, this.config.refreshInterval);
|
}, this.config.refreshInterval);
|
||||||
},
|
},
|
||||||
|
|
||||||
suspend() {
|
suspend () {
|
||||||
this.suspended = true;
|
this.suspended = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
resume() {
|
resume () {
|
||||||
this.suspended = false;
|
this.suspended = false;
|
||||||
this.updateDom(2);
|
this.updateDom(2);
|
||||||
},
|
},
|
||||||
|
|
||||||
notificationReceived(notification) {
|
notificationReceived (notification) {
|
||||||
if (notification === "DOM_OBJECTS_CREATED") {
|
switch (notification) {
|
||||||
this.sendSocketNotification("CONFIG", this.config);
|
case "DOM_OBJECTS_CREATED":
|
||||||
this.sendSocketNotification("MODULES", Object.keys(Module.definitions));
|
this.sendSocketNotification("CONFIG", this.config);
|
||||||
|
this.sendSocketNotification("MODULES", Object.keys(Module.definitions));
|
||||||
|
break;
|
||||||
|
case "SCAN_UPDATES":
|
||||||
|
this.sendSocketNotification("SCAN_UPDATES");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
socketNotificationReceived(notification, payload) {
|
socketNotificationReceived (notification, payload) {
|
||||||
if (notification === "STATUS") {
|
switch (notification) {
|
||||||
this.updateUI(payload);
|
case "REPO_STATUS":
|
||||||
|
this.updateUI(payload);
|
||||||
|
break;
|
||||||
|
case "UPDATES":
|
||||||
|
this.sendNotification("UPDATES", payload);
|
||||||
|
break;
|
||||||
|
case "UPDATE_STATUS":
|
||||||
|
this.updatesNotifier(payload);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getStyles() {
|
getStyles () {
|
||||||
return [`${this.name}.css`];
|
return [`${this.name}.css`];
|
||||||
},
|
},
|
||||||
|
|
||||||
getTemplate() {
|
getTemplate () {
|
||||||
return `${this.name}.njk`;
|
return `${this.name}.njk`;
|
||||||
},
|
},
|
||||||
|
|
||||||
getTemplateData() {
|
getTemplateData () {
|
||||||
return { moduleList: this.moduleList, suspended: this.suspended };
|
return { moduleList: this.moduleList, updatesList: this.updates, suspended: this.suspended, needRestart: this.needRestart };
|
||||||
},
|
},
|
||||||
|
|
||||||
updateUI(payload) {
|
updateUI (payload) {
|
||||||
if (payload && payload.behind > 0) {
|
if (payload && payload.behind > 0) {
|
||||||
// if we haven't seen info for this module
|
// if we haven't seen info for this module
|
||||||
if (this.moduleList[payload.module] === undefined) {
|
if (this.moduleList[payload.module] === undefined) {
|
||||||
@@ -75,7 +88,7 @@ Module.register("updatenotification", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
addFilters() {
|
addFilters () {
|
||||||
this.nunjucksEnvironment().addFilter("diffLink", (text, status) => {
|
this.nunjucksEnvironment().addFilter("diffLink", (text, status) => {
|
||||||
if (status.module !== "MagicMirror") {
|
if (status.module !== "MagicMirror") {
|
||||||
return text;
|
return text;
|
||||||
@@ -83,7 +96,31 @@ Module.register("updatenotification", {
|
|||||||
|
|
||||||
const localRef = status.hash;
|
const localRef = status.hash;
|
||||||
const remoteRef = status.tracking.replace(/.*\//, "");
|
const remoteRef = status.tracking.replace(/.*\//, "");
|
||||||
return `<a href="https://github.com/MichMich/MagicMirror/compare/${localRef}...${remoteRef}" class="xsmall dimmed difflink" target="_blank">${text}</a>`;
|
return `<a href="https://github.com/MagicMirrorOrg/MagicMirror/compare/${localRef}...${remoteRef}" class="xsmall dimmed difflink" target="_blank">${text}</a>`;
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
updatesNotifier (payload, done = true) {
|
||||||
|
if (this.updates[payload.name] === undefined) {
|
||||||
|
this.updates[payload.name] = {
|
||||||
|
name: payload.name,
|
||||||
|
done: done
|
||||||
|
};
|
||||||
|
|
||||||
|
if (payload.error) {
|
||||||
|
this.sendSocketNotification("UPDATE_ERROR", payload.name);
|
||||||
|
this.updates[payload.name].done = false;
|
||||||
|
} else {
|
||||||
|
if (payload.updated) {
|
||||||
|
delete this.moduleList[payload.name];
|
||||||
|
this.updates[payload.name].done = true;
|
||||||
|
}
|
||||||
|
if (payload.needRestart) {
|
||||||
|
this.needRestart = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateDom(2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,15 +1,41 @@
|
|||||||
{% if not suspended %}
|
{% if not suspended %}
|
||||||
{% for name, status in moduleList %}
|
{% if needRestart %}
|
||||||
<div class="small bright">
|
<div class="small bright">
|
||||||
<i class="fas fa-exclamation-circle"></i>
|
<i class="fas fa-rotate"></i>
|
||||||
<span>
|
<span>
|
||||||
{% set mainTextLabel = "UPDATE_NOTIFICATION" if name === "MagicMirror" else "UPDATE_NOTIFICATION_MODULE" %}
|
{% set restartTextLabel = "UPDATE_NOTIFICATION_NEED-RESTART" %}
|
||||||
{{ mainTextLabel | translate({MODULE_NAME: name}) }}
|
{{ restartTextLabel | translate() | safe }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="xsmall dimmed">
|
{% endif %}
|
||||||
{% set subTextLabel = "UPDATE_INFO_SINGLE" if status.behind === 1 else "UPDATE_INFO_MULTIPLE" %}
|
{% for name, status in moduleList %}
|
||||||
{{ subTextLabel | translate({COMMIT_COUNT: status.behind, BRANCH_NAME: status.current}) | diffLink(status) | safe }}
|
<div class="small bright">
|
||||||
</div>
|
<i class="fas fa-exclamation-circle"></i>
|
||||||
{% endfor %}
|
<span>
|
||||||
|
{% set mainTextLabel = "UPDATE_NOTIFICATION" if name === "MagicMirror" else "UPDATE_NOTIFICATION_MODULE" %}
|
||||||
|
{{ mainTextLabel | translate({MODULE_NAME: name}) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="xsmall dimmed">
|
||||||
|
{% set subTextLabel = "UPDATE_INFO_SINGLE" if status.behind === 1 else "UPDATE_INFO_MULTIPLE" %}
|
||||||
|
{{ subTextLabel | translate({COMMIT_COUNT: status.behind, BRANCH_NAME: status.current}) | diffLink(status) | safe }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% for name, status in updatesList %}
|
||||||
|
<div class="small bright">
|
||||||
|
{% if status.done %}
|
||||||
|
<i class="fas fa-check" style="color: lightgreen;"></i>
|
||||||
|
<span>
|
||||||
|
{% set updateTextLabel = "UPDATE_NOTIFICATION_DONE" %}
|
||||||
|
{{ updateTextLabel | translate({MODULE_NAME: name}) | safe }}
|
||||||
|
</span>
|
||||||
|
{% else %}
|
||||||
|
<i class="fas fa-xmark" style="color: red;"></i>
|
||||||
|
<span>
|
||||||
|
{% set updateTextLabel = "UPDATE_NOTIFICATION_ERROR" %}
|
||||||
|
{{ updateTextLabel | translate({MODULE_NAME: name}) | safe }}
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* A function to make HTTP requests via the server to avoid CORS-errors.
|
* A function to make HTTP requests via the server to avoid CORS-errors.
|
||||||
*
|
|
||||||
* @param {string} url the url to fetch from
|
* @param {string} url the url to fetch from
|
||||||
* @param {string} type what contenttype to expect in the response, can be "json" or "xml"
|
* @param {string} type what contenttype to expect in the response, can be "json" or "xml"
|
||||||
* @param {boolean} useCorsProxy A flag to indicate
|
* @param {boolean} useCorsProxy A flag to indicate
|
||||||
@@ -8,14 +7,16 @@
|
|||||||
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to receive
|
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to receive
|
||||||
* @returns {Promise} resolved when the fetch is done. The response headers is placed in a headers-property (provided the response does not already contain a headers-property).
|
* @returns {Promise} resolved when the fetch is done. The response headers is placed in a headers-property (provided the response does not already contain a headers-property).
|
||||||
*/
|
*/
|
||||||
async function performWebRequest(url, type = "json", useCorsProxy = false, requestHeaders = undefined, expectedResponseHeaders = undefined) {
|
async function performWebRequest (url, type = "json", useCorsProxy = false, requestHeaders = undefined, expectedResponseHeaders = undefined) {
|
||||||
const request = {};
|
const request = {};
|
||||||
|
let requestUrl;
|
||||||
if (useCorsProxy) {
|
if (useCorsProxy) {
|
||||||
url = getCorsUrl(url, requestHeaders, expectedResponseHeaders);
|
requestUrl = getCorsUrl(url, requestHeaders, expectedResponseHeaders);
|
||||||
} else {
|
} else {
|
||||||
|
requestUrl = url;
|
||||||
request.headers = getHeadersToSend(requestHeaders);
|
request.headers = getHeadersToSend(requestHeaders);
|
||||||
}
|
}
|
||||||
const response = await fetch(url, request);
|
const response = await fetch(requestUrl, request);
|
||||||
const data = await response.text();
|
const data = await response.text();
|
||||||
|
|
||||||
if (type === "xml") {
|
if (type === "xml") {
|
||||||
@@ -33,7 +34,6 @@ async function performWebRequest(url, type = "json", useCorsProxy = false, reque
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a URL that will be used when calling the CORS-method on the server.
|
* Gets a URL that will be used when calling the CORS-method on the server.
|
||||||
*
|
|
||||||
* @param {string} url the url to fetch from
|
* @param {string} url the url to fetch from
|
||||||
* @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send
|
* @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send
|
||||||
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to receive
|
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to receive
|
||||||
@@ -64,7 +64,6 @@ const getCorsUrl = function (url, requestHeaders, expectedResponseHeaders) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the part of the CORS URL that represents the HTTP headers to send.
|
* Gets the part of the CORS URL that represents the HTTP headers to send.
|
||||||
*
|
|
||||||
* @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send
|
* @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send
|
||||||
* @returns {string} to be used as request-headers component in CORS URL.
|
* @returns {string} to be used as request-headers component in CORS URL.
|
||||||
*/
|
*/
|
||||||
@@ -85,7 +84,6 @@ const getRequestHeaderString = function (requestHeaders) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets headers and values to attach to the web request.
|
* Gets headers and values to attach to the web request.
|
||||||
*
|
|
||||||
* @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send
|
* @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send
|
||||||
* @returns {object} An object specifying name and value of the headers.
|
* @returns {object} An object specifying name and value of the headers.
|
||||||
*/
|
*/
|
||||||
@@ -102,7 +100,6 @@ const getHeadersToSend = (requestHeaders) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the part of the CORS URL that represents the expected HTTP headers to receive.
|
* Gets the part of the CORS URL that represents the expected HTTP headers to receive.
|
||||||
*
|
|
||||||
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to receive
|
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to receive
|
||||||
* @returns {string} to be used as the expected HTTP-headers component in CORS URL.
|
* @returns {string} to be used as the expected HTTP-headers component in CORS URL.
|
||||||
*/
|
*/
|
||||||
@@ -123,7 +120,6 @@ const getExpectedResponseHeadersString = function (expectedResponseHeaders) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the values for the expected headers from the response.
|
* Gets the values for the expected headers from the response.
|
||||||
*
|
|
||||||
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to receive
|
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to receive
|
||||||
* @param {Response} response the HTTP response
|
* @param {Response} response the HTTP response
|
||||||
* @returns {string} to be used as the expected HTTP-headers component in CORS URL.
|
* @returns {string} to be used as the expected HTTP-headers component in CORS URL.
|
||||||
@@ -141,7 +137,35 @@ const getHeadersFromResponse = (expectedResponseHeaders, response) => {
|
|||||||
return responseHeaders;
|
return responseHeaders;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof module !== "undefined")
|
/**
|
||||||
module.exports = {
|
* Format the time according to the config
|
||||||
performWebRequest
|
* @param {object} config The config of the module
|
||||||
};
|
* @param {object} time time to format
|
||||||
|
* @returns {string} The formatted time string
|
||||||
|
*/
|
||||||
|
const formatTime = (config, time) => {
|
||||||
|
let date = moment(time);
|
||||||
|
|
||||||
|
if (config.timezone) {
|
||||||
|
date = date.tz(config.timezone);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.timeFormat !== 24) {
|
||||||
|
if (config.showPeriod) {
|
||||||
|
if (config.showPeriodUpper) {
|
||||||
|
return date.format("h:mm A");
|
||||||
|
} else {
|
||||||
|
return date.format("h:mm a");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return date.format("h:mm");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return date.format("HH:mm");
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof module !== "undefined") module.exports = {
|
||||||
|
performWebRequest,
|
||||||
|
formatTime
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
{% macro humidity() %}
|
||||||
|
{% if current.humidity %}
|
||||||
|
<span class="humidity"><span>{{ current.humidity | decimalSymbol }}</span><sup> <i class="wi wi-humidity humidity-icon"></i></sup></span>
|
||||||
|
{% endif %}
|
||||||
|
{% endmacro %}
|
||||||
{% if current %}
|
{% if current %}
|
||||||
{% if not config.onlyTemp %}
|
{% if not config.onlyTemp %}
|
||||||
<div class="normal medium">
|
<div class="normal medium">
|
||||||
@@ -7,7 +12,7 @@
|
|||||||
{% if config.showWindDirection %}
|
{% if config.showWindDirection %}
|
||||||
<sup>
|
<sup>
|
||||||
{% if config.showWindDirectionAsArrow %}
|
{% if config.showWindDirectionAsArrow %}
|
||||||
<i class="fas fa-long-arrow-alt-down" style="transform:rotate({{ current.windFromDirection }}deg);"></i>
|
<i class="fas fa-long-arrow-alt-down" style="transform:rotate({{ current.windFromDirection }}deg)"></i>
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ current.cardinalWindDirection() | translate }}
|
{{ current.cardinalWindDirection() | translate }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -15,8 +20,8 @@
|
|||||||
</sup>
|
</sup>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
{% if config.showHumidity and current.humidity %}
|
{% if config.showHumidity === "wind" %}
|
||||||
<span>{{ current.humidity | decimalSymbol }}</span><sup> <i class="wi wi-humidity humidity-icon"></i></sup>
|
{{ humidity() }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if config.showSun %}
|
{% if config.showSun %}
|
||||||
<span class="wi dimmed wi-{{ current.nextSunAction() }}"></span>
|
<span class="wi dimmed wi-{{ current.nextSunAction() }}"></span>
|
||||||
@@ -28,56 +33,69 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if config.showUVIndex %}
|
||||||
|
<td class="align-right bright uv-index">
|
||||||
|
<div class="wi dimmed wi-hot"></div>
|
||||||
|
{{ current.uv_index }}
|
||||||
|
</td>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="large light">
|
<div class="large">
|
||||||
<span class="wi weathericon wi-{{current.weatherType}}"></span>
|
{% if config.showIndoorTemperature and indoor.temperature or config.showIndoorHumidity and indoor.humidity %}
|
||||||
<span class="bright">
|
<span class="medium fas fa-home"></span>
|
||||||
{{ current.temperature | roundValue | unit("temperature") | decimalSymbol }}
|
<span style="display: inline-block">
|
||||||
</span>
|
{% if config.showIndoorTemperature and indoor.temperature %}
|
||||||
</div>
|
<sup class="small" style="position: relative; display: block; text-align: left;">
|
||||||
<div class="normal light indoor">
|
<span>
|
||||||
{% if config.showIndoorTemperature and indoor.temperature %}
|
{{ indoor.temperature | roundValue | unit("temperature") | decimalSymbol }}
|
||||||
<div>
|
</span>
|
||||||
<span class="fas fa-home"></span>
|
</sup>
|
||||||
<span class="bright">
|
{% endif %}
|
||||||
{{ indoor.temperature | roundValue | unit("temperature") | decimalSymbol }}
|
{% if config.showIndoorHumidity and indoor.humidity %}
|
||||||
</span>
|
<sub class="small" style="position: relative; display: block; text-align: left;">
|
||||||
</div>
|
<span>
|
||||||
|
{{ indoor.humidity | roundValue | unit("humidity") | decimalSymbol }}
|
||||||
|
</span>
|
||||||
|
</sub>
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if config.showIndoorHumidity and indoor.humidity %}
|
<span class="light wi weathericon wi-{{ current.weatherType }}"></span>
|
||||||
<div>
|
<span class="light bright">{{ current.temperature | roundValue | unit("temperature") | decimalSymbol }}</span>
|
||||||
<span class="fas fa-tint"></span>
|
{% if config.showHumidity === "temp" %}
|
||||||
<span class="bright">
|
<span class="medium bright">{{ humidity() }}</span>
|
||||||
{{ indoor.humidity | roundValue | unit("humidity") | decimalSymbol }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% if (config.showFeelsLike or config.showPrecipitationAmount or config.showPrecipitationProbability) and not config.onlyTemp %}
|
{% if (config.showFeelsLike or config.showPrecipitationAmount or config.showPrecipitationProbability) and not config.onlyTemp %}
|
||||||
<div class="normal medium feelslike">
|
<div class="normal medium feelslike">
|
||||||
{% if config.showFeelsLike %}
|
{% if config.showFeelsLike %}
|
||||||
<span class="dimmed">
|
<span class="dimmed">
|
||||||
|
{% if config.showHumidity === "feelslike" %}
|
||||||
|
{{ humidity() }}
|
||||||
|
{% endif %}
|
||||||
{{ "FEELS" | translate({DEGREE: current.feelsLike() | roundValue | unit("temperature") | decimalSymbol }) }}
|
{{ "FEELS" | translate({DEGREE: current.feelsLike() | roundValue | unit("temperature") | decimalSymbol }) }}
|
||||||
</span><br/>
|
</span>
|
||||||
|
<br />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if config.showPrecipitationAmount and current.precipitationAmount %}
|
{% if config.showPrecipitationAmount and current.precipitationAmount %}
|
||||||
<span class="dimmed">
|
<span class="dimmed">
|
||||||
<span class="precipitationLeadText">{{ "PRECIP_AMOUNT" | translate }}</span> {{ current.precipitationAmount | unit("precip", current.precipitationUnits) }}
|
<span class="precipitationLeadText">{{ "PRECIP_AMOUNT" | translate }}</span> {{ current.precipitationAmount | unit("precip", current.precipitationUnits) }}
|
||||||
</span><br/>
|
</span>
|
||||||
|
<br />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if config.showPrecipitationProbability and current.precipitationProbability %}
|
{% if config.showPrecipitationProbability and current.precipitationProbability %}
|
||||||
<span class="dimmed">
|
<span class="dimmed">
|
||||||
<span class="precipitationLeadText">{{ "PRECIP_POP" | translate }}</span> {{ current.precipitationProbability }}%
|
<span class="precipitationLeadText">{{ "PRECIP_POP" | translate }}</span> {{ current.precipitationProbability }}%
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if config.showHumidity === "below" %}
|
||||||
|
<span class="medium dimmed">{{ humidity() }}</span>
|
||||||
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="dimmed light small">
|
<div class="dimmed light small">{{ "LOADING" | translate }}</div>
|
||||||
{{ "LOADING" | translate }}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<!-- Uncomment the line below to see the contents of the `current` object. -->
|
<!-- Uncomment the line below to see the contents of the `current` object. -->
|
||||||
<!-- <div style="word-wrap:break-word" class="xsmall dimmed">{{current | dump}}</div> -->
|
<!-- <div style="word-wrap:break-word" class="xsmall dimmed">{{current | dump}}</div> -->
|
||||||
|
|||||||
@@ -7,15 +7,18 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% set forecast = forecast.slice(0, numSteps) %}
|
{% set forecast = forecast.slice(0, numSteps) %}
|
||||||
{% for f in forecast %}
|
{% for f in forecast %}
|
||||||
<tr {% if config.colored %}class="colored"{% endif %} {% if config.fade %}style="opacity: {{ currentStep | opacity(numSteps) }};"{% endif %}>
|
<tr {% if config.colored %}class="colored"{% endif %}
|
||||||
|
{% if config.fade %}style="opacity: {{ currentStep | opacity(numSteps) }};"{% endif %}>
|
||||||
{% if (currentStep == 0) and config.ignoreToday == false and config.absoluteDates == false %}
|
{% if (currentStep == 0) and config.ignoreToday == false and config.absoluteDates == false %}
|
||||||
<td class="day">{{ "TODAY" | translate }}</td>
|
<td class="day">{{ "TODAY" | translate }}</td>
|
||||||
{% elif (currentStep == 1) and config.ignoreToday == false and config.absoluteDates == false %}
|
{% elif (currentStep == 1) and config.ignoreToday == false and config.absoluteDates == false %}
|
||||||
<td class="day">{{ "TOMORROW" | translate }}</td>
|
<td class="day">{{ "TOMORROW" | translate }}</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td class="day">{{ f.date.format('ddd') }}</td>
|
<td class="day">{{ f.date.format("ddd") }}</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td class="bright weather-icon"><span class="wi weathericon wi-{{ f.weatherType }}"></span></td>
|
<td class="bright weather-icon">
|
||||||
|
<span class="wi weathericon wi-{{ f.weatherType }}"></span>
|
||||||
|
</td>
|
||||||
<td class="align-right bright max-temp">
|
<td class="align-right bright max-temp">
|
||||||
{{ f.maxTemperature | roundValue | unit("temperature") | decimalSymbol }}
|
{{ f.maxTemperature | roundValue | unit("temperature") | decimalSymbol }}
|
||||||
</td>
|
</td>
|
||||||
@@ -29,7 +32,13 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% if config.showPrecipitationProbability %}
|
{% if config.showPrecipitationProbability %}
|
||||||
<td class="align-right bright precipitation-prob">
|
<td class="align-right bright precipitation-prob">
|
||||||
{{ f.precipitationProbability | unit("precip", "%") }}
|
{{ f.precipitationProbability | unit('precip', '%') }}
|
||||||
|
</td>
|
||||||
|
{% endif %}
|
||||||
|
{% if config.showUVIndex %}
|
||||||
|
<td class="align-right dimmed uv-index">
|
||||||
|
{{ f.uv_index }}
|
||||||
|
<span class="wi dimmed weathericon wi-hot"></span>
|
||||||
</td>
|
</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
@@ -37,10 +46,7 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="dimmed light small">
|
<div class="dimmed light small">{{ "LOADING" | translate }}</div>
|
||||||
{{ "LOADING" | translate }}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<!-- Uncomment the line below to see the contents of the `forecast` object. -->
|
<!-- Uncomment the line below to see the contents of the `forecast` object. -->
|
||||||
<!-- <div style="word-wrap:break-word" class="xsmall dimmed">{{forecast | dump}}</div> -->
|
<!-- <div style="word-wrap:break-word" class="xsmall dimmed">{{forecast | dump}}</div> -->
|
||||||
|
|||||||
@@ -4,12 +4,23 @@
|
|||||||
<table class="{{ config.tableClass }}">
|
<table class="{{ config.tableClass }}">
|
||||||
{% set hours = hourly.slice(0, numSteps) %}
|
{% set hours = hourly.slice(0, numSteps) %}
|
||||||
{% for hour in hours %}
|
{% for hour in hours %}
|
||||||
<tr {% if config.colored %}class="colored"{% endif %} {% if config.fade %}style="opacity: {{ currentStep | opacity(numSteps) }};"{% endif %}>
|
<tr {% if config.colored %}class="colored"{% endif %}
|
||||||
|
{% if config.fade %}style="opacity: {{ currentStep | opacity(numSteps) }};"{% endif %}>
|
||||||
<td class="day">{{ hour.date | formatTime }}</td>
|
<td class="day">{{ hour.date | formatTime }}</td>
|
||||||
<td class="bright weather-icon"><span class="wi weathericon wi-{{ hour.weatherType }}"></span></td>
|
<td class="bright weather-icon">
|
||||||
|
<span class="wi weathericon wi-{{ hour.weatherType }}"></span>
|
||||||
|
</td>
|
||||||
<td class="align-right bright">
|
<td class="align-right bright">
|
||||||
{{ hour.temperature | roundValue | unit("temperature") }}
|
{{ hour.temperature | roundValue | unit("temperature") }}
|
||||||
</td>
|
</td>
|
||||||
|
{% if config.showUVIndex %}
|
||||||
|
<td class="align-right bright uv-index">
|
||||||
|
{% if hour.uv_index!=0 %}
|
||||||
|
{{ hour.uv_index }}
|
||||||
|
<span class="wi weathericon wi-hot"></span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
{% endif %}
|
||||||
{% if config.showPrecipitationAmount %}
|
{% if config.showPrecipitationAmount %}
|
||||||
<td class="align-right bright precipitation-amount">
|
<td class="align-right bright precipitation-amount">
|
||||||
{{ hour.precipitationAmount | unit("precip", hour.precipitationUnits) }}
|
{{ hour.precipitationAmount | unit("precip", hour.precipitationUnits) }}
|
||||||
@@ -17,7 +28,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% if config.showPrecipitationProbability %}
|
{% if config.showPrecipitationProbability %}
|
||||||
<td class="align-right bright precipitation-prob">
|
<td class="align-right bright precipitation-prob">
|
||||||
{{ hour.precipitationProbability | unit("precip", "%") }}
|
{{ hour.precipitationProbability | unit('precip', '%') }}
|
||||||
</td>
|
</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
@@ -25,10 +36,7 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="dimmed light small">
|
<div class="dimmed light small">{{ "LOADING" | translate }}</div>
|
||||||
{{ "LOADING" | translate }}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<!-- Uncomment the line below to see the contents of the `hourly` object. -->
|
<!-- Uncomment the line below to see the contents of the `hourly` object. -->
|
||||||
<!-- <div style="word-wrap:break-word" class="xsmall dimmed">{{hourly | dump}}</div> -->
|
<!-- <div style="word-wrap:break-word" class="xsmall dimmed">{{hourly | dump}}</div> -->
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
/* global WeatherProvider, WeatherObject, WeatherUtils */
|
/* global WeatherProvider, WeatherObject, WeatherUtils */
|
||||||
|
|
||||||
/* MagicMirror²
|
/* This class is a provider for Environment Canada MSC Datamart
|
||||||
* Module: Weather
|
|
||||||
* Provider: Environment Canada (EC)
|
|
||||||
*
|
|
||||||
* This class is a provider for Environment Canada MSC Datamart
|
|
||||||
* Note that this is only for Canadian locations and does not require an API key (access is anonymous)
|
* Note that this is only for Canadian locations and does not require an API key (access is anonymous)
|
||||||
*
|
*
|
||||||
* EC Documentation at following links:
|
* EC Documentation at following links:
|
||||||
@@ -27,8 +23,6 @@
|
|||||||
* with locations you can search under column B (English Names), with the corresponding siteCode under
|
* with locations you can search under column B (English Names), with the corresponding siteCode under
|
||||||
* column A (Codes) and provCode under column C (Province).
|
* column A (Codes) and provCode under column C (Province).
|
||||||
*
|
*
|
||||||
* Original by Kevin Godin
|
|
||||||
*
|
|
||||||
* License to use Environment Canada (EC) data is detailed here:
|
* License to use Environment Canada (EC) data is detailed here:
|
||||||
* https://eccc-msc.github.io/open-data/licence/readme_en/
|
* https://eccc-msc.github.io/open-data/licence/readme_en/
|
||||||
*
|
*
|
||||||
@@ -49,7 +43,7 @@ WeatherProvider.register("envcanada", {
|
|||||||
// Set config values (equates to weather module config values). Also set values pertaining to caching of
|
// Set config values (equates to weather module config values). Also set values pertaining to caching of
|
||||||
// Today's temperature forecast (for use in the Forecast functions below)
|
// Today's temperature forecast (for use in the Forecast functions below)
|
||||||
//
|
//
|
||||||
setConfig: function (config) {
|
setConfig (config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
this.todayTempCacheMin = 0;
|
this.todayTempCacheMin = 0;
|
||||||
@@ -61,7 +55,7 @@ WeatherProvider.register("envcanada", {
|
|||||||
//
|
//
|
||||||
// Called when the weather provider is started
|
// Called when the weather provider is started
|
||||||
//
|
//
|
||||||
start: function () {
|
start () {
|
||||||
Log.info(`Weather provider: ${this.providerName} started.`);
|
Log.info(`Weather provider: ${this.providerName} started.`);
|
||||||
this.setFetchedLocation(this.config.location);
|
this.setFetchedLocation(this.config.location);
|
||||||
},
|
},
|
||||||
@@ -69,7 +63,7 @@ WeatherProvider.register("envcanada", {
|
|||||||
//
|
//
|
||||||
// Override the fetchCurrentWeather method to query EC and construct a Current weather object
|
// Override the fetchCurrentWeather method to query EC and construct a Current weather object
|
||||||
//
|
//
|
||||||
fetchCurrentWeather() {
|
fetchCurrentWeather () {
|
||||||
this.fetchData(this.getUrl(), "xml")
|
this.fetchData(this.getUrl(), "xml")
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
@@ -89,7 +83,7 @@ WeatherProvider.register("envcanada", {
|
|||||||
//
|
//
|
||||||
// Override the fetchWeatherForecast method to query EC and construct Forecast weather objects
|
// Override the fetchWeatherForecast method to query EC and construct Forecast weather objects
|
||||||
//
|
//
|
||||||
fetchWeatherForecast() {
|
fetchWeatherForecast () {
|
||||||
this.fetchData(this.getUrl(), "xml")
|
this.fetchData(this.getUrl(), "xml")
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
@@ -109,7 +103,7 @@ WeatherProvider.register("envcanada", {
|
|||||||
//
|
//
|
||||||
// Override the fetchWeatherHourly method to query EC and construct Forecast weather objects
|
// Override the fetchWeatherHourly method to query EC and construct Forecast weather objects
|
||||||
//
|
//
|
||||||
fetchWeatherHourly() {
|
fetchWeatherHourly () {
|
||||||
this.fetchData(this.getUrl(), "xml")
|
this.fetchData(this.getUrl(), "xml")
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
@@ -137,7 +131,7 @@ WeatherProvider.register("envcanada", {
|
|||||||
// URL defaults to the English version simply because there is no language dependency in the data
|
// URL defaults to the English version simply because there is no language dependency in the data
|
||||||
// being accessed. This is only pertinent when using the EC data elements that contain a textual forecast.
|
// being accessed. This is only pertinent when using the EC data elements that contain a textual forecast.
|
||||||
//
|
//
|
||||||
getUrl() {
|
getUrl () {
|
||||||
return `https://dd.weather.gc.ca/citypage_weather/xml/${this.config.provCode}/${this.config.siteCode}_e.xml`;
|
return `https://dd.weather.gc.ca/citypage_weather/xml/${this.config.provCode}/${this.config.siteCode}_e.xml`;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -145,7 +139,7 @@ WeatherProvider.register("envcanada", {
|
|||||||
// Generate a WeatherObject based on current EC weather conditions
|
// Generate a WeatherObject based on current EC weather conditions
|
||||||
//
|
//
|
||||||
|
|
||||||
generateWeatherObjectFromCurrentWeather(ECdoc) {
|
generateWeatherObjectFromCurrentWeather (ECdoc) {
|
||||||
const currentWeather = new WeatherObject();
|
const currentWeather = new WeatherObject();
|
||||||
|
|
||||||
// There are instances where EC will update weather data and current temperature will not be
|
// There are instances where EC will update weather data and current temperature will not be
|
||||||
@@ -216,7 +210,7 @@ WeatherProvider.register("envcanada", {
|
|||||||
// Generate an array of WeatherObjects based on EC weather forecast
|
// Generate an array of WeatherObjects based on EC weather forecast
|
||||||
//
|
//
|
||||||
|
|
||||||
generateWeatherObjectsFromForecast(ECdoc) {
|
generateWeatherObjectsFromForecast (ECdoc) {
|
||||||
// Declare an array to hold each day's forecast object
|
// Declare an array to hold each day's forecast object
|
||||||
|
|
||||||
const days = [];
|
const days = [];
|
||||||
@@ -360,7 +354,7 @@ WeatherProvider.register("envcanada", {
|
|||||||
// Generate an array of WeatherObjects based on EC hourly weather forecast
|
// Generate an array of WeatherObjects based on EC hourly weather forecast
|
||||||
//
|
//
|
||||||
|
|
||||||
generateWeatherObjectsFromHourly(ECdoc) {
|
generateWeatherObjectsFromHourly (ECdoc) {
|
||||||
// Declare an array to hold each hour's forecast object
|
// Declare an array to hold each hour's forecast object
|
||||||
|
|
||||||
const hours = [];
|
const hours = [];
|
||||||
@@ -384,7 +378,7 @@ WeatherProvider.register("envcanada", {
|
|||||||
|
|
||||||
const foreTime = moment(hourGroup[stepHour].getAttribute("dateTimeUTC"), "YYYYMMDDhhmmss");
|
const foreTime = moment(hourGroup[stepHour].getAttribute("dateTimeUTC"), "YYYYMMDDhhmmss");
|
||||||
const currTime = foreTime.add(hourOffset, "hours");
|
const currTime = foreTime.add(hourOffset, "hours");
|
||||||
weather.date = moment.unix(currTime);
|
weather.date = moment(currTime);
|
||||||
|
|
||||||
// Capture the temperature
|
// Capture the temperature
|
||||||
|
|
||||||
@@ -416,7 +410,7 @@ WeatherProvider.register("envcanada", {
|
|||||||
// the next Forecast element should be considered - i.e. look at Today *and* Tonight vs.Tonight-only
|
// the next Forecast element should be considered - i.e. look at Today *and* Tonight vs.Tonight-only
|
||||||
//
|
//
|
||||||
|
|
||||||
setMinMaxTemps(weather, foreGroup, today, fullDay, currentTemp) {
|
setMinMaxTemps (weather, foreGroup, today, fullDay, currentTemp) {
|
||||||
const todayTemp = foreGroup[today].querySelector("temperatures temperature").textContent;
|
const todayTemp = foreGroup[today].querySelector("temperatures temperature").textContent;
|
||||||
|
|
||||||
const todayClass = foreGroup[today].querySelector("temperatures temperature").getAttribute("class");
|
const todayClass = foreGroup[today].querySelector("temperatures temperature").getAttribute("class");
|
||||||
@@ -498,23 +492,23 @@ WeatherProvider.register("envcanada", {
|
|||||||
// the nightime forecast after a certain point in that specific scenario.
|
// the nightime forecast after a certain point in that specific scenario.
|
||||||
//
|
//
|
||||||
|
|
||||||
setPrecipitation(weather, foreGroup, today) {
|
setPrecipitation (weather, foreGroup, today) {
|
||||||
if (foreGroup[today].querySelector("precipitation accumulation")) {
|
if (foreGroup[today].querySelector("precipitation accumulation")) {
|
||||||
weather.precipitationAmount = foreGroup[today].querySelector("precipitation accumulation amount").textContent * 1.0;
|
weather.precipitationAmount = foreGroup[today].querySelector("precipitation accumulation amount").textContent * 1.0;
|
||||||
weather.precipitationUnits = foreGroup[today].querySelector("precipitation accumulation amount").getAttribute("units");
|
weather.precipitationUnits = foreGroup[today].querySelector("precipitation accumulation amount").getAttribute("units");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Today element for POP
|
// Check Today element for POP
|
||||||
|
const precipPOP = foreGroup[today].querySelector("abbreviatedForecast pop").textContent * 1.0;
|
||||||
if (foreGroup[today].querySelector("abbreviatedForecast pop").textContent > 0) {
|
if (precipPOP > 0) {
|
||||||
weather.precipitationProbability = foreGroup[today].querySelector("abbreviatedForecast pop").textContent;
|
weather.precipitationProbability = precipPOP;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
//
|
//
|
||||||
// Convert the icons to a more usable name.
|
// Convert the icons to a more usable name.
|
||||||
//
|
//
|
||||||
convertWeatherType(weatherType) {
|
convertWeatherType (weatherType) {
|
||||||
const weatherTypes = {
|
const weatherTypes = {
|
||||||
"00": "day-sunny",
|
"00": "day-sunny",
|
||||||
"01": "day-sunny",
|
"01": "day-sunny",
|
||||||
|
|||||||
@@ -1,15 +1,9 @@
|
|||||||
/* global WeatherProvider, WeatherObject */
|
/* global WeatherProvider, WeatherObject */
|
||||||
|
|
||||||
/* MagicMirror²
|
/* This class is a provider for Open-Meteo,
|
||||||
* Module: Weather
|
* see https://open-meteo.com/
|
||||||
* Provider: Open-Meteo
|
|
||||||
*
|
|
||||||
* By Andrés Vanegas
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* This class is a provider for Open-Meteo, based on Andrew Pometti's class
|
|
||||||
* for Weatherbit.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// https://www.bigdatacloud.com/docs/api/free-reverse-geocode-to-city-api
|
// https://www.bigdatacloud.com/docs/api/free-reverse-geocode-to-city-api
|
||||||
const GEOCODE_BASE = "https://api.bigdatacloud.net/data/reverse-geocode-client";
|
const GEOCODE_BASE = "https://api.bigdatacloud.net/data/reverse-geocode-client";
|
||||||
const OPEN_METEO_BASE = "https://api.open-meteo.com/v1";
|
const OPEN_METEO_BASE = "https://api.open-meteo.com/v1";
|
||||||
@@ -76,6 +70,10 @@ WeatherProvider.register("openmeteo", {
|
|||||||
"et0_fao_evapotranspiration",
|
"et0_fao_evapotranspiration",
|
||||||
// Total precipitation (rain, showers, snow) sum of the preceding hour
|
// Total precipitation (rain, showers, snow) sum of the preceding hour
|
||||||
"precipitation",
|
"precipitation",
|
||||||
|
// Precipitation Probability
|
||||||
|
"precipitation_probability",
|
||||||
|
// UV index
|
||||||
|
"uv_index",
|
||||||
// Snowfall amount of the preceding hour in centimeters. For the water equivalent in millimeter, divide by 7. E.g. 7 cm snow = 10 mm precipitation water equivalent
|
// Snowfall amount of the preceding hour in centimeters. For the water equivalent in millimeter, divide by 7. E.g. 7 cm snow = 10 mm precipitation water equivalent
|
||||||
"snowfall",
|
"snowfall",
|
||||||
// Rain from large scale weather systems of the preceding hour in millimeter
|
// Rain from large scale weather systems of the preceding hour in millimeter
|
||||||
@@ -130,15 +128,17 @@ WeatherProvider.register("openmeteo", {
|
|||||||
"winddirection_10m_dominant",
|
"winddirection_10m_dominant",
|
||||||
// The sum of solar radiation on a given day in Megajoules
|
// The sum of solar radiation on a given day in Megajoules
|
||||||
"shortwave_radiation_sum",
|
"shortwave_radiation_sum",
|
||||||
|
//UV Index
|
||||||
|
"uv_index_max",
|
||||||
// Daily sum of ET₀ Reference Evapotranspiration of a well watered grass field
|
// Daily sum of ET₀ Reference Evapotranspiration of a well watered grass field
|
||||||
"et0_fao_evapotranspiration"
|
"et0_fao_evapotranspiration"
|
||||||
],
|
],
|
||||||
|
|
||||||
fetchedLocation: function () {
|
fetchedLocation () {
|
||||||
return this.fetchedLocationName || "";
|
return this.fetchedLocationName || "";
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchCurrentWeather() {
|
fetchCurrentWeather () {
|
||||||
this.fetchData(this.getUrl())
|
this.fetchData(this.getUrl())
|
||||||
.then((data) => this.parseWeatherApiResponse(data))
|
.then((data) => this.parseWeatherApiResponse(data))
|
||||||
.then((parsedData) => {
|
.then((parsedData) => {
|
||||||
@@ -156,7 +156,7 @@ WeatherProvider.register("openmeteo", {
|
|||||||
.finally(() => this.updateAvailable());
|
.finally(() => this.updateAvailable());
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchWeatherForecast() {
|
fetchWeatherForecast () {
|
||||||
this.fetchData(this.getUrl())
|
this.fetchData(this.getUrl())
|
||||||
.then((data) => this.parseWeatherApiResponse(data))
|
.then((data) => this.parseWeatherApiResponse(data))
|
||||||
.then((parsedData) => {
|
.then((parsedData) => {
|
||||||
@@ -174,7 +174,7 @@ WeatherProvider.register("openmeteo", {
|
|||||||
.finally(() => this.updateAvailable());
|
.finally(() => this.updateAvailable());
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchWeatherHourly() {
|
fetchWeatherHourly () {
|
||||||
this.fetchData(this.getUrl())
|
this.fetchData(this.getUrl())
|
||||||
.then((data) => this.parseWeatherApiResponse(data))
|
.then((data) => this.parseWeatherApiResponse(data))
|
||||||
.then((parsedData) => {
|
.then((parsedData) => {
|
||||||
@@ -194,10 +194,9 @@ WeatherProvider.register("openmeteo", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Overrides method for setting config to check if endpoint is correct for hourly
|
* Overrides method for setting config to check if endpoint is correct for hourly
|
||||||
*
|
|
||||||
* @param {object} config The configuration object
|
* @param {object} config The configuration object
|
||||||
*/
|
*/
|
||||||
setConfig(config) {
|
setConfig (config) {
|
||||||
this.config = {
|
this.config = {
|
||||||
lang: config.lang ?? "en",
|
lang: config.lang ?? "en",
|
||||||
...this.defaults,
|
...this.defaults,
|
||||||
@@ -221,7 +220,7 @@ WeatherProvider.register("openmeteo", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Generate valid query params to perform the request
|
// Generate valid query params to perform the request
|
||||||
getQueryParameters() {
|
getQueryParameters () {
|
||||||
let params = {
|
let params = {
|
||||||
latitude: this.config.lat,
|
latitude: this.config.lat,
|
||||||
longitude: this.config.lon,
|
longitude: this.config.lon,
|
||||||
@@ -273,25 +272,23 @@ WeatherProvider.register("openmeteo", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Create a URL from the config and base URL.
|
// Create a URL from the config and base URL.
|
||||||
getUrl() {
|
getUrl () {
|
||||||
return `${this.config.apiBase}/forecast?${this.getQueryParameters()}`;
|
return `${this.config.apiBase}/forecast?${this.getQueryParameters()}`;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Transpose hourly and daily data matrices
|
// Transpose hourly and daily data matrices
|
||||||
transposeDataMatrix(data) {
|
transposeDataMatrix (data) {
|
||||||
return data.time.map((_, index) =>
|
return data.time.map((_, index) => Object.keys(data).reduce((row, key) => {
|
||||||
Object.keys(data).reduce((row, key) => {
|
return {
|
||||||
return {
|
...row,
|
||||||
...row,
|
// Parse time values as momentjs instances
|
||||||
// Parse time values as momentjs instances
|
[key]: ["time", "sunrise", "sunset"].includes(key) ? moment.unix(data[key][index]) : data[key][index]
|
||||||
[key]: ["time", "sunrise", "sunset"].includes(key) ? moment.unix(data[key][index]) : data[key][index]
|
};
|
||||||
};
|
}, {}));
|
||||||
}, {})
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Sanitize and validate API response
|
// Sanitize and validate API response
|
||||||
parseWeatherApiResponse(data) {
|
parseWeatherApiResponse (data) {
|
||||||
const validByType = {
|
const validByType = {
|
||||||
current: data.current_weather && data.current_weather.time,
|
current: data.current_weather && data.current_weather.time,
|
||||||
hourly: data.hourly && data.hourly.time && Array.isArray(data.hourly.time) && data.hourly.time.length > 0,
|
hourly: data.hourly && data.hourly.time && Array.isArray(data.hourly.time) && data.hourly.time.length > 0,
|
||||||
@@ -329,7 +326,7 @@ WeatherProvider.register("openmeteo", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Reverse geocoding from latitude and longitude provided
|
// Reverse geocoding from latitude and longitude provided
|
||||||
fetchLocation() {
|
fetchLocation () {
|
||||||
this.fetchData(`${GEOCODE_BASE}?latitude=${this.config.lat}&longitude=${this.config.lon}&localityLanguage=${this.config.lang}`)
|
this.fetchData(`${GEOCODE_BASE}?latitude=${this.config.lat}&longitude=${this.config.lon}&localityLanguage=${this.config.lang}`)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (!data || !data.city) {
|
if (!data || !data.city) {
|
||||||
@@ -344,7 +341,8 @@ WeatherProvider.register("openmeteo", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Implement WeatherDay generator.
|
// Implement WeatherDay generator.
|
||||||
generateWeatherDayFromCurrentWeather(weather) {
|
generateWeatherDayFromCurrentWeather (weather) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Since some units comes from API response "splitted" into daily, hourly and current_weather
|
* Since some units comes from API response "splitted" into daily, hourly and current_weather
|
||||||
* every time you request it, you have to ensure to get the data from the right place every time.
|
* every time you request it, you have to ensure to get the data from the right place every time.
|
||||||
@@ -382,15 +380,17 @@ WeatherProvider.register("openmeteo", {
|
|||||||
currentWeather.rain = parseFloat(weather.hourly[h].rain);
|
currentWeather.rain = parseFloat(weather.hourly[h].rain);
|
||||||
currentWeather.snow = parseFloat(weather.hourly[h].snowfall * 10);
|
currentWeather.snow = parseFloat(weather.hourly[h].snowfall * 10);
|
||||||
currentWeather.precipitationAmount = parseFloat(weather.hourly[h].precipitation);
|
currentWeather.precipitationAmount = parseFloat(weather.hourly[h].precipitation);
|
||||||
|
currentWeather.precipitationProbability = parseFloat(weather.hourly[h].precipitation_probability);
|
||||||
|
currentWeather.uv_index = parseFloat(weather.hourly[h].uv_index);
|
||||||
|
|
||||||
return currentWeather;
|
return currentWeather;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Implement WeatherForecast generator.
|
// Implement WeatherForecast generator.
|
||||||
generateWeatherObjectsFromForecast(weathers) {
|
generateWeatherObjectsFromForecast (weathers) {
|
||||||
const days = [];
|
const days = [];
|
||||||
|
|
||||||
weathers.daily.forEach((weather, i) => {
|
weathers.daily.forEach((weather) => {
|
||||||
const currentWeather = new WeatherObject();
|
const currentWeather = new WeatherObject();
|
||||||
|
|
||||||
currentWeather.date = weather.time;
|
currentWeather.date = weather.time;
|
||||||
@@ -405,6 +405,8 @@ WeatherProvider.register("openmeteo", {
|
|||||||
currentWeather.rain = parseFloat(weather.rain_sum);
|
currentWeather.rain = parseFloat(weather.rain_sum);
|
||||||
currentWeather.snow = parseFloat(weather.snowfall_sum * 10);
|
currentWeather.snow = parseFloat(weather.snowfall_sum * 10);
|
||||||
currentWeather.precipitationAmount = parseFloat(weather.precipitation_sum);
|
currentWeather.precipitationAmount = parseFloat(weather.precipitation_sum);
|
||||||
|
currentWeather.precipitationProbability = parseFloat(weather.precipitation_probability);
|
||||||
|
currentWeather.uv_index = parseFloat(weather.uv_index_max);
|
||||||
|
|
||||||
days.push(currentWeather);
|
days.push(currentWeather);
|
||||||
});
|
});
|
||||||
@@ -413,7 +415,7 @@ WeatherProvider.register("openmeteo", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Implement WeatherHourly generator.
|
// Implement WeatherHourly generator.
|
||||||
generateWeatherObjectsFromHourly(weathers) {
|
generateWeatherObjectsFromHourly (weathers) {
|
||||||
const hours = [];
|
const hours = [];
|
||||||
const now = moment();
|
const now = moment();
|
||||||
|
|
||||||
@@ -438,6 +440,8 @@ WeatherProvider.register("openmeteo", {
|
|||||||
currentWeather.rain = parseFloat(weather.rain);
|
currentWeather.rain = parseFloat(weather.rain);
|
||||||
currentWeather.snow = parseFloat(weather.snowfall * 10);
|
currentWeather.snow = parseFloat(weather.snowfall * 10);
|
||||||
currentWeather.precipitationAmount = parseFloat(weather.precipitation);
|
currentWeather.precipitationAmount = parseFloat(weather.precipitation);
|
||||||
|
currentWeather.precipitationProbability = parseFloat(weather.precipitation_probability);
|
||||||
|
currentWeather.uv_index = parseFloat(weather.uv_index);
|
||||||
|
|
||||||
hours.push(currentWeather);
|
hours.push(currentWeather);
|
||||||
});
|
});
|
||||||
@@ -446,7 +450,7 @@ WeatherProvider.register("openmeteo", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Map icons from Dark Sky to our icons.
|
// Map icons from Dark Sky to our icons.
|
||||||
convertWeatherType(weathercode, isDayTime) {
|
convertWeatherType (weathercode, isDayTime) {
|
||||||
const weatherConditions = {
|
const weatherConditions = {
|
||||||
0: "clear",
|
0: "clear",
|
||||||
1: "mainly-clear",
|
1: "mainly-clear",
|
||||||
@@ -531,7 +535,7 @@ WeatherProvider.register("openmeteo", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
getScripts: function () {
|
getScripts () {
|
||||||
return ["moment.js"];
|
return ["moment.js"];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
/* global WeatherProvider, WeatherObject */
|
/* global WeatherProvider, WeatherObject */
|
||||||
|
|
||||||
/* MagicMirror²
|
/* This class is a provider for Openweathermap,
|
||||||
* Module: Weather
|
* see https://openweathermap.org/
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*
|
|
||||||
* This class is the blueprint for a weather provider.
|
|
||||||
*/
|
*/
|
||||||
WeatherProvider.register("openweathermap", {
|
WeatherProvider.register("openweathermap", {
|
||||||
// Set the name of the provider.
|
// Set the name of the provider.
|
||||||
@@ -27,7 +22,7 @@ WeatherProvider.register("openweathermap", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Overwrite the fetchCurrentWeather method.
|
// Overwrite the fetchCurrentWeather method.
|
||||||
fetchCurrentWeather() {
|
fetchCurrentWeather () {
|
||||||
this.fetchData(this.getUrl())
|
this.fetchData(this.getUrl())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
let currentWeather;
|
let currentWeather;
|
||||||
@@ -46,7 +41,7 @@ WeatherProvider.register("openweathermap", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Overwrite the fetchWeatherForecast method.
|
// Overwrite the fetchWeatherForecast method.
|
||||||
fetchWeatherForecast() {
|
fetchWeatherForecast () {
|
||||||
this.fetchData(this.getUrl())
|
this.fetchData(this.getUrl())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
let forecast;
|
let forecast;
|
||||||
@@ -68,7 +63,7 @@ WeatherProvider.register("openweathermap", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Overwrite the fetchWeatherHourly method.
|
// Overwrite the fetchWeatherHourly method.
|
||||||
fetchWeatherHourly() {
|
fetchWeatherHourly () {
|
||||||
this.fetchData(this.getUrl())
|
this.fetchData(this.getUrl())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
@@ -90,10 +85,9 @@ WeatherProvider.register("openweathermap", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Overrides method for setting config to check if endpoint is correct for hourly
|
* Overrides method for setting config to check if endpoint is correct for hourly
|
||||||
*
|
|
||||||
* @param {object} config The configuration object
|
* @param {object} config The configuration object
|
||||||
*/
|
*/
|
||||||
setConfig(config) {
|
setConfig (config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
if (!this.config.weatherEndpoint) {
|
if (!this.config.weatherEndpoint) {
|
||||||
switch (this.config.type) {
|
switch (this.config.type) {
|
||||||
@@ -117,14 +111,14 @@ WeatherProvider.register("openweathermap", {
|
|||||||
/*
|
/*
|
||||||
* Gets the complete url for the request
|
* Gets the complete url for the request
|
||||||
*/
|
*/
|
||||||
getUrl() {
|
getUrl () {
|
||||||
return this.config.apiBase + this.config.apiVersion + this.config.weatherEndpoint + this.getParams();
|
return this.config.apiBase + this.config.apiVersion + this.config.weatherEndpoint + this.getParams();
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generate a WeatherObject based on currentWeatherInformation
|
* Generate a WeatherObject based on currentWeatherInformation
|
||||||
*/
|
*/
|
||||||
generateWeatherObjectFromCurrentWeather(currentWeatherData) {
|
generateWeatherObjectFromCurrentWeather (currentWeatherData) {
|
||||||
const currentWeather = new WeatherObject();
|
const currentWeather = new WeatherObject();
|
||||||
|
|
||||||
currentWeather.date = moment.unix(currentWeatherData.dt);
|
currentWeather.date = moment.unix(currentWeatherData.dt);
|
||||||
@@ -143,7 +137,7 @@ WeatherProvider.register("openweathermap", {
|
|||||||
/*
|
/*
|
||||||
* Generate WeatherObjects based on forecast information
|
* Generate WeatherObjects based on forecast information
|
||||||
*/
|
*/
|
||||||
generateWeatherObjectsFromForecast(forecasts) {
|
generateWeatherObjectsFromForecast (forecasts) {
|
||||||
if (this.config.weatherEndpoint === "/forecast") {
|
if (this.config.weatherEndpoint === "/forecast") {
|
||||||
return this.generateForecastHourly(forecasts);
|
return this.generateForecastHourly(forecasts);
|
||||||
} else if (this.config.weatherEndpoint === "/forecast/daily") {
|
} else if (this.config.weatherEndpoint === "/forecast/daily") {
|
||||||
@@ -156,7 +150,7 @@ WeatherProvider.register("openweathermap", {
|
|||||||
/*
|
/*
|
||||||
* Generate WeatherObjects based on One Call forecast information
|
* Generate WeatherObjects based on One Call forecast information
|
||||||
*/
|
*/
|
||||||
generateWeatherObjectsFromOnecall(data) {
|
generateWeatherObjectsFromOnecall (data) {
|
||||||
if (this.config.weatherEndpoint === "/onecall") {
|
if (this.config.weatherEndpoint === "/onecall") {
|
||||||
return this.fetchOnecall(data);
|
return this.fetchOnecall(data);
|
||||||
}
|
}
|
||||||
@@ -168,7 +162,7 @@ WeatherProvider.register("openweathermap", {
|
|||||||
* Generate forecast information for 3-hourly forecast (available for free
|
* Generate forecast information for 3-hourly forecast (available for free
|
||||||
* subscription).
|
* subscription).
|
||||||
*/
|
*/
|
||||||
generateForecastHourly(forecasts) {
|
generateForecastHourly (forecasts) {
|
||||||
// initial variable declaration
|
// initial variable declaration
|
||||||
const days = [];
|
const days = [];
|
||||||
// variables for temperature range and rain
|
// variables for temperature range and rain
|
||||||
@@ -242,7 +236,7 @@ WeatherProvider.register("openweathermap", {
|
|||||||
* Generate forecast information for daily forecast (available for paid
|
* Generate forecast information for daily forecast (available for paid
|
||||||
* subscription or old apiKey).
|
* subscription or old apiKey).
|
||||||
*/
|
*/
|
||||||
generateForecastDaily(forecasts) {
|
generateForecastDaily (forecasts) {
|
||||||
// initial variable declaration
|
// initial variable declaration
|
||||||
const days = [];
|
const days = [];
|
||||||
|
|
||||||
@@ -282,7 +276,7 @@ WeatherProvider.register("openweathermap", {
|
|||||||
* Factors in timezone offsets.
|
* Factors in timezone offsets.
|
||||||
* Minutely forecasts are excluded for the moment, see getParams().
|
* Minutely forecasts are excluded for the moment, see getParams().
|
||||||
*/
|
*/
|
||||||
fetchOnecall(data) {
|
fetchOnecall (data) {
|
||||||
let precip = false;
|
let precip = false;
|
||||||
|
|
||||||
// get current weather, if requested
|
// get current weather, if requested
|
||||||
@@ -296,6 +290,7 @@ WeatherProvider.register("openweathermap", {
|
|||||||
current.temperature = data.current.temp;
|
current.temperature = data.current.temp;
|
||||||
current.weatherType = this.convertWeatherType(data.current.weather[0].icon);
|
current.weatherType = this.convertWeatherType(data.current.weather[0].icon);
|
||||||
current.humidity = data.current.humidity;
|
current.humidity = data.current.humidity;
|
||||||
|
current.uv_index = data.current.uvi;
|
||||||
if (data.current.hasOwnProperty("rain") && !isNaN(data.current["rain"]["1h"])) {
|
if (data.current.hasOwnProperty("rain") && !isNaN(data.current["rain"]["1h"])) {
|
||||||
current.rain = data.current["rain"]["1h"];
|
current.rain = data.current["rain"]["1h"];
|
||||||
precip = true;
|
precip = true;
|
||||||
@@ -324,6 +319,7 @@ WeatherProvider.register("openweathermap", {
|
|||||||
weather.windFromDirection = hour.wind_deg;
|
weather.windFromDirection = hour.wind_deg;
|
||||||
weather.weatherType = this.convertWeatherType(hour.weather[0].icon);
|
weather.weatherType = this.convertWeatherType(hour.weather[0].icon);
|
||||||
weather.precipitationProbability = hour.pop ? hour.pop * 100 : undefined;
|
weather.precipitationProbability = hour.pop ? hour.pop * 100 : undefined;
|
||||||
|
weather.uv_index = hour.uvi;
|
||||||
precip = false;
|
precip = false;
|
||||||
if (hour.hasOwnProperty("rain") && !isNaN(hour.rain["1h"])) {
|
if (hour.hasOwnProperty("rain") && !isNaN(hour.rain["1h"])) {
|
||||||
weather.rain = hour.rain["1h"];
|
weather.rain = hour.rain["1h"];
|
||||||
@@ -356,6 +352,7 @@ WeatherProvider.register("openweathermap", {
|
|||||||
weather.windFromDirection = day.wind_deg;
|
weather.windFromDirection = day.wind_deg;
|
||||||
weather.weatherType = this.convertWeatherType(day.weather[0].icon);
|
weather.weatherType = this.convertWeatherType(day.weather[0].icon);
|
||||||
weather.precipitationProbability = day.pop ? day.pop * 100 : undefined;
|
weather.precipitationProbability = day.pop ? day.pop * 100 : undefined;
|
||||||
|
weather.uv_index = day.uvi;
|
||||||
precip = false;
|
precip = false;
|
||||||
if (!isNaN(day.rain)) {
|
if (!isNaN(day.rain)) {
|
||||||
weather.rain = day.rain;
|
weather.rain = day.rain;
|
||||||
@@ -380,7 +377,7 @@ WeatherProvider.register("openweathermap", {
|
|||||||
/*
|
/*
|
||||||
* Convert the OpenWeatherMap icons to a more usable name.
|
* Convert the OpenWeatherMap icons to a more usable name.
|
||||||
*/
|
*/
|
||||||
convertWeatherType(weatherType) {
|
convertWeatherType (weatherType) {
|
||||||
const weatherTypes = {
|
const weatherTypes = {
|
||||||
"01d": "day-sunny",
|
"01d": "day-sunny",
|
||||||
"02d": "day-cloudy",
|
"02d": "day-cloudy",
|
||||||
@@ -410,7 +407,7 @@ WeatherProvider.register("openweathermap", {
|
|||||||
*
|
*
|
||||||
* return String - URL params.
|
* return String - URL params.
|
||||||
*/
|
*/
|
||||||
getParams() {
|
getParams () {
|
||||||
let params = "?";
|
let params = "?";
|
||||||
if (this.config.weatherEndpoint === "/onecall") {
|
if (this.config.weatherEndpoint === "/onecall") {
|
||||||
params += `lat=${this.config.lat}`;
|
params += `lat=${this.config.lat}`;
|
||||||
@@ -435,6 +432,7 @@ WeatherProvider.register("openweathermap", {
|
|||||||
} else if (this.firstEvent && this.firstEvent.location) {
|
} else if (this.firstEvent && this.firstEvent.location) {
|
||||||
params += `q=${this.firstEvent.location}`;
|
params += `q=${this.firstEvent.location}`;
|
||||||
} else {
|
} else {
|
||||||
|
// TODO hide doesnt exist!
|
||||||
this.hide(this.config.animationSpeed, { lockString: this.identifier });
|
this.hide(this.config.animationSpeed, { lockString: this.identifier });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
112
modules/default/weather/providers/overrideWrapper.js
Normal file
112
modules/default/weather/providers/overrideWrapper.js
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
/* global Class, WeatherObject */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Wrapper class to enable overrides of currentOverrideWeatherObject.
|
||||||
|
*
|
||||||
|
* Sits between the weather.js module and the provider implementations to allow us to
|
||||||
|
* combine the incoming data from the CURRENT_WEATHER_OVERRIDE notification with the
|
||||||
|
* existing data received from the current api provider. If no notifications have
|
||||||
|
* been received then the api provider's data is used.
|
||||||
|
*
|
||||||
|
* The intent is to allow partial WeatherObjects from local sensors to augment or
|
||||||
|
* replace the WeatherObjects from the api providers.
|
||||||
|
*
|
||||||
|
* This class shares the signature of WeatherProvider, and passes any methods not
|
||||||
|
* concerning the current weather directly to the api provider implementation that
|
||||||
|
* is currently in use.
|
||||||
|
*/
|
||||||
|
const OverrideWrapper = Class.extend({
|
||||||
|
baseProvider: null,
|
||||||
|
providerName: "localWrapper",
|
||||||
|
notificationWeatherObject: null,
|
||||||
|
currentOverrideWeatherObject: null,
|
||||||
|
|
||||||
|
init (baseProvider) {
|
||||||
|
this.baseProvider = baseProvider;
|
||||||
|
|
||||||
|
// Binding the scope of current weather functions so any fetchData calls with
|
||||||
|
// setCurrentWeather nested in them call this classes implementation instead
|
||||||
|
// of the provider's default
|
||||||
|
this.baseProvider.setCurrentWeather = this.setCurrentWeather.bind(this);
|
||||||
|
this.baseProvider.currentWeather = this.currentWeather.bind(this);
|
||||||
|
},
|
||||||
|
|
||||||
|
/* Unchanged Api Provider Methods */
|
||||||
|
|
||||||
|
setConfig (config) {
|
||||||
|
this.baseProvider.setConfig(config);
|
||||||
|
},
|
||||||
|
start () {
|
||||||
|
this.baseProvider.start();
|
||||||
|
},
|
||||||
|
fetchCurrentWeather () {
|
||||||
|
this.baseProvider.fetchCurrentWeather();
|
||||||
|
},
|
||||||
|
fetchWeatherForecast () {
|
||||||
|
this.baseProvider.fetchWeatherForecast();
|
||||||
|
},
|
||||||
|
fetchWeatherHourly () {
|
||||||
|
this.baseProvider.fetchEatherHourly();
|
||||||
|
},
|
||||||
|
weatherForecast () {
|
||||||
|
this.baseProvider.weatherForecast();
|
||||||
|
},
|
||||||
|
weatherHourly () {
|
||||||
|
this.baseProvider.weatherHourly();
|
||||||
|
},
|
||||||
|
fetchedLocation () {
|
||||||
|
this.baseProvider.fetchedLocation();
|
||||||
|
},
|
||||||
|
setWeatherForecast (weatherForecastArray) {
|
||||||
|
this.baseProvider.setWeatherForecast(weatherForecastArray);
|
||||||
|
},
|
||||||
|
setWeatherHourly (weatherHourlyArray) {
|
||||||
|
this.baseProvider.setWeatherHourly(weatherHourlyArray);
|
||||||
|
},
|
||||||
|
setFetchedLocation (name) {
|
||||||
|
this.baseProvider.setFetchedLocation(name);
|
||||||
|
},
|
||||||
|
updateAvailable () {
|
||||||
|
this.baseProvider.updateAvailable();
|
||||||
|
},
|
||||||
|
async fetchData (url, type = "json", requestHeaders = undefined, expectedResponseHeaders = undefined) {
|
||||||
|
this.baseProvider.fetchData(url, type, requestHeaders, expectedResponseHeaders);
|
||||||
|
},
|
||||||
|
|
||||||
|
/* Override Methods */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override to return this scope's
|
||||||
|
* @returns {WeatherObject} The current weather object. May or may not contain overridden data.
|
||||||
|
*/
|
||||||
|
currentWeather () {
|
||||||
|
return this.currentOverrideWeatherObject;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override to combine the overrideWeatherObejct provided in the
|
||||||
|
* notificationReceived method with the currentOverrideWeatherObject provided by the
|
||||||
|
* api provider fetchData implementation.
|
||||||
|
* @param {WeatherObject} currentWeatherObject - the api provider weather object
|
||||||
|
*/
|
||||||
|
setCurrentWeather (currentWeatherObject) {
|
||||||
|
this.currentOverrideWeatherObject = Object.assign(currentWeatherObject, this.notificationWeatherObject);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the overrideWeatherObject, calls setCurrentWeather to combine it with
|
||||||
|
* the existing current weather object provided by the base provider, and signals
|
||||||
|
* that an update is ready.
|
||||||
|
* @param {WeatherObject} payload - the weather object received from the CURRENT_WEATHER_OVERRIDE
|
||||||
|
* notification. Represents information to augment the
|
||||||
|
* existing currentOverrideWeatherObject with.
|
||||||
|
*/
|
||||||
|
notificationReceived (payload) {
|
||||||
|
this.notificationWeatherObject = payload;
|
||||||
|
|
||||||
|
// setCurrentWeather combines the newly received notification weather with
|
||||||
|
// the existing weather object we return for current weather
|
||||||
|
this.setCurrentWeather(this.currentOverrideWeatherObject);
|
||||||
|
this.updateAvailable();
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -1,14 +1,7 @@
|
|||||||
/* global WeatherProvider, WeatherObject */
|
/* global WeatherProvider, WeatherObject */
|
||||||
|
|
||||||
/* MagicMirror²
|
/* This class is a provider for Pirate Weather, it is a replacement for Dark Sky (same api),
|
||||||
* Module: Weather
|
* see http://pirateweather.net/en/latest/
|
||||||
* Provider: Pirate Weather
|
|
||||||
*
|
|
||||||
* Written by Nicholas Hubbard https://github.com/nhubbard for formerly Dark Sky Provider
|
|
||||||
* Modified by Karsten Hassel for Pirate Weather
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* This class is a provider for Pirate Weather, it is a replacement for Dark Sky (same api).
|
|
||||||
*/
|
*/
|
||||||
WeatherProvider.register("pirateweather", {
|
WeatherProvider.register("pirateweather", {
|
||||||
// Set the name of the provider.
|
// Set the name of the provider.
|
||||||
@@ -25,7 +18,7 @@ WeatherProvider.register("pirateweather", {
|
|||||||
lon: 0
|
lon: 0
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchCurrentWeather() {
|
fetchCurrentWeather () {
|
||||||
this.fetchData(this.getUrl())
|
this.fetchData(this.getUrl())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (!data || !data.currently || typeof data.currently.temperature === "undefined") {
|
if (!data || !data.currently || typeof data.currently.temperature === "undefined") {
|
||||||
@@ -42,7 +35,7 @@ WeatherProvider.register("pirateweather", {
|
|||||||
.finally(() => this.updateAvailable());
|
.finally(() => this.updateAvailable());
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchWeatherForecast() {
|
fetchWeatherForecast () {
|
||||||
this.fetchData(this.getUrl())
|
this.fetchData(this.getUrl())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (!data || !data.daily || !data.daily.data.length) {
|
if (!data || !data.daily || !data.daily.data.length) {
|
||||||
@@ -60,12 +53,12 @@ WeatherProvider.register("pirateweather", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Create a URL from the config and base URL.
|
// Create a URL from the config and base URL.
|
||||||
getUrl() {
|
getUrl () {
|
||||||
return `${this.config.apiBase}${this.config.weatherEndpoint}/${this.config.apiKey}/${this.config.lat},${this.config.lon}?units=si&lang=${this.config.lang}`;
|
return `${this.config.apiBase}${this.config.weatherEndpoint}/${this.config.apiKey}/${this.config.lat},${this.config.lon}?units=si&lang=${this.config.lang}`;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Implement WeatherDay generator.
|
// Implement WeatherDay generator.
|
||||||
generateWeatherDayFromCurrentWeather(currentWeatherData) {
|
generateWeatherDayFromCurrentWeather (currentWeatherData) {
|
||||||
const currentWeather = new WeatherObject();
|
const currentWeather = new WeatherObject();
|
||||||
|
|
||||||
currentWeather.date = moment();
|
currentWeather.date = moment();
|
||||||
@@ -80,7 +73,7 @@ WeatherProvider.register("pirateweather", {
|
|||||||
return currentWeather;
|
return currentWeather;
|
||||||
},
|
},
|
||||||
|
|
||||||
generateWeatherObjectsFromForecast(forecasts) {
|
generateWeatherObjectsFromForecast (forecasts) {
|
||||||
const days = [];
|
const days = [];
|
||||||
|
|
||||||
for (const forecast of forecasts) {
|
for (const forecast of forecasts) {
|
||||||
@@ -114,7 +107,7 @@ WeatherProvider.register("pirateweather", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Map icons from Pirate Weather to our icons.
|
// Map icons from Pirate Weather to our icons.
|
||||||
convertWeatherType(weatherType) {
|
convertWeatherType (weatherType) {
|
||||||
const weatherTypes = {
|
const weatherTypes = {
|
||||||
"clear-day": "day-sunny",
|
"clear-day": "day-sunny",
|
||||||
"clear-night": "night-clear",
|
"clear-night": "night-clear",
|
||||||
|
|||||||
@@ -1,14 +1,8 @@
|
|||||||
/* global WeatherProvider, WeatherObject */
|
/* global WeatherProvider, WeatherObject */
|
||||||
|
|
||||||
/* MagicMirror²
|
/* This class is a provider for SMHI (Sweden only).
|
||||||
* Module: Weather
|
* Metric system is the only supported unit,
|
||||||
* Provider: SMHI
|
* see https://www.smhi.se/
|
||||||
*
|
|
||||||
* By BuXXi https://github.com/buxxi
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* This class is a provider for SMHI (Sweden only). Metric system is the only
|
|
||||||
* supported unit.
|
|
||||||
*/
|
*/
|
||||||
WeatherProvider.register("smhi", {
|
WeatherProvider.register("smhi", {
|
||||||
providerName: "SMHI",
|
providerName: "SMHI",
|
||||||
@@ -24,7 +18,7 @@ WeatherProvider.register("smhi", {
|
|||||||
/**
|
/**
|
||||||
* Implements method in interface for fetching current weather.
|
* Implements method in interface for fetching current weather.
|
||||||
*/
|
*/
|
||||||
fetchCurrentWeather() {
|
fetchCurrentWeather () {
|
||||||
this.fetchData(this.getURL())
|
this.fetchData(this.getURL())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
const closest = this.getClosestToCurrentTime(data.timeSeries);
|
const closest = this.getClosestToCurrentTime(data.timeSeries);
|
||||||
@@ -40,7 +34,7 @@ WeatherProvider.register("smhi", {
|
|||||||
/**
|
/**
|
||||||
* Implements method in interface for fetching a multi-day forecast.
|
* Implements method in interface for fetching a multi-day forecast.
|
||||||
*/
|
*/
|
||||||
fetchWeatherForecast() {
|
fetchWeatherForecast () {
|
||||||
this.fetchData(this.getURL())
|
this.fetchData(this.getURL())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
const coordinates = this.resolveCoordinates(data);
|
const coordinates = this.resolveCoordinates(data);
|
||||||
@@ -55,7 +49,7 @@ WeatherProvider.register("smhi", {
|
|||||||
/**
|
/**
|
||||||
* Implements method in interface for fetching hourly forecasts.
|
* Implements method in interface for fetching hourly forecasts.
|
||||||
*/
|
*/
|
||||||
fetchWeatherHourly() {
|
fetchWeatherHourly () {
|
||||||
this.fetchData(this.getURL())
|
this.fetchData(this.getURL())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
const coordinates = this.resolveCoordinates(data);
|
const coordinates = this.resolveCoordinates(data);
|
||||||
@@ -69,10 +63,9 @@ WeatherProvider.register("smhi", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Overrides method for setting config with checks for the precipitationValue being unset or invalid
|
* Overrides method for setting config with checks for the precipitationValue being unset or invalid
|
||||||
*
|
|
||||||
* @param {object} config The configuration object
|
* @param {object} config The configuration object
|
||||||
*/
|
*/
|
||||||
setConfig(config) {
|
setConfig (config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
if (!config.precipitationValue || ["pmin", "pmean", "pmedian", "pmax"].indexOf(config.precipitationValue) === -1) {
|
if (!config.precipitationValue || ["pmin", "pmean", "pmedian", "pmax"].indexOf(config.precipitationValue) === -1) {
|
||||||
Log.log(`invalid or not set: ${config.precipitationValue}`);
|
Log.log(`invalid or not set: ${config.precipitationValue}`);
|
||||||
@@ -82,11 +75,10 @@ WeatherProvider.register("smhi", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Of all the times returned find out which one is closest to the current time, should be the first if the data isn't old.
|
* Of all the times returned find out which one is closest to the current time, should be the first if the data isn't old.
|
||||||
*
|
|
||||||
* @param {object[]} times Array of time objects
|
* @param {object[]} times Array of time objects
|
||||||
* @returns {object} The weatherdata closest to the current time
|
* @returns {object} The weatherdata closest to the current time
|
||||||
*/
|
*/
|
||||||
getClosestToCurrentTime(times) {
|
getClosestToCurrentTime (times) {
|
||||||
let now = moment();
|
let now = moment();
|
||||||
let minDiff = undefined;
|
let minDiff = undefined;
|
||||||
for (const time of times) {
|
for (const time of times) {
|
||||||
@@ -100,10 +92,9 @@ WeatherProvider.register("smhi", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the forecast url for the configured coordinates
|
* Get the forecast url for the configured coordinates
|
||||||
*
|
|
||||||
* @returns {string} the url for the specified coordinates
|
* @returns {string} the url for the specified coordinates
|
||||||
*/
|
*/
|
||||||
getURL() {
|
getURL () {
|
||||||
const formatter = new Intl.NumberFormat("en-US", {
|
const formatter = new Intl.NumberFormat("en-US", {
|
||||||
minimumFractionDigits: 6,
|
minimumFractionDigits: 6,
|
||||||
maximumFractionDigits: 6
|
maximumFractionDigits: 6
|
||||||
@@ -115,11 +106,10 @@ WeatherProvider.register("smhi", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the apparent temperature based on known atmospheric data.
|
* Calculates the apparent temperature based on known atmospheric data.
|
||||||
*
|
|
||||||
* @param {object} weatherData Weatherdata to use for the calculation
|
* @param {object} weatherData Weatherdata to use for the calculation
|
||||||
* @returns {number} The apparent temperature
|
* @returns {number} The apparent temperature
|
||||||
*/
|
*/
|
||||||
calculateApparentTemperature(weatherData) {
|
calculateApparentTemperature (weatherData) {
|
||||||
const Ta = this.paramValue(weatherData, "t");
|
const Ta = this.paramValue(weatherData, "t");
|
||||||
const rh = this.paramValue(weatherData, "r");
|
const rh = this.paramValue(weatherData, "r");
|
||||||
const ws = this.paramValue(weatherData, "ws");
|
const ws = this.paramValue(weatherData, "ws");
|
||||||
@@ -132,12 +122,11 @@ WeatherProvider.register("smhi", {
|
|||||||
* Converts the returned data into a WeatherObject with required properties set for both current weather and forecast.
|
* Converts the returned data into a WeatherObject with required properties set for both current weather and forecast.
|
||||||
* The returned units is always in metric system.
|
* The returned units is always in metric system.
|
||||||
* Requires coordinates to determine if its daytime or nighttime to know which icon to use and also to set sunrise and sunset.
|
* Requires coordinates to determine if its daytime or nighttime to know which icon to use and also to set sunrise and sunset.
|
||||||
*
|
|
||||||
* @param {object} weatherData Weatherdata to convert
|
* @param {object} weatherData Weatherdata to convert
|
||||||
* @param {object} coordinates Coordinates of the locations of the weather
|
* @param {object} coordinates Coordinates of the locations of the weather
|
||||||
* @returns {WeatherObject} The converted weatherdata at the specified location
|
* @returns {WeatherObject} The converted weatherdata at the specified location
|
||||||
*/
|
*/
|
||||||
convertWeatherDataToObject(weatherData, coordinates) {
|
convertWeatherDataToObject (weatherData, coordinates) {
|
||||||
let currentWeather = new WeatherObject();
|
let currentWeather = new WeatherObject();
|
||||||
|
|
||||||
currentWeather.date = moment(weatherData.validTime);
|
currentWeather.date = moment(weatherData.validTime);
|
||||||
@@ -178,13 +167,12 @@ WeatherProvider.register("smhi", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes all the data points and converts it to one WeatherObject per day.
|
* Takes all the data points and converts it to one WeatherObject per day.
|
||||||
*
|
|
||||||
* @param {object[]} allWeatherData Array of weatherdata
|
* @param {object[]} allWeatherData Array of weatherdata
|
||||||
* @param {object} coordinates Coordinates of the locations of the weather
|
* @param {object} coordinates Coordinates of the locations of the weather
|
||||||
* @param {string} groupBy The interval to use for grouping the data (day, hour)
|
* @param {string} groupBy The interval to use for grouping the data (day, hour)
|
||||||
* @returns {WeatherObject[]} Array of weatherobjects
|
* @returns {WeatherObject[]} Array of weatherobjects
|
||||||
*/
|
*/
|
||||||
convertWeatherDataGroupedBy(allWeatherData, coordinates, groupBy = "day") {
|
convertWeatherDataGroupedBy (allWeatherData, coordinates, groupBy = "day") {
|
||||||
let currentWeather;
|
let currentWeather;
|
||||||
let result = [];
|
let result = [];
|
||||||
|
|
||||||
@@ -230,22 +218,20 @@ WeatherProvider.register("smhi", {
|
|||||||
/**
|
/**
|
||||||
* Resolve coordinates from the response data (probably preferably to use
|
* Resolve coordinates from the response data (probably preferably to use
|
||||||
* this if it's not matching the config values exactly)
|
* this if it's not matching the config values exactly)
|
||||||
*
|
|
||||||
* @param {object} data Response data from the weather service
|
* @param {object} data Response data from the weather service
|
||||||
* @returns {{lon, lat}} the lat/long coordinates of the data
|
* @returns {{lon, lat}} the lat/long coordinates of the data
|
||||||
*/
|
*/
|
||||||
resolveCoordinates(data) {
|
resolveCoordinates (data) {
|
||||||
return { lat: data.geometry.coordinates[0][1], lon: data.geometry.coordinates[0][0] };
|
return { lat: data.geometry.coordinates[0][1], lon: data.geometry.coordinates[0][0] };
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The distance between the data points is increasing in the data the more distant the prediction is.
|
* The distance between the data points is increasing in the data the more distant the prediction is.
|
||||||
* Find these gaps and fill them with the previous hours data to make the data returned a complete set.
|
* Find these gaps and fill them with the previous hours data to make the data returned a complete set.
|
||||||
*
|
|
||||||
* @param {object[]} data Response data from the weather service
|
* @param {object[]} data Response data from the weather service
|
||||||
* @returns {object[]} Given data with filled gaps
|
* @returns {object[]} Given data with filled gaps
|
||||||
*/
|
*/
|
||||||
fillInGaps(data) {
|
fillInGaps (data) {
|
||||||
let result = [];
|
let result = [];
|
||||||
for (let i = 1; i < data.length; i++) {
|
for (let i = 1; i < data.length; i++) {
|
||||||
let to = moment(data[i].validTime);
|
let to = moment(data[i].validTime);
|
||||||
@@ -263,12 +249,11 @@ WeatherProvider.register("smhi", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to get a property from the returned data set.
|
* Helper method to get a property from the returned data set.
|
||||||
*
|
|
||||||
* @param {object} currentWeatherData Weatherdata to get from
|
* @param {object} currentWeatherData Weatherdata to get from
|
||||||
* @param {string} name The name of the property
|
* @param {string} name The name of the property
|
||||||
* @returns {*} The value of the property in the weatherdata
|
* @returns {*} The value of the property in the weatherdata
|
||||||
*/
|
*/
|
||||||
paramValue(currentWeatherData, name) {
|
paramValue (currentWeatherData, name) {
|
||||||
return currentWeatherData.parameters.filter((p) => p.name === name).flatMap((p) => p.values)[0];
|
return currentWeatherData.parameters.filter((p) => p.name === name).flatMap((p) => p.values)[0];
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -276,12 +261,11 @@ WeatherProvider.register("smhi", {
|
|||||||
* Map the icon value from SMHI to an icon that MagicMirror² understands.
|
* Map the icon value from SMHI to an icon that MagicMirror² understands.
|
||||||
* Uses different icons depending on if its daytime or nighttime.
|
* Uses different icons depending on if its daytime or nighttime.
|
||||||
* SMHI's description of what the numeric value means is the comment after the case.
|
* SMHI's description of what the numeric value means is the comment after the case.
|
||||||
*
|
|
||||||
* @param {number} input The SMHI icon value
|
* @param {number} input The SMHI icon value
|
||||||
* @param {boolean} isDayTime True if the icon should be for daytime, false for nighttime
|
* @param {boolean} isDayTime True if the icon should be for daytime, false for nighttime
|
||||||
* @returns {string} The icon name for the MagicMirror
|
* @returns {string} The icon name for the MagicMirror
|
||||||
*/
|
*/
|
||||||
convertWeatherType(input, isDayTime) {
|
convertWeatherType (input, isDayTime) {
|
||||||
switch (input) {
|
switch (input) {
|
||||||
case 1:
|
case 1:
|
||||||
return isDayTime ? "day-sunny" : "night-clear"; // Clear sky
|
return isDayTime ? "day-sunny" : "night-clear"; // Clear sky
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
/* global WeatherProvider, WeatherObject, WeatherUtils */
|
/* global WeatherProvider, WeatherObject, WeatherUtils */
|
||||||
|
|
||||||
/* MagicMirror²
|
/* This class is a provider for UK Met Office Datapoint,
|
||||||
* Module: Weather
|
* see https://www.metoffice.gov.uk/
|
||||||
*
|
|
||||||
* By Malcolm Oakes https://github.com/maloakes
|
|
||||||
* MIT Licensed.
|
|
||||||
*
|
|
||||||
* This class is a provider for UK Met Office Datapoint.
|
|
||||||
*/
|
*/
|
||||||
WeatherProvider.register("ukmetoffice", {
|
WeatherProvider.register("ukmetoffice", {
|
||||||
// Set the name of the provider.
|
// Set the name of the provider.
|
||||||
@@ -22,7 +17,7 @@ WeatherProvider.register("ukmetoffice", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Overwrite the fetchCurrentWeather method.
|
// Overwrite the fetchCurrentWeather method.
|
||||||
fetchCurrentWeather() {
|
fetchCurrentWeather () {
|
||||||
this.fetchData(this.getUrl("3hourly"))
|
this.fetchData(this.getUrl("3hourly"))
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (!data || !data.SiteRep || !data.SiteRep.DV || !data.SiteRep.DV.Location || !data.SiteRep.DV.Location.Period || data.SiteRep.DV.Location.Period.length === 0) {
|
if (!data || !data.SiteRep || !data.SiteRep.DV || !data.SiteRep.DV.Location || !data.SiteRep.DV.Location.Period || data.SiteRep.DV.Location.Period.length === 0) {
|
||||||
@@ -43,7 +38,7 @@ WeatherProvider.register("ukmetoffice", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Overwrite the fetchCurrentWeather method.
|
// Overwrite the fetchCurrentWeather method.
|
||||||
fetchWeatherForecast() {
|
fetchWeatherForecast () {
|
||||||
this.fetchData(this.getUrl("daily"))
|
this.fetchData(this.getUrl("daily"))
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (!data || !data.SiteRep || !data.SiteRep.DV || !data.SiteRep.DV.Location || !data.SiteRep.DV.Location.Period || data.SiteRep.DV.Location.Period.length === 0) {
|
if (!data || !data.SiteRep || !data.SiteRep.DV || !data.SiteRep.DV.Location || !data.SiteRep.DV.Location.Period || data.SiteRep.DV.Location.Period.length === 0) {
|
||||||
@@ -67,14 +62,14 @@ WeatherProvider.register("ukmetoffice", {
|
|||||||
/*
|
/*
|
||||||
* Gets the complete url for the request
|
* Gets the complete url for the request
|
||||||
*/
|
*/
|
||||||
getUrl(forecastType) {
|
getUrl (forecastType) {
|
||||||
return this.config.apiBase + this.config.locationID + this.getParams(forecastType);
|
return this.config.apiBase + this.config.locationID + this.getParams(forecastType);
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generate a WeatherObject based on currentWeatherInformation
|
* Generate a WeatherObject based on currentWeatherInformation
|
||||||
*/
|
*/
|
||||||
generateWeatherObjectFromCurrentWeather(currentWeatherData) {
|
generateWeatherObjectFromCurrentWeather (currentWeatherData) {
|
||||||
const currentWeather = new WeatherObject();
|
const currentWeather = new WeatherObject();
|
||||||
const location = currentWeatherData.SiteRep.DV.Location;
|
const location = currentWeatherData.SiteRep.DV.Location;
|
||||||
|
|
||||||
@@ -119,7 +114,7 @@ WeatherProvider.register("ukmetoffice", {
|
|||||||
/*
|
/*
|
||||||
* Generate WeatherObjects based on forecast information
|
* Generate WeatherObjects based on forecast information
|
||||||
*/
|
*/
|
||||||
generateWeatherObjectsFromForecast(forecasts) {
|
generateWeatherObjectsFromForecast (forecasts) {
|
||||||
const days = [];
|
const days = [];
|
||||||
|
|
||||||
// loop round the (5) periods getting the data
|
// loop round the (5) periods getting the data
|
||||||
@@ -150,7 +145,7 @@ WeatherProvider.register("ukmetoffice", {
|
|||||||
/*
|
/*
|
||||||
* Convert the Met Office icons to a more usable name.
|
* Convert the Met Office icons to a more usable name.
|
||||||
*/
|
*/
|
||||||
convertWeatherType(weatherType) {
|
convertWeatherType (weatherType) {
|
||||||
const weatherTypes = {
|
const weatherTypes = {
|
||||||
0: "night-clear",
|
0: "night-clear",
|
||||||
1: "day-sunny",
|
1: "day-sunny",
|
||||||
@@ -189,11 +184,10 @@ WeatherProvider.register("ukmetoffice", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates an url with api parameters based on the config.
|
* Generates an url with api parameters based on the config.
|
||||||
*
|
|
||||||
* @param {string} forecastType daily or 3hourly forecast
|
* @param {string} forecastType daily or 3hourly forecast
|
||||||
* @returns {string} url
|
* @returns {string} url
|
||||||
*/
|
*/
|
||||||
getParams(forecastType) {
|
getParams (forecastType) {
|
||||||
let params = "?";
|
let params = "?";
|
||||||
params += `res=${forecastType}`;
|
params += `res=${forecastType}`;
|
||||||
params += `&key=${this.config.apiKey}`;
|
params += `&key=${this.config.apiKey}`;
|
||||||
|
|||||||
@@ -1,13 +1,6 @@
|
|||||||
/* global WeatherProvider, WeatherObject */
|
/* global WeatherProvider, WeatherObject */
|
||||||
|
|
||||||
/* MagicMirror²
|
/* This class is a provider for UK Met Office Data Hub (the replacement for their Data Point services).
|
||||||
* Module: Weather
|
|
||||||
*
|
|
||||||
* By Malcolm Oakes https://github.com/maloakes
|
|
||||||
* Existing Met Office provider edited for new MetOffice Data Hub by CreepinJesus http://github.com/XBCreepinJesus
|
|
||||||
* MIT Licensed.
|
|
||||||
*
|
|
||||||
* This class is a provider for UK Met Office Data Hub (the replacement for their Data Point services).
|
|
||||||
* For more information on Data Hub, see https://www.metoffice.gov.uk/services/data/datapoint/notifications/weather-datahub
|
* For more information on Data Hub, see https://www.metoffice.gov.uk/services/data/datapoint/notifications/weather-datahub
|
||||||
* Data available:
|
* Data available:
|
||||||
* Hourly data for next 2 days ("hourly") - https://www.metoffice.gov.uk/binaries/content/assets/metofficegovuk/pdf/data/global-spot-data-hourly.pdf
|
* Hourly data for next 2 days ("hourly") - https://www.metoffice.gov.uk/binaries/content/assets/metofficegovuk/pdf/data/global-spot-data-hourly.pdf
|
||||||
@@ -53,7 +46,7 @@ WeatherProvider.register("ukmetofficedatahub", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Build URL with query strings according to DataHub API (https://metoffice.apiconnect.ibmcloud.com/metoffice/production/api)
|
// Build URL with query strings according to DataHub API (https://metoffice.apiconnect.ibmcloud.com/metoffice/production/api)
|
||||||
getUrl(forecastType) {
|
getUrl (forecastType) {
|
||||||
let queryStrings = "?";
|
let queryStrings = "?";
|
||||||
queryStrings += `latitude=${this.config.lat}`;
|
queryStrings += `latitude=${this.config.lat}`;
|
||||||
queryStrings += `&longitude=${this.config.lon}`;
|
queryStrings += `&longitude=${this.config.lon}`;
|
||||||
@@ -66,7 +59,7 @@ WeatherProvider.register("ukmetofficedatahub", {
|
|||||||
// Build the list of headers for the request
|
// Build the list of headers for the request
|
||||||
// For DataHub requests, the API key/secret are sent in the headers rather than as query strings.
|
// For DataHub requests, the API key/secret are sent in the headers rather than as query strings.
|
||||||
// Headers defined according to Data Hub API (https://metoffice.apiconnect.ibmcloud.com/metoffice/production/api)
|
// Headers defined according to Data Hub API (https://metoffice.apiconnect.ibmcloud.com/metoffice/production/api)
|
||||||
getHeaders() {
|
getHeaders () {
|
||||||
return {
|
return {
|
||||||
accept: "application/json",
|
accept: "application/json",
|
||||||
"x-ibm-client-id": this.config.apiKey,
|
"x-ibm-client-id": this.config.apiKey,
|
||||||
@@ -75,7 +68,7 @@ WeatherProvider.register("ukmetofficedatahub", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Fetch data using supplied URL and request headers
|
// Fetch data using supplied URL and request headers
|
||||||
async fetchWeather(url, headers) {
|
async fetchWeather (url, headers) {
|
||||||
const response = await fetch(url, { headers: headers });
|
const response = await fetch(url, { headers: headers });
|
||||||
|
|
||||||
// Return JSON data
|
// Return JSON data
|
||||||
@@ -83,7 +76,7 @@ WeatherProvider.register("ukmetofficedatahub", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Fetch hourly forecast data (to use for current weather)
|
// Fetch hourly forecast data (to use for current weather)
|
||||||
fetchCurrentWeather() {
|
fetchCurrentWeather () {
|
||||||
this.fetchWeather(this.getUrl("hourly"), this.getHeaders())
|
this.fetchWeather(this.getUrl("hourly"), this.getHeaders())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
// Check data is usable
|
// Check data is usable
|
||||||
@@ -111,7 +104,7 @@ WeatherProvider.register("ukmetofficedatahub", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Create a WeatherObject using current weather data (data for the current hour)
|
// Create a WeatherObject using current weather data (data for the current hour)
|
||||||
generateWeatherObjectFromCurrentWeather(currentWeatherData) {
|
generateWeatherObjectFromCurrentWeather (currentWeatherData) {
|
||||||
const currentWeather = new WeatherObject();
|
const currentWeather = new WeatherObject();
|
||||||
|
|
||||||
// Extract the actual forecasts
|
// Extract the actual forecasts
|
||||||
@@ -152,7 +145,7 @@ WeatherProvider.register("ukmetofficedatahub", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Fetch daily forecast data
|
// Fetch daily forecast data
|
||||||
fetchWeatherForecast() {
|
fetchWeatherForecast () {
|
||||||
this.fetchWeather(this.getUrl("daily"), this.getHeaders())
|
this.fetchWeather(this.getUrl("daily"), this.getHeaders())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
// Check data is usable
|
// Check data is usable
|
||||||
@@ -180,7 +173,7 @@ WeatherProvider.register("ukmetofficedatahub", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Create a WeatherObject for each day using daily forecast data
|
// Create a WeatherObject for each day using daily forecast data
|
||||||
generateWeatherObjectsFromForecast(forecasts) {
|
generateWeatherObjectsFromForecast (forecasts) {
|
||||||
const dailyForecasts = [];
|
const dailyForecasts = [];
|
||||||
|
|
||||||
// Extract the actual forecasts
|
// Extract the actual forecasts
|
||||||
@@ -225,14 +218,14 @@ WeatherProvider.register("ukmetofficedatahub", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Set the fetched location name.
|
// Set the fetched location name.
|
||||||
setFetchedLocation: function (name) {
|
setFetchedLocation (name) {
|
||||||
this.fetchedLocationName = name;
|
this.fetchedLocationName = name;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Match the Met Office "significant weather code" to a weathericons.css icon
|
// Match the Met Office "significant weather code" to a weathericons.css icon
|
||||||
// Use: https://metoffice.apiconnect.ibmcloud.com/metoffice/production/node/264
|
// Use: https://metoffice.apiconnect.ibmcloud.com/metoffice/production/node/264
|
||||||
// and: https://erikflowers.github.io/weather-icons/
|
// and: https://erikflowers.github.io/weather-icons/
|
||||||
convertWeatherType(weatherType) {
|
convertWeatherType (weatherType) {
|
||||||
const weatherTypes = {
|
const weatherTypes = {
|
||||||
0: "night-clear",
|
0: "night-clear",
|
||||||
1: "day-sunny",
|
1: "day-sunny",
|
||||||
|
|||||||
@@ -1,14 +1,7 @@
|
|||||||
/* global WeatherProvider, WeatherObject */
|
/* global WeatherProvider, WeatherObject */
|
||||||
|
|
||||||
/* MagicMirror²
|
/* This class is a provider for Weatherbit,
|
||||||
* Module: Weather
|
* see https://www.weatherbit.io/
|
||||||
* Provider: Weatherbit
|
|
||||||
*
|
|
||||||
* By Andrew Pometti
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* This class is a provider for Weatherbit, based on Nicholas Hubbard's class
|
|
||||||
* for Dark Sky & Vince Peri's class for Weather.gov.
|
|
||||||
*/
|
*/
|
||||||
WeatherProvider.register("weatherbit", {
|
WeatherProvider.register("weatherbit", {
|
||||||
// Set the name of the provider.
|
// Set the name of the provider.
|
||||||
@@ -23,11 +16,11 @@ WeatherProvider.register("weatherbit", {
|
|||||||
lon: 0
|
lon: 0
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchedLocation: function () {
|
fetchedLocation () {
|
||||||
return this.fetchedLocationName || "";
|
return this.fetchedLocationName || "";
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchCurrentWeather() {
|
fetchCurrentWeather () {
|
||||||
this.fetchData(this.getUrl())
|
this.fetchData(this.getUrl())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (!data || !data.data[0] || typeof data.data[0].temp === "undefined") {
|
if (!data || !data.data[0] || typeof data.data[0].temp === "undefined") {
|
||||||
@@ -44,7 +37,7 @@ WeatherProvider.register("weatherbit", {
|
|||||||
.finally(() => this.updateAvailable());
|
.finally(() => this.updateAvailable());
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchWeatherForecast() {
|
fetchWeatherForecast () {
|
||||||
this.fetchData(this.getUrl())
|
this.fetchData(this.getUrl())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (!data || !data.data) {
|
if (!data || !data.data) {
|
||||||
@@ -65,10 +58,9 @@ WeatherProvider.register("weatherbit", {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Overrides method for setting config to check if endpoint is correct for hourly
|
* Overrides method for setting config to check if endpoint is correct for hourly
|
||||||
*
|
|
||||||
* @param {object} config The configuration object
|
* @param {object} config The configuration object
|
||||||
*/
|
*/
|
||||||
setConfig(config) {
|
setConfig (config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
if (!this.config.weatherEndpoint) {
|
if (!this.config.weatherEndpoint) {
|
||||||
switch (this.config.type) {
|
switch (this.config.type) {
|
||||||
@@ -89,12 +81,12 @@ WeatherProvider.register("weatherbit", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Create a URL from the config and base URL.
|
// Create a URL from the config and base URL.
|
||||||
getUrl() {
|
getUrl () {
|
||||||
return `${this.config.apiBase}${this.config.weatherEndpoint}?lat=${this.config.lat}&lon=${this.config.lon}&units=M&key=${this.config.apiKey}`;
|
return `${this.config.apiBase}${this.config.weatherEndpoint}?lat=${this.config.lat}&lon=${this.config.lon}&units=M&key=${this.config.apiKey}`;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Implement WeatherDay generator.
|
// Implement WeatherDay generator.
|
||||||
generateWeatherDayFromCurrentWeather(currentWeatherData) {
|
generateWeatherDayFromCurrentWeather (currentWeatherData) {
|
||||||
//Calculate TZ Offset and invert to convert Sunrise/Sunset times to Local
|
//Calculate TZ Offset and invert to convert Sunrise/Sunset times to Local
|
||||||
const d = new Date();
|
const d = new Date();
|
||||||
let tzOffset = d.getTimezoneOffset();
|
let tzOffset = d.getTimezoneOffset();
|
||||||
@@ -116,7 +108,7 @@ WeatherProvider.register("weatherbit", {
|
|||||||
return currentWeather;
|
return currentWeather;
|
||||||
},
|
},
|
||||||
|
|
||||||
generateWeatherObjectsFromForecast(forecasts) {
|
generateWeatherObjectsFromForecast (forecasts) {
|
||||||
const days = [];
|
const days = [];
|
||||||
|
|
||||||
for (const forecast of forecasts) {
|
for (const forecast of forecasts) {
|
||||||
@@ -136,7 +128,7 @@ WeatherProvider.register("weatherbit", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Map icons from Dark Sky to our icons.
|
// Map icons from Dark Sky to our icons.
|
||||||
convertWeatherType(weatherType) {
|
convertWeatherType (weatherType) {
|
||||||
const weatherTypes = {
|
const weatherTypes = {
|
||||||
t01d: "day-thunderstorm",
|
t01d: "day-thunderstorm",
|
||||||
t01n: "night-alt-thunderstorm",
|
t01n: "night-alt-thunderstorm",
|
||||||
|
|||||||
@@ -1,16 +1,8 @@
|
|||||||
/* global WeatherProvider, WeatherObject, WeatherUtils */
|
/* global WeatherProvider, WeatherObject, WeatherUtils */
|
||||||
|
|
||||||
/* MagicMirror²
|
/* This class is a provider for Weatherflow.
|
||||||
* Module: Weather
|
|
||||||
* Provider: Weatherflow
|
|
||||||
*
|
|
||||||
* By Tobias Dreyem https://github.com/10bias
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* This class is a provider for Weatherflow.
|
|
||||||
* Note that the Weatherflow API does not provide snowfall.
|
* Note that the Weatherflow API does not provide snowfall.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
WeatherProvider.register("weatherflow", {
|
WeatherProvider.register("weatherflow", {
|
||||||
// Set the name of the provider.
|
// Set the name of the provider.
|
||||||
// Not strictly required, but helps for debugging
|
// Not strictly required, but helps for debugging
|
||||||
@@ -23,7 +15,7 @@ WeatherProvider.register("weatherflow", {
|
|||||||
stationid: ""
|
stationid: ""
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchCurrentWeather() {
|
fetchCurrentWeather () {
|
||||||
this.fetchData(this.getUrl())
|
this.fetchData(this.getUrl())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
const currentWeather = new WeatherObject();
|
const currentWeather = new WeatherObject();
|
||||||
@@ -44,7 +36,7 @@ WeatherProvider.register("weatherflow", {
|
|||||||
.finally(() => this.updateAvailable());
|
.finally(() => this.updateAvailable());
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchWeatherForecast() {
|
fetchWeatherForecast () {
|
||||||
this.fetchData(this.getUrl())
|
this.fetchData(this.getUrl())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
const days = [];
|
const days = [];
|
||||||
@@ -71,7 +63,7 @@ WeatherProvider.register("weatherflow", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Create a URL from the config and base URL.
|
// Create a URL from the config and base URL.
|
||||||
getUrl() {
|
getUrl () {
|
||||||
return `${this.config.apiBase}better_forecast?station_id=${this.config.stationid}&units_temp=c&units_wind=kph&units_pressure=mb&units_precip=mm&units_distance=km&token=${this.config.token}`;
|
return `${this.config.apiBase}better_forecast?station_id=${this.config.stationid}&units_temp=c&units_wind=kph&units_pressure=mb&units_precip=mm&units_distance=km&token=${this.config.token}`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
/* global WeatherProvider, WeatherObject, WeatherUtils */
|
/* global WeatherProvider, WeatherObject, WeatherUtils */
|
||||||
|
|
||||||
/* MagicMirror²
|
/* Provider: weather.gov
|
||||||
* Module: Weather
|
|
||||||
* Provider: weather.gov
|
|
||||||
* https://weather-gov.github.io/api/general-faqs
|
* https://weather-gov.github.io/api/general-faqs
|
||||||
*
|
*
|
||||||
* Original by Vince Peri
|
|
||||||
* MIT Licensed.
|
|
||||||
*
|
|
||||||
* This class is a provider for weather.gov.
|
* This class is a provider for weather.gov.
|
||||||
* Note that this is only for US locations (lat and lon) and does not require an API key
|
* Note that this is only for US locations (lat and lon) and does not require an API key
|
||||||
* Since it is free, there are some items missing - like sunrise, sunset
|
* Since it is free, there are some items missing - like sunrise, sunset
|
||||||
@@ -37,24 +32,23 @@ WeatherProvider.register("weathergov", {
|
|||||||
stationObsURL: "tbd",
|
stationObsURL: "tbd",
|
||||||
|
|
||||||
// Called to set the config, this config is the same as the weather module's config.
|
// Called to set the config, this config is the same as the weather module's config.
|
||||||
setConfig: function (config) {
|
setConfig (config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.config.apiBase = "https://api.weather.gov";
|
|
||||||
this.fetchWxGovURLs(this.config);
|
this.fetchWxGovURLs(this.config);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Called when the weather provider is about to start.
|
// Called when the weather provider is about to start.
|
||||||
start: function () {
|
start () {
|
||||||
Log.info(`Weather provider: ${this.providerName} started.`);
|
Log.info(`Weather provider: ${this.providerName} started.`);
|
||||||
},
|
},
|
||||||
|
|
||||||
// This returns the name of the fetched location or an empty string.
|
// This returns the name of the fetched location or an empty string.
|
||||||
fetchedLocation: function () {
|
fetchedLocation () {
|
||||||
return this.fetchedLocationName || "";
|
return this.fetchedLocationName || "";
|
||||||
},
|
},
|
||||||
|
|
||||||
// Overwrite the fetchCurrentWeather method.
|
// Overwrite the fetchCurrentWeather method.
|
||||||
fetchCurrentWeather() {
|
fetchCurrentWeather () {
|
||||||
if (!this.configURLs) {
|
if (!this.configURLs) {
|
||||||
Log.info("fetchCurrentWeather: fetch wx waiting on config URLs");
|
Log.info("fetchCurrentWeather: fetch wx waiting on config URLs");
|
||||||
return;
|
return;
|
||||||
@@ -75,7 +69,7 @@ WeatherProvider.register("weathergov", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Overwrite the fetchWeatherForecast method.
|
// Overwrite the fetchWeatherForecast method.
|
||||||
fetchWeatherForecast() {
|
fetchWeatherForecast () {
|
||||||
if (!this.configURLs) {
|
if (!this.configURLs) {
|
||||||
Log.info("fetchWeatherForecast: fetch wx waiting on config URLs");
|
Log.info("fetchWeatherForecast: fetch wx waiting on config URLs");
|
||||||
return;
|
return;
|
||||||
@@ -96,7 +90,7 @@ WeatherProvider.register("weathergov", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Overwrite the fetchWeatherHourly method.
|
// Overwrite the fetchWeatherHourly method.
|
||||||
fetchWeatherHourly() {
|
fetchWeatherHourly () {
|
||||||
if (!this.configURLs) {
|
if (!this.configURLs) {
|
||||||
Log.info("fetchWeatherHourly: fetch wx waiting on config URLs");
|
Log.info("fetchWeatherHourly: fetch wx waiting on config URLs");
|
||||||
return;
|
return;
|
||||||
@@ -122,8 +116,8 @@ WeatherProvider.register("weathergov", {
|
|||||||
/*
|
/*
|
||||||
* Get specific URLs
|
* Get specific URLs
|
||||||
*/
|
*/
|
||||||
fetchWxGovURLs(config) {
|
fetchWxGovURLs (config) {
|
||||||
this.fetchData(`${config.apiBase}/points/${config.lat},${config.lon}`)
|
this.fetchData(`${config.apiBase}/${config.lat},${config.lon}`)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (!data || !data.properties) {
|
if (!data || !data.properties) {
|
||||||
// points URL did not respond with usable data.
|
// points URL did not respond with usable data.
|
||||||
@@ -162,12 +156,13 @@ WeatherProvider.register("weathergov", {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generate a WeatherObject based on hourlyWeatherInformation
|
* Generate a WeatherObject based on hourlyWeatherInformation
|
||||||
* Weather.gov API uses specific units; API does not include choice of units
|
* Weather.gov API uses specific units; API does not include choice of units
|
||||||
* ... object needs data in units based on config!
|
* ... object needs data in units based on config!
|
||||||
*/
|
*/
|
||||||
generateWeatherObjectsFromHourly(forecasts) {
|
generateWeatherObjectsFromHourly (forecasts) {
|
||||||
const days = [];
|
const days = [];
|
||||||
|
|
||||||
// variable for date
|
// variable for date
|
||||||
@@ -182,6 +177,12 @@ WeatherProvider.register("weathergov", {
|
|||||||
weather.windSpeed = WeatherUtils.convertWindToMs(weather.windSpeed);
|
weather.windSpeed = WeatherUtils.convertWindToMs(weather.windSpeed);
|
||||||
weather.windFromDirection = forecast.windDirection;
|
weather.windFromDirection = forecast.windDirection;
|
||||||
weather.temperature = forecast.temperature;
|
weather.temperature = forecast.temperature;
|
||||||
|
//assign probability of precipitation
|
||||||
|
if (forecast.probabilityOfPrecipitation.value === null) {
|
||||||
|
weather.precipitationProbability = 0;
|
||||||
|
} else {
|
||||||
|
weather.precipitationProbability = forecast.probabilityOfPrecipitation.value;
|
||||||
|
}
|
||||||
// use the forecast isDayTime attribute to help build the weatherType label
|
// use the forecast isDayTime attribute to help build the weatherType label
|
||||||
weather.weatherType = this.convertWeatherType(forecast.shortForecast, forecast.isDaytime);
|
weather.weatherType = this.convertWeatherType(forecast.shortForecast, forecast.isDaytime);
|
||||||
|
|
||||||
@@ -200,7 +201,7 @@ WeatherProvider.register("weathergov", {
|
|||||||
* Weather.gov API uses specific units; API does not include choice of units
|
* Weather.gov API uses specific units; API does not include choice of units
|
||||||
* ... object needs data in units based on config!
|
* ... object needs data in units based on config!
|
||||||
*/
|
*/
|
||||||
generateWeatherObjectFromCurrentWeather(currentWeatherData) {
|
generateWeatherObjectFromCurrentWeather (currentWeatherData) {
|
||||||
const currentWeather = new WeatherObject();
|
const currentWeather = new WeatherObject();
|
||||||
|
|
||||||
currentWeather.date = moment(currentWeatherData.timestamp);
|
currentWeather.date = moment(currentWeatherData.timestamp);
|
||||||
@@ -230,16 +231,14 @@ WeatherProvider.register("weathergov", {
|
|||||||
/*
|
/*
|
||||||
* Generate WeatherObjects based on forecast information
|
* Generate WeatherObjects based on forecast information
|
||||||
*/
|
*/
|
||||||
generateWeatherObjectsFromForecast(forecasts) {
|
generateWeatherObjectsFromForecast (forecasts) {
|
||||||
return this.fetchForecastDaily(forecasts);
|
return this.fetchForecastDaily(forecasts);
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* fetch forecast information for daily forecast.
|
* fetch forecast information for daily forecast.
|
||||||
*/
|
*/
|
||||||
fetchForecastDaily(forecasts) {
|
fetchForecastDaily (forecasts) {
|
||||||
const precipitationProbabilityRegEx = "Chance of precipitation is ([0-9]+?)%";
|
|
||||||
|
|
||||||
// initial variable declaration
|
// initial variable declaration
|
||||||
const days = [];
|
const days = [];
|
||||||
// variables for temperature range and rain
|
// variables for temperature range and rain
|
||||||
@@ -262,8 +261,12 @@ WeatherProvider.register("weathergov", {
|
|||||||
|
|
||||||
minTemp = [];
|
minTemp = [];
|
||||||
maxTemp = [];
|
maxTemp = [];
|
||||||
const precipitation = new RegExp(precipitationProbabilityRegEx, "g").exec(forecast.detailedForecast);
|
//assign probability of precipitation
|
||||||
if (precipitation) weather.precipitationProbability = precipitation[1];
|
if (forecast.probabilityOfPrecipitation.value === null) {
|
||||||
|
weather.precipitationProbability = 0;
|
||||||
|
} else {
|
||||||
|
weather.precipitationProbability = forecast.probabilityOfPrecipitation.value;
|
||||||
|
}
|
||||||
|
|
||||||
// set new date
|
// set new date
|
||||||
date = moment(forecast.startTime).format("YYYY-MM-DD");
|
date = moment(forecast.startTime).format("YYYY-MM-DD");
|
||||||
@@ -298,7 +301,7 @@ WeatherProvider.register("weathergov", {
|
|||||||
/*
|
/*
|
||||||
* Convert the icons to a more usable name.
|
* Convert the icons to a more usable name.
|
||||||
*/
|
*/
|
||||||
convertWeatherType(weatherType, isDaytime) {
|
convertWeatherType (weatherType, isDaytime) {
|
||||||
//https://w1.weather.gov/xml/current_obs/weather.php
|
//https://w1.weather.gov/xml/current_obs/weather.php
|
||||||
// There are way too many types to create, so lets just look for certain strings
|
// There are way too many types to create, so lets just look for certain strings
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,6 @@
|
|||||||
/* global WeatherProvider, WeatherObject */
|
/* global WeatherProvider, WeatherObject */
|
||||||
|
|
||||||
/* MagicMirror²
|
/* This class is a provider for Yr.no, a norwegian weather service.
|
||||||
* Module: Weather
|
|
||||||
* Provider: Yr.no
|
|
||||||
*
|
|
||||||
* By Magnus Marthinsen
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* This class is a provider for Yr.no, a norwegian weather service.
|
|
||||||
*
|
|
||||||
* Terms of service: https://developer.yr.no/doc/TermsOfService/
|
* Terms of service: https://developer.yr.no/doc/TermsOfService/
|
||||||
*/
|
*/
|
||||||
WeatherProvider.register("yr", {
|
WeatherProvider.register("yr", {
|
||||||
@@ -18,11 +10,13 @@ WeatherProvider.register("yr", {
|
|||||||
defaults: {
|
defaults: {
|
||||||
useCorsProxy: true,
|
useCorsProxy: true,
|
||||||
apiBase: "https://api.met.no/weatherapi",
|
apiBase: "https://api.met.no/weatherapi",
|
||||||
|
forecastApiVersion: "2.0",
|
||||||
|
sunriseApiVersion: "3.0",
|
||||||
altitude: 0,
|
altitude: 0,
|
||||||
currentForecastHours: 1 //1, 6 or 12
|
currentForecastHours: 1 //1, 6 or 12
|
||||||
},
|
},
|
||||||
|
|
||||||
start() {
|
start () {
|
||||||
if (typeof Storage === "undefined") {
|
if (typeof Storage === "undefined") {
|
||||||
//local storage unavailable
|
//local storage unavailable
|
||||||
Log.error("The Yr weather provider requires local storage.");
|
Log.error("The Yr weather provider requires local storage.");
|
||||||
@@ -31,7 +25,7 @@ WeatherProvider.register("yr", {
|
|||||||
Log.info(`Weather provider: ${this.providerName} started.`);
|
Log.info(`Weather provider: ${this.providerName} started.`);
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchCurrentWeather() {
|
fetchCurrentWeather () {
|
||||||
this.getCurrentWeather()
|
this.getCurrentWeather()
|
||||||
.then((currentWeather) => {
|
.then((currentWeather) => {
|
||||||
this.setCurrentWeather(currentWeather);
|
this.setCurrentWeather(currentWeather);
|
||||||
@@ -43,9 +37,8 @@ WeatherProvider.register("yr", {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
async getCurrentWeather() {
|
async getCurrentWeather () {
|
||||||
const getRequests = [this.getWeatherData(), this.getStellarData()];
|
const [weatherData, stellarData] = await Promise.all([this.getWeatherData(), this.getStellarData()]);
|
||||||
const [weatherData, stellarData] = await Promise.all(getRequests);
|
|
||||||
if (!stellarData) {
|
if (!stellarData) {
|
||||||
Log.warn("No stellar data available.");
|
Log.warn("No stellar data available.");
|
||||||
}
|
}
|
||||||
@@ -72,7 +65,7 @@ WeatherProvider.register("yr", {
|
|||||||
return this.getWeatherDataFrom(forecast, stellarData, weatherData.properties.meta.units);
|
return this.getWeatherDataFrom(forecast, stellarData, weatherData.properties.meta.units);
|
||||||
},
|
},
|
||||||
|
|
||||||
getWeatherData() {
|
getWeatherData () {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// If a user has several Yr-modules, for instance one current and one forecast, the API calls must be synchronized across classes.
|
// If a user has several Yr-modules, for instance one current and one forecast, the API calls must be synchronized across classes.
|
||||||
// This is to avoid multiple similar calls to the API.
|
// This is to avoid multiple similar calls to the API.
|
||||||
@@ -98,7 +91,7 @@ WeatherProvider.register("yr", {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getWeatherDataFromYrOrCache(resolve, reject) {
|
getWeatherDataFromYrOrCache (resolve, reject) {
|
||||||
localStorage.setItem("yrIsFetchingWeatherData", "true");
|
localStorage.setItem("yrIsFetchingWeatherData", "true");
|
||||||
|
|
||||||
let weatherData = this.getWeatherDataFromCache();
|
let weatherData = this.getWeatherDataFromCache();
|
||||||
@@ -110,13 +103,15 @@ WeatherProvider.register("yr", {
|
|||||||
this.getWeatherDataFromYr(weatherData?.downloadedAt)
|
this.getWeatherDataFromYr(weatherData?.downloadedAt)
|
||||||
.then((weatherData) => {
|
.then((weatherData) => {
|
||||||
Log.debug("Got weather data from yr.");
|
Log.debug("Got weather data from yr.");
|
||||||
|
let data;
|
||||||
if (weatherData) {
|
if (weatherData) {
|
||||||
this.cacheWeatherData(weatherData);
|
this.cacheWeatherData(weatherData);
|
||||||
|
data = weatherData;
|
||||||
} else {
|
} else {
|
||||||
//Undefined if unchanged
|
//Undefined if unchanged
|
||||||
weatherData = this.getWeatherDataFromCache();
|
data = this.getWeatherDataFromCache();
|
||||||
}
|
}
|
||||||
resolve(weatherData);
|
resolve(data);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
Log.error(err);
|
Log.error(err);
|
||||||
@@ -128,16 +123,16 @@ WeatherProvider.register("yr", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
weatherDataIsValid(weatherData) {
|
weatherDataIsValid (weatherData) {
|
||||||
return (
|
return (
|
||||||
weatherData &&
|
weatherData
|
||||||
weatherData.timeout &&
|
&& weatherData.timeout
|
||||||
0 < moment(weatherData.timeout).diff(moment()) &&
|
&& 0 < moment(weatherData.timeout).diff(moment())
|
||||||
(!weatherData.geometry || !weatherData.geometry.coordinates || !weatherData.geometry.coordinates.length < 2 || (weatherData.geometry.coordinates[0] === this.config.lat && weatherData.geometry.coordinates[1] === this.config.lon))
|
&& (!weatherData.geometry || !weatherData.geometry.coordinates || !weatherData.geometry.coordinates.length < 2 || (weatherData.geometry.coordinates[0] === this.config.lat && weatherData.geometry.coordinates[1] === this.config.lon))
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
getWeatherDataFromCache() {
|
getWeatherDataFromCache () {
|
||||||
const weatherData = localStorage.getItem("weatherData");
|
const weatherData = localStorage.getItem("weatherData");
|
||||||
if (weatherData) {
|
if (weatherData) {
|
||||||
return JSON.parse(weatherData);
|
return JSON.parse(weatherData);
|
||||||
@@ -146,7 +141,7 @@ WeatherProvider.register("yr", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getWeatherDataFromYr(currentDataFetchedAt) {
|
getWeatherDataFromYr (currentDataFetchedAt) {
|
||||||
const requestHeaders = [{ name: "Accept", value: "application/json" }];
|
const requestHeaders = [{ name: "Accept", value: "application/json" }];
|
||||||
if (currentDataFetchedAt) {
|
if (currentDataFetchedAt) {
|
||||||
requestHeaders.push({ name: "If-Modified-Since", value: currentDataFetchedAt });
|
requestHeaders.push({ name: "If-Modified-Since", value: currentDataFetchedAt });
|
||||||
@@ -168,7 +163,7 @@ WeatherProvider.register("yr", {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getForecastUrl() {
|
getConfigOptions () {
|
||||||
if (!this.config.lat) {
|
if (!this.config.lat) {
|
||||||
Log.error("Latitude not provided.");
|
Log.error("Latitude not provided.");
|
||||||
throw new Error("Latitude not provided.");
|
throw new Error("Latitude not provided.");
|
||||||
@@ -181,6 +176,11 @@ WeatherProvider.register("yr", {
|
|||||||
let lat = this.config.lat.toString();
|
let lat = this.config.lat.toString();
|
||||||
let lon = this.config.lon.toString();
|
let lon = this.config.lon.toString();
|
||||||
const altitude = this.config.altitude ?? 0;
|
const altitude = this.config.altitude ?? 0;
|
||||||
|
return { lat, lon, altitude };
|
||||||
|
},
|
||||||
|
|
||||||
|
getForecastUrl () {
|
||||||
|
let { lat, lon, altitude } = this.getConfigOptions();
|
||||||
|
|
||||||
if (lat.includes(".") && lat.split(".")[1].length > 4) {
|
if (lat.includes(".") && lat.split(".")[1].length > 4) {
|
||||||
Log.warn("Latitude is too specific for weather data. Do not use more than four decimals. Trimming to maximum length.");
|
Log.warn("Latitude is too specific for weather data. Do not use more than four decimals. Trimming to maximum length.");
|
||||||
@@ -193,19 +193,14 @@ WeatherProvider.register("yr", {
|
|||||||
lon = `${lonParts[0]}.${lonParts[1].substring(0, 4)}`;
|
lon = `${lonParts[0]}.${lonParts[1].substring(0, 4)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${this.config.apiBase}/locationforecast/2.0/complete?&altitude=${altitude}&lat=${lat}&lon=${lon}`;
|
return `${this.config.apiBase}/locationforecast/${this.config.forecastApiVersion}/complete?&altitude=${altitude}&lat=${lat}&lon=${lon}`;
|
||||||
},
|
},
|
||||||
|
|
||||||
cacheWeatherData(weatherData) {
|
cacheWeatherData (weatherData) {
|
||||||
localStorage.setItem("weatherData", JSON.stringify(weatherData));
|
localStorage.setItem("weatherData", JSON.stringify(weatherData));
|
||||||
},
|
},
|
||||||
|
|
||||||
getAuthenticationString() {
|
getStellarData () {
|
||||||
if (!this.config.authenticationEmail) throw new Error("Authentication email not provided.");
|
|
||||||
return `${this.config.applicaitionName} ${this.config.authenticationEmail}`;
|
|
||||||
},
|
|
||||||
|
|
||||||
getStellarData() {
|
|
||||||
// If a user has several Yr-modules, for instance one current and one forecast, the API calls must be synchronized across classes.
|
// If a user has several Yr-modules, for instance one current and one forecast, the API calls must be synchronized across classes.
|
||||||
// This is to avoid multiple similar calls to the API.
|
// This is to avoid multiple similar calls to the API.
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -231,7 +226,7 @@ WeatherProvider.register("yr", {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getStellarDataFromYrOrCache(resolve, reject) {
|
getStellarDataFromYrOrCache (resolve, reject) {
|
||||||
localStorage.setItem("yrIsFetchingStellarData", "true");
|
localStorage.setItem("yrIsFetchingStellarData", "true");
|
||||||
|
|
||||||
let stellarData = this.getStellarDataFromCache();
|
let stellarData = this.getStellarDataFromCache();
|
||||||
@@ -266,14 +261,14 @@ WeatherProvider.register("yr", {
|
|||||||
this.getStellarDataFromYr(today, 2)
|
this.getStellarDataFromYr(today, 2)
|
||||||
.then((stellarData) => {
|
.then((stellarData) => {
|
||||||
if (stellarData) {
|
if (stellarData) {
|
||||||
stellarData = {
|
const data = {
|
||||||
today: stellarData
|
today: stellarData
|
||||||
};
|
};
|
||||||
stellarData.tomorrow = Object.assign({}, stellarData.today);
|
data.tomorrow = Object.assign({}, data.today);
|
||||||
stellarData.today.date = today;
|
data.today.date = today;
|
||||||
stellarData.tomorrow.date = tomorrow;
|
data.tomorrow.date = tomorrow;
|
||||||
this.cacheStellarData(stellarData);
|
this.cacheStellarData(data);
|
||||||
resolve(stellarData);
|
resolve(data);
|
||||||
} else {
|
} else {
|
||||||
Log.error(`Something went wrong when fetching stellar data. Responses: ${stellarData}`);
|
Log.error(`Something went wrong when fetching stellar data. Responses: ${stellarData}`);
|
||||||
reject(stellarData);
|
reject(stellarData);
|
||||||
@@ -289,7 +284,7 @@ WeatherProvider.register("yr", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getStellarDataFromCache() {
|
getStellarDataFromCache () {
|
||||||
const stellarData = localStorage.getItem("stellarData");
|
const stellarData = localStorage.getItem("stellarData");
|
||||||
if (stellarData) {
|
if (stellarData) {
|
||||||
return JSON.parse(stellarData);
|
return JSON.parse(stellarData);
|
||||||
@@ -298,9 +293,9 @@ WeatherProvider.register("yr", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getStellarDataFromYr(date, days = 1) {
|
getStellarDataFromYr (date, days = 1) {
|
||||||
const requestHeaders = [{ name: "Accept", value: "application/json" }];
|
const requestHeaders = [{ name: "Accept", value: "application/json" }];
|
||||||
return this.fetchData(this.getStellarDatatUrl(date, days), "json", requestHeaders)
|
return this.fetchData(this.getStellarDataUrl(date, days), "json", requestHeaders)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
Log.debug("Got stellar data from yr.");
|
Log.debug("Got stellar data from yr.");
|
||||||
return data;
|
return data;
|
||||||
@@ -311,19 +306,8 @@ WeatherProvider.register("yr", {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getStellarDatatUrl(date, days) {
|
getStellarDataUrl (date, days) {
|
||||||
if (!this.config.lat) {
|
let { lat, lon, altitude } = this.getConfigOptions();
|
||||||
Log.error("Latitude not provided.");
|
|
||||||
throw new Error("Latitude not provided.");
|
|
||||||
}
|
|
||||||
if (!this.config.lon) {
|
|
||||||
Log.error("Longitude not provided.");
|
|
||||||
throw new Error("Longitude not provided.");
|
|
||||||
}
|
|
||||||
|
|
||||||
let lat = this.config.lat.toString();
|
|
||||||
let lon = this.config.lon.toString();
|
|
||||||
const altitude = this.config.altitude ?? 0;
|
|
||||||
|
|
||||||
if (lat.includes(".") && lat.split(".")[1].length > 4) {
|
if (lat.includes(".") && lat.split(".")[1].length > 4) {
|
||||||
Log.warn("Latitude is too specific for stellar data. Do not use more than four decimals. Trimming to maximum length.");
|
Log.warn("Latitude is too specific for stellar data. Do not use more than four decimals. Trimming to maximum length.");
|
||||||
@@ -350,18 +334,15 @@ WeatherProvider.register("yr", {
|
|||||||
if (hours.length < 2) {
|
if (hours.length < 2) {
|
||||||
hours = `0${hours}`;
|
hours = `0${hours}`;
|
||||||
}
|
}
|
||||||
|
return `${this.config.apiBase}/sunrise/${this.config.sunriseApiVersion}/sun?lat=${lat}&lon=${lon}&date=${date}&offset=${utcOffsetPrefix}${hours}%3A${minutes}`;
|
||||||
return `${this.config.apiBase}/sunrise/2.0/.json?date=${date}&days=${days}&height=${altitude}&lat=${lat}&lon=${lon}&offset=${utcOffsetPrefix}${hours}%3A${minutes}`;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
cacheStellarData(data) {
|
cacheStellarData (data) {
|
||||||
localStorage.setItem("stellarData", JSON.stringify(data));
|
localStorage.setItem("stellarData", JSON.stringify(data));
|
||||||
},
|
},
|
||||||
|
|
||||||
getWeatherDataFrom(forecast, stellarData, units) {
|
getWeatherDataFrom (forecast, stellarData, units) {
|
||||||
const weather = new WeatherObject();
|
const weather = new WeatherObject();
|
||||||
const stellarTimesToday = stellarData?.today ? this.getStellarTimesFrom(stellarData.today, moment().format("YYYY-MM-DD")) : undefined;
|
|
||||||
const stellarTimesTomorrow = stellarData?.tomorrow ? this.getStellarTimesFrom(stellarData.tomorrow, moment().add(1, "days").format("YYYY-MM-DD")) : undefined;
|
|
||||||
|
|
||||||
weather.date = moment(forecast.time);
|
weather.date = moment(forecast.time);
|
||||||
weather.windSpeed = forecast.data.instant.details.wind_speed;
|
weather.windSpeed = forecast.data.instant.details.wind_speed;
|
||||||
@@ -375,15 +356,13 @@ WeatherProvider.register("yr", {
|
|||||||
weather.precipitationProbability = forecast.precipitationProbability;
|
weather.precipitationProbability = forecast.precipitationProbability;
|
||||||
weather.precipitationUnits = units.precipitation_amount;
|
weather.precipitationUnits = units.precipitation_amount;
|
||||||
|
|
||||||
if (stellarTimesToday) {
|
weather.sunrise = stellarData?.today?.properties?.sunrise?.time;
|
||||||
weather.sunset = moment(stellarTimesToday.sunset.time);
|
weather.sunset = stellarData?.today?.properties?.sunset?.time;
|
||||||
weather.sunrise = weather.sunset < moment() && stellarTimesTomorrow ? moment(stellarTimesTomorrow.sunrise.time) : moment(stellarTimesToday.sunrise.time);
|
|
||||||
}
|
|
||||||
|
|
||||||
return weather;
|
return weather;
|
||||||
},
|
},
|
||||||
|
|
||||||
convertWeatherType(weatherType, weatherTime) {
|
convertWeatherType (weatherType, weatherTime) {
|
||||||
const weatherHour = moment(weatherTime).format("HH");
|
const weatherHour = moment(weatherTime).format("HH");
|
||||||
|
|
||||||
const weatherTypes = {
|
const weatherTypes = {
|
||||||
@@ -475,16 +454,7 @@ WeatherProvider.register("yr", {
|
|||||||
return weatherTypes.hasOwnProperty(weatherType) ? weatherTypes[weatherType] : null;
|
return weatherTypes.hasOwnProperty(weatherType) ? weatherTypes[weatherType] : null;
|
||||||
},
|
},
|
||||||
|
|
||||||
getStellarTimesFrom(stellarData, date) {
|
getForecastForXHoursFrom (weather) {
|
||||||
for (const time of stellarData.location.time) {
|
|
||||||
if (time.date === date) {
|
|
||||||
return time;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
},
|
|
||||||
|
|
||||||
getForecastForXHoursFrom(weather) {
|
|
||||||
if (this.config.currentForecastHours === 1) {
|
if (this.config.currentForecastHours === 1) {
|
||||||
if (weather.next_1_hours) {
|
if (weather.next_1_hours) {
|
||||||
return weather.next_1_hours;
|
return weather.next_1_hours;
|
||||||
@@ -512,7 +482,7 @@ WeatherProvider.register("yr", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchWeatherHourly() {
|
fetchWeatherHourly () {
|
||||||
this.getWeatherForecast("hourly")
|
this.getWeatherForecast("hourly")
|
||||||
.then((forecast) => {
|
.then((forecast) => {
|
||||||
this.setWeatherHourly(forecast);
|
this.setWeatherHourly(forecast);
|
||||||
@@ -524,9 +494,8 @@ WeatherProvider.register("yr", {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
async getWeatherForecast(type) {
|
async getWeatherForecast (type) {
|
||||||
const getRequests = [this.getWeatherData(), this.getStellarData()];
|
const [weatherData, stellarData] = await Promise.all([this.getWeatherData(), this.getStellarData()]);
|
||||||
const [weatherData, stellarData] = await Promise.all(getRequests);
|
|
||||||
if (!weatherData.properties.timeseries || !weatherData.properties.timeseries[0]) {
|
if (!weatherData.properties.timeseries || !weatherData.properties.timeseries[0]) {
|
||||||
Log.error("No weather data available.");
|
Log.error("No weather data available.");
|
||||||
return;
|
return;
|
||||||
@@ -551,7 +520,7 @@ WeatherProvider.register("yr", {
|
|||||||
return series;
|
return series;
|
||||||
},
|
},
|
||||||
|
|
||||||
getHourlyForecastFrom(weatherData) {
|
getHourlyForecastFrom (weatherData) {
|
||||||
const series = [];
|
const series = [];
|
||||||
|
|
||||||
for (const forecast of weatherData.properties.timeseries) {
|
for (const forecast of weatherData.properties.timeseries) {
|
||||||
@@ -566,7 +535,7 @@ WeatherProvider.register("yr", {
|
|||||||
return series;
|
return series;
|
||||||
},
|
},
|
||||||
|
|
||||||
getDailyForecastFrom(weatherData) {
|
getDailyForecastFrom (weatherData) {
|
||||||
const series = [];
|
const series = [];
|
||||||
|
|
||||||
const days = weatherData.properties.timeseries.reduce(function (days, forecast) {
|
const days = weatherData.properties.timeseries.reduce(function (days, forecast) {
|
||||||
@@ -576,7 +545,7 @@ WeatherProvider.register("yr", {
|
|||||||
return days;
|
return days;
|
||||||
}, Object.create(null));
|
}, Object.create(null));
|
||||||
|
|
||||||
Object.keys(days).forEach(function (time, index) {
|
Object.keys(days).forEach(function (time) {
|
||||||
let minTemperature = undefined;
|
let minTemperature = undefined;
|
||||||
let maxTemperature = undefined;
|
let maxTemperature = undefined;
|
||||||
|
|
||||||
@@ -616,7 +585,7 @@ WeatherProvider.register("yr", {
|
|||||||
return series;
|
return series;
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchWeatherForecast() {
|
fetchWeatherForecast () {
|
||||||
this.getWeatherForecast("daily")
|
this.getWeatherForecast("daily")
|
||||||
.then((forecast) => {
|
.then((forecast) => {
|
||||||
this.setWeatherForecast(forecast);
|
this.setWeatherForecast(forecast);
|
||||||
|
|||||||
@@ -30,7 +30,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.weather .precipitation-amount,
|
.weather .precipitation-amount,
|
||||||
.weather .precipitation-prob {
|
.weather .precipitation-prob,
|
||||||
|
.weather .uv-index {
|
||||||
padding-left: 20px;
|
padding-left: 20px;
|
||||||
padding-right: 0;
|
padding-right: 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
/* global WeatherProvider, WeatherUtils */
|
/* global WeatherProvider, WeatherUtils, formatTime */
|
||||||
|
|
||||||
/* MagicMirror²
|
|
||||||
* Module: Weather
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
Module.register("weather", {
|
Module.register("weather", {
|
||||||
// Default module config.
|
// Default module config.
|
||||||
defaults: {
|
defaults: {
|
||||||
@@ -20,13 +14,15 @@ Module.register("weather", {
|
|||||||
updateInterval: 10 * 60 * 1000, // every 10 minutes
|
updateInterval: 10 * 60 * 1000, // every 10 minutes
|
||||||
animationSpeed: 1000,
|
animationSpeed: 1000,
|
||||||
showFeelsLike: true,
|
showFeelsLike: true,
|
||||||
showHumidity: false,
|
showHumidity: "none", // this is now a string; see current.njk
|
||||||
showIndoorHumidity: false,
|
showIndoorHumidity: false,
|
||||||
showIndoorTemperature: false,
|
showIndoorTemperature: false,
|
||||||
|
allowOverrideNotification: false,
|
||||||
showPeriod: true,
|
showPeriod: true,
|
||||||
showPeriodUpper: false,
|
showPeriodUpper: false,
|
||||||
showPrecipitationAmount: false,
|
showPrecipitationAmount: false,
|
||||||
showPrecipitationProbability: false,
|
showPrecipitationProbability: false,
|
||||||
|
showUVIndex: false,
|
||||||
showSun: true,
|
showSun: true,
|
||||||
showWindDirection: true,
|
showWindDirection: true,
|
||||||
showWindDirectionAsArrow: false,
|
showWindDirectionAsArrow: false,
|
||||||
@@ -54,17 +50,17 @@ Module.register("weather", {
|
|||||||
firstEvent: null,
|
firstEvent: null,
|
||||||
|
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
getStyles: function () {
|
getStyles () {
|
||||||
return ["font-awesome.css", "weather-icons.css", "weather.css"];
|
return ["font-awesome.css", "weather-icons.css", "weather.css"];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Return the scripts that are necessary for the weather module.
|
// Return the scripts that are necessary for the weather module.
|
||||||
getScripts: function () {
|
getScripts () {
|
||||||
return ["moment.js", this.file("../utils.js"), "weatherutils.js", "weatherprovider.js", "weatherobject.js", "suncalc.js", this.file(`providers/${this.config.weatherProvider.toLowerCase()}.js`)];
|
return ["moment.js", "weatherutils.js", "weatherobject.js", this.file("providers/overrideWrapper.js"), "weatherprovider.js", "suncalc.js", this.file(`providers/${this.config.weatherProvider.toLowerCase()}.js`)];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Override getHeader method.
|
// Override getHeader method.
|
||||||
getHeader: function () {
|
getHeader () {
|
||||||
if (this.config.appendLocationNameToHeader && this.weatherProvider) {
|
if (this.config.appendLocationNameToHeader && this.weatherProvider) {
|
||||||
if (this.data.header) return `${this.data.header} ${this.weatherProvider.fetchedLocation()}`;
|
if (this.data.header) return `${this.data.header} ${this.weatherProvider.fetchedLocation()}`;
|
||||||
else return this.weatherProvider.fetchedLocation();
|
else return this.weatherProvider.fetchedLocation();
|
||||||
@@ -74,7 +70,7 @@ Module.register("weather", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Start the weather module.
|
// Start the weather module.
|
||||||
start: function () {
|
start () {
|
||||||
moment.locale(this.config.lang);
|
moment.locale(this.config.lang);
|
||||||
|
|
||||||
if (this.config.useKmh) {
|
if (this.config.useKmh) {
|
||||||
@@ -84,6 +80,10 @@ Module.register("weather", {
|
|||||||
Log.warn("Your are using the deprecated config values 'useBeaufort'. Please switch to windUnits!");
|
Log.warn("Your are using the deprecated config values 'useBeaufort'. Please switch to windUnits!");
|
||||||
this.windUnits = "beaufort";
|
this.windUnits = "beaufort";
|
||||||
}
|
}
|
||||||
|
if (typeof this.config.showHumidity === "boolean") {
|
||||||
|
Log.warn("[weather] Deprecation warning: Please consider updating showHumidity to the new style (config string).");
|
||||||
|
this.config.showHumidity = this.config.showHumidity ? "wind" : "none";
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize the weather provider.
|
// Initialize the weather provider.
|
||||||
this.weatherProvider = WeatherProvider.initialize(this.config.weatherProvider, this);
|
this.weatherProvider = WeatherProvider.initialize(this.config.weatherProvider, this);
|
||||||
@@ -99,7 +99,7 @@ Module.register("weather", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Override notification handler.
|
// Override notification handler.
|
||||||
notificationReceived: function (notification, payload, sender) {
|
notificationReceived (notification, payload, sender) {
|
||||||
if (notification === "CALENDAR_EVENTS") {
|
if (notification === "CALENDAR_EVENTS") {
|
||||||
const senderClasses = sender.data.classes.toLowerCase().split(" ");
|
const senderClasses = sender.data.classes.toLowerCase().split(" ");
|
||||||
if (senderClasses.indexOf(this.config.calendarClass.toLowerCase()) !== -1) {
|
if (senderClasses.indexOf(this.config.calendarClass.toLowerCase()) !== -1) {
|
||||||
@@ -118,11 +118,13 @@ Module.register("weather", {
|
|||||||
} else if (notification === "INDOOR_HUMIDITY") {
|
} else if (notification === "INDOOR_HUMIDITY") {
|
||||||
this.indoorHumidity = this.roundValue(payload);
|
this.indoorHumidity = this.roundValue(payload);
|
||||||
this.updateDom(300);
|
this.updateDom(300);
|
||||||
|
} else if (notification === "CURRENT_WEATHER_OVERRIDE" && this.config.allowOverrideNotification) {
|
||||||
|
this.weatherProvider.notificationReceived(payload);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Select the template depending on the display type.
|
// Select the template depending on the display type.
|
||||||
getTemplate: function () {
|
getTemplate () {
|
||||||
switch (this.config.type.toLowerCase()) {
|
switch (this.config.type.toLowerCase()) {
|
||||||
case "current":
|
case "current":
|
||||||
return "current.njk";
|
return "current.njk";
|
||||||
@@ -138,7 +140,7 @@ Module.register("weather", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Add all the data to the template.
|
// Add all the data to the template.
|
||||||
getTemplateData: function () {
|
getTemplateData () {
|
||||||
const currentData = this.weatherProvider.currentWeather();
|
const currentData = this.weatherProvider.currentWeather();
|
||||||
const forecastData = this.weatherProvider.weatherForecast();
|
const forecastData = this.weatherProvider.weatherForecast();
|
||||||
|
|
||||||
@@ -158,7 +160,7 @@ Module.register("weather", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// What to do when the weather provider has new information available?
|
// What to do when the weather provider has new information available?
|
||||||
updateAvailable: function () {
|
updateAvailable () {
|
||||||
Log.log("New weather information available.");
|
Log.log("New weather information available.");
|
||||||
this.updateDom(0);
|
this.updateDom(0);
|
||||||
this.scheduleUpdate();
|
this.scheduleUpdate();
|
||||||
@@ -177,7 +179,7 @@ Module.register("weather", {
|
|||||||
this.sendNotification("WEATHER_UPDATED", notificationPayload);
|
this.sendNotification("WEATHER_UPDATED", notificationPayload);
|
||||||
},
|
},
|
||||||
|
|
||||||
scheduleUpdate: function (delay = null) {
|
scheduleUpdate (delay = null) {
|
||||||
let nextLoad = this.config.updateInterval;
|
let nextLoad = this.config.updateInterval;
|
||||||
if (delay !== null && delay >= 0) {
|
if (delay !== null && delay >= 0) {
|
||||||
nextLoad = delay;
|
nextLoad = delay;
|
||||||
@@ -201,60 +203,47 @@ Module.register("weather", {
|
|||||||
}, nextLoad);
|
}, nextLoad);
|
||||||
},
|
},
|
||||||
|
|
||||||
roundValue: function (temperature) {
|
roundValue (temperature) {
|
||||||
const decimals = this.config.roundTemp ? 0 : 1;
|
const decimals = this.config.roundTemp ? 0 : 1;
|
||||||
const roundValue = parseFloat(temperature).toFixed(decimals);
|
const roundValue = parseFloat(temperature).toFixed(decimals);
|
||||||
return roundValue === "-0" ? 0 : roundValue;
|
return roundValue === "-0" ? 0 : roundValue;
|
||||||
},
|
},
|
||||||
|
|
||||||
addFilters() {
|
addFilters () {
|
||||||
this.nunjucksEnvironment().addFilter(
|
this.nunjucksEnvironment().addFilter(
|
||||||
"formatTime",
|
"formatTime",
|
||||||
function (date) {
|
function (date) {
|
||||||
date = moment(date);
|
return formatTime(this.config, date);
|
||||||
|
|
||||||
if (this.config.timeFormat !== 24) {
|
|
||||||
if (this.config.showPeriod) {
|
|
||||||
if (this.config.showPeriodUpper) {
|
|
||||||
return date.format("h:mm A");
|
|
||||||
} else {
|
|
||||||
return date.format("h:mm a");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return date.format("h:mm");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return date.format("HH:mm");
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.nunjucksEnvironment().addFilter(
|
this.nunjucksEnvironment().addFilter(
|
||||||
"unit",
|
"unit",
|
||||||
function (value, type, valueUnit) {
|
function (value, type, valueUnit) {
|
||||||
|
let formattedValue;
|
||||||
if (type === "temperature") {
|
if (type === "temperature") {
|
||||||
value = `${this.roundValue(WeatherUtils.convertTemp(value, this.config.tempUnits))}°`;
|
formattedValue = `${this.roundValue(WeatherUtils.convertTemp(value, this.config.tempUnits))}°`;
|
||||||
if (this.config.degreeLabel) {
|
if (this.config.degreeLabel) {
|
||||||
if (this.config.tempUnits === "metric") {
|
if (this.config.tempUnits === "metric") {
|
||||||
value += "C";
|
formattedValue += "C";
|
||||||
} else if (this.config.tempUnits === "imperial") {
|
} else if (this.config.tempUnits === "imperial") {
|
||||||
value += "F";
|
formattedValue += "F";
|
||||||
} else {
|
} else {
|
||||||
value += "K";
|
formattedValue += "K";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (type === "precip") {
|
} else if (type === "precip") {
|
||||||
if (value === null || isNaN(value) || value === 0 || value.toFixed(2) === "0.00") {
|
if (value === null || isNaN(value)) {
|
||||||
value = "";
|
formattedValue = "";
|
||||||
} else {
|
} else {
|
||||||
value = WeatherUtils.convertPrecipitationUnit(value, valueUnit, this.config.units);
|
formattedValue = WeatherUtils.convertPrecipitationUnit(value, valueUnit, this.config.units);
|
||||||
}
|
}
|
||||||
} else if (type === "humidity") {
|
} else if (type === "humidity") {
|
||||||
value += "%";
|
formattedValue = `${value}%`;
|
||||||
} else if (type === "wind") {
|
} else if (type === "wind") {
|
||||||
value = WeatherUtils.convertWind(value, this.config.windUnits);
|
formattedValue = WeatherUtils.convertWind(value, this.config.windUnits);
|
||||||
}
|
}
|
||||||
return value;
|
return formattedValue;
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,14 @@
|
|||||||
/* global SunCalc, WeatherUtils */
|
/* global SunCalc, WeatherUtils */
|
||||||
|
|
||||||
/* MagicMirror²
|
|
||||||
* Module: Weather
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*
|
|
||||||
* This class is the blueprint for a day which includes weather information.
|
|
||||||
*
|
|
||||||
* Currently this is focused on the information which is necessary for the current weather.
|
|
||||||
* As soon as we start implementing the forecast, mode properties will be added.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @external Moment
|
* @external Moment
|
||||||
*/
|
*/
|
||||||
class WeatherObject {
|
class WeatherObject {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for a WeatherObject
|
* Constructor for a WeatherObject
|
||||||
*/
|
*/
|
||||||
constructor() {
|
constructor () {
|
||||||
this.date = null;
|
this.date = null;
|
||||||
this.windSpeed = null;
|
this.windSpeed = null;
|
||||||
this.windFromDirection = null;
|
this.windFromDirection = null;
|
||||||
@@ -36,7 +25,7 @@ class WeatherObject {
|
|||||||
this.feelsLikeTemp = null;
|
this.feelsLikeTemp = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
cardinalWindDirection() {
|
cardinalWindDirection () {
|
||||||
if (this.windFromDirection > 11.25 && this.windFromDirection <= 33.75) {
|
if (this.windFromDirection > 11.25 && this.windFromDirection <= 33.75) {
|
||||||
return "NNE";
|
return "NNE";
|
||||||
} else if (this.windFromDirection > 33.75 && this.windFromDirection <= 56.25) {
|
} else if (this.windFromDirection > 33.75 && this.windFromDirection <= 56.25) {
|
||||||
@@ -75,16 +64,15 @@ class WeatherObject {
|
|||||||
/**
|
/**
|
||||||
* Determines if the sun sets or rises next. Uses the current time and not
|
* Determines if the sun sets or rises next. Uses the current time and not
|
||||||
* the date from the weather-forecast.
|
* the date from the weather-forecast.
|
||||||
*
|
|
||||||
* @param {Moment} date an optional date where you want to get the next
|
* @param {Moment} date an optional date where you want to get the next
|
||||||
* action for. Useful only in tests, defaults to the current time.
|
* action for. Useful only in tests, defaults to the current time.
|
||||||
* @returns {string} "sunset" or "sunrise"
|
* @returns {string} "sunset" or "sunrise"
|
||||||
*/
|
*/
|
||||||
nextSunAction(date = moment()) {
|
nextSunAction (date = moment()) {
|
||||||
return date.isBetween(this.sunrise, this.sunset) ? "sunset" : "sunrise";
|
return date.isBetween(this.sunrise, this.sunset) ? "sunset" : "sunrise";
|
||||||
}
|
}
|
||||||
|
|
||||||
feelsLike() {
|
feelsLike () {
|
||||||
if (this.feelsLikeTemp) {
|
if (this.feelsLikeTemp) {
|
||||||
return this.feelsLikeTemp;
|
return this.feelsLikeTemp;
|
||||||
}
|
}
|
||||||
@@ -93,10 +81,9 @@ class WeatherObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the weatherObject is at dayTime.
|
* Checks if the weatherObject is at dayTime.
|
||||||
*
|
|
||||||
* @returns {boolean} true if it is at dayTime
|
* @returns {boolean} true if it is at dayTime
|
||||||
*/
|
*/
|
||||||
isDayTime() {
|
isDayTime () {
|
||||||
const now = !this.date ? moment() : this.date;
|
const now = !this.date ? moment() : this.date;
|
||||||
return now.isBetween(this.sunrise, this.sunset, undefined, "[]");
|
return now.isBetween(this.sunrise, this.sunset, undefined, "[]");
|
||||||
}
|
}
|
||||||
@@ -105,11 +92,10 @@ class WeatherObject {
|
|||||||
* Update the sunrise / sunset time depending on the location. This can be
|
* Update the sunrise / sunset time depending on the location. This can be
|
||||||
* used if your provider doesn't provide that data by itself. Then SunCalc
|
* used if your provider doesn't provide that data by itself. Then SunCalc
|
||||||
* is used here to calculate them according to the location.
|
* is used here to calculate them according to the location.
|
||||||
*
|
|
||||||
* @param {number} lat latitude
|
* @param {number} lat latitude
|
||||||
* @param {number} lon longitude
|
* @param {number} lon longitude
|
||||||
*/
|
*/
|
||||||
updateSunTime(lat, lon) {
|
updateSunTime (lat, lon) {
|
||||||
const now = !this.date ? new Date() : this.date.toDate();
|
const now = !this.date ? new Date() : this.date.toDate();
|
||||||
const times = SunCalc.getTimes(now, lat, lon);
|
const times = SunCalc.getTimes(now, lat, lon);
|
||||||
this.sunrise = moment(times.sunrise);
|
this.sunrise = moment(times.sunrise);
|
||||||
@@ -121,10 +107,9 @@ class WeatherObject {
|
|||||||
*
|
*
|
||||||
* Before being handed to other modules, mutable values must be cloned safely.
|
* Before being handed to other modules, mutable values must be cloned safely.
|
||||||
* Especially 'moment' object is not immutable, so original 'date', 'sunrise', 'sunset' could be corrupted or changed by other modules.
|
* Especially 'moment' object is not immutable, so original 'date', 'sunrise', 'sunset' could be corrupted or changed by other modules.
|
||||||
*
|
|
||||||
* @returns {object} plained object clone of original weatherObject
|
* @returns {object} plained object clone of original weatherObject
|
||||||
*/
|
*/
|
||||||
simpleClone() {
|
simpleClone () {
|
||||||
const toFlat = ["date", "sunrise", "sunset"];
|
const toFlat = ["date", "sunrise", "sunset"];
|
||||||
let clone = { ...this };
|
let clone = { ...this };
|
||||||
for (const prop of toFlat) {
|
for (const prop of toFlat) {
|
||||||
|
|||||||
@@ -1,13 +1,6 @@
|
|||||||
/* global Class, performWebRequest */
|
/* global Class, performWebRequest, OverrideWrapper */
|
||||||
|
|
||||||
/* MagicMirror²
|
// This class is the blueprint for a weather provider.
|
||||||
* Module: Weather
|
|
||||||
*
|
|
||||||
* By Michael Teeuw https://michaelteeuw.nl
|
|
||||||
* MIT Licensed.
|
|
||||||
*
|
|
||||||
* This class is the blueprint for a weather provider.
|
|
||||||
*/
|
|
||||||
const WeatherProvider = Class.extend({
|
const WeatherProvider = Class.extend({
|
||||||
// Weather Provider Properties
|
// Weather Provider Properties
|
||||||
providerName: null,
|
providerName: null,
|
||||||
@@ -30,97 +23,96 @@ const WeatherProvider = Class.extend({
|
|||||||
// All the following methods can be overwritten, although most are good as they are.
|
// All the following methods can be overwritten, although most are good as they are.
|
||||||
|
|
||||||
// Called when a weather provider is initialized.
|
// Called when a weather provider is initialized.
|
||||||
init: function (config) {
|
init (config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
Log.info(`Weather provider: ${this.providerName} initialized.`);
|
Log.info(`Weather provider: ${this.providerName} initialized.`);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Called to set the config, this config is the same as the weather module's config.
|
// Called to set the config, this config is the same as the weather module's config.
|
||||||
setConfig: function (config) {
|
setConfig (config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
Log.info(`Weather provider: ${this.providerName} config set.`, this.config);
|
Log.info(`Weather provider: ${this.providerName} config set.`, this.config);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Called when the weather provider is about to start.
|
// Called when the weather provider is about to start.
|
||||||
start: function () {
|
start () {
|
||||||
Log.info(`Weather provider: ${this.providerName} started.`);
|
Log.info(`Weather provider: ${this.providerName} started.`);
|
||||||
},
|
},
|
||||||
|
|
||||||
// This method should start the API request to fetch the current weather.
|
// This method should start the API request to fetch the current weather.
|
||||||
// This method should definitely be overwritten in the provider.
|
// This method should definitely be overwritten in the provider.
|
||||||
fetchCurrentWeather: function () {
|
fetchCurrentWeather () {
|
||||||
Log.warn(`Weather provider: ${this.providerName} does not subclass the fetchCurrentWeather method.`);
|
Log.warn(`Weather provider: ${this.providerName} does not subclass the fetchCurrentWeather method.`);
|
||||||
},
|
},
|
||||||
|
|
||||||
// This method should start the API request to fetch the weather forecast.
|
// This method should start the API request to fetch the weather forecast.
|
||||||
// This method should definitely be overwritten in the provider.
|
// This method should definitely be overwritten in the provider.
|
||||||
fetchWeatherForecast: function () {
|
fetchWeatherForecast () {
|
||||||
Log.warn(`Weather provider: ${this.providerName} does not subclass the fetchWeatherForecast method.`);
|
Log.warn(`Weather provider: ${this.providerName} does not subclass the fetchWeatherForecast method.`);
|
||||||
},
|
},
|
||||||
|
|
||||||
// This method should start the API request to fetch the weather hourly.
|
// This method should start the API request to fetch the weather hourly.
|
||||||
// This method should definitely be overwritten in the provider.
|
// This method should definitely be overwritten in the provider.
|
||||||
fetchWeatherHourly: function () {
|
fetchWeatherHourly () {
|
||||||
Log.warn(`Weather provider: ${this.providerName} does not subclass the fetchWeatherHourly method.`);
|
Log.warn(`Weather provider: ${this.providerName} does not subclass the fetchWeatherHourly method.`);
|
||||||
},
|
},
|
||||||
|
|
||||||
// This returns a WeatherDay object for the current weather.
|
// This returns a WeatherDay object for the current weather.
|
||||||
currentWeather: function () {
|
currentWeather () {
|
||||||
return this.currentWeatherObject;
|
return this.currentWeatherObject;
|
||||||
},
|
},
|
||||||
|
|
||||||
// This returns an array of WeatherDay objects for the weather forecast.
|
// This returns an array of WeatherDay objects for the weather forecast.
|
||||||
weatherForecast: function () {
|
weatherForecast () {
|
||||||
return this.weatherForecastArray;
|
return this.weatherForecastArray;
|
||||||
},
|
},
|
||||||
|
|
||||||
// This returns an object containing WeatherDay object(s) depending on the type of call.
|
// This returns an object containing WeatherDay object(s) depending on the type of call.
|
||||||
weatherHourly: function () {
|
weatherHourly () {
|
||||||
return this.weatherHourlyArray;
|
return this.weatherHourlyArray;
|
||||||
},
|
},
|
||||||
|
|
||||||
// This returns the name of the fetched location or an empty string.
|
// This returns the name of the fetched location or an empty string.
|
||||||
fetchedLocation: function () {
|
fetchedLocation () {
|
||||||
return this.fetchedLocationName || "";
|
return this.fetchedLocationName || "";
|
||||||
},
|
},
|
||||||
|
|
||||||
// Set the currentWeather and notify the delegate that new information is available.
|
// Set the currentWeather and notify the delegate that new information is available.
|
||||||
setCurrentWeather: function (currentWeatherObject) {
|
setCurrentWeather (currentWeatherObject) {
|
||||||
// We should check here if we are passing a WeatherDay
|
// We should check here if we are passing a WeatherDay
|
||||||
this.currentWeatherObject = currentWeatherObject;
|
this.currentWeatherObject = currentWeatherObject;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Set the weatherForecastArray and notify the delegate that new information is available.
|
// Set the weatherForecastArray and notify the delegate that new information is available.
|
||||||
setWeatherForecast: function (weatherForecastArray) {
|
setWeatherForecast (weatherForecastArray) {
|
||||||
// We should check here if we are passing a WeatherDay
|
// We should check here if we are passing a WeatherDay
|
||||||
this.weatherForecastArray = weatherForecastArray;
|
this.weatherForecastArray = weatherForecastArray;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Set the weatherHourlyArray and notify the delegate that new information is available.
|
// Set the weatherHourlyArray and notify the delegate that new information is available.
|
||||||
setWeatherHourly: function (weatherHourlyArray) {
|
setWeatherHourly (weatherHourlyArray) {
|
||||||
this.weatherHourlyArray = weatherHourlyArray;
|
this.weatherHourlyArray = weatherHourlyArray;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Set the fetched location name.
|
// Set the fetched location name.
|
||||||
setFetchedLocation: function (name) {
|
setFetchedLocation (name) {
|
||||||
this.fetchedLocationName = name;
|
this.fetchedLocationName = name;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Notify the delegate that new weather is available.
|
// Notify the delegate that new weather is available.
|
||||||
updateAvailable: function () {
|
updateAvailable () {
|
||||||
this.delegate.updateAvailable(this);
|
this.delegate.updateAvailable(this);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A convenience function to make requests.
|
* A convenience function to make requests.
|
||||||
*
|
|
||||||
* @param {string} url the url to fetch from
|
* @param {string} url the url to fetch from
|
||||||
* @param {string} type what contenttype to expect in the response, can be "json" or "xml"
|
* @param {string} type what contenttype to expect in the response, can be "json" or "xml"
|
||||||
* @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send
|
* @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send
|
||||||
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to recieve
|
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to recieve
|
||||||
* @returns {Promise} resolved when the fetch is done
|
* @returns {Promise} resolved when the fetch is done
|
||||||
*/
|
*/
|
||||||
fetchData: async function (url, type = "json", requestHeaders = undefined, expectedResponseHeaders = undefined) {
|
async fetchData (url, type = "json", requestHeaders = undefined, expectedResponseHeaders = undefined) {
|
||||||
const mockData = this.config.mockData;
|
const mockData = this.config.mockData;
|
||||||
if (mockData) {
|
if (mockData) {
|
||||||
const data = mockData.substring(1, mockData.length - 1);
|
const data = mockData.substring(1, mockData.length - 1);
|
||||||
@@ -138,7 +130,6 @@ WeatherProvider.providers = [];
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Static method to register a new weather provider.
|
* Static method to register a new weather provider.
|
||||||
*
|
|
||||||
* @param {string} providerIdentifier The name of the weather provider
|
* @param {string} providerIdentifier The name of the weather provider
|
||||||
* @param {object} providerDetails The details of the weather provider
|
* @param {object} providerDetails The details of the weather provider
|
||||||
*/
|
*/
|
||||||
@@ -148,23 +139,26 @@ WeatherProvider.register = function (providerIdentifier, providerDetails) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Static method to initialize a new weather provider.
|
* Static method to initialize a new weather provider.
|
||||||
*
|
|
||||||
* @param {string} providerIdentifier The name of the weather provider
|
* @param {string} providerIdentifier The name of the weather provider
|
||||||
* @param {object} delegate The weather module
|
* @param {object} delegate The weather module
|
||||||
* @returns {object} The new weather provider
|
* @returns {object} The new weather provider
|
||||||
*/
|
*/
|
||||||
WeatherProvider.initialize = function (providerIdentifier, delegate) {
|
WeatherProvider.initialize = function (providerIdentifier, delegate) {
|
||||||
providerIdentifier = providerIdentifier.toLowerCase();
|
const pi = providerIdentifier.toLowerCase();
|
||||||
|
|
||||||
const provider = new WeatherProvider.providers[providerIdentifier]();
|
const provider = new WeatherProvider.providers[pi]();
|
||||||
const config = Object.assign({}, provider.defaults, delegate.config);
|
const config = Object.assign({}, provider.defaults, delegate.config);
|
||||||
|
|
||||||
provider.delegate = delegate;
|
provider.delegate = delegate;
|
||||||
provider.setConfig(config);
|
provider.setConfig(config);
|
||||||
|
|
||||||
provider.providerIdentifier = providerIdentifier;
|
provider.providerIdentifier = pi;
|
||||||
if (!provider.providerName) {
|
if (!provider.providerName) {
|
||||||
provider.providerName = providerIdentifier;
|
provider.providerName = pi;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.allowOverrideNotification) {
|
||||||
|
return new OverrideWrapper(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
return provider;
|
return provider;
|
||||||
|
|||||||
@@ -1,17 +1,11 @@
|
|||||||
/* MagicMirror²
|
|
||||||
* Weather Util Methods
|
|
||||||
*
|
|
||||||
* By Rejas
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
const WeatherUtils = {
|
const WeatherUtils = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert wind (from m/s) to beaufort scale
|
* Convert wind (from m/s) to beaufort scale
|
||||||
*
|
|
||||||
* @param {number} speedInMS the windspeed you want to convert
|
* @param {number} speedInMS the windspeed you want to convert
|
||||||
* @returns {number} the speed in beaufort
|
* @returns {number} the speed in beaufort
|
||||||
*/
|
*/
|
||||||
beaufortWindSpeed(speedInMS) {
|
beaufortWindSpeed (speedInMS) {
|
||||||
const windInKmh = this.convertWind(speedInMS, "kmh");
|
const windInKmh = this.convertWind(speedInMS, "kmh");
|
||||||
const speeds = [1, 5, 11, 19, 28, 38, 49, 61, 74, 88, 102, 117, 1000];
|
const speeds = [1, 5, 11, 19, 28, 38, 49, 61, 74, 88, 102, 117, 1000];
|
||||||
for (const [index, speed] of speeds.entries()) {
|
for (const [index, speed] of speeds.entries()) {
|
||||||
@@ -25,47 +19,46 @@ const WeatherUtils = {
|
|||||||
/**
|
/**
|
||||||
* Convert a value in a given unit to a string with a converted
|
* Convert a value in a given unit to a string with a converted
|
||||||
* value and a postfix matching the output unit system.
|
* value and a postfix matching the output unit system.
|
||||||
*
|
|
||||||
* @param {number} value - The value to convert.
|
* @param {number} value - The value to convert.
|
||||||
* @param {string} valueUnit - The unit the values has. Default is mm.
|
* @param {string} valueUnit - The unit the values has. Default is mm.
|
||||||
* @param {string} outputUnit - The unit system (imperial/metric) the return value should have.
|
* @param {string} outputUnit - The unit system (imperial/metric) the return value should have.
|
||||||
* @returns {string} - A string with tha value and a unit postfix.
|
* @returns {string} - A string with tha value and a unit postfix.
|
||||||
*/
|
*/
|
||||||
convertPrecipitationUnit(value, valueUnit, outputUnit) {
|
convertPrecipitationUnit (value, valueUnit, outputUnit) {
|
||||||
if (outputUnit === "imperial") {
|
|
||||||
if (valueUnit && valueUnit.toLowerCase() === "cm") value = value * 0.3937007874;
|
|
||||||
else value = value * 0.03937007874;
|
|
||||||
valueUnit = "in";
|
|
||||||
} else {
|
|
||||||
valueUnit = valueUnit ? valueUnit : "mm";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (valueUnit === "%") return `${value.toFixed(0)} ${valueUnit}`;
|
if (valueUnit === "%") return `${value.toFixed(0)} ${valueUnit}`;
|
||||||
|
|
||||||
return `${value.toFixed(2)} ${valueUnit}`;
|
let convertedValue = value;
|
||||||
|
let conversionUnit = valueUnit;
|
||||||
|
if (outputUnit === "imperial") {
|
||||||
|
if (valueUnit && valueUnit.toLowerCase() === "cm") convertedValue = convertedValue * 0.3937007874;
|
||||||
|
else convertedValue = convertedValue * 0.03937007874;
|
||||||
|
conversionUnit = "in";
|
||||||
|
} else {
|
||||||
|
conversionUnit = valueUnit ? valueUnit : "mm";
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${convertedValue.toFixed(2)} ${conversionUnit}`;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert temp (from degrees C) into imperial or metric unit depending on
|
* Convert temp (from degrees C) into imperial or metric unit depending on
|
||||||
* your config
|
* your config
|
||||||
*
|
|
||||||
* @param {number} tempInC the temperature in celsius you want to convert
|
* @param {number} tempInC the temperature in celsius you want to convert
|
||||||
* @param {string} unit can be 'imperial' or 'metric'
|
* @param {string} unit can be 'imperial' or 'metric'
|
||||||
* @returns {number} the converted temperature
|
* @returns {number} the converted temperature
|
||||||
*/
|
*/
|
||||||
convertTemp(tempInC, unit) {
|
convertTemp (tempInC, unit) {
|
||||||
return unit === "imperial" ? tempInC * 1.8 + 32 : tempInC;
|
return unit === "imperial" ? tempInC * 1.8 + 32 : tempInC;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert wind speed into another unit.
|
* Convert wind speed into another unit.
|
||||||
*
|
|
||||||
* @param {number} windInMS the windspeed in meter/sec you want to convert
|
* @param {number} windInMS the windspeed in meter/sec you want to convert
|
||||||
* @param {string} unit can be 'beaufort', 'kmh', 'knots, 'imperial' (mph)
|
* @param {string} unit can be 'beaufort', 'kmh', 'knots, 'imperial' (mph)
|
||||||
* or 'metric' (mps)
|
* or 'metric' (mps)
|
||||||
* @returns {number} the converted windspeed
|
* @returns {number} the converted windspeed
|
||||||
*/
|
*/
|
||||||
convertWind(windInMS, unit) {
|
convertWind (windInMS, unit) {
|
||||||
switch (unit) {
|
switch (unit) {
|
||||||
case "beaufort":
|
case "beaufort":
|
||||||
return this.beaufortWindSpeed(windInMS);
|
return this.beaufortWindSpeed(windInMS);
|
||||||
@@ -84,7 +77,7 @@ const WeatherUtils = {
|
|||||||
/*
|
/*
|
||||||
* Convert the wind direction cardinal to value
|
* Convert the wind direction cardinal to value
|
||||||
*/
|
*/
|
||||||
convertWindDirection(windDirection) {
|
convertWindDirection (windDirection) {
|
||||||
const windCardinals = {
|
const windCardinals = {
|
||||||
N: 0,
|
N: 0,
|
||||||
NNE: 22,
|
NNE: 22,
|
||||||
@@ -107,15 +100,15 @@ const WeatherUtils = {
|
|||||||
return windCardinals.hasOwnProperty(windDirection) ? windCardinals[windDirection] : null;
|
return windCardinals.hasOwnProperty(windDirection) ? windCardinals[windDirection] : null;
|
||||||
},
|
},
|
||||||
|
|
||||||
convertWindToMetric(mph) {
|
convertWindToMetric (mph) {
|
||||||
return mph / 2.2369362920544;
|
return mph / 2.2369362920544;
|
||||||
},
|
},
|
||||||
|
|
||||||
convertWindToMs(kmh) {
|
convertWindToMs (kmh) {
|
||||||
return kmh * 0.27777777777778;
|
return kmh * 0.27777777777778;
|
||||||
},
|
},
|
||||||
|
|
||||||
calculateFeelsLike(temperature, windSpeed, humidity) {
|
calculateFeelsLike (temperature, windSpeed, humidity) {
|
||||||
const windInMph = this.convertWind(windSpeed, "imperial");
|
const windInMph = this.convertWind(windSpeed, "imperial");
|
||||||
const tempInF = this.convertTemp(temperature, "imperial");
|
const tempInF = this.convertTemp(temperature, "imperial");
|
||||||
let feelsLike = tempInF;
|
let feelsLike = tempInF;
|
||||||
@@ -123,16 +116,16 @@ const WeatherUtils = {
|
|||||||
if (windInMph > 3 && tempInF < 50) {
|
if (windInMph > 3 && tempInF < 50) {
|
||||||
feelsLike = Math.round(35.74 + 0.6215 * tempInF - 35.75 * Math.pow(windInMph, 0.16) + 0.4275 * tempInF * Math.pow(windInMph, 0.16));
|
feelsLike = Math.round(35.74 + 0.6215 * tempInF - 35.75 * Math.pow(windInMph, 0.16) + 0.4275 * tempInF * Math.pow(windInMph, 0.16));
|
||||||
} else if (tempInF > 80 && humidity > 40) {
|
} else if (tempInF > 80 && humidity > 40) {
|
||||||
feelsLike =
|
feelsLike
|
||||||
-42.379 +
|
= -42.379
|
||||||
2.04901523 * tempInF +
|
+ 2.04901523 * tempInF
|
||||||
10.14333127 * humidity -
|
+ 10.14333127 * humidity
|
||||||
0.22475541 * tempInF * humidity -
|
- 0.22475541 * tempInF * humidity
|
||||||
6.83783 * Math.pow(10, -3) * tempInF * tempInF -
|
- 6.83783 * Math.pow(10, -3) * tempInF * tempInF
|
||||||
5.481717 * Math.pow(10, -2) * humidity * humidity +
|
- 5.481717 * Math.pow(10, -2) * humidity * humidity
|
||||||
1.22874 * Math.pow(10, -3) * tempInF * tempInF * humidity +
|
+ 1.22874 * Math.pow(10, -3) * tempInF * tempInF * humidity
|
||||||
8.5282 * Math.pow(10, -4) * tempInF * humidity * humidity -
|
+ 8.5282 * Math.pow(10, -4) * tempInF * humidity * humidity
|
||||||
1.99 * Math.pow(10, -6) * tempInF * tempInF * humidity * humidity;
|
- 1.99 * Math.pow(10, -6) * tempInF * tempInF * humidity * humidity;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((feelsLike - 32) * 5) / 9;
|
return ((feelsLike - 32) * 5) / 9;
|
||||||
|
|||||||
14267
package-lock.json
generated
14267
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
88
package.json
88
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "magicmirror",
|
"name": "magicmirror",
|
||||||
"version": "2.23.0",
|
"version": "2.27.0",
|
||||||
"description": "The open source modular smart mirror platform.",
|
"description": "The open source modular smart mirror platform.",
|
||||||
"main": "js/electron.js",
|
"main": "js/electron.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -18,19 +18,19 @@
|
|||||||
"test:e2e": "NODE_ENV=test jest --selectProjects e2e -i --forceExit",
|
"test:e2e": "NODE_ENV=test jest --selectProjects e2e -i --forceExit",
|
||||||
"test:unit": "NODE_ENV=test jest --selectProjects unit",
|
"test:unit": "NODE_ENV=test jest --selectProjects unit",
|
||||||
"test:prettier": "prettier . --check",
|
"test:prettier": "prettier . --check",
|
||||||
"test:js": "eslint 'js/**/*.js' 'modules/default/**/*.js' 'clientonly/*.js' 'serveronly/*.js' 'translations/*.js' 'vendor/*.js' 'tests/**/*.js' 'config/*' --config .eslintrc.json",
|
"test:js": "eslint .",
|
||||||
"test:css": "stylelint 'css/main.css' 'fonts/*.css' 'modules/default/**/*.css' 'vendor/*.css' --config .stylelintrc.json",
|
"test:css": "stylelint 'css/main.css' 'fonts/*.css' 'modules/default/**/*.css' 'vendor/*.css' --config .stylelintrc.json",
|
||||||
"test:calendar": "node ./modules/default/calendar/debug.js",
|
"test:calendar": "node ./modules/default/calendar/debug.js",
|
||||||
"config:check": "node js/check_config.js",
|
"config:check": "node js/check_config.js",
|
||||||
"lint:prettier": "prettier . --write",
|
"lint:prettier": "prettier . --write",
|
||||||
"lint:js": "eslint 'js/**/*.js' 'modules/default/**/*.js' 'clientonly/*.js' 'serveronly/*.js' 'translations/*.js' 'vendor/*.js' 'tests/**/*.js' 'config/*' --config .eslintrc.json --fix",
|
"lint:js": "eslint . --fix",
|
||||||
"lint:css": "stylelint 'css/main.css' 'fonts/*.css' 'modules/default/**/*.css' 'vendor/*.css' --config .stylelintrc.json --fix",
|
"lint:css": "stylelint 'css/main.css' 'fonts/*.css' 'modules/default/**/*.css' 'vendor/*.css' --config .stylelintrc.json --fix",
|
||||||
"lint:staged": "pretty-quick --staged",
|
"lint:staged": "lint-staged",
|
||||||
"prepare": "[ -f node_modules/.bin/husky ] && husky install || echo no husky installed."
|
"prepare": "[ -f node_modules/.bin/husky ] && husky || echo no husky installed."
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/MichMich/MagicMirror.git"
|
"url": "https://github.com/MagicMirrorOrg/MagicMirror"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"magic mirror",
|
"magic mirror",
|
||||||
@@ -41,60 +41,64 @@
|
|||||||
],
|
],
|
||||||
"author": "Michael Teeuw",
|
"author": "Michael Teeuw",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"https://github.com/MichMich/MagicMirror/graphs/contributors"
|
"https://github.com/MagicMirrorOrg/MagicMirror/graphs/contributors"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/MichMich/MagicMirror/issues"
|
"url": "https://github.com/MagicMirrorOrg/MagicMirror/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://magicmirror.builders",
|
"homepage": "https://magicmirror.builders",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint-config-prettier": "^8.8.0",
|
"@stylistic/eslint-plugin": "^1.7.0",
|
||||||
"eslint-plugin-import": "^2.27.5",
|
"eslint-plugin-import": "^2.29.1",
|
||||||
"eslint-plugin-jest": "^27.2.1",
|
"eslint-plugin-jest": "^27.9.0",
|
||||||
"eslint-plugin-jsdoc": "^40.1.0",
|
"eslint-plugin-jsdoc": "^48.2.2",
|
||||||
"eslint-plugin-prettier": "^4.2.1",
|
"eslint-plugin-package-json": "^0.12.1",
|
||||||
|
"eslint-plugin-unicorn": "^51.0.1",
|
||||||
"express-basic-auth": "^1.2.1",
|
"express-basic-auth": "^1.2.1",
|
||||||
"husky": "^8.0.3",
|
"husky": "^9.0.11",
|
||||||
"jest": "^29.5.0",
|
"jest": "^29.7.0",
|
||||||
"jsdom": "^21.1.1",
|
"jsdom": "^24.0.0",
|
||||||
"lodash": "^4.17.21",
|
"lint-staged": "^15.2.2",
|
||||||
"playwright": "^1.32.1",
|
"playwright": "^1.42.1",
|
||||||
"prettier": "^2.8.7",
|
"prettier": "^3.2.5",
|
||||||
"pretty-quick": "^3.1.3",
|
"sinon": "^17.0.1",
|
||||||
"sinon": "^15.0.2",
|
"stylelint": "^16.3.1",
|
||||||
"stylelint": "^15.3.0",
|
"stylelint-config-standard": "^36.0.0",
|
||||||
"stylelint-config-standard": "^31.0.0",
|
"stylelint-prettier": "^5.0.0"
|
||||||
"stylelint-prettier": "^3.0.0",
|
|
||||||
"suncalc": "^1.9.0"
|
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"electron": "^22.3.4"
|
"electron": "^29.1.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"colors": "^1.4.0",
|
"ansis": "^2.3.0",
|
||||||
"console-stamp": "^3.1.1",
|
"console-stamp": "^3.1.2",
|
||||||
"digest-fetch": "^2.0.1",
|
|
||||||
"envsub": "^4.1.0",
|
"envsub": "^4.1.0",
|
||||||
"eslint": "^8.36.0",
|
"eslint": "^8.57.0",
|
||||||
"express": "^4.18.2",
|
"express": "^4.19.2",
|
||||||
"express-ipfilter": "^1.3.1",
|
"express-ipfilter": "^1.3.2",
|
||||||
"feedme": "^2.0.2",
|
"feedme": "^2.0.2",
|
||||||
"helmet": "^6.0.1",
|
"helmet": "^7.1.0",
|
||||||
|
"html-to-text": "^9.0.5",
|
||||||
"iconv-lite": "^0.6.3",
|
"iconv-lite": "^0.6.3",
|
||||||
"luxon": "^1.28.1",
|
"module-alias": "^2.2.3",
|
||||||
"module-alias": "^2.2.2",
|
"moment": "^2.30.1",
|
||||||
"moment": "^2.29.4",
|
"node-ical": "^0.18.0",
|
||||||
"node-fetch": "^2.6.9",
|
"pm2": "^5.3.1",
|
||||||
"node-ical": "^0.16.0",
|
"socket.io": "^4.7.5",
|
||||||
"socket.io": "^4.6.1"
|
"suncalc": "^1.9.0",
|
||||||
|
"systeminformation": "^5.22.6"
|
||||||
|
},
|
||||||
|
"lint-staged": {
|
||||||
|
"*": "prettier --write",
|
||||||
|
"*.js": "eslint --fix",
|
||||||
|
"*.css": "stylelint --fix"
|
||||||
},
|
},
|
||||||
"_moduleAliases": {
|
"_moduleAliases": {
|
||||||
"node_helper": "js/node_helper.js",
|
"node_helper": "js/node_helper.js",
|
||||||
"logger": "js/logger.js",
|
"logger": "js/logger.js"
|
||||||
"fetch": "js/fetch.js"
|
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ const Log = require("../js/logger");
|
|||||||
app.start().then((config) => {
|
app.start().then((config) => {
|
||||||
const bindAddress = config.address ? config.address : "localhost";
|
const bindAddress = config.address ? config.address : "localhost";
|
||||||
const httpType = config.useHttps ? "https" : "http";
|
const httpType = config.useHttps ? "https" : "http";
|
||||||
Log.log(`\nReady to go! Please point your browser to: ${httpType}://${bindAddress}:${config.port}`);
|
Log.info(`\n>>> Ready to go! Please point your browser to: ${httpType}://${bindAddress}:${config.port} <<<`);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
/* MagicMirror² Test default config for modules
|
|
||||||
*
|
|
||||||
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
|
|
||||||
* MIT Licensed.
|
|
||||||
*/
|
|
||||||
exports.configFactory = (options) => {
|
exports.configFactory = (options) => {
|
||||||
return Object.assign(
|
return Object.assign(
|
||||||
{
|
{
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user