Skip to content

Commit

Permalink
Made it so AppleBlox is hidden when roblox is active
Browse files Browse the repository at this point in the history
  • Loading branch information
OrigamingWasTaken committed Jul 28, 2024
1 parent 005cfe6 commit aa9cce5
Showing 1 changed file with 80 additions and 19 deletions.
99 changes: 80 additions & 19 deletions frontend/src/windows/main/ts/roblox/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { toast } from "svelte-sonner";
import { dataPath, loadSettings } from "../settings";
import { pathExists } from "../utils";
import { filesystem, os } from "@neutralinojs/lib";
import path from "path-browserify";
import { sleep } from "@/windows/main/ts/utils";
import { getRobloxPath } from "./path";
import { toast } from 'svelte-sonner';
import { dataPath, loadSettings } from '../settings';
import { pathExists } from '../utils';
import { filesystem, os } from '@neutralinojs/lib';
import path from 'path-browserify';
import { sleep } from '@/windows/main/ts/utils';
import { getRobloxPath } from './path';
import AppIcon from '@/assets/play.icns';
import { libraryPath } from '../libraries';

export class RobloxUtils {
/** Checks if roblox is installed, and if not show a popup */
static async hasRoblox(popup = true): Promise<boolean> {
if (await pathExists(path.join(getRobloxPath(), "Contents/MacOS/RobloxPlayer"))) {
if (await pathExists(path.join(getRobloxPath(), 'Contents/MacOS/RobloxPlayer'))) {
return true;
} else {
if (!popup) return false;
Expand All @@ -29,7 +31,7 @@ END`);
/** Uses cli to check if any instance of roblox is open */
static async isRobloxOpen() {
const cmd = await os.execCommand('ps aux | grep "Roblox" | grep -v "grep"');
return cmd.stdOut.includes("Roblox");
return cmd.stdOut.includes('Roblox');
}

/** Returns a JSON object in the form of the ClientSettings.json file for the FFLags */
Expand All @@ -38,25 +40,25 @@ END`);
try {
if (!(await this.hasRoblox())) return;
if (await this.isRobloxOpen()) {
toast.info("Closing Roblox...", { duration: 1000 });
console.log("Closing Roblox");
toast.info('Closing Roblox...', { duration: 1000 });
console.log('Closing Roblox');
const robloxKill = await os.execCommand(`pkill -9 Roblox`);
console.log(robloxKill);

await sleep(2000);
}

toast.info("Opening Roblox...", { duration: 1000 });
console.log("Opening Roblox");
toast.info('Opening Roblox...', { duration: 1000 });
console.log('Opening Roblox');
await os.execCommand(`open "${getRobloxPath()}"`, { background: true });

await sleep(1000);

toast.info("Terminating all processes...", { duration: 1000 });
console.log("Terminating all Roblox processes");
toast.info('Terminating all processes...', { duration: 1000 });
console.log('Terminating all Roblox processes');
const result = await os.execCommand("ps aux | grep -i roblox | grep -v grep | awk '{print $2}' | xargs");
console.log(result);
const processes = result.stdOut.trim().split(" ");
const processes = result.stdOut.trim().split(' ');
for (const proc of processes) {
console.log(`Terminating Roblox Process (PID: ${proc})`);

Expand All @@ -69,11 +71,70 @@ END`);
}
}

toast.success("Multi-instance should now be working!");
toast.success('Multi-instance should now be working!');
} catch (err) {
toast.error("An error occured while enabling MultiInstance");
console.error("An error occured while enabling MultiInstance");
toast.error('An error occured while enabling MultiInstance');
console.error('An error occured while enabling MultiInstance');
console.error(err);
}
}

/** Creates a Launch shortcut where the user chooses */
static async createShortcut() {
const savePath = await os.showFolderDialog('Where should the shortcut be created?', { defaultPath: '/Applications/' }).catch(console.error);
if (!savePath) {
return;
}
if (await pathExists(path.join(savePath, 'Launch Roblox.app'))) {
await filesystem.remove(path.join(savePath, 'Launch Roblox.app'));
}
await filesystem.createDirectory(path.join(savePath, 'Launch Roblox.app/Contents/MacOS'));
await filesystem.createDirectory(path.join(savePath, 'Launch Roblox.app/Contents/Resources'));
await filesystem.writeFile(
path.join(savePath, 'Launch Roblox.app/Contents/Info.plist'),
`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>launch</string>
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>LSMinimumSystemVersion</key>
<string>14.0</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.games</string>
</dict>
</plist>`
);
const response = await fetch(AppIcon);
const blob = await response.blob();
await filesystem.writeBinaryFile(path.join(savePath, 'Launch Roblox.app/Contents/Resources/icon.icns'), await blob.arrayBuffer());
await filesystem.writeFile(path.join(savePath, 'Launch Roblox.app/Contents/MacOS/launch'), '#!/bin/bash\n' + path.join(path.dirname(window.NL_PATH), 'MacOS/bootstrap') + ' --launch');
await os.execCommand(`chmod +x ${path.join(savePath, 'Launch Roblox.app/Contents/MacOS/launch').replaceAll(' ', '\\ ')}`);
toast.success(`Created a shortcut at "${path.join(savePath, 'Launch Roblox.app')}"`);
}

/** Toggles wether or not opening roblox:// and roblox-player:// links should open AppleBlox */
static async toggleURI(state: boolean, notif = true) {
const urlscheme = `${libraryPath('urlscheme')}`;
if (state) {
// await os.execCommand(`open "${libraryPath("urlhandler")}"`)
await os.execCommand(`${urlscheme} set roblox ch.origaming.appleblox.url`);
await os.execCommand(`${urlscheme} set roblox-player ch.origaming.appleblox.url`);
if (notif) {
toast.success('Replaced roblox URI');
}
} else {
await os.execCommand(`${urlscheme} set roblox com.roblox.RobloxPlayer`);
await os.execCommand(`${urlscheme} set roblox-player com.roblox.RobloxPlayer`);
if (notif) {
toast.success('Restored roblox URI');
}
}
}
}

0 comments on commit aa9cce5

Please sign in to comment.