Skip to content

Commit

Permalink
External API dependency removed + AutoUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
nishantshah977 committed May 26, 2024
1 parent 43e3468 commit f1f29f2
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 3,933 deletions.
50 changes: 47 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
const { app, BrowserWindow, shell } = require("electron");
const { app, BrowserWindow, shell, ipcMain } = require("electron");
const { autoUpdater } = require("electron-updater");
const ytubes = require("ytubes");
const ytdl = require("ytdl-core");
const path = require("path");

let win;
const createWindow = () => {

function createWindow() {
win = new BrowserWindow({
width: 800,
height: 600,
autoHideMenuBar: true,
icon: "./public/logo.jpg",
webPreferences: {
preload: path.join(__dirname, "preload.js"),
contextIsolation: true,
enableRemoteModule: false,
},
});

win.webContents.setWindowOpenHandler(({ url }) => {
Expand All @@ -14,8 +25,41 @@ const createWindow = () => {
});

win.loadFile("./public/index.html");
};
}

app.whenReady().then(() => {
createWindow();
autoUpdater.checkForUpdatesAndNotify();
});

app.on("window-all-closed", () => {
if (process.platform !== "darwin") app.quit();
});

/*
IPC Start
*/

ipcMain.on("fetch-music", async (event, query) => {
try {
const musicResults = await ytubes.getMusic(query);
event.sender.send("music-fetched", musicResults);
} catch (error) {
console.error("Error fetching music:", error);
event.sender.send("music-fetched", { error: error.message });
}
});

ipcMain.on("stream-music", async (event, videoId) => {
try {
const music = await ytdl.getInfo(videoId);
const audioFormat = ytdl.chooseFormat(music.formats, {
quality: "highestaudio",
filter: "audioonly",
});
event.sender.send("stream-url", audioFormat.url);
} catch (error) {
console.error("Error streaming music:", error);
event.sender.send("stream-url", { error: error.message });
}
});
Loading

0 comments on commit f1f29f2

Please sign in to comment.