Skip to content

Commit

Permalink
Attempt to fix launch issues & process killing
Browse files Browse the repository at this point in the history
  • Loading branch information
OrigamingWasTaken committed Jul 2, 2024
1 parent 11c2f13 commit 13cf19f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
1 change: 1 addition & 0 deletions frontend/src/windows/main/pages/Misc.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
switch (id) {
case "redirect_console":
if (state) {
console.log(state)
enableConsoleRedirection();
} else {
disableConsoleRedirection();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/windows/main/pages/Settings/Panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<FfButtonsCustom />
{:else if inter.options.type === "boolean"}
<Switch class="ml-auto mr-4" bind:checked={sections[section.id][inter.id]} on:click={()=>{
dispatch("switchClicked",{id: inter.id, state: sections[section.id][inter.id]})
dispatch("switchClicked",{id: inter.id, state: !sections[section.id][inter.id]})
}} />
{:else if inter.options.type === "string"}
<Input
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/windows/main/ts/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ export async function createRPC(opts: createRPCOpts) {
}
}
const cmd = `${libraryPath("discordrpc")} -c ${APPLICATION_ID} ${args.join(" ")}`;
const proc = await os.execCommand(cmd,{background: true});
const proc = await os.spawnProcess(cmd);
console.log(`[RPC] Start with: ${cmd}`)
}

export async function terminateRPC() {
await os.execCommand(`ps aux | grep -i discordrpc_ablox | grep -v grep | awk '{print $2}' | xargs kill -9`)
for (const proc of (await os.execCommand(`pgrep -f "discordrpc_ablox"`)).stdOut.split("\n")) {
await os.execCommand(`kill -9 ${proc}`)
}
}
28 changes: 16 additions & 12 deletions frontend/src/windows/main/ts/settings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { debug, filesystem, os } from "@neutralinojs/lib";
import { pathExists } from "./utils";
import path from "path-browserify";

export async function dataPath(): Promise<string> {
return `${await os.getPath("data")}/AppleBlox/config`;
return path.join(await os.getPath("data"),"AppleBlox","config")
}

/** Copies the settings folder to Application Support */
Expand All @@ -23,28 +24,31 @@ export async function dataPath(): Promise<string> {
// }

/** Saves the data provided to the Application Support folder */
let saveQueue: {path: string,data:string}[] = []
let saveQueue: {[key: string]: string} = {}
let hasInterval = false;
if (!hasInterval) {
hasInterval = true
setInterval(()=>{
for (const file of saveQueue) {
filesystem.writeFile(file.path,file.data).catch(console.error)
for (const [path,data] of Object.entries(saveQueue)) {
filesystem.writeFile(path,data).catch(console.error);
delete saveQueue[path]
}
},1000)
}

export async function saveSettings(panelId: string, data: Object): Promise<void> {
try {
const path = await dataPath();
if (!(await pathExists(path))) {
await filesystem.createDirectory(path);
const savePath = (await dataPath());
// const savePath = path.join(await os.getPath("downloads"),"aaa")
if (!(await pathExists(savePath))) {
await filesystem.createDirectory(savePath);
}
try {
const filepath = `${path}/${panelId}.json`;
if (await pathExists(filepath)) {
await filesystem.remove(filepath);
}
saveQueue.push({path: `${path}/${panelId}.json`, data: JSON.stringify(data)});
// const filepath = `${savePath}/${panelId}.json`;
// if (await pathExists(filepath)) {
// await filesystem.remove(filepath);
// }
saveQueue[`${savePath}/${panelId}.json`] = JSON.stringify(data);
} catch (err) {
console.error(err);
}
Expand Down

0 comments on commit 13cf19f

Please sign in to comment.