fix: minor fix

This commit is contained in:
JellyBrick
2023-09-04 17:45:25 +09:00
parent 9b6e3c850a
commit ce264c5d65
5 changed files with 16 additions and 22 deletions

View File

@ -242,7 +242,7 @@ export const mainMenuTemplate = (win: BrowserWindow): MenuTemplate => {
{ {
label: 'Enabled + app visible', label: 'Enabled + app visible',
type: 'radio', type: 'radio',
checked: !!(config.get('options.tray') && config.get('options.appVisible')), checked: config.get('options.tray') && config.get('options.appVisible'),
click() { click() {
config.setMenuOption('options.tray', true); config.setMenuOption('options.tray', true);
config.setMenuOption('options.appVisible', true); config.setMenuOption('options.appVisible', true);
@ -251,7 +251,7 @@ export const mainMenuTemplate = (win: BrowserWindow): MenuTemplate => {
{ {
label: 'Enabled + app hidden', label: 'Enabled + app hidden',
type: 'radio', type: 'radio',
checked: !!(config.get('options.tray') && !config.get('options.appVisible')), checked: config.get('options.tray') && !config.get('options.appVisible'),
click() { click() {
config.setMenuOption('options.tray', true); config.setMenuOption('options.tray', true);
config.setMenuOption('options.appVisible', false); config.setMenuOption('options.appVisible', false);
@ -316,7 +316,7 @@ export const mainMenuTemplate = (win: BrowserWindow): MenuTemplate => {
is.macOS() is.macOS()
? { ? {
label: 'Toggle DevTools', label: 'Toggle DevTools',
// Cannot use "toggleDevTools" role in MacOS // Cannot use "toggleDevTools" role in macOS
click() { click() {
const { webContents } = win; const { webContents } = win;
if (webContents.isDevToolsOpened()) { if (webContents.isDevToolsOpened()) {

View File

@ -1,15 +1,11 @@
import { ipcMain } from 'electron'; import { ipcMain } from 'electron';
import { Innertube } from 'youtubei.js'; import { Innertube } from 'youtubei.js';
import config from './config';
export default async () => { export default async () => {
const yt = await Innertube.create(); const yt = await Innertube.create();
ipcMain.handle('audio-url', async (_, videoID: string) => { ipcMain.handle('audio-url', async (_, videoID: string) => {
const info = await yt.getBasicInfo(videoID); const info = await yt.getBasicInfo(videoID);
const url = info.streaming_data?.formats[0].decipher(yt.session.player); return info.streaming_data?.formats[0].decipher(yt.session.player);
return url;
}); });
}; };

View File

@ -63,8 +63,8 @@ interface VolumeFade {
// Main class // Main class
export class VolumeFader { export class VolumeFader {
private media: HTMLMediaElement; private readonly media: HTMLMediaElement;
private logger: VolumeLogger | false; private readonly logger: VolumeLogger | false;
private scale: { private scale: {
internalToVolume: (level: number) => number; internalToVolume: (level: number) => number;
volumeToInternal: (level: number) => number; volumeToInternal: (level: number) => number;

View File

@ -1,10 +1,4 @@
import { createWriteStream, existsSync, mkdirSync, writeFileSync, } from 'node:fs';
import {
existsSync,
mkdirSync,
createWriteStream,
writeFileSync,
} from 'node:fs';
import { join } from 'node:path'; import { join } from 'node:path';
import { randomBytes } from 'node:crypto'; import { randomBytes } from 'node:crypto';
@ -12,7 +6,7 @@ import { app, BrowserWindow, dialog, ipcMain } from 'electron';
import { ClientType, Innertube, UniversalCache, Utils } from 'youtubei.js'; import { ClientType, Innertube, UniversalCache, Utils } from 'youtubei.js';
import is from 'electron-is'; import is from 'electron-is';
import ytpl from 'ytpl'; import ytpl from 'ytpl';
// REPLACE with youtubei getplaylist https://github.com/LuanRT/YouTube.js#getplaylistid // REPLACE with youtubei getplaylist https://github.com/LuanRT/YouTube.js#getplaylistid
import filenamify from 'filenamify'; import filenamify from 'filenamify';
import { Mutex } from 'async-mutex'; import { Mutex } from 'async-mutex';
import { createFFmpeg } from '@ffmpeg/ffmpeg'; import { createFFmpeg } from '@ffmpeg/ffmpeg';
@ -260,11 +254,10 @@ async function iterableStreamToMP3(
) { ) {
const chunks = []; const chunks = [];
let downloaded = 0; let downloaded = 0;
const total = contentLength;
for await (const chunk of stream) { for await (const chunk of stream) {
downloaded += chunk.length; downloaded += chunk.length;
chunks.push(chunk); chunks.push(chunk);
const ratio = downloaded / total; const ratio = downloaded / contentLength;
const progress = Math.floor(ratio * 100); const progress = Math.floor(ratio * 100);
sendFeedback(`Download: ${progress}%`, ratio); sendFeedback(`Download: ${progress}%`, ratio);
// 15% for download, 85% for conversion // 15% for download, 85% for conversion
@ -552,8 +545,7 @@ const getAndroidTvInfo = async (id: string): Promise<VideoInfo> => {
generate_session_locally: true, generate_session_locally: true,
retrieve_player: true, retrieve_player: true,
}); });
const info = await innertube.getBasicInfo(id, 'TV_EMBEDDED');
// GetInfo 404s with the bypass, so we use getBasicInfo instead // GetInfo 404s with the bypass, so we use getBasicInfo instead
// that's fine as we only need the streaming data // that's fine as we only need the streaming data
return info; return await innertube.getBasicInfo(id, 'TV_EMBEDDED');
}; };

View File

@ -6,10 +6,16 @@ export const ACTIONS = Actions;
export function goToNextPage() { export function goToNextPage() {
triggerAction(CHANNEL, Actions.NEXT); triggerAction(CHANNEL, Actions.NEXT);
} }
// for HTML
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-explicit-any
(global as any).goToNextPage = goToNextPage;
export function goToPreviousPage() { export function goToPreviousPage() {
triggerAction(CHANNEL, Actions.BACK); triggerAction(CHANNEL, Actions.BACK);
} }
// for HTML
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-explicit-any
(global as any).goToPreviousPage = goToPreviousPage;
export default { export default {
CHANNEL, CHANNEL,