Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some icons example and load in the selector #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/instances_icon/CREPER.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/instances_icon/DIRT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/instances_icon/FABRIC.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/instances_icon/INDIUM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/instances_icon/LITHIUM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/instances_icon/OPENMC.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/instances_icon/OPTIFINE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/instances_icon/PICKAXE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/instances_icon/PIXELMON.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/instances_icon/SKY_FACTORY.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/instances_icon/SODIUM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/instances_icon/WARPED_NYLIUM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/main/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default class Manager {

ipc.on('instances:list', async (event) => {
Logger.debug(`Renderer call IPC function "instances:list"`);
await this.icons.loadDefault();
const instances = await this.instances
.listInstances()
.catch((e) => Logger.crit(e.toString()));
Expand Down
26 changes: 23 additions & 3 deletions src/main/providers/icons.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@ import path from 'path';

import Logger from '../logger';
import { getSafeLauncherDir } from '../utils/dir.utils';
import { imageToBase64 } from '../utils/file.utils';
import { imageToBase64, downloadFileIfNotExist } from '../utils/file.utils';

const FILES_EXT = ['.png', '.jpg', '.jpeg', '.webp', '.ico'];
const DEFAULT_ICONS = {
DIRT: 'https://i.imgur.com/aH72PI6.png',
OPENMC: 'https://i.imgur.com/YLMEwEs.png',
OPTIFINE: 'https://i.imgur.com/mYgYa08.png',
PICKAXE: 'https://i.imgur.com/QMbqAdp.png',
CREPER: 'https://i.imgur.com/g6khqjd.png',
FABRIC: 'https://i.imgur.com/manAkYB.png',
INDIUM: 'https://i.imgur.com/40tzeVD.png',
LITHIUM: 'https://i.imgur.com/Ekywi3v.png',
SKYFACTORY: 'https://i.imgur.com/2ezp9rw.png',
SODIUM: 'https://i.imgur.com/Shz61E5.png',
WARPED_NYLLIUM: 'https://i.imgur.com/UWGrZMf.png',
};

export default class IconsProvider {
private iconsDir: string;
Expand All @@ -14,10 +27,18 @@ export default class IconsProvider {
this.iconsDir = getSafeLauncherDir('icons');
}

async loadDefault() {
// eslint-disable-next-line no-restricted-syntax
for (const [name, url] of Object.entries(DEFAULT_ICONS)) {
const filePath = path.join(this.iconsDir, `${name}.png`);
Logger.debug(`Downloading icon ${name} from ${url} to ${filePath}`);
await downloadFileIfNotExist(filePath, url);
}
}

async listIcons() {
const icons = [];
const files = await fs.readdir(this.iconsDir);

for (let i = 0; i < files.length; i += 1) {
const file = files[i];
const ext = path.extname(file);
Expand All @@ -27,7 +48,6 @@ export default class IconsProvider {
icons.push(icon);
}
}

Logger.debug(`Loaded ${icons.length} icons.`);
return icons;
}
Expand Down