Skip to content

Commit c227cfa

Browse files
Fix Discord RPC [release]
1 parent acbf14a commit c227cfa

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

local/start.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,18 @@
120120
var rpcinfo;
121121
function discordrpc() {
122122
try {
123-
rpcinfo = document.getElementById("content-frame").contentWindow.window.rpcinfo;
123+
// Try to get RPC info from the iframe content
124+
const frameWindow = document.getElementById("content-frame").contentWindow;
125+
if (frameWindow && frameWindow.rpcinfo) {
126+
rpcinfo = frameWindow.rpcinfo;
127+
// Update the Discord RPC status in the main process
128+
if (window.electronAPI && window.electronAPI.updateRpcStatus) {
129+
window.electronAPI.updateRpcStatus(rpcinfo);
130+
}
131+
}
124132
} catch (error) {
125-
console.error('Error in discordrpc:', error);
133+
// Silently handle cross-origin errors or other issues
134+
// This is expected when the iframe contains external content
126135
}
127136
}
128137
setInterval(discordrpc, 15000);

src/main/index.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,7 @@ ipcMain.handle('window-is-maximized', (event) => {
7777
});
7878

7979
ipcMain.handle('get-rpc-info', async (event) => {
80-
if (!win) return '';
81-
try {
82-
const status = await win.webContents.executeJavaScript('window.rpcinfo || ""');
83-
currentStatus = status || 'Playing Sploder';
84-
return status;
85-
} catch (error) {
86-
return '';
87-
}
80+
return currentStatus;
8881
});
8982

9083
ipcMain.handle('update-rpc-status', (event, status) => {

src/renderer/preload.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
77
closeWindow: () => ipcRenderer.invoke('window-close'),
88
isWindowMaximized: () => ipcRenderer.invoke('window-is-maximized'),
99
getRpcInfo: () => ipcRenderer.invoke('get-rpc-info'),
10+
updateRpcStatus: (status) => ipcRenderer.invoke('update-rpc-status', status),
1011
onWindowStateChange: (callback) => {
1112
ipcRenderer.on('window-state-change', (_, isMaximized) => {
1213
callback(isMaximized);

0 commit comments

Comments
 (0)