mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
feat: use LoggerPrefix const instead of hardcoded string
This commit is contained in:
@ -48,6 +48,8 @@ import {
|
||||
loadAllMainPlugins,
|
||||
} from '@/loader/main';
|
||||
|
||||
import { LoggerPrefix } from '@/utils';
|
||||
|
||||
import type { PluginConfig } from '@/types/plugins';
|
||||
|
||||
// Catch errors and log them
|
||||
@ -221,7 +223,7 @@ function initTheme(win: BrowserWindow) {
|
||||
},
|
||||
() => {
|
||||
console.warn(
|
||||
'[YTMusic]',
|
||||
LoggerPrefix,
|
||||
`CSS file "${cssFile}" does not exist, ignoring`,
|
||||
);
|
||||
},
|
||||
@ -231,7 +233,7 @@ function initTheme(win: BrowserWindow) {
|
||||
|
||||
win.webContents.once('did-finish-load', () => {
|
||||
if (is.dev()) {
|
||||
console.log('[YTMusic]', 'did finish load');
|
||||
console.log(LoggerPrefix, 'did finish load');
|
||||
win.webContents.openDevTools();
|
||||
}
|
||||
});
|
||||
|
||||
@ -4,7 +4,7 @@ import { deepmerge } from 'deepmerge-ts';
|
||||
import { allPlugins, mainPlugins } from 'virtual:plugins';
|
||||
|
||||
import config from '@/config';
|
||||
import { startPlugin, stopPlugin } from '@/utils';
|
||||
import { LoggerPrefix, startPlugin, stopPlugin } from '@/utils';
|
||||
|
||||
import type { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
import type { BackendContext } from '@/types/contexts';
|
||||
@ -63,18 +63,18 @@ export const forceUnloadMainPlugin = async (
|
||||
)
|
||||
) {
|
||||
delete loadedPluginMap[id];
|
||||
console.log('[YTMusic]', `"${id}" plugin is unloaded`);
|
||||
console.log(LoggerPrefix, `"${id}" plugin is unloaded`);
|
||||
resolve();
|
||||
} else {
|
||||
console.log(
|
||||
'[YTMusic]',
|
||||
LoggerPrefix,
|
||||
`Cannot unload "${id}" plugin`,
|
||||
);
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('[YTMusic]', `Cannot unload "${id}" plugin: ${String(err)}`);
|
||||
console.log(LoggerPrefix, `Cannot unload "${id}" plugin: ${String(err)}`);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
@ -103,12 +103,12 @@ export const forceLoadMainPlugin = async (
|
||||
loadedPluginMap[id] = plugin;
|
||||
resolve();
|
||||
} else {
|
||||
console.log('[YTMusic]', `Cannot load "${id}" plugin`);
|
||||
console.log(LoggerPrefix, `Cannot load "${id}" plugin`);
|
||||
reject();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(
|
||||
'[YTMusic]',
|
||||
LoggerPrefix,
|
||||
`Cannot initialize "${id}" plugin: `,
|
||||
);
|
||||
console.trace(err);
|
||||
@ -118,7 +118,7 @@ export const forceLoadMainPlugin = async (
|
||||
};
|
||||
|
||||
export const loadAllMainPlugins = async (win: BrowserWindow) => {
|
||||
console.log('[YTMusic]', 'Loading all plugins');
|
||||
console.log(LoggerPrefix, 'Loading all plugins');
|
||||
const pluginConfigs = config.plugins.getPlugins();
|
||||
const queue: Promise<void>[] = [];
|
||||
|
||||
|
||||
@ -4,6 +4,8 @@ import { allPlugins } from 'virtual:plugins';
|
||||
import config from '@/config';
|
||||
import { setApplicationMenu } from '@/menu';
|
||||
|
||||
import { LoggerPrefix } from '@/utils';
|
||||
|
||||
import type { MenuContext } from '@/types/contexts';
|
||||
import type { BrowserWindow, MenuItemConstructorOptions } from 'electron';
|
||||
import type { PluginConfig } from '@/types/plugins';
|
||||
@ -37,9 +39,9 @@ export const forceLoadMenuPlugin = async (id: string, win: BrowserWindow) => {
|
||||
if (menu) menuTemplateMap[id] = await menu;
|
||||
else return;
|
||||
|
||||
console.log('[YTMusic]', `Successfully loaded '${id}::menu'`);
|
||||
console.log(LoggerPrefix, `Successfully loaded '${id}::menu'`);
|
||||
} catch (err) {
|
||||
console.error('[YTMusic]', `Cannot initialize '${id}::menu': `);
|
||||
console.error(LoggerPrefix, `Cannot initialize '${id}::menu': `);
|
||||
console.trace(err);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { deepmerge } from 'deepmerge-ts';
|
||||
import { allPlugins, preloadPlugins } from 'virtual:plugins';
|
||||
|
||||
import { startPlugin, stopPlugin } from '@/utils';
|
||||
import { LoggerPrefix, startPlugin, stopPlugin } from '@/utils';
|
||||
|
||||
import config from '@/config';
|
||||
|
||||
@ -32,10 +32,10 @@ export const forceUnloadPreloadPlugin = (id: string) => {
|
||||
typeof loadedPluginMap[id].preload !== 'function' && loadedPluginMap[id].preload
|
||||
)
|
||||
) {
|
||||
console.log('[YTMusic]', `"${id}" plugin is unloaded`);
|
||||
console.log(LoggerPrefix, `"${id}" plugin is unloaded`);
|
||||
delete loadedPluginMap[id];
|
||||
} else {
|
||||
console.error('[YTMusic]', `Cannot stop "${id}" plugin`);
|
||||
console.error(LoggerPrefix, `Cannot stop "${id}" plugin`);
|
||||
}
|
||||
};
|
||||
|
||||
@ -59,10 +59,10 @@ export const forceLoadPreloadPlugin = (id: string) => {
|
||||
loadedPluginMap[id] = plugin;
|
||||
}
|
||||
|
||||
console.log('[YTMusic]', `"${id}" plugin is loaded`);
|
||||
console.log(LoggerPrefix, `"${id}" plugin is loaded`);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
'[YTMusic]',
|
||||
LoggerPrefix,
|
||||
`Cannot initialize "${id}" plugin: `,
|
||||
);
|
||||
console.trace(err);
|
||||
|
||||
@ -2,7 +2,7 @@ import { deepmerge } from 'deepmerge-ts';
|
||||
|
||||
import { rendererPlugins } from 'virtual:plugins';
|
||||
|
||||
import { startPlugin, stopPlugin } from '@/utils';
|
||||
import { LoggerPrefix, startPlugin, stopPlugin } from '@/utils';
|
||||
|
||||
import type { RendererContext } from '@/types/contexts';
|
||||
import type { PluginConfig, PluginDef } from '@/types/plugins';
|
||||
@ -51,9 +51,9 @@ export const forceUnloadRendererPlugin = (id: string) => {
|
||||
typeof plugin?.renderer !== 'function' && plugin?.renderer
|
||||
)
|
||||
) {
|
||||
console.log('[YTMusic]', `"${id}" plugin is unloaded`);
|
||||
console.log(LoggerPrefix, `"${id}" plugin is unloaded`);
|
||||
} else {
|
||||
console.error('[YTMusic]', `Cannot stop "${id}" plugin`);
|
||||
console.error(LoggerPrefix, `Cannot stop "${id}" plugin`);
|
||||
}
|
||||
};
|
||||
|
||||
@ -87,9 +87,9 @@ export const forceLoadRendererPlugin = (id: string) => {
|
||||
document.adoptedStyleSheets = [...document.adoptedStyleSheets, ...styleSheetList];
|
||||
}
|
||||
|
||||
console.log('[YTMusic]', `"${id}" plugin is loaded`);
|
||||
console.log(LoggerPrefix, `"${id}" plugin is loaded`);
|
||||
} else {
|
||||
console.log('[YTMusic]', `Cannot initialize "${id}" plugin`);
|
||||
console.log(LoggerPrefix, `Cannot initialize "${id}" plugin`);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -13,6 +13,8 @@ import type {
|
||||
RendererPluginLifecycle,
|
||||
} from '@/types/plugins';
|
||||
|
||||
export const LoggerPrefix = '[YTMusic]';
|
||||
|
||||
export const createPlugin = <
|
||||
BackendProperties,
|
||||
PreloadProperties,
|
||||
@ -103,14 +105,14 @@ export const startPlugin = <Config extends PluginConfig>(
|
||||
);
|
||||
|
||||
console.log(
|
||||
'[YTMusic]', `Executed ${id}::${options.ctx} in ${
|
||||
LoggerPrefix, `Executed ${id}::${options.ctx} in ${
|
||||
performance.now() - start
|
||||
} ms`,
|
||||
);
|
||||
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.error('[YTMusic]', `Failed to start ${id}::${options.ctx}`);
|
||||
console.error(LoggerPrefix, `Failed to start ${id}::${options.ctx}`);
|
||||
console.trace(err);
|
||||
return false;
|
||||
}
|
||||
@ -134,14 +136,14 @@ export const stopPlugin = <Config extends PluginConfig>(
|
||||
);
|
||||
|
||||
console.log(
|
||||
'[YTMusic]', `Executed ${id}::${options.ctx} in ${
|
||||
LoggerPrefix, `Executed ${id}::${options.ctx} in ${
|
||||
performance.now() - start
|
||||
} ms`,
|
||||
);
|
||||
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.error('[YTMusic]', `Failed to execute ${id}::${options.ctx}`);
|
||||
console.error(LoggerPrefix, `Failed to execute ${id}::${options.ctx}`);
|
||||
console.trace(err);
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user