Skip to content

Commit

Permalink
Attempt at fixing RPC bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
OrigamingWasTaken committed Jul 22, 2024
1 parent 17f739d commit 21eda59
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 35 deletions.
12 changes: 0 additions & 12 deletions frontend/src/windows/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@ events.on('ready', async () => {
/** Launch the process manager */
const watchdog = new AbloxWatchdog();
watchdog.start().catch(console.error);

// DiscordRPC
const settings = await loadSettings('integrations');
if (settings && settings.rpc.enable_rpc) {
await RPCController.set({
clientId: '1257650541677383721',
details: 'Currently in the launcher',
largeImage: 'appleblox',
largeImageText: 'AppleBlox Logo',
enableTime: true,
});
}
}, 500);
});

Expand Down
11 changes: 1 addition & 10 deletions frontend/src/windows/main/pages/Integrations.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import Panel from './Settings/Panel.svelte';
import { loadSettings, saveSettings } from '../ts/settings';
import { RPCController } from '../ts/rpc';
import { os } from '@neutralinojs/lib';
async function loadRPC(settings?: { [key: string]: any }) {
if (settings == null) {
Expand All @@ -12,15 +11,7 @@
return;
}
}
if (settings.rpc.enable_rpc) {
await RPCController.set({
clientId: '1257650541677383721',
details: 'Currently in the launcher',
largeImage: 'appleblox',
largeImageText: 'AppleBlox Logo',
enableTime: true,
}).catch(console.error);
} else {
if (!settings.rpc.enable_rpc) {
await RPCController.stop();
}
}
Expand Down
20 changes: 11 additions & 9 deletions frontend/src/windows/main/ts/roblox/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,9 @@ async function onGameEvent(data: GameEventInfo) {
break;
case 'GameDisconnected':
case 'GameLeaving':
const normalRpcOptions = {
clientId: '1257650541677383721',
details: 'Currently in the launcher',
largeImage: 'appleblox',
largeImageText: 'AppleBlox Logo',
enableTime: true,
};
RPCController.set(normalRpcOptions);
if (settings && settings.rpc.enable_rpc) {
RPCController.preset('inRobloxApp');
}
console.log('Disconnected/Left game');
break;
case 'GameJoinedEntry':
Expand Down Expand Up @@ -294,7 +289,7 @@ export async function launchRoblox(
Roblox.Window.setDesktopRes(maxRes[0], maxRes[2], 5);
showNotification({
title: 'Resolution changed',
content: "Your resolution was temporarily changed (5s) by the 'Spoof Resolution' setting.",
content: "Your resolution was temporarily changed (5s) by the 'Fix Resolution' setting.",
timeout: 10,
});
}
Expand All @@ -304,6 +299,12 @@ export async function launchRoblox(
await robloxInstance.start();
setRobloxConnected(true);
rbxInstance = robloxInstance;

const integrationsSettings = await loadSettings('integrations');
if (integrationsSettings && integrationsSettings.rpc.enable_rpc) {
RPCController.preset('inRobloxApp');
}

robloxInstance.on('gameEvent', onGameEvent);
robloxInstance.on('exit', async () => {
if (modSettings && modSettings.general.enable_mods) {
Expand All @@ -313,6 +314,7 @@ export async function launchRoblox(
console.log(`Removed mod files from "${path.join(robloxPath, 'Contents/Resources/')}"`);
});
}
RPCController.stop()
setRobloxConnected(false);
rbxInstance = null;
console.log('Roblox exited');
Expand Down
24 changes: 21 additions & 3 deletions frontend/src/windows/main/ts/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,32 @@ export class DiscordRPC {
}

let discordRPC: DiscordRPC | null = null;
const presets: {[key: string]: RPCOptions} = {
inRobloxApp: {
clientId: '1257650541677383721',
details: 'Currently browsing the menus',
state: 'In the launcher',
largeImage: 'roblox',
largeImageText: 'Roblox',
enableTime: true,
},
};

export class RPCController {
public static preset(preset: string) {
if (presets[preset]) {
this.set(presets[preset])
}
}

public static async set(options: RPCOptions) {
if (discordRPC) {
await discordRPC.update(options);
discordRPC.stop();
} else {
discordRPC = new DiscordRPC();
await discordRPC.start(options);
await os.execCommand(`pkill -f "discordrpc_ablox"`);
}
discordRPC = new DiscordRPC();
await discordRPC.start(options);
}

public static async stop() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "appleblox",
"version": "0.6.4",
"version": "0.6.5",
"description": "MacOS roblox launcher",
"main": "frontend/src/windows/main/main.ts",
"scripts": {
Expand Down

0 comments on commit 21eda59

Please sign in to comment.