Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
Added a very simple pause rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
Prince527GitHub committed Jun 30, 2024
1 parent 39bac80 commit af9950e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow, Tray, Menu } = require("electron");
const { app, BrowserWindow, Tray, Menu, ipcMain } = require("electron");
const path = require("path");

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
Expand All @@ -14,7 +14,10 @@ const createWindow = () => {
autoHideMenuBar: true,
resizable: false,
fullscreenable: false,
maximizable: false
maximizable: false,
webPreferences: {
preload: path.join(__dirname, "js/preload.js")
}
});

const icon = path.join(__dirname, "img/logo.png");
Expand Down Expand Up @@ -67,11 +70,16 @@ app.on("window-all-closed", () => {
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and import them here.
const { Client } = require("@xhayper/discord-rpc");
let isPaused = false;

app.on("ready", () => {
ipcMain.on("set-paused", (event, state) => isPaused = state);

const client = new Client({ clientId: "1253772057926303804" });

async function setActivity() {
if (isPaused) return client.user?.clearActivity();

const song = await (await fetch("https://gensokyoradio.net/api/station/playing/")).json();

client.user?.setActivity({
Expand Down
5 changes: 5 additions & 0 deletions src/js/preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { contextBridge, ipcRenderer } = require("electron")

contextBridge.exposeInMainWorld("electron", {
setPaused: (state) => ipcRenderer.send("set-paused", state)
});
8 changes: 6 additions & 2 deletions src/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ const title = document.getElementById("title");
const author = document.getElementById("author");
const progress = document.getElementById("progress");

const audio = new Audio("https://stream.gensokyoradio.net/3");
const audio = new Audio("https://stream.gensokyoradio.net/3/");

audio.play();

audio.volume = level;

async function getCurrent() {
const current = await (await fetch("https://gensokyoradio.net/api/station/playing")).json();
const current = await (await fetch("https://gensokyoradio.net/api/station/playing/")).json();

return current;
}
Expand Down Expand Up @@ -59,9 +59,13 @@ control.addEventListener("click", () => {
if (audio.volume === 0) {
control.innerHTML = `<i data-feather="pause"></i>`;
audio.volume = level;

window.electron.setPaused(false);
} else {
control.innerHTML = `<i data-feather="play"></i>`;
audio.volume = 0;

window.electron.setPaused(true);
}

feather.replace();
Expand Down

0 comments on commit af9950e

Please sign in to comment.