Skip to content

Commit a2eb2de

Browse files
committed
fix: add png module to load icons
Signed-off-by: Denis Golovin <[email protected]>
1 parent cafd206 commit a2eb2de

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

src/extension.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
***********************************************************************/
1818

19-
import { readFileSync } from 'node:fs';
20-
import path from 'node:path';
21-
2219
import * as extensionApi from '@podman-desktop/api';
2320
import type { ServiceAccountV1 } from '@redhat-developer/rhcra-client';
2421
import { ContainerRegistryAuthorizerClient } from '@redhat-developer/rhcra-client';
2522
import { SubscriptionManagerClient } from '@redhat-developer/rhsm-client';
2623

24+
import icon from '../icon.png';
2725
import { onDidChangeSessions, RedHatAuthenticationService } from './authentication-service';
2826
import { getAuthConfig } from './configuration';
2927
import {
@@ -55,14 +53,6 @@ async function getAuthenticationService(): Promise<RedHatAuthenticationService>
5553
return authenticationServicePromise;
5654
}
5755

58-
// function to encode file data to base64 encoded string
59-
function fileToBase64(file: string): string {
60-
// read binary data
61-
const bitmap = readFileSync(file);
62-
// convert binary data to base64 encoded string
63-
return bitmap.toString('base64');
64-
}
65-
6656
function parseJwt(token: string): JwtToken {
6757
const base64Url = token.split('.')[1];
6858
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
@@ -322,7 +312,7 @@ export async function activate(context: extensionApi.ExtensionContext): Promise<
322312
context.subscriptions.push(
323313
extensionApi.registry.suggestRegistry({
324314
name: 'Red Hat Container Registry',
325-
icon: fileToBase64(path.resolve(__dirname, '..', 'icon.png')),
315+
icon,
326316
url: 'registry.redhat.io',
327317
}),
328318
);

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
"esModuleInterop": true
1616
},
1717
"include": [
18-
"src/**/*.ts"
18+
"src/**/*.ts", "types/*.d.ts"
1919
]
2020
}

types/template.d.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**********************************************************************
2+
* Copyright (C) 2024 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
declare module '*.png' {
20+
const contents: string;
21+
export = contents;
22+
}

0 commit comments

Comments
 (0)