mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-12 02:51:46 +00:00
feat: run prettier
This commit is contained in:
@ -10,19 +10,23 @@ export interface Plugin<ConfigType extends Config> {
|
||||
config: ConfigType;
|
||||
}
|
||||
|
||||
export interface RendererPlugin<ConfigType extends Config> extends Plugin<ConfigType> {
|
||||
export interface RendererPlugin<ConfigType extends Config>
|
||||
extends Plugin<ConfigType> {
|
||||
onEnable: (config: ConfigType) => void;
|
||||
}
|
||||
|
||||
export interface MainPlugin<ConfigType extends Config> extends Plugin<ConfigType> {
|
||||
export interface MainPlugin<ConfigType extends Config>
|
||||
extends Plugin<ConfigType> {
|
||||
onEnable: (window: BrowserWindow, config: ConfigType) => string;
|
||||
}
|
||||
|
||||
export interface PreloadPlugin<ConfigType extends Config> extends Plugin<ConfigType> {
|
||||
export interface PreloadPlugin<ConfigType extends Config>
|
||||
extends Plugin<ConfigType> {
|
||||
onEnable: (config: ConfigType) => void;
|
||||
}
|
||||
|
||||
export interface MenuPlugin<ConfigType extends Config> extends Plugin<ConfigType> {
|
||||
export interface MenuPlugin<ConfigType extends Config>
|
||||
extends Plugin<ConfigType> {
|
||||
onEnable: (config: ConfigType) => void;
|
||||
}
|
||||
|
||||
|
||||
@ -4,9 +4,18 @@ type Unregister = () => void;
|
||||
|
||||
let isLoaded = false;
|
||||
|
||||
const cssToInject = new Map<string, ((unregister: Unregister) => void) | undefined>();
|
||||
const cssToInjectFile = new Map<string, ((unregister: Unregister) => void) | undefined>();
|
||||
export const injectCSS = async (webContents: Electron.WebContents, css: string): Promise<Unregister> => {
|
||||
const cssToInject = new Map<
|
||||
string,
|
||||
((unregister: Unregister) => void) | undefined
|
||||
>();
|
||||
const cssToInjectFile = new Map<
|
||||
string,
|
||||
((unregister: Unregister) => void) | undefined
|
||||
>();
|
||||
export const injectCSS = async (
|
||||
webContents: Electron.WebContents,
|
||||
css: string,
|
||||
): Promise<Unregister> => {
|
||||
if (isLoaded) {
|
||||
const key = await webContents.insertCSS(css);
|
||||
return async () => await webContents.removeInsertedCSS(key);
|
||||
@ -20,7 +29,10 @@ export const injectCSS = async (webContents: Electron.WebContents, css: string):
|
||||
});
|
||||
};
|
||||
|
||||
export const injectCSSAsFile = async (webContents: Electron.WebContents, filepath: string): Promise<Unregister> => {
|
||||
export const injectCSSAsFile = async (
|
||||
webContents: Electron.WebContents,
|
||||
filepath: string,
|
||||
): Promise<Unregister> => {
|
||||
if (isLoaded) {
|
||||
const key = await webContents.insertCSS(fs.readFileSync(filepath, 'utf-8'));
|
||||
return async () => await webContents.removeInsertedCSS(key);
|
||||
@ -47,7 +59,9 @@ const setupCssInjection = (webContents: Electron.WebContents) => {
|
||||
});
|
||||
|
||||
cssToInjectFile.forEach(async (callback, filepath) => {
|
||||
const key = await webContents.insertCSS(fs.readFileSync(filepath, 'utf-8'));
|
||||
const key = await webContents.insertCSS(
|
||||
fs.readFileSync(filepath, 'utf-8'),
|
||||
);
|
||||
const remove = async () => await webContents.removeInsertedCSS(key);
|
||||
|
||||
callback?.(remove);
|
||||
|
||||
@ -1,21 +1,22 @@
|
||||
import { net } from 'electron';
|
||||
|
||||
export const getNetFetchAsFetch = () => (async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const url =
|
||||
typeof input === 'string'
|
||||
? new URL(input)
|
||||
: input instanceof URL
|
||||
export const getNetFetchAsFetch = () =>
|
||||
(async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const url =
|
||||
typeof input === 'string'
|
||||
? new URL(input)
|
||||
: input instanceof URL
|
||||
? input
|
||||
: new URL(input.url);
|
||||
|
||||
if (init?.body && !init.method) {
|
||||
init.method = 'POST';
|
||||
}
|
||||
if (init?.body && !init.method) {
|
||||
init.method = 'POST';
|
||||
}
|
||||
|
||||
const request = new Request(
|
||||
url,
|
||||
input instanceof Request ? input : undefined,
|
||||
);
|
||||
const request = new Request(
|
||||
url,
|
||||
input instanceof Request ? input : undefined,
|
||||
);
|
||||
|
||||
return net.fetch(request, init);
|
||||
}) as typeof fetch;
|
||||
return net.fetch(request, init);
|
||||
}) as typeof fetch;
|
||||
|
||||
@ -2,7 +2,7 @@ import fs from 'node:fs';
|
||||
|
||||
export const fileExists = (
|
||||
path: fs.PathLike,
|
||||
callbackIfExists: { (): void; (): void; (): void; },
|
||||
callbackIfExists: { (): void; (): void; (): void },
|
||||
callbackIfError: (() => void) | undefined = undefined,
|
||||
) => {
|
||||
fs.access(path, fs.constants.F_OK, (error) => {
|
||||
|
||||
@ -1,7 +1,13 @@
|
||||
import type { Config, MainPlugin, MenuPlugin, PreloadPlugin } from '../common';
|
||||
|
||||
export const defineMainPlugin = <ConfigType extends Config>(plugin: MainPlugin<ConfigType>) => plugin;
|
||||
export const defineMainPlugin = <ConfigType extends Config>(
|
||||
plugin: MainPlugin<ConfigType>,
|
||||
) => plugin;
|
||||
|
||||
export const definePreloadPlugin = <ConfigType extends Config>(plugin: PreloadPlugin<ConfigType>) => plugin;
|
||||
export const definePreloadPlugin = <ConfigType extends Config>(
|
||||
plugin: PreloadPlugin<ConfigType>,
|
||||
) => plugin;
|
||||
|
||||
export const defineMenuPlugin = <ConfigType extends Config>(plugin: MenuPlugin<ConfigType>) => plugin;
|
||||
export const defineMenuPlugin = <ConfigType extends Config>(
|
||||
plugin: MenuPlugin<ConfigType>,
|
||||
) => plugin;
|
||||
|
||||
Reference in New Issue
Block a user