Skip to content

Commit

Permalink
Finished delegate feature (launching from web)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrigamingWasTaken committed Oct 3, 2024
1 parent 73627c6 commit 5cc5178
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 88 deletions.
40 changes: 14 additions & 26 deletions frontend/src/windows/main/components/LoadingSpinner.svelte
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 100 100"
preserveAspectRatio="xMidYMid"
width="200"
height="200"
style="shape-rendering: auto; display: block; background: transparent;"
xmlns:xlink="http://www.w3.org/1999/xlink"
><g
><g transform="translate(50 50)">
<g>
<animateTransform
attributeName="transform"
type="rotate"
values="0;45"
keyTimes="0;1"
dur="0.2s"
repeatCount="indefinite"
></animateTransform><path
d="M29.491524206117255 -5.5 L37.491524206117255 -5.5 L37.491524206117255 5.5 L29.491524206117255 5.5 A30 30 0 0 1 24.742744050198738 16.964569457146712 L24.742744050198738 16.964569457146712 L30.399598299691117 22.621423706639092 L22.621423706639096 30.399598299691114 L16.964569457146716 24.742744050198734 A30 30 0 0 1 5.5 29.491524206117255 L5.5 29.491524206117255 L5.5 37.491524206117255 L-5.499999999999997 37.491524206117255 L-5.499999999999997 29.491524206117255 A30 30 0 0 1 -16.964569457146705 24.742744050198738 L-16.964569457146705 24.742744050198738 L-22.621423706639085 30.399598299691117 L-30.399598299691117 22.621423706639092 L-24.742744050198738 16.964569457146712 A30 30 0 0 1 -29.491524206117255 5.500000000000009 L-29.491524206117255 5.500000000000009 L-37.491524206117255 5.50000000000001 L-37.491524206117255 -5.500000000000001 L-29.491524206117255 -5.500000000000002 A30 30 0 0 1 -24.742744050198738 -16.964569457146705 L-24.742744050198738 -16.964569457146705 L-30.399598299691117 -22.621423706639085 L-22.621423706639092 -30.399598299691117 L-16.964569457146712 -24.742744050198738 A30 30 0 0 1 -5.500000000000011 -29.491524206117255 L-5.500000000000011 -29.491524206117255 L-5.500000000000012 -37.491524206117255 L5.499999999999998 -37.491524206117255 L5.5 -29.491524206117255 A30 30 0 0 1 16.964569457146702 -24.74274405019874 L16.964569457146702 -24.74274405019874 L22.62142370663908 -30.39959829969112 L30.399598299691117 -22.6214237066391 L24.742744050198738 -16.964569457146716 A30 30 0 0 1 29.491524206117255 -5.500000000000013 M0 -20A20 20 0 1 0 0 20 A20 20 0 1 0 0 -20"
fill="#e15b64"
></path></g
></g
><g></g></g
><!-- [ldio] generated by https://loading.io --></svg
>
<script lang="ts">
import CatGif from '@/assets/panel/cat.gif';
import { sleep } from '../ts/utils';
import { cn } from '$lib/utils';
let className = '';
export { className as class };
</script>

