Skip to content

Commit

Permalink
RPC Stability
Browse files Browse the repository at this point in the history
  • Loading branch information
OrigamingWasTaken committed Jul 17, 2024
1 parent 1a42504 commit 9aba492
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 124 deletions.
56 changes: 25 additions & 31 deletions frontend/src/windows/main/main.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,54 @@
import "./app.css";
import "./ts/window";
import "./ts/roblox/path"
import "./ts/debugging";
import App from "./App.svelte";
import { events, init, os } from "@neutralinojs/lib";
import { version } from "../../../../package.json";
import { DiscordRPC } from "./ts/rpc";
import { loadSettings } from "./ts/settings";
import { AbloxWatchdog } from "./ts/watchdog";
import './app.css';
import './ts/window';
import './ts/roblox/path';
import './ts/debugging';
import App from './App.svelte';
import { events, init, os } from '@neutralinojs/lib';
import { version } from '../../../../package.json';
import { RPCController } from './ts/rpc';
import { loadSettings } from './ts/settings';
import { AbloxWatchdog } from './ts/watchdog';

// Initialize NeutralinoJS
init();

// Store the RPC instance
let rpc: DiscordRPC | null = null;

// When NeutralinoJS is ready:
events.on("ready", async () => {
events.on('ready', async () => {
setTimeout(async () => {
console.log("\n");
console.log("===========");
console.log('\n');
console.log('===========');
console.log(`AppleBlox v${version}`);
console.log(`Current Time: ${new Date().toLocaleString()}`);
console.log(`NeutralinoJS Version: ${window.NL_VERSION}`);
console.log(`${(await os.execCommand("uname -a")).stdOut.trim()}`);
console.log("===========");
console.log(`${(await os.execCommand('uname -a')).stdOut.trim()}`);
console.log('===========');

/** Launch the process manager */
const watchdog = new AbloxWatchdog();
watchdog.start().catch(console.error);

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

// Cleanup when the application is closing
events.on("windowClose", async () => {
if (rpc) {
await rpc.destroy();
}
events.on('windowClose', async () => {
await RPCController.stop();
});

const app = new App({
// @ts-expect-error
target: document.getElementById("app"),
target: document.getElementById('app'),
});

export default app;
128 changes: 60 additions & 68 deletions frontend/src/windows/main/pages/Integrations.svelte
Original file line number Diff line number Diff line change
@@ -1,136 +1,128 @@
<script lang="ts">
import type { SettingsPanel } from "@/types/settings";
import Panel from "./Settings/Panel.svelte";
import { loadSettings, saveSettings } from "../ts/settings";
import { DiscordRPC } from "../ts/rpc";
import { os } from "@neutralinojs/lib";
let rpc: DiscordRPC | null = null;
import type { SettingsPanel } from '@/types/settings';
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) {
settings = await loadSettings("integrations");
settings = await loadSettings('integrations');
if (settings == null) {
return;
}
}
if (settings.rpc.enable_rpc) {
if (!rpc) {
rpc = new DiscordRPC();
}
await rpc
.start({
clientId: "1257650541677383721",
details: "Currently in the launcher",
largeImage: "appleblox",
largeImageText: "AppleBlox Logo",
enableTime: true,
})
.catch(console.error);
} else if (rpc) {
await rpc.destroy();
rpc = null;
await RPCController.set({
clientId: '1257650541677383721',
details: 'Currently in the launcher',
largeImage: 'appleblox',
largeImageText: 'AppleBlox Logo',
enableTime: true,
}).catch(console.error);
} else {
await RPCController.stop();
}
}
function settingsChanged(o: { [key: string]: any }) {
saveSettings("integrations", o);
saveSettings('integrations', o);
loadRPC(o);
}
const panelOpts: SettingsPanel = {
name: "Integrations",
description: "Configure the integrations between AppleBlox and various apps like Discord with Roblox",
id: "integrations",
name: 'Integrations',
description: 'Configure the integrations between AppleBlox and various apps like Discord with Roblox',
id: 'integrations',
sections: [
{
name: "Activity Notifications",
name: 'Activity Notifications',
description: "Notifications about the game you're playing & your server location",
id: "activity",
id: 'activity',
interactables: [
{
label: "See server location when joining a game",
description: "You will be notified of your current server location (EU, US, etc..)",
id: "notify_location",
label: 'See server location when joining a game',
description: 'You will be notified of your current server location (EU, US, etc..)',
id: 'notify_location',
options: {
type: "boolean",
type: 'boolean',
state: true,
},
}
},
],
},
{
name: "Bloxstrap SDK",
description: "Replica of the Bloxstrap SDK. Makes it so games can control certain aspect of your Roblox instance",
id: "sdk",
name: 'Bloxstrap SDK',
description: 'Replica of the Bloxstrap SDK. Makes it so games can control certain aspect of your Roblox instance',
id: 'sdk',
interactables: [
{
label: "Enable SDK",
description: "Activate a compatibility layer which tries to support every functions of the Bloxstrap SDK",
id: "enabled",
label: 'Enable SDK',
description: 'Activate a compatibility layer which tries to support every functions of the Bloxstrap SDK',
id: 'enabled',
options: {
type: "boolean",
type: 'boolean',
state: false,
},
},
{
label: "Control RPC",
description: "Games can change your DiscordRPC",
id: "sdk_rpc",
label: 'Control RPC',
description: 'Games can change your DiscordRPC',
id: 'sdk_rpc',
options: {
type: "boolean",
type: 'boolean',
state: false,
},
},
{
label: "Control Roblox window",
description: "Games can define the size of your Roblox window",
id: "window",
label: 'Control Roblox window',
description: 'Games can define the size of your Roblox window',
id: 'window',
options: {
type: "boolean",
type: 'boolean',
state: false,
},
},
]
],
},
{
name: "Discord Rich Presence",
name: 'Discord Rich Presence',
description: "Show information about what you're playing on Discord",
id: "rpc",
id: 'rpc',
interactables: [
{
label: "Enable RPC",
description: "Whether to enable or disable the Discord RPC",
id: "enable_rpc",
label: 'Enable RPC',
description: 'Whether to enable or disable the Discord RPC',
id: 'enable_rpc',
options: {
type: "boolean",
type: 'boolean',
state: true,
},
},
{
label: "Show game activity",
label: 'Show game activity',
description: "Shows the game you're playing on your profile",
id: "rpc_activity",
id: 'rpc_activity',
options: {
type: "boolean",
type: 'boolean',
state: true,
},
},
{
label: "Show game time",
description: "Show the time since you started playing Roblox",
id: "rpc_time",
label: 'Show game time',
description: 'Show the time since you started playing Roblox',
id: 'rpc_time',
options: {
type: "boolean",
type: 'boolean',
state: true,
},
},
{
label: "Allow joining",
description: "Allow friends / everyone (depends on your roblox settings) to join you in-game",
id: "rpc_join",
label: 'Allow joining',
description: 'Allow friends / everyone (depends on your roblox settings) to join you in-game',
id: 'rpc_join',
options: {
type: "boolean",
type: 'boolean',
state: false,
},
},
Expand All @@ -144,6 +136,6 @@
panel={panelOpts}
on:settingsChanged={(e) => {
settingsChanged(e.detail);
console.log(e.detail)
console.log(e.detail);
}}
/>
28 changes: 5 additions & 23 deletions frontend/src/windows/main/ts/roblox/launch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { pathExists, curlGet } from '../utils';
import shellFS from '../shellfs';
import { GameEventInfo, RobloxInstance } from './instance';
import { DiscordRPC, RPCOptions } from '../rpc';
import { RPCController, RPCOptions } from '../rpc';
import { computer, os } from '@neutralinojs/lib';
import { loadSettings } from '../settings';
import { toast } from 'svelte-sonner';
Expand Down Expand Up @@ -65,7 +65,6 @@ export interface IPResponse {
readme: string;
}

let rpc: DiscordRPC | null = null;
let rpcOptions: RPCOptions = {
clientId: '1257650541677383721',
smallImage: 'appleblox',
Expand Down Expand Up @@ -133,14 +132,8 @@ async function onGameEvent(data: GameEventInfo) {
delete rpcOptions.buttonUrl2;
}

if (rpc) {
await rpc.update(rpcOptions);
console.log('Updated Roblox Game RPC');
} else {
rpc = new DiscordRPC();
await rpc.start(rpcOptions);
console.log('Started Roblox Game RPC');
}
await RPCController.set(rpcOptions);
console.log('Message Roblox Game RPC');
break;
case 'GameDisconnected':
case 'GameLeaving':
Expand All @@ -151,12 +144,7 @@ async function onGameEvent(data: GameEventInfo) {
largeImageText: 'AppleBlox Logo',
enableTime: true,
};
if (rpc) {
await rpc.update(normalRpcOptions);
} else {
rpc = new DiscordRPC();
await rpc.start(normalRpcOptions);
}
RPCController.set(normalRpcOptions);
console.log('Disconnected/Left game');
break;
case 'GameJoinedEntry':
Expand Down Expand Up @@ -199,13 +187,7 @@ async function onGameEvent(data: GameEventInfo) {
options.largeImage = `https://assetdelivery.roblox.com/v1/asset/?id=${inst.largeImage.assetId}`;
}
console.log('GameMessageEntry RPC:', options);
if (rpc) {
await rpc.update(options);
} else {
rpc = new DiscordRPC();
rpcOptions = options;
await rpc.start(options);
}
RPCController.set(options);
break;
case 'SetWindow':
if (settings && !settings.sdk.window) return;
Expand Down
25 changes: 24 additions & 1 deletion frontend/src/windows/main/ts/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ export class DiscordRPC {
return;
}

const args = DiscordRPC.buildArgs(options);
const rpcOptions = {
...options,
state: options.state || ""
}
const args = DiscordRPC.buildArgs(rpcOptions);

// Kill any existing discordrpc processes
await os.execCommand(`pkill -f "discordrpc_ablox"`);
Expand Down Expand Up @@ -232,3 +236,22 @@ export class DiscordRPC {
return args;
}
}

let discordRPC: DiscordRPC | null = null;
export class RPCController {
public static async set(options: RPCOptions) {
if (discordRPC) {
await discordRPC.update(options)
} else {
discordRPC = new DiscordRPC()
await discordRPC.start(options)
}
}

public static async stop() {
if (discordRPC) {
discordRPC.destroy()
}
await os.execCommand(`pkill -f "discordrpc_ablox"`);
}
}
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.1",
"version": "0.6.2",
"description": "MacOS roblox launcher",
"main": "frontend/src/windows/main/main.ts",
"scripts": {
Expand Down

0 comments on commit 9aba492

Please sign in to comment.