Skip to content

Commit

Permalink
Merge branch 'master' into patch-18
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox authored May 29, 2024
2 parents 9593734 + 75f8c01 commit 787528f
Show file tree
Hide file tree
Showing 148 changed files with 1,819 additions and 1,287 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
# if: failure()
uses: actions/upload-artifact@v4
with:
path: tmp/screenshots/**/*.png
path: packages/admin/tmp/screenshots/**/*.png
retention-days: 3

# Deploys the final package to NPM
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@fnando/sparkline": "^0.3.10",
"@honkhonk/vite-plugin-svgr": "^1.1.0",
"@iobroker/adapter-react-v5": "^4.13.23",
"@iobroker/adapter-react-v5": "^5.0.1",
"@iobroker/admin-component-easy-access": "^0.3.2",
"@iobroker/dm-utils": "^0.1.9",
"@iobroker/dm-utils": "^0.2.0",
"@iobroker/legacy-testing": "^1.0.12",
"@iobroker/socket-client": "^2.4.13",
"@iobroker/testing": "^4.1.3",
Expand Down Expand Up @@ -73,7 +73,7 @@
"date-fns": "^2.30.0",
"echarts": "^5.5.0",
"echarts-for-react": "^3.0.2",
"eslint": "^9.3.0",
"eslint": "^8.56.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^9.1.0",
"eslint-config-react-app": "^7.0.1",
Expand Down
112 changes: 65 additions & 47 deletions packages/admin/src-backend/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ class Admin extends utils.Adapter {

for (const _adapter of adapters) {
if (repository[_adapter].blockedVersions) {
// read current version
// read a current version
if (Array.isArray(repository[_adapter].blockedVersions)) {
const instance = instances.rows.find(
item => item.value?.common.name === _adapter && item.value.common.enabled
Expand Down Expand Up @@ -1344,34 +1344,46 @@ class Admin extends utils.Adapter {
}
}

restartRepoUpdate() {
// start the next cycle
if (this.config.autoUpdate) {
this.timerRepo && clearTimeout(this.timerRepo);
this.log.debug(
`Next repo update on ${new Date(
Date.now() + this.config.autoUpdate * ONE_HOUR_MS + 1
).toLocaleString()}`
);
this.timerRepo = setTimeout(
() => {
this.timerRepo = null;
this.updateRegister();
},
this.config.autoUpdate * ONE_HOUR_MS + 1
);
}
}

/**
* Read repository information from active repository
*/
updateRegister() {
if (lastRepoUpdate && Date.now() - lastRepoUpdate < 3600000) {
this.log.error('Automatic repository update is not allowed more than once a hour');
if (this.config.autoUpdate) {
this.timerRepo && clearTimeout(this.timerRepo);
this.timerRepo = setTimeout(
() => {
this.timerRepo = null;
this.updateRegister();
},
this.config.autoUpdate * ONE_HOUR_MS + 1
);
}
this.restartRepoUpdate();
return;
}

lastRepoUpdate = Date.now();

this.getForeignObject('system.config', (err, systemConfig) => {
this.getForeignObject('system.config', async (err, systemConfig) => {
err && this.log.error('May not read "system.config"');

if (systemConfig && systemConfig.common) {
this.getForeignObject('system.repositories', (err, repos) => {
err && this.log.error('May not read "system.repositories"');
if (systemConfig?.common) {
try {
const repos = await this.getForeignObjectAsync('system.repositories');
if (!repos || repos.ts === undefined) {
// start the next cycle
this.restartRepoUpdate();
return;
}

Expand All @@ -1380,16 +1392,32 @@ class Admin extends utils.Adapter {
const active = systemConfig.common.activeRepo;

// if repo is valid and actual
if (
!err &&
repos?.native?.repositories?.[active] &&
Date.now() < repos.ts + this.config.autoUpdate * ONE_HOUR_MS
) {
exists = true;
if (Array.isArray(active)) {
if (!err &&
Date.now() < repos.ts + this.config.autoUpdate * ONE_HOUR_MS &&
!active.find(repo => !repos?.native?.repositories?.[repo]?.json)
) {
exists = true;
}
} else {
if (!err &&
repos?.native?.repositories?.[active]?.json &&
Date.now() < repos.ts + this.config.autoUpdate * ONE_HOUR_MS
) {
exists = true;
}
}

if (!exists) {
this.log.info('Request actual repository...');
// first check if the host is running
const aliveState = await this.getForeignStateAsync(`system.host.${this.host}.alive`);
if (!aliveState || !aliveState.val) {
this.log.error('Host is not alive');
// start the next cycle
this.restartRepoUpdate();
return;
}

// request repo from host
this.sendToHost(
this.host,
Expand All @@ -1406,25 +1434,12 @@ class Admin extends utils.Adapter {
this.log.info('Repository received successfully.');

socket && socket.repoUpdated();
this.checkRevokedVersions(_repository).then(() => {});
this.checkRevokedVersions(_repository)
.catch(e => this.log.error(`Cannot check revoked versions: ${e}`));
}

// start the next cycle
if (this.config.autoUpdate) {
this.timerRepo && clearTimeout(this.timerRepo);
this.log.debug(
`Next repo update on ${new Date(
Date.now() + this.config.autoUpdate * ONE_HOUR_MS + 1
).toLocaleString()}`
);
this.timerRepo = setTimeout(
() => {
this.timerRepo = null;
this.updateRegister();
},
this.config.autoUpdate * ONE_HOUR_MS + 1
);
}
this.restartRepoUpdate();
}
);
} else if (this.config.autoUpdate) {
Expand All @@ -1439,7 +1454,9 @@ class Admin extends utils.Adapter {
this.updateRegister();
}, interval);
}
});
} catch (err) {
err && this.log.error(`May not read "system.repositories": ${err}`);
}
}
});
}
Expand Down Expand Up @@ -1482,15 +1499,16 @@ class Admin extends utils.Adapter {
}

// check info.connected
this.getObjectAsync('info.connected').then(obj => {
if (!obj) {
const packageJson = JSON.parse(fs.readFileSync(`${__dirname}/../io-package.json`).toString('utf8'));
const obj = packageJson.instanceObjects.find(o => o._id === 'info.connected');
if (obj) {
return this.setObjectAsync(obj._id, obj);
this.getObjectAsync('info.connected')
.then(obj => {
if (!obj) {
const packageJson = JSON.parse(fs.readFileSync(`${__dirname}/../io-package.json`).toString('utf8'));
const obj = packageJson.instanceObjects.find(o => o._id === 'info.connected');
if (obj) {
return this.setObjectAsync(obj._id, obj);
}
}
}
});
});

this.config.autoUpdate && this.updateRegister();

Expand Down
2 changes: 2 additions & 0 deletions packages/admin/src/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,7 @@ module.exports = {
requireLast: false,
},
}],
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
},
};
3 changes: 2 additions & 1 deletion packages/admin/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"not op_mini all"
],
"dependencies": {
"@iobroker/json-config": "file:../../jsonConfig"
"@iobroker/json-config": "file:../../jsonConfig",
"@iobroker/dm-gui-components": "file:../../dm-gui-components"
},
"proxy": "http://127.0.0.1:8081",
"plugins": [
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ class App extends Router {
/**
* Get a theme
* @param {string} name Theme name
* @returns {Theme}
* @returns {IobTheme}
*/
static createTheme(name) {
return Theme(Utils.getThemeName(name));
Expand Down
11 changes: 9 additions & 2 deletions packages/admin/src/src/Utils.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { I18n } from '@iobroker/adapter-react-v5';
import semver from 'semver';
import { type Translate } from '@iobroker/adapter-react-v5';

const ANSI_RESET = 0;
const ANSI_RESET_COLOR = 39;
Expand Down Expand Up @@ -147,7 +147,7 @@ class Utils {
* @param seconds
* @param t i18n.t function
*/
static formatSeconds(seconds: number, t: typeof I18n.t): string {
static formatSeconds(seconds: number, t: Translate): string {
const days = Math.floor(seconds / (3600 * 24));
let minutesRes: string;
let secondsRes: string;
Expand Down Expand Up @@ -667,4 +667,11 @@ class Utils {
}
}

declare module '@mui/material/Button' {
interface ButtonPropsColorOverrides {
grey: true;
gray: true;
}
}

export default Utils;
9 changes: 4 additions & 5 deletions packages/admin/src/src/components/Adapters/AdapterRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import React, { Component } from 'react';

import { type Styles, withStyles } from '@mui/styles';

import { i18n, Utils } from '@iobroker/adapter-react-v5';

import {
Avatar,
CardMedia,
Expand All @@ -14,7 +12,6 @@ import {
Tooltip,
Typography,
Rating,
type Theme,
Link,
} from '@mui/material';

Expand Down Expand Up @@ -44,11 +41,13 @@ import {
MonetizationOn,
} from '@mui/icons-material';

import { type Translate, type IobTheme, Utils } from '@iobroker/adapter-react-v5';

import IsVisible from '../IsVisible';
import MaterialDynamicIcon from '../../helpers/MaterialDynamicIcon';
import sentryIcon from '../../assets/sentry.svg';

const styles = (theme: Theme) => ({
const styles = (theme: IobTheme) => ({
smallAvatar: {
width: theme.spacing(4),
height: theme.spacing(4),
Expand Down Expand Up @@ -188,7 +187,7 @@ interface AdapterRowProps {
connectionType: string;
openInstallVersionDialog: () => void;
dataSource: string;
t: typeof i18n.t;
t: Translate;
installedFrom: string;
sentry: boolean;
allowAdapterInstall: boolean;
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/src/components/Adapters/AdapterTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from '@mui/icons-material';
import { amber } from '@mui/material/colors';

import { i18n, Utils } from '@iobroker/adapter-react-v5';
import { type Translate, Utils } from '@iobroker/adapter-react-v5';

import Link from '@mui/material/Link';
import sentryIcon from '../../assets/sentry.svg';
Expand Down Expand Up @@ -282,7 +282,7 @@ interface AdapterTileProps {
connectionType: string;
openInstallVersionDialog: () => void;
dataSource: string;
t: typeof i18n.t;
t: Translate;
installedFrom: string;
sentry: boolean;
allowAdapterInstall: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ class AdaptersUpdater extends Component<AdaptersUpdaterProps, AdaptersUpdaterSta
<Button
variant="contained"
onClick={() => this.setState({ showNews: null })}
// @ts-expect-error this is fine
color="grey"
startIcon={<CloseIcon />}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
AccordionSummary,
Typography,
Fab,
type Theme,
} from '@mui/material';

// Icons
Expand All @@ -32,10 +31,10 @@ import {
Computer as IconSyslog,
Send as IconStream,
} from '@mui/icons-material';
import { withWidth } from '@iobroker/adapter-react-v5';
import { withWidth, type IobTheme } from '@iobroker/adapter-react-v5';
import IconSeq from '../../assets/seq.png';

const styles: Styles<any, any> = (theme: Theme) => ({
const styles: Styles<any, any> = (theme: IobTheme) => ({
paper: {
height: '100%',
maxHeight: '100%',
Expand Down Expand Up @@ -96,7 +95,7 @@ interface TransportSettings {
ssl?: boolean;
}

interface SettingsLog {
export interface SettingsLog {
transport?: Record<string, TransportSettings>;
level?: string;
maxDays?: number;
Expand Down Expand Up @@ -919,7 +918,6 @@ class BaseSettingsLog extends Component<BaseSettingsLogProps, BaseSettingsLogSta
</Grid>
<Toolbar>
<Button
// @ts-expect-error grey is a valid color
color="grey"
className={this.props.classes.addButton}
variant="contained"
Expand All @@ -930,7 +928,6 @@ class BaseSettingsLog extends Component<BaseSettingsLogProps, BaseSettingsLogSta
{this.props.t('File log')}
</Button>
<Button
// @ts-expect-error grey is a valid color
color="grey"
className={this.props.classes.addButton}
variant="contained"
Expand All @@ -941,7 +938,6 @@ class BaseSettingsLog extends Component<BaseSettingsLogProps, BaseSettingsLogSta
{this.props.t('Syslog')}
</Button>
<Button
// @ts-expect-error grey is a valid color
color="grey"
className={this.props.classes.addButton}
variant="contained"
Expand All @@ -952,7 +948,6 @@ class BaseSettingsLog extends Component<BaseSettingsLogProps, BaseSettingsLogSta
{this.props.t('HTTP log')}
</Button>
<Button
// @ts-expect-error grey is a valid color
color="grey"
className={this.props.classes.addButton}
variant="contained"
Expand All @@ -963,7 +958,6 @@ class BaseSettingsLog extends Component<BaseSettingsLogProps, BaseSettingsLogSta
{this.props.t('Stream log')}
</Button>
<Button
// @ts-expect-error grey is a valid color
color="grey"
className={this.props.classes.addButton}
variant="contained"
Expand Down
Loading

0 comments on commit 787528f

Please sign in to comment.