diff --git a/src/index.js b/src/index.js
index 3edb8b8..0fe428b 100644
--- a/src/index.js
+++ b/src/index.js
@@ -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.
@@ -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");
@@ -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({
diff --git a/src/js/preload.js b/src/js/preload.js
new file mode 100644
index 0000000..859f59b
--- /dev/null
+++ b/src/js/preload.js
@@ -0,0 +1,5 @@
+const { contextBridge, ipcRenderer } = require("electron")
+
+contextBridge.exposeInMainWorld("electron", {
+ setPaused: (state) => ipcRenderer.send("set-paused", state)
+});
\ No newline at end of file
diff --git a/src/js/script.js b/src/js/script.js
index 6992f90..adcacc6 100644
--- a/src/js/script.js
+++ b/src/js/script.js
@@ -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;
}
@@ -59,9 +59,13 @@ control.addEventListener("click", () => {
if (audio.volume === 0) {
control.innerHTML = ``;
audio.volume = level;
+
+ window.electron.setPaused(false);
} else {
control.innerHTML = ``;
audio.volume = 0;
+
+ window.electron.setPaused(true);
}
feather.replace();