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