{#await sleep(500)}
<div></div>
{:then}
<img src={CatGif} alt="Loading gif" class={cn('w-12 h-12', className)} />
{/await}
2 changes: 1 addition & 1 deletion frontend/src/windows/main/components/Onboarding.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
</Button>
<Button
on:click={async () => {
await setValue('roblox.roblox_launching.delegate_launching', true, true);
await setValue('roblox.launching.delegate', true, true);
toast.info('Roblox will now open AppleBlox before starting');
}}
variant="secondary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
type EditorFlag,
type Profile,
} from '.';
import CatGif from '@/assets/panel/cat.gif';
import SillyCat from '@/assets/panel/silly.webp';
import { formatConsoleLog } from '../../ts/debugging';
import SmallButton from './small-button.svelte';
Expand All @@ -33,6 +32,7 @@
import Combox from '../Combox.svelte';
import FlagTable from './flag-table.svelte';
import { cn } from '$lib/utils';
import LoadingSpinner from '../LoadingSpinner.svelte';
type SelectElement = Selected<string>;
Expand Down Expand Up @@ -300,7 +300,7 @@
</div>
<div class="w-full flex flex-col items-center justify-center mt-10">
{#await loadProfiles()}
<img src={CatGif} alt="cat walkin :3" class="w-20 h-20" />
<LoadingSpinner class="w-20 h-20" />
<h2>Loading profile...</h2>
{:then}
{#if currentProfile}
Expand Down
6 changes: 1 addition & 5 deletions frontend/src/windows/main/components/settings/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ export async function saveSettings(panelId: string, data: Object): Promise<void>
await filesystem.createDirectory(savePath);
}
try {
const filepath = `${savePath}/${panelId}.json`;
if (await shellFS.exists(filepath)) {
await filesystem.remove(filepath);
}
saveQueue[`${savePath}/${panelId}.json`] = JSON.stringify(data);
} catch (err) {
console.error('[Settings] ', err);
Expand Down Expand Up @@ -104,7 +100,7 @@ interface CacheEntry {

let settingsCache: { [key: string]: CacheEntry } = {};

const CACHE_LIFETIME = 10000; // Cache lifetime: 10 seconds
const CACHE_LIFETIME = 500; // Cache lifetime: 0.5 seconds

/** Get the value of a setting */
export async function getValue<T>(
Expand Down
22 changes: 18 additions & 4 deletions frontend/src/windows/main/components/settings/panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
export let fadeIn = true;
/** Don't render the panel. Only generate its settings. */
export let render = true;
export let overrides: SettingsOutput = {};
// Load settings
let settingsLoaded = false;
Expand Down Expand Up @@ -119,6 +120,17 @@
updateSettings();
}
}
// Apply overrides
if (Object.keys(overrides).length > 0) {
for (const [category, widgets] of Object.entries(overrides)) {
for (const [widget, value] of Object.entries(widgets)) {
settings[category][widget] = value;
}
}
await saveSettings(panel.id, settings);
}
// Show the page
settingsLoaded = true;
dispatch('loaded', { settings });
Expand Down Expand Up @@ -172,8 +184,8 @@
{#each panel.categories || [] as category (category.id)}
<div class="mt-5">
<!-- Category Description -->
<p class="text-xl font-bold text-red-600 dark:text-red-400">{category.name}</p>
<p class="text-[13px] text-primary-foreground font-semibold">{category.description}</p>
<p class="text-xl font-bold text-primary">{category.name}</p>
<p class="text-[13px] text-primary saturate-[20%] brightness-200 font-semibold">{category.description}</p>
{#each category.widgets || [] as widget (widget.id)}
<!-- Separator for the widgets (except button) -->
{#if widget.options.type !== 'button'}
Expand Down Expand Up @@ -253,7 +265,9 @@
<!-- Dropdown Widget -->
{:else if widget.options.type === 'select'}
<SelectWidget
items={widget.options.items.sort((a, b) => (a.value === "default" ? -1 : b.value === "default" ? 1 : 0))}
items={widget.options.items.sort((a, b) =>
a.value === 'default' ? -1 : b.value === 'default' ? 1 : 0
)}
defaultItem={settings[category.id][widget.id]}
on:itemSelected={(e) => {
const { item } = e.detail;
Expand Down Expand Up @@ -289,7 +303,7 @@
</Card.Root>
</div>
{:else}
<div class="flex h-[100vh] w-full opacity-30 items-center justify-center">
<div class="flex h-[100vh] w-full items-center justify-center">
<LoadingSpinner />
</div>
{/if}
Expand Down
34 changes: 26 additions & 8 deletions frontend/src/windows/main/pages/Roblox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import { toast } from 'svelte-sonner';
import Panel from '../components/settings/panel.svelte';
import { SettingsPanelBuilder } from '../components/settings';
import type { SettingsOutput } from '../components/settings/types';
import LoadingSpinner from '../components/LoadingSpinner.svelte';
export let render = true;
Expand Down Expand Up @@ -49,11 +51,9 @@
async function switchClicked(e: CustomEvent) {
const { id, state } = e.detail;
switch (id) {
case 'redirect_appleblox':
Roblox.Utils.toggleURI(state).catch((err) => {
toast.error('An error occured');
console.error('[RobloxPanel] ', err);
});
case 'delegate':
await Roblox.Delegate.toggle(state);
break;
}
}
Expand Down Expand Up @@ -92,7 +92,7 @@
category
.setName('Launching')
.setDescription('Launching phase settings')
.setId('roblox_launching')
.setId('launching')
.addButton({
label: 'Create a launch shortcut',
description:
Expand All @@ -113,11 +113,20 @@
label: 'Delegate launching to AppleBlox',
description:
'When you launch Roblox, AppleBlox will open first in the background and apply the chosen settings',
id: 'delegate_launching',
id: 'delegate',
default: false,
})
)
.build();
let overrides: SettingsOutput = {};
async function loadOverrides() {
overrides = {
launching: {
delegate: await Roblox.Delegate.check(true),
},
};
}
</script>

<AlertDialog.Root bind:open={closeRobloxPopup}>
Expand All @@ -138,4 +147,13 @@
</AlertDialog.Content>
</AlertDialog.Root>

<Panel {panel} on:switch={switchClicked} on:button={buttonClicked} {render} />
{#await loadOverrides()}
{#if render}
<LoadingSpinner />
{/if}
{:then}
<Panel {panel} on:switch={switchClicked} on:button={buttonClicked} {render} {overrides} />
{:catch error}
<h2 class="text-red-500">An error occured while loading settings overrides</h2>
<p class="text-red-300">{error}</p>
{/await}
10 changes: 5 additions & 5 deletions frontend/src/windows/main/ts/libraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ const LibPaths = {
notifications: {
darwin: {
prod: '/lib/alerter_ablox',
dev: '/build/lib/MacOS/alerter_ablox',
dev: '/bin/alerter_ablox',
},
},
discordrpc: {
darwin: {
prod: '/lib/discordrpc_ablox',
dev: '/build/lib/MacOS/discordrpc_ablox',
dev: '/bin/discordrpc_ablox',
},
},
watchdog: {
darwin: {
prod: '/lib/watchdog',
dev: '/build/lib/MacOS/watchdog',
dev: '/bin/watchdog',
},
},
window_manager: {
darwin: {
prod: '/lib/window_manager',
dev: '/build/lib/MacOS/window_manager',
dev: '/bin/window_manager',
},
},
urlscheme: {
darwin: {
prod: '/lib/urlscheme',
dev: '/build/lib/MacOS/urlscheme',
dev: '/bin/urlscheme',
},
},
} as const;
Expand Down
51 changes: 51 additions & 0 deletions frontend/src/windows/main/ts/roblox/delegate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { shell } from '../tools/shell';
import { getValue } from '../../components/settings';
import { libraryPath } from '../libraries';
import { toast } from 'svelte-sonner';

const urlscheme = libraryPath('urlscheme');

async function setUrlscheme(
uri: string,
bundleId: string
): Promise<{ toggled: true } | { toggled: false; stdErr: string; stdOut: string }> {
const command = await shell(`${urlscheme}`, ['set', uri, bundleId], { skipStderrCheck: true });
if (!command.stdout.includes('Successfully') && !command.stderr.includes('Successfully')) {
return { toggled: false, stdErr: command.stderr, stdOut: command.stdout };
}
return { toggled: true };
}

export class RobloxDelegate {
/** Checks if the app is already redirected */
static async check(retoggle = false) {
// If it's not active but toggled in settings, retoggle.
const cmd = await shell(`${urlscheme}`, ['check', 'roblox-player', 'ch.origaming.appleblox'], { skipStderrCheck: true });
const toggled = cmd.stdout.includes('true') || cmd.stderr.includes('true');
if (!toggled && retoggle && (await getValue<boolean>('roblox.launching.delegate')) === true) {
await this.toggle(true);
return true;
} else if (toggled && retoggle && (await getValue<boolean>('roblox.launching.delegate')) === false) {
await this.toggle(false);
return false;
}
return toggled;
}

/** Enable/disable delegation */
static async toggle(delegate: boolean) {
if (delegate) {
const toggled = await setUrlscheme('roblox-player', 'ch.origaming.appleblox');
if (!toggled.toggled) {
toast.error("Couldn't set Roblox's URI");
console.error("Couldn't set Roblox's URI:", toggled.stdErr, toggled.stdOut);
}
} else {
const toggled = await setUrlscheme('roblox-player', 'com.roblox.RobloxPlayer');
if (!toggled.toggled) {
toast.error("Couldn't set Roblox's URI");
console.error("Couldn't set Roblox's URI:", toggled.stdErr, toggled.stdOut);
}
}
}
}
4 changes: 0 additions & 4 deletions frontend/src/windows/main/ts/roblox/fflags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,7 @@ async function buildFlagsList(): Promise<FastFlagsList> {
name: 'Menu version (Version 4 Chrome)',
flags: {
FFlagEnableInGameMenuChrome: true,
FFlagEnableReportAbuseMenuRoactABTest2: true,
FFlagChromeBetaFeature: true,
FFlagEnableInGameMenuChromeABTest2: true,
},
path: 'fastflags.ui.menu_version',
type: 'select',
Expand Down Expand Up @@ -391,7 +389,6 @@ export class RobloxFFlags {
if (preset) {
flagsList = await buildFlagsList();
const data = await flagsList.build();
console.log(data)

const { validFlags, invalidFlags, nameMap } = data;
return { validFlags, invalidFlags, nameMap };
Expand Down Expand Up @@ -619,7 +616,6 @@ export class FastFlagsList {
}

if (!addFlag && opts.value != null) continue;
// console.log(opts,addFlag)

// Check if the flag is valid from the flag tracker repository
await this.fetchTracker();
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/windows/main/ts/roblox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RobloxMods } from './mods';
import { robloxPath } from './path';
import { RobloxUtils } from './utils';
import { RobloxWindow } from './window';
import { RobloxDelegate } from './delegate';

// Simple export
class Roblox {
Expand All @@ -13,6 +14,7 @@ class Roblox {
static Utils = RobloxUtils;
static Window = RobloxWindow;
static Mods = RobloxMods;
static Delegate = RobloxDelegate;
static launch = launchRoblox;
static path = robloxPath;
}
Expand Down
20 changes: 13 additions & 7 deletions frontend/src/windows/main/ts/roblox/instance.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { events, filesystem, os } from '@neutralinojs/lib';
import { clipboard, events, filesystem, os } from '@neutralinojs/lib';
import path from 'path-browserify';
import Roblox from '.';
import { isProcessAlive, sleep } from '../utils';
import { getValue } from '../../components/settings';
import { shell } from '../tools/shell';

type EventHandler = (data?: any) => void;
type Event = 'exit' | 'gameInfo' | 'gameEvent';
Expand Down Expand Up @@ -122,7 +124,7 @@ export class RobloxInstance {
}

watchLogs: boolean;
constructor(watch: boolean, url?: string) {
constructor(watch: boolean) {
this.watchLogs = watch;
}

Expand All @@ -140,17 +142,21 @@ export class RobloxInstance {
// Launch Roblox
if (url) {
console.info(`[Roblox.Instance] Opening from URL: ${url}`);
await Roblox.Utils.toggleURI(false, false);
await os.execCommand(`open ${url}`);
await Roblox.Delegate.toggle(false);
await clipboard.writeText(url)
await shell("open",[url]);
} else {
await os.execCommand(`open "${Roblox.path}"`);
await shell("open",[Roblox.path]);
}

await sleep(1000);
await Roblox.Utils.toggleURI(true, false);
// If block because settings can be edited and maybe it will not be boolean
if ((await getValue<boolean>('roblox.launching.delegate')) === true) {
await Roblox.Delegate.toggle(true);
}

// We find every roblox processes and get the RobloxPlayer one
const robloxProcess = await (await os.execCommand('pgrep -f "Roblox"')).stdOut.split('\n');
const robloxProcess = (await os.execCommand('pgrep -f "Roblox"')).stdOut.split('\n');
for (const pid of robloxProcess) {
const info = (await os.execCommand(`ps -p ${pid} -o command=`)).stdOut.trim();
if (info.length < 2) continue;
Expand Down
Loading

0 comments on commit 5cc5178

Please sign in to comment.