Skip to content

Commit

Permalink
Fixed DiscordRPC not respecting settings
Browse files Browse the repository at this point in the history
  • Loading branch information
OrigamingWasTaken committed Jul 31, 2024
1 parent c1a73da commit 5216ea1
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 43 deletions.
65 changes: 58 additions & 7 deletions frontend/src/windows/main/pages/Settings/Panel.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
<script lang="ts" type="module">
import type { SettingsPanel } from '@/types/settings';
import { os, filesystem } from '@neutralinojs/lib';
import path from 'path-browserify';
import shellFS from '../../ts/shellfs';
import { toast } from 'svelte-sonner';
import { Input } from '$lib/components/ui/input/index.js';
import { Label } from '$lib/components/ui/label/index.js';
import Separator from '$lib/components/ui/separator/separator.svelte';
import Switch from '$lib/components/ui/switch/switch.svelte';
import * as Select from '$lib/components/ui/select/index.js';
import { Slider } from '$lib/components/ui/slider/index.js';
import * as Tooltip from '$lib/components/ui/tooltip';
import Button from '$lib/components/ui/button/button.svelte';
import { Trash2, Upload } from 'lucide-svelte';
import { createEventDispatcher } from 'svelte';
import LoadingSpinner from '../../util/LoadingSpinner.svelte';
import { loadSettings } from '../../ts/settings';
import Button from '$lib/components/ui/button/button.svelte';
import FfButtonsCustom from './FFButtonsCustom.svelte';
import * as Tooltip from '$lib/components/ui/tooltip';
import { haveSameKeys } from '../../ts/utils';
import ModsUi from './ModsUI.svelte';
import { cn } from '$lib/utils.js';
Expand All @@ -22,6 +29,8 @@
settingsChanged: Object;
buttonClicked: string;
switchClicked: { id: string; state: boolean };
fileAdded: { id: string; filePath: string };
fileRemoved: { id: string; filePath: string };
}>();
let settingsLoaded = false;
Expand All @@ -41,6 +50,8 @@
case 'number':
sections[section.id][inter.id] = [inter.options.default];
break;
case 'file':
sections[section.id][inter.id] = null;
}
}
}
Expand Down Expand Up @@ -81,9 +92,9 @@
{#if inter.options.type !== 'button' && inter.options.type !== 'ff_buttons_custom'}
<Separator class="my-3 bg-gray-300 opacity-25" el={undefined} decorative={true} />
{/if}
<div class="flex items-center">
<div class={`flex items-center ${inter.toggle ? (sections[section.id][inter.toggle] ? '' : 'grayscale cursor-not-allowed opacity-60 select-one pointer-events-none') : ''}`}>
{#if inter.options.type !== 'button' && inter.options.type !== 'ff_buttons_custom' && !inter.hideTitle}
<div>
<div class={inter.options.type === "number" ? 'w-[500px]': ''}>
<p class="font-semibold text-[#1f1717] dark:text-red-100">{inter.label}</p>
<p class="text-[13px] text-neutral-700 dark:text-neutral-200">{@html inter.description}</p>
</div>
Expand All @@ -99,9 +110,9 @@
}}
>
{#if inter.options.icon?.component}
<svelte:component this={inter.options.icon.component} class={cn(inter.options.icon.props,"h-5 w-5 mr-2")} />
<svelte:component this={inter.options.icon.component} class={cn(inter.options.icon.props, 'h-5 w-5 mr-2')} />
{:else if inter.options.icon?.src}
<img src={inter.options.icon?.src} alt="Panel Icon" class={cn(inter.options.icon.props,"h-5 w-5 mr-2")}>
<img src={inter.options.icon?.src} alt="Panel Icon" class={cn(inter.options.icon.props, 'h-5 w-5 mr-2')} />
{/if}
{inter.label}</Button
>
Expand Down Expand Up @@ -129,6 +140,46 @@
bind:value={sections[section.id][inter.id]}
placeholder={inter.options.default}
/>
{:else if inter.options.type === 'file'}
<Button
class="ml-auto mr-4 bg-background border w-64 text-foreground data-[hasfile=true]:bg-red-500 data-[hasfile=true]:border-neutral-800 data-[hasfile=true]:border-2"
variant="ghost"
data-hasfile={sections[section.id][inter.id] ? true : false}
on:click={async () => {
try {
// Remove file
if (inter.options.type !== 'file') return;
if (sections[section.id][inter.id]) {
dispatch('fileRemoved', { id: inter.id, filePath: sections[section.id][inter.id] });
sections[section.id][inter.id] = null;
return;
}

// Chose file
let options = { multiSelections: false, filters: [{ name: 'Font files', extensions: inter.options.accept }] };
if (inter.options.default) {
// @ts-expect-error
options.defaultPath = inter.options.default;
}

const entries = await os.showOpenDialog('Choose your font file', options);
if (entries.length < 1) return;
dispatch('fileAdded', { id: inter.id, filePath: entries[0] });
sections[section.id][inter.id] = entries[0];
} catch (err) {
toast.error('An error occured');
console.error(err);
}
}}
>
{#if sections[section.id][inter.id]}
<Trash2 class="w-5 h-5 mr-2" />
<p class="inline-block align-middle overflow-hidden whitespace-nowrap overflow-ellipsis [direction:rtl] w-full">{path.basename(sections[section.id][inter.id])}</p>
{:else}
<Upload class="w-5 h-5 mr-2" />
Choose file
{/if}
</Button>
{:else if inter.options.type === 'dropdown'}
<Select.Root items={inter.options.list} bind:selected={sections[section.id][inter.id]}>
<Select.Trigger class="w-[180px] dark:bg-neutral-900 bg-neutral-300 ml-auto mr-4 border-none">
Expand Down Expand Up @@ -162,4 +213,4 @@
<div class="flex h-[100vh] w-full opacity-30 grayscale items-center justify-center">
<LoadingSpinner />
</div>
{/if}
{/if}
81 changes: 45 additions & 36 deletions frontend/src/windows/main/ts/roblox/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { showNotification } from '../notifications';
import { getRobloxPath } from './path';
import path from 'path-browserify';
import Roblox from '.';
import { setWindowVisibility } from '../window';
import { focusWindow, setWindowVisibility } from '../window';

interface RobloxGame {
id: number;
Expand Down Expand Up @@ -111,30 +111,32 @@ async function onGameEvent(data: GameEventInfo) {
console.log('Game Image: ', gameImageReq);
const gameImage: GameImageRes = gameImageReq.data[0];

rpcOptions = {
...rpcOptions,
details: `Playing ${gameInfo.name}`,
state: `by ${gameInfo.creator.name}`,
buttonText1: 'See game page',
buttonUrl1: `https://www.roblox.com/games/${placeId}/`,
largeImage: gameImage.imageUrl,
largeImageText: gameInfo.name,
enableTime: settings ? settings.rpc.rpc_time : true,
};

if (jobId && settings && settings.rpc.rpc_join) {
if (settings && settings.rpc.enable_rpc) {
rpcOptions = {
...rpcOptions,
buttonText2: 'Join server',
buttonUrl2: `"roblox://experiences/start?placeId=${placeId}&gameInstanceId=${jobId}"`,
details: `Playing ${gameInfo.name}`,
state: `by ${gameInfo.creator.name}`,
buttonText1: 'See game page',
buttonUrl1: `https://www.roblox.com/games/${placeId}/`,
largeImage: gameImage.imageUrl,
largeImageText: gameInfo.name,
enableTime: settings ? settings.rpc.rpc_time : true,
};
} else {
delete rpcOptions.buttonText2;
delete rpcOptions.buttonUrl2;
}

await RPCController.set(rpcOptions);
console.log('Message Roblox Game RPC');
if (jobId && settings && settings.rpc.rpc_join) {
rpcOptions = {
...rpcOptions,
buttonText2: 'Join server',
buttonUrl2: `"roblox://experiences/start?placeId=${placeId}&gameInstanceId=${jobId}"`,
};
} else {
delete rpcOptions.buttonText2;
delete rpcOptions.buttonUrl2;
}

await RPCController.set(rpcOptions);
console.log('Message Roblox Game RPC');
}
break;
case 'GameDisconnected':
case 'GameLeaving':
Expand Down Expand Up @@ -257,23 +259,26 @@ export async function launchRoblox(
return;
}

const modSettings = await loadSettings('mods');
if (modSettings) {
if (modSettings.general.enable_mods) {
setLaunchProgress(20);
setLaunchText('Copying Mods...');

await Roblox.Mods.copyToFiles();
}
await Roblox.Mods.applyCustomFont(modSettings);
}

const robloxPath = getRobloxPath();

setLaunchProgress(20);
setLaunchProgress(30);
if (await pathExists(path.join(robloxPath, 'Contents/MacOS/ClientSettings/ClientAppSettings.json'))) {
console.log(`Removing current ClientAppSettings.json file in ${path.join(robloxPath, 'Contents/MacOS/ClientSettings/ClientAppSettings.json')}`);
await shellFS.remove(path.join(robloxPath, 'Contents/MacOS/ClientSettings/'));
setLaunchText('Removing current ClientAppSettings...');
}

const modSettings = await loadSettings('mods');
if (modSettings && modSettings.general.enable_mods) {
setLaunchProgress(30);
setLaunchText('Copying Mods...');

await Roblox.Mods.copyToFiles();
}

setLaunchProgress(40);
setLaunchText('Copying fast flags...');
console.log('Copying fast flags');
Expand Down Expand Up @@ -308,15 +313,19 @@ export async function launchRoblox(

robloxInstance.on('gameEvent', onGameEvent);
robloxInstance.on('exit', async () => {
if (modSettings && modSettings.general.enable_mods) {
await Roblox.Mods.restoreRobloxFolders()
.catch(console.error)
.then(() => {
console.log(`Removed mod files from "${path.join(robloxPath, 'Contents/Resources/')}"`);
});
if (modSettings) {
if (modSettings.general.enable_mods) {
await Roblox.Mods.restoreRobloxFolders()
.catch(console.error)
.then(() => {
console.log(`Removed mod files from "${path.join(robloxPath, 'Contents/Resources/')}"`);
});
}
await Roblox.Mods.removeCustomFont(modSettings);
}
RPCController.stop();
setWindowVisibility(true);
focusWindow();
setRobloxConnected(false);
rbxInstance = null;
console.log('Roblox exited');
Expand Down

0 comments on commit 5216ea1

Please sign in to comment.