Skip to content

Commit

Permalink
update plugin icons
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 committed Nov 27, 2023
1 parent 0120f6f commit 99c3d67
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 63 deletions.
100 changes: 50 additions & 50 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
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
23 changes: 22 additions & 1 deletion 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,6 +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 @@ -349,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 @@ -363,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 @@ -1201,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 @@ -1474,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 @@ -65,10 +65,9 @@ export class PluginCardComponent implements OnInit {
}

ngOnInit(): void {
this.plugin.icon = this.plugin.verifiedPlugin && this.plugin?.links?.homepage
? `${this.plugin.links.homepage.split('#')[0]}/latest/branding/icon.png`
.replace('github.com', 'raw.githubusercontent.com')
: this.defaultIcon;
if (!this.plugin.icon) {
this.plugin.icon = this.defaultIcon;
}

if (
this.plugin.installedVersion
Expand Down

0 comments on commit 99c3d67

Please sign in to comment.