Add ts checking

pull/191/head
Andrew 3 years ago
parent db2dd3e008
commit 14f45830f2

@ -9,7 +9,7 @@ const {
clipboard,
} = require("electron");
const {autoUpdater} = require("electron-updater");
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true;
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = "true";
const fs = require("fs");
const path = require("path");
@ -26,6 +26,7 @@ function createWindow() {
autoHideMenuBar: true,
show: false,
icon: __dirname + "/assets/images/icon.png",
// @ts-ignore
spellcheck: false,
webPreferences: {
nodeIntegration: true,
@ -262,6 +263,9 @@ ipcMain.on("autoUpdate", (event, status) => {
(_event, releaseNotes, releaseName) => {
// For macOS
if (process.platform === "darwin") {
/**
* @type {Electron.MessageBoxOptions}
*/
const dialogOpts = {
type: "info",
buttons: [i18n("Download"), i18n("No")],
@ -281,6 +285,9 @@ ipcMain.on("autoUpdate", (event, status) => {
}
// For Windows and Linux
else {
/**
* @type {Electron.MessageBoxOptions}
*/
const dialogOpts = {
type: "info",
buttons: [i18n("Update"), i18n("No")],
@ -305,6 +312,9 @@ ipcMain.on("autoUpdate", (event, status) => {
});
autoUpdater.on("update-downloaded", (_event, releaseNotes, releaseName) => {
/**
* @type {Electron.MessageBoxOptions}
*/
const dialogOpts = {
type: "info",
buttons: [i18n("Restart"), i18n("Later")],
@ -315,7 +325,7 @@ autoUpdater.on("update-downloaded", (_event, releaseNotes, releaseName) => {
if (returnValue.response === 0) {
autoUpdater.quitAndInstall();
} else {
autoUpdater.autoInstallOnAppQuit();
autoUpdater.autoInstallOnAppQuit;
}
});
});

28
package-lock.json generated

@ -1,12 +1,12 @@
{
"name": "ytdownloader",
"version": "3.15.0",
"version": "3.16.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "ytdownloader",
"version": "3.15.0",
"version": "3.16.1",
"license": "GPL-3.0",
"dependencies": {
"electron-updater": "^5.3.0",
@ -14,7 +14,8 @@
},
"devDependencies": {
"electron": "^27.0.2",
"electron-builder": "^24.6.4"
"electron-builder": "^24.6.4",
"typescript": "^5.3.3"
}
},
"node_modules/@develar/schema-utils": {
@ -1108,6 +1109,19 @@
"typescript": "^4.0.2"
}
},
"node_modules/config-file-ts/node_modules/typescript": {
"version": "4.9.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz",
"integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==",
"dev": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=4.2.0"
}
},
"node_modules/core-util-is": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
@ -3028,16 +3042,16 @@
}
},
"node_modules/typescript": {
"version": "4.9.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz",
"integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==",
"version": "5.3.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz",
"integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==",
"dev": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=4.2.0"
"node": ">=14.17"
}
},
"node_modules/undici-types": {

@ -35,7 +35,8 @@
"description": "Download videos and audios from YouTube and many other sites",
"devDependencies": {
"electron": "^27.0.2",
"electron-builder": "^24.6.4"
"electron-builder": "^24.6.4",
"typescript": "^5.3.3"
},
"build": {
"productName": "YTDownloader",

@ -1,5 +1,9 @@
const electron = require("electron")
const electron = require("electron");
/**
*
* @param {string} id
* @returns {any}
*/
function getId(id) {
return document.getElementById(id);
}
@ -33,16 +37,15 @@ getId("menuIcon").addEventListener("click", () => {
}
});
getId("themeToggle").addEventListener("change", ()=>{
document.documentElement.setAttribute("theme", getId("themeToggle").value)
localStorage.setItem("theme", getId("themeToggle").value)
})
getId("themeToggle").addEventListener("change", () => {
document.documentElement.setAttribute("theme", getId("themeToggle").value);
localStorage.setItem("theme", getId("themeToggle").value);
});
const storageTheme = localStorage.getItem("theme");
if (storageTheme){
document.documentElement.setAttribute("theme", storageTheme)
getId("themeToggle").value = storageTheme
if (storageTheme) {
document.documentElement.setAttribute("theme", storageTheme);
getId("themeToggle").value = storageTheme;
}
////
@ -78,7 +81,7 @@ function scrollFunction() {
// Function to scroll go to top
getId("goToTop").addEventListener("click", () => {
window.scrollTo({ top: 0, behavior: "smooth" });
window.scrollTo({top: 0, behavior: "smooth"});
});
// Showing and hiding error details
@ -86,9 +89,11 @@ function toggleErrorDetails() {
const status = getId("errorDetails").style.display;
if (status === "none") {
getId("errorDetails").style.display = "block";
// @ts-ignore
getId("errorBtn").textContent = i18n.__("Error Details") + " ▲";
} else {
getId("errorDetails").style.display = "none";
// @ts-ignore
getId("errorBtn").textContent = i18n.__("Error Details") + " ▼";
}
}
@ -98,15 +103,16 @@ function toggleErrorDetails() {
function copyErrorToClipboard() {
const error = getId("errorDetails").textContent;
electron.clipboard.writeText(error);
// @ts-ignore
showPopup(i18n.__("Copied text"));
}
// Popup message
function showPopup(text) {
console.log("Triggered showpopup")
getId("popupText").textContent = text
console.log("Triggered showpopup");
getId("popupText").textContent = text;
getId("popupText").style.display = "inline-block";
setTimeout(() => {
getId("popupText").style.display = "none"
getId("popupText").style.display = "none";
}, 2200);
}
}

@ -57,11 +57,11 @@ if (!fs.existsSync(ffmpegPath)) {
console.log("ffmpeg:", ffmpeg);
if (localStorage.getItem("preferredVideoQuality")) {
preferredVideoQuality = localStorage.getItem("preferredVideoQuality");
const preferredVideoQuality = localStorage.getItem("preferredVideoQuality");
getId('select').value = preferredVideoQuality
}
if (localStorage.getItem("preferredAudioQuality")) {
preferredAudioQuality = localStorage.getItem("preferredAudioQuality");
const preferredAudioQuality = localStorage.getItem("preferredAudioQuality");
getId("audioSelect").value = preferredAudioQuality;
}
@ -70,6 +70,11 @@ let filenameFormat = "%(playlist_index)s.%(title)s.%(ext)s";
let playlistIndex = 1;
let playlistEnd = "";
/**
*
* @param {string} id
* @returns {any}
*/
function getId(id) {
return document.getElementById(id);
}
@ -97,6 +102,9 @@ const playlistTxt = "Downloading playlist: ";
const videoIndex = "Downloading item ";
const oldVideoIndex = "Downloading video ";
/**
* @param {string} type
*/
function download(type) {
// Config file
let configArg = "";
@ -121,6 +129,7 @@ function download(type) {
cookieArg = "";
}
let count = 0;
let subs, subLangs;
let playlistName;
// If subtitles are checked
@ -135,7 +144,7 @@ function download(type) {
hideOptions();
let quality, format, downloadProcess, videoType;
let quality, format, downloadProcess, videoType, audioQuality;
if (type === "video") {
quality = getId("select").value;
videoType = getId("videoTypeSelect").value;
@ -328,7 +337,7 @@ function managePlaylistRange() {
playlistIndex = Number(getId("playlistIndex").value);
}
if (getId("playlistEnd").value) {
playlistEnd = Number(getId("playlistEnd").value);
playlistEnd = getId("playlistEnd").value;
}
console.log(`Range: ${playlistIndex}:${playlistEnd}`);
if (playlistIndex > 0) {
@ -396,6 +405,7 @@ function hideOptions(justHide = false) {
function downloadThumbnails() {
let count = 0;
let playlistName;
hideOptions();
nameFormatting();
managePlaylistRange();
@ -465,6 +475,7 @@ function downloadThumbnails() {
// Download video links
function saveLinks() {
let count = 0;
let playlistName;
hideOptions();
nameFormatting();
managePlaylistRange();
@ -565,7 +576,6 @@ function openFolder(location) {
function closeMenu() {
getId("menuIcon").style.transform = "rotate(0deg)";
menuIsOpen = false;
let count = 0;
let opacity = 1;
const fade = setInterval(() => {
@ -573,7 +583,7 @@ function closeMenu() {
clearInterval(fade);
} else {
opacity -= 0.1;
getId("menu").style.opacity = opacity;
getId("menu").style.opacity = String(opacity);
count++;
}
}, 50);
@ -600,7 +610,7 @@ audioToggle.addEventListener("click", (event) => {
});
getId("select").addEventListener("change", () => {
value = getId("select").value;
const value = getId("select").value;
if (value == "best" || value == "worst" || value == "useConfig") {
getId("typeSelectBox").style.display = "none";
} else {

@ -3,17 +3,17 @@ if (storageTheme){
document.documentElement.setAttribute("theme", storageTheme)
}
let rightToLeft = false;
let rightToLeft = "false";
if (localStorage.getItem("rightToLeft")) {
rightToLeft = localStorage.getItem("rightToLeft");
}
if (rightToLeft == "true") {
document.querySelectorAll(".prefBox").forEach((item) => {
document.querySelectorAll(".prefBox").forEach((/** @type {HTMLElement} */ item) => {
item.style.flexDirection = "row-reverse";
});
} else {
console.log("Change to left to right");
document.querySelectorAll(".prefBox").forEach((item) => {
document.querySelectorAll(".prefBox").forEach((/** @type {HTMLElement} */ item) => {
item.style.flexDirection = "row";
});
}
@ -21,6 +21,11 @@ let downloadPath = localStorage.getItem("downloadPath");
getId("path").textContent = downloadPath;
const { ipcRenderer } = require("electron");
/**
*
* @param {string} id
* @returns {any}
*/
function getId(id) {
return document.getElementById(id);
}
@ -81,11 +86,11 @@ function changeLanguage() {
const language = getId("select").value;
localStorage.setItem("language", language);
if (language === "fa") {
rightToLeft = true;
localStorage.setItem("rightToLeft", true);
rightToLeft = "true";
localStorage.setItem("rightToLeft", "true");
} else {
rightToLeft = false;
localStorage.setItem("rightToLeft", false);
rightToLeft = "false";
localStorage.setItem("rightToLeft", "false");
}
}
@ -179,10 +184,10 @@ getId("maxDownloads").addEventListener("input", ()=>{
const number = Number(getId("maxDownloads").value)
if (number < 1){
localStorage.setItem("maxActiveDownloads", 1)
localStorage.setItem("maxActiveDownloads", "1")
}
else{
localStorage.setItem("maxActiveDownloads", number)
localStorage.setItem("maxActiveDownloads", String(number))
}
})

@ -12,7 +12,6 @@ const fs = require("fs");
/////////////////////////////////////
// Do not change the lines at the top
/////////////////////////////////////
const path = require("path");
const {shell, ipcRenderer, clipboard} = require("electron");
const {default: YTDlpWrap} = require("yt-dlp-wrap-plus");
@ -91,7 +90,11 @@ let controllers = new Object();
let preferredVideoQuality = 720;
let preferredAudioQuality = "";
let preferredVideoCodec = "avc1";
/**
*
* @param {string} id
* @returns {any}
*/
function getId(id) {
return document.getElementById(id);
}
@ -258,14 +261,18 @@ async function getInfo(url) {
// Cleaning text
getId("videoFormatSelect").innerHTML = "";
getId("audioFormatSelect").innerHTML = "";
getId("startTime").value = "";
const startTime = getId("startTime");
startTime.value = "";
getId("endTime").value = "";
getId("errorBtn").style.display = "none";
getId("errorDetails").style.display = "none";
getId("errorDetails").textContent = "";
if (localStorage.getItem("preferredVideoQuality")) {
preferredVideoQuality = localStorage.getItem("preferredVideoQuality");
preferredVideoQuality = Number(
localStorage.getItem("preferredVideoQuality")
);
}
if (localStorage.getItem("preferredAudioQuality")) {
preferredAudioQuality = localStorage.getItem("preferredAudioQuality");
@ -291,6 +298,7 @@ async function getInfo(url) {
}
let validInfo = true;
let info = "";
const infoProcess = cp.spawn(
@ -331,22 +339,29 @@ async function getInfo(url) {
infoProcess.on("close", () => {
if (validInfo) {
info = JSON.parse(info);
console.log(info);
/**
* @typedef {import("./types").info} info
* @type {info}
*/
const parsedInfo = JSON.parse(info);
console.log(parsedInfo);
title = info.title;
id = info.id;
thumbnail = info.thumbnail;
duration = info.duration;
title = parsedInfo.title;
id = parsedInfo.id;
thumbnail = parsedInfo.thumbnail;
duration = parsedInfo.duration;
/**
* @typedef {import("./types").format} format
* @type {format[]}
*/
const formats = info.formats;
const formats = parsedInfo.formats;
console.log(formats);
/**
* @type {HTMLInputElement[]}
*/
// @ts-ignore
const urlElements = document.querySelectorAll(".url");
urlElements.forEach((element) => {
element.value = url;
});
@ -753,7 +768,6 @@ getId("extractBtn").addEventListener("click", () => {
download("extract");
currentDownloads++;
} else {
// Handling active downloads for extracting audio
manageAdvanced(duration);
const range1 = rangeOption;
const range2 = rangeCmd;
@ -978,7 +992,7 @@ function download(
let audioFormat;
if (ext === "mp4") {
if (!audioExtensionList.length == 0) {
if (!(audioExtensionList.length == 0)) {
if (audioExtensionList.includes("m4a")) {
audioFormat = "+m4a";
} else {
@ -1220,7 +1234,6 @@ function renameTitle() {
// Opening windows
function closeMenu() {
getId("menuIcon").style.transform = "rotate(0deg)";
menuIsOpen = false;
let count = 0;
let opacity = 1;
const fade = setInterval(() => {
@ -1229,7 +1242,7 @@ function closeMenu() {
getId("menu").style.display = "none";
} else {
opacity -= 0.1;
getId("menu").style.opacity = opacity;
getId("menu").style.opacity = String(opacity);
count++;
}
}, 50);
@ -1245,7 +1258,6 @@ function hideHidden() {
}
// Menu
getId("preferenceWin").addEventListener("click", () => {
closeMenu();
ipcRenderer.send("load-page", __dirname + "/preferences.html");

@ -1,9 +1,6 @@
function getId(id) {
return document.getElementById(id);
}
function querySelector(element) {
return document.querySelector(element);
}
const i18n = new (require("../translations/i18n"))();
// Translating texts

11
src/types.d.ts vendored

@ -10,8 +10,19 @@ type format = {
video_ext: string,
audio_ext: string,
filesize_approx?: number,
tbr: number,
fps: number,
}
type info = {
title: string,
id: string,
thumbnail: string,
duration: number,
formats: format[],
}
export {
format,
info
}

@ -0,0 +1,6 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
}
}
Loading…
Cancel
Save