tabs/src/Meta.ts

68 lines
2.0 KiB
TypeScript
Raw Normal View History

2020-05-21 07:38:44 +02:00
import Service from "./Service";
2020-05-22 10:25:19 +02:00
import path from "path";
import fs from "fs";
2020-05-21 07:38:44 +02:00
export default class Meta {
public static readonly title = 'Tabs';
2020-05-22 10:25:19 +02:00
// Paths
public static readonly RESOURCES_PATH = path.resolve(__dirname, '../resources');
public static readonly ICON_PATH = path.resolve(Meta.RESOURCES_PATH, 'images/logo.png');
2020-05-22 10:25:19 +02:00
// Icons
public static readonly BRAND_ICONS = Meta.listIcons('brands');
public static readonly SOLID_ICONS = Meta.listIcons('solid');
public static readonly REGULAR_ICONS = Meta.listIcons('regular');
2020-09-29 20:43:41 +02:00
public static readonly ICON_SETS: IconSet[] = [
Meta.BRAND_ICONS,
Meta.SOLID_ICONS,
Meta.REGULAR_ICONS,
];
2020-05-22 10:25:19 +02:00
2020-05-21 07:38:44 +02:00
private static devMode?: boolean;
2020-09-29 20:43:41 +02:00
public static isDevMode(): boolean {
2020-05-21 07:38:44 +02:00
if (this.devMode === undefined) {
this.devMode = process.argv.length > 2 && process.argv[2] === '--dev';
console.debug('Dev mode:', this.devMode);
}
return this.devMode;
}
2020-09-29 20:43:41 +02:00
public static getTitleForService(service: Service, viewTitle: string): string {
2020-05-21 07:38:44 +02:00
let suffix = '';
if (viewTitle.length > 0) {
suffix = ' - ' + viewTitle;
}
return this.title + ' - ' + service.name + suffix;
}
2020-05-22 10:25:19 +02:00
2020-09-29 20:43:41 +02:00
private static listIcons(set: string): IconSet {
2020-05-22 10:25:19 +02:00
console.log('Loading icon set', set);
const directory = path.resolve(Meta.RESOURCES_PATH, `images/icons/${set}`);
const icons: { name: string; faIcon: string; set: string; }[] = [];
const dir = `fa${set[0]}`;
2020-05-22 10:25:19 +02:00
fs.readdirSync(directory).forEach(i => icons.push({
name: i.split('.svg')[0],
faIcon: dir + ' fa-' + i.split('.svg')[0],
set: set,
2020-05-22 10:25:19 +02:00
}));
return icons;
}
}
2020-09-29 20:43:41 +02:00
export type SpecialPages = {
empty: string;
connectionError: string;
fileNotFound: string;
};
export type IconProperties = {
name: string;
faIcon: string;
set: string;
};
export type IconSet = IconProperties[];