feat: start implementing chromecast API

This commit is contained in:
JellyBrick
2024-02-13 11:39:23 +09:00
parent eabb3392b4
commit a689980049
8 changed files with 155 additions and 6 deletions

14
src/electron-chromecast.d.ts vendored Normal file
View File

@ -0,0 +1,14 @@
declare module '@jellybrick/electron-chromecast' {
export const chrome: typeof window.chrome;
export const requestHandler: (receiverList: Array<object>) => Promise<unknown>;
export const castSetting: {
devMode: boolean;
};
export const castConsole: {
log: (message: unknown[]) => void;
info: (message: unknown[]) => void;
warn: (message: unknown[]) => void;
error: (message: unknown[]) => void;
};
export const injectChromeCompatToObject: (obj: object) => void;
}

View File

@ -1,6 +1,8 @@
import { contextBridge, ipcRenderer, IpcRendererEvent, webFrame } from 'electron';
import is from 'electron-is';
import { injectChromeCompatToObject, chrome } from '@jellybrick/electron-chromecast';
import config from './config';
import {
@ -53,6 +55,8 @@ contextBridge.exposeInMainWorld(
'ELECTRON_RENDERER_URL',
process.env.ELECTRON_RENDERER_URL,
);
injectChromeCompatToObject(global);
contextBridge.exposeInMainWorld('caster', chrome);
const [path, script] = ipcRenderer.sendSync('get-renderer-script') as [string | null, string];
let blocked = true;

View File

@ -16,6 +16,8 @@ import { loadI18n, setLanguage, t as i18t } from '@/i18n';
import type { PluginConfig } from '@/types/plugins';
import type { YoutubePlayer } from '@/types/youtube-player';
window.chrome.cast = window.caster.cast;
let api: (Element & YoutubePlayer) | null = null;
let isPluginLoaded = false;
let isApiLoaded = false;

1
src/reset.d.ts vendored
View File

@ -22,6 +22,7 @@ declare global {
ipcRenderer: typeof electronIpcRenderer;
mainConfig: typeof config;
electronIs: typeof is;
caster: typeof window.chrome;
ELECTRON_RENDERER_URL: string | undefined;
/**
* YouTube Music internal variable (Last interaction time)

View File

@ -35,11 +35,6 @@ img {
user-select: none;
}
/* Hide cast button which doesn't work */
ytmusic-cast-button {
display: none !important;
}
/* Remove useless inaccessible button on top-right corner of the video player */
.ytp-chrome-top-buttons {
display: none !important;