refactor: remove dynamic require (partial of #2)

Co-authored-by: Su-Yong <simssy2205@gmail.com>
This commit is contained in:
JellyBrick
2023-10-03 23:42:12 +09:00
parent 6eadc7f7e5
commit 6e315b9af2
24 changed files with 841 additions and 745 deletions

View File

@ -3,7 +3,10 @@ import path from 'node:path';
import { ipcMain, ipcRenderer } from 'electron';
import is from 'electron-is';
import { ValueOf } from '../utils/type-utils';
import defaultConfig from '../config/defaults';
// Creates a DOM element from an HTML string
export const ElementFromHtml = (html: string): HTMLElement => {
@ -64,11 +67,15 @@ const setupCssInjection = (webContents: Electron.WebContents) => {
});
};
export const getAllPlugins = () => {
const isDirectory = (source: fs.PathLike) => fs.lstatSync(source).isDirectory();
return fs
.readdirSync(__dirname)
.map((name) => path.join(__dirname, name))
.filter(isDirectory)
.map((name) => path.basename(name));
export const getAvailablePluginNames = () => {
return Object.keys(defaultConfig.plugins).filter((name) => {
if (is.windows() && name === 'touchbar') {
return false;
} else if (is.macOS() && name === 'taskbar-mediacontrol') {
return false;
} else if (is.linux() && (name === 'taskbar-mediacontrol' || name === 'touchbar')) {
return false;
}
return true;
});
};