Skip to content

Commit

Permalink
add api work for plugin icons
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 committed Nov 28, 2023
1 parent daed611 commit 4a77134
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 79 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ All notable changes to homebridge-config-ui-x will be documented in this file.
- add power options modal (#1820)
- remove hb-ui card from plugins page (#1830)
- add some support links (#1833)
- plugin logs feature (#1834)
- add plugin logs feature (#1834)
- update module headers (#1836)
- restart modals, tidy plugin card
- use restart modals, tidy plugin card

### Translation Changes

Expand All @@ -20,6 +20,7 @@ All notable changes to homebridge-config-ui-x will be documented in this file.
### Other Changes

- Add Raspberry Pi 5 to list of Pi devices in bug-report template (#1824) (@jsiegenthaler)
- add api work for plugin icons

## 4.53.0 (2023-11-24)

Expand Down
108 changes: 54 additions & 54 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"commander": "11.1.0",
"dayjs": "1.11.10",
"fastify": "4.24.3",
"fs-extra": "11.1.1",
"fs-extra": "11.2.0",
"jsonwebtoken": "9.0.2",
"lodash": "4.17.21",
"node-cache": "5.1.2",
Expand Down Expand Up @@ -109,8 +109,8 @@
"@types/tar": "^6.1.10",
"@types/tcp-port-used": "^1.0.4",
"@types/unzipper": "^0.10.9",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"@typescript-eslint/eslint-plugin": "^6.13.0",
"@typescript-eslint/parser": "^6.13.0",
"babel-jest": "^29.7.0",
"concurrently": "^8.2.2",
"eslint": "^8.54.0",
Expand Down
24 changes: 22 additions & 2 deletions src/modules/plugins/plugins.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export class PluginsService {

// verified plugins cache
private verifiedPlugins: string[] = [];
private verifiedPluginsIcons: { [key: string]: string } = {};
private verifiedPluginsIconsPrefix = 'https://raw.githubusercontent.com/homebridge/verified/latest/';

private verifiedPluginsJson = 'https://raw.githubusercontent.com/homebridge/verified/latest/verified-plugins.json';
private verifiedPluginsIconsJson = 'https://raw.githubusercontent.com/homebridge/verified/latest/plugin-icons.json';

// misc schemas
private miscSchemas = {
Expand Down Expand Up @@ -293,7 +298,9 @@ export class PluginsService {
plugin.links = pkg.package.links;
plugin.author = (pkg.package.publisher) ? pkg.package.publisher.username : null;
plugin.verifiedPlugin = this.verifiedPlugins.includes(pkg.package.name);

plugin.icon = this.verifiedPluginsIcons[pkg.package.name]
? `${this.verifiedPluginsIconsPrefix}${this.verifiedPluginsIcons[pkg.package.name]}`
: null;
return plugin;
});

Expand Down Expand Up @@ -350,6 +357,7 @@ export class PluginsService {
description: (pkg.description) ?
pkg.description.replace(/(?:https?|ftp):\/\/[\n\S]+/g, '').trim() : pkg.name,
verifiedPlugin: this.verifiedPlugins.includes(pkg.name),
icon: this.verifiedPluginsIcons[pkg.name],
} as HomebridgePlugin;

// it's not installed; finish building the response
Expand All @@ -364,6 +372,9 @@ export class PluginsService {
};
plugin.author = (pkg.maintainers.length) ? pkg.maintainers[0].name : null;
plugin.verifiedPlugin = this.verifiedPlugins.includes(pkg.name);
plugin.icon = this.verifiedPluginsIcons[pkg.name]
? `${this.verifiedPluginsIconsPrefix}${this.verifiedPluginsIcons[pkg.name]}`
: null;

return [plugin];
} catch (e) {
Expand Down Expand Up @@ -1202,6 +1213,9 @@ export class PluginsService {
description: (pjson.description) ?
pjson.description.replace(/(?:https?|ftp):\/\/[\n\S]+/g, '').trim() : pjson.name,
verifiedPlugin: this.verifiedPlugins.includes(pjson.name),
icon: this.verifiedPluginsIcons[pjson.name]
? `${this.verifiedPluginsIconsPrefix}${this.verifiedPluginsIcons[pjson.name]}`
: null,
installedVersion: installPath ? (pjson.version || '0.0.1') : null,
globalInstall: (installPath !== this.configService.customPluginPath),
settingsSchema: await pathExists(resolve(installPath, pjson.name, 'config.schema.json')) || this.miscSchemas[pjson.name],
Expand Down Expand Up @@ -1475,7 +1489,13 @@ export class PluginsService {
clearTimeout(this.verifiedPluginsRetryTimeout);
try {
this.verifiedPlugins = (
await this.httpService.get('https://raw.githubusercontent.com/homebridge/verified/latest/verified-plugins.json', {
await this.httpService.get(this.verifiedPluginsJson, {
httpsAgent: null,
}).toPromise()
).data;

this.verifiedPluginsIcons = (
await this.httpService.get(this.verifiedPluginsIconsJson, {
httpsAgent: null,
}).toPromise()
).data;
Expand Down
1 change: 1 addition & 0 deletions src/modules/plugins/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface HomebridgePlugin {
displayName?: string;
description?: string;
verifiedPlugin?: boolean;
icon?: string;
publicPackage?: boolean;
installedVersion?: string;
latestVersion?: string;
Expand Down
13 changes: 7 additions & 6 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export class ManagePluginsModalComponent implements OnInit, OnDestroy {
termRows: this.term.rows,
}).subscribe(
() => {
this.activeModal.close();
this.$router.navigate(['/plugins']);
this.$modal.open(RestartHomebridgeComponent);
},
Expand Down
Loading

0 comments on commit 4a77134

Please sign in to comment.