mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 20:01:47 +00:00
feat: use '.call' instead of '.bind'
This commit is contained in:
@ -165,7 +165,7 @@ const initHook = (win: BrowserWindow) => {
|
|||||||
const mainPlugin = getAllLoadedMainPlugins()[id];
|
const mainPlugin = getAllLoadedMainPlugins()[id];
|
||||||
if (mainPlugin) {
|
if (mainPlugin) {
|
||||||
if (config.enabled && typeof mainPlugin.backend !== 'function') {
|
if (config.enabled && typeof mainPlugin.backend !== 'function') {
|
||||||
mainPlugin.backend?.onConfigChange?.bind(mainPlugin.backend)?.(config);
|
mainPlugin.backend?.onConfigChange?.call(mainPlugin.backend, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -55,7 +55,7 @@ async function onApiLoaded() {
|
|||||||
|
|
||||||
for (const [id, plugin] of Object.entries(getAllLoadedRendererPlugins())) {
|
for (const [id, plugin] of Object.entries(getAllLoadedRendererPlugins())) {
|
||||||
if (typeof plugin.renderer !== 'function') {
|
if (typeof plugin.renderer !== 'function') {
|
||||||
await plugin.renderer?.onPlayerApiReady?.bind(plugin.renderer)?.(api!, createContext(id));
|
await plugin.renderer?.onPlayerApiReady?.call(plugin.renderer, api!, createContext(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ async function onApiLoaded() {
|
|||||||
if (api) {
|
if (api) {
|
||||||
const plugin = getLoadedRendererPlugin(id);
|
const plugin = getLoadedRendererPlugin(id);
|
||||||
if (plugin && typeof plugin.renderer !== 'function') {
|
if (plugin && typeof plugin.renderer !== 'function') {
|
||||||
plugin.renderer?.onPlayerApiReady?.bind(plugin.renderer)?.(api, createContext(id));
|
plugin.renderer?.onPlayerApiReady?.call(plugin.renderer, api, createContext(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -153,7 +153,7 @@ async function onApiLoaded() {
|
|||||||
(_event, id: string, newConfig: PluginConfig) => {
|
(_event, id: string, newConfig: PluginConfig) => {
|
||||||
const plugin = getAllLoadedRendererPlugins()[id];
|
const plugin = getAllLoadedRendererPlugins()[id];
|
||||||
if (plugin && typeof plugin.renderer !== 'function') {
|
if (plugin && typeof plugin.renderer !== 'function') {
|
||||||
plugin.renderer?.onConfigChange?.bind(plugin.renderer)?.(newConfig);
|
plugin.renderer?.onConfigChange?.call(plugin.renderer, newConfig);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@ -85,8 +85,6 @@ export const startPlugin = <Config extends PluginConfig>(
|
|||||||
>
|
>
|
||||||
)?.start;
|
)?.start;
|
||||||
|
|
||||||
if (!lifecycle) return null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// HACK: for bind 'this' to context
|
// HACK: for bind 'this' to context
|
||||||
const defContext = def[options.ctx];
|
const defContext = def[options.ctx];
|
||||||
@ -100,7 +98,9 @@ export const startPlugin = <Config extends PluginConfig>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const start = performance.now();
|
const start = performance.now();
|
||||||
lifecycle.bind(def[options.ctx])(
|
|
||||||
|
lifecycle?.call(
|
||||||
|
defContext,
|
||||||
options.context as Config & typeof options.context,
|
options.context as Config & typeof options.context,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ export const startPlugin = <Config extends PluginConfig>(
|
|||||||
} ms`,
|
} ms`,
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return lifecycle ? true : null;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(LoggerPrefix, `Failed to start ${id}::${options.ctx}`);
|
console.error(LoggerPrefix, `Failed to start ${id}::${options.ctx}`);
|
||||||
console.trace(err);
|
console.trace(err);
|
||||||
@ -132,7 +132,8 @@ export const stopPlugin = <Config extends PluginConfig>(
|
|||||||
try {
|
try {
|
||||||
const stop = defCtx.stop;
|
const stop = defCtx.stop;
|
||||||
const start = performance.now();
|
const start = performance.now();
|
||||||
stop.bind(def[options.ctx])(
|
stop.call(
|
||||||
|
def[options.ctx],
|
||||||
options.context as Config & typeof options.context,
|
options.context as Config & typeof options.context,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user