diff --git a/frontend/src/windows/main/pages/Misc.svelte b/frontend/src/windows/main/pages/Misc.svelte index 67686bb..afe9e27 100644 --- a/frontend/src/windows/main/pages/Misc.svelte +++ b/frontend/src/windows/main/pages/Misc.svelte @@ -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"; @@ -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 { const response = await fetch(url); const blob = await response.blob(); @@ -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"); diff --git a/frontend/src/windows/main/ts/roblox.ts b/frontend/src/windows/main/ts/roblox.ts index 40153e1..d1c7708 100644 --- a/frontend/src/windows/main/ts/roblox.ts +++ b/frontend/src/windows/main/ts/roblox.ts @@ -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 { @@ -110,3 +112,44 @@ export async function parseFFlags(preset = false): Promise { 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); + // } +}