Skip to content

Commit

Permalink
Trying to fix MultiInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
OrigamingWasTaken committed Jul 1, 2024
1 parent f1d2225 commit 0771777
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 32 deletions.
34 changes: 2 additions & 32 deletions frontend/src/windows/main/pages/Misc.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Panel from "./Settings/Panel.svelte";
import { saveSettings } from "../ts/settings";
import { toast } from "svelte-sonner";
import { isRobloxOpen, parseFFlags } from "../ts/roblox";
import { enableMultiInstance, isRobloxOpen, parseFFlags } from "../ts/roblox";
import { events, filesystem, os } from "@neutralinojs/lib";
import { sleep } from "$lib/appleblox";
import AppIcon from "@/assets/play.icns";
Expand All @@ -14,27 +14,6 @@
saveSettings("misc", o);
}
let robloxProcessIds: number[] = [];
let processingIds: number[] = [];
events.on("spawnedProcess", async (e) => {
if (robloxProcessIds.includes(e.detail.id)) {
switch (e.detail.action) {
case "stdErr":
case "stdOut":
if (processingIds.includes(e.detail.id)) return;
processingIds.push(e.detail.id);
await sleep(1000);
toast.info("Terminating every Roblox processes...");
await os.execCommand(`ps aux | grep -i roblox | grep -v grep | awk '{print $2}' | xargs kill -9`);
break;
case "exit":
robloxProcessIds = robloxProcessIds.filter((id) => id !== e.detail.id);
toast.success("Multi-Instances should be active.");
break;
}
}
});
async function loadImageToBlob(url: string): Promise<Blob> {
const response = await fetch(url);
const blob = await response.blob();
Expand All @@ -45,16 +24,7 @@
const id = e.detail;
switch (id) {
case "multi_roblox_btn":
if (!(await isRobloxOpen())) {
toast.info("Closing Roblox...", { duration: 1000 });
await os.execCommand(`pkill -9 Roblox`);
await sleep(1000);
toast.info("Opening Roblox...", { duration: 1000 });
const proc = await os.spawnProcess("/Applications/Roblox.app/Contents/MacOS/RobloxPlayer");
robloxProcessIds.push(proc.id);
}
await enableMultiInstance()
break;
case "open_instance_btn":
os.spawnProcess("/Applications/Roblox.app/Contents/MacOS/RobloxPlayer; exit");
Expand Down
43 changes: 43 additions & 0 deletions frontend/src/windows/main/ts/roblox.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { toast } from "svelte-sonner";
import { dataPath } from "./settings";
import { pathExists } from "./utils";
import { filesystem, os } from "@neutralinojs/lib";
import path from "path-browserify";
import { sleep } from "$lib/appleblox";

/** Checks if roblox is installed, and if not show a popup */
export async function hasRoblox(): Promise<boolean> {
Expand Down Expand Up @@ -110,3 +112,44 @@ export async function parseFFlags(preset = false): Promise<Object> {
return fflagsJson;
}
}

export async function enableMultiInstance() {
if (!(await hasRoblox())) return;
if (await isRobloxOpen()) {
toast.info("Closing Roblox...",{duration: 1000})
await os.execCommand(`pkill -9 Roblox`)

await sleep(2000)

toast.info("Opening Roblox...",{duration: 1000})
await os.execCommand("open /Applications/Roblox.app",{background: true})

await sleep(1000);

toast.info("Terminating all processes...",{duration: 1000})
const result = await os.execCommand('ps aux | grep -i roblox | grep -v grep');
const processes = result.stdOut.split('\n').filter(line => line.includes('roblox'));
for (const proc of processes) {
const columns = proc.trim().split(/\s+/);
const pid = columns[1];
console.log(`Terminating Roblox Process (PID: ${pid})`);

try {
await os.execCommand(`kill -9 ${pid}`);
} catch (err) {
console.error(`Error terminating process ${pid}: ${err}`);
toast.error(`Error terminating process ${pid}: ${err}`)
}
}
}
// if (!(await isRobloxOpen())) {
// toast.info("Closing Roblox...", { duration: 1000 });
// await os.execCommand(`pkill -9 Roblox`);

// await sleep(1000);

// toast.info("Opening Roblox...", { duration: 1000 });
// const proc = await os.spawnProcess("/Applications/Roblox.app/Contents/MacOS/RobloxPlayer");
// robloxProcessIds.push(proc.id);
// }
}

0 comments on commit 0771777

Please sign in to comment.