Skip to content

Commit

Permalink
Removed functions that modified the App's bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
OrigamingWasTaken committed Jul 1, 2024
1 parent 431751f commit 43098e9
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 38 deletions.
4 changes: 2 additions & 2 deletions frontend/src/windows/main/pages/Misc.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import type { SettingsPanel } from "@/types/settings";
import Panel from "./Settings/Panel.svelte";
import { saveSettings } from "../ts/settings";
import { dataPath, saveSettings } from "../ts/settings";
import { toast } from "svelte-sonner";
import { enableMultiInstance, isRobloxOpen, parseFFlags } from "../ts/roblox";
import { events, filesystem, os } from "@neutralinojs/lib";
Expand Down Expand Up @@ -108,7 +108,7 @@
toast.success("Console redirection enabled", { duration: 1000 });
break;
case "open_logs":
const logPath = path.join(window.NL_PATH,"neutralinojs.log")
const logPath = path.join(path.dirname(await dataPath()),"appleblox.log")
if (!await pathExists(logPath)) {
toast.error("The logs file doesn't seem to exist.")
return;
Expand Down
36 changes: 25 additions & 11 deletions frontend/src/windows/main/ts/debugging.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// This serves the purpose of redirecting every console logs to the neutralinojs.log file for debugging on the users' end.

import { debug } from "@neutralinojs/lib";

let isRedirectionEnabled = false;
import { filesystem, os } from "@neutralinojs/lib";
import path from "path-browserify";
import { dataPath } from "./settings";
import { pathExists } from "./utils";

function formatConsoleLog(...args: any[]): string {
return args
Expand Down Expand Up @@ -43,53 +42,68 @@ function getCircularReplacer() {
};
}

async function appendLog(message: string) {
try {
const appleBloxDir = path.dirname(await dataPath());
await filesystem.appendFile(path.join(appleBloxDir,"appleblox.log"), message + "\n");
} catch (err) {
console.error("Failed to write log to file", err);
}
}

const originalConsoleLog = console.log;
const originalConsoleError = console.error;
const originalConsoleWarn = console.warn;
const originalConsoleInfo = console.info;
const originalConsoleDebug = console.debug;

let isRedirectionEnabled = true;

console.log = (...args: any[]) => {
if (isRedirectionEnabled) {
const formattedMessage = formatConsoleLog(...args);
debug.log(formattedMessage);
appendLog(formattedMessage);
}
originalConsoleLog.apply(console, args);
};

console.error = (...args: any[]) => {
if (isRedirectionEnabled) {
const formattedMessage = formatConsoleLog(...args);
debug.log(formattedMessage);
appendLog(formattedMessage);
}
originalConsoleError.apply(console, args);
};

console.warn = (...args: any[]) => {
if (isRedirectionEnabled) {
const formattedMessage = formatConsoleLog(...args);
debug.log(formattedMessage);
appendLog(formattedMessage);
}
originalConsoleWarn.apply(console, args);
};

console.info = (...args: any[]) => {
if (isRedirectionEnabled) {
const formattedMessage = formatConsoleLog(...args);
debug.log(formattedMessage);
appendLog(formattedMessage);
}
originalConsoleInfo.apply(console, args);
};

console.debug = (...args: any[]) => {
if (isRedirectionEnabled) {
const formattedMessage = formatConsoleLog(...args);
debug.log(formattedMessage);
appendLog(formattedMessage);
}
originalConsoleDebug.apply(console, args);
};

export function enableConsoleRedirection() {
export async function enableConsoleRedirection() {
const appleBloxDir = path.dirname(await dataPath());
if (!pathExists(appleBloxDir)) {
await filesystem.createDirectory(appleBloxDir);
}
isRedirectionEnabled = true;
}

Expand Down
67 changes: 44 additions & 23 deletions frontend/src/windows/main/ts/settings.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,67 @@
import {debug, storage, filesystem, os} from '@neutralinojs/lib';
import {pathExists} from './utils';
import { debug, storage, filesystem, os } from "@neutralinojs/lib";
import { pathExists } from "./utils";

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

/** Copies the settings folder to Application Support */
async function copyNeuStorage(panelId: string) {
const path = await dataPath();
if (!(await pathExists(path))) {
await filesystem.createDirectory(path);
}
try {
const filepath = `${path}/${panelId}.neustorage`;
if (await pathExists(filepath)) {
await filesystem.remove(filepath);
// async function copyNeuStorage(panelId: string) {
// const path = await dataPath();
// if (!(await pathExists(path))) {
// await filesystem.createDirectory(path);
// }
// try {
// const filepath = `${path}/${panelId}.json`;
// if (await pathExists(filepath)) {
// await filesystem.remove(filepath);
// }
// await filesystem.copy(`${window.NL_PATH}/.storage/${panelId}.json`, filepath);
// } catch (err) {
// console.error(err);
// }
// }

/** Saves the data provided to the Application Support folder */
let saveQueue: {path: string,data:string}[] = []
let hasInterval = false;
if (!hasInterval) {
setInterval(()=>{
for (const file of saveQueue) {
filesystem.writeFile(file.path,file.data).catch(console.error)
}
await filesystem.copy(`${window.NL_PATH}/.storage/${panelId}.neustorage`, filepath);
} catch (err) {
console.error(err);
}
},1000)
}

/** Saves the data provided to the Application Support folder */
export async function saveSettings(panelId: string, data: Object): Promise<void> {
try {
await storage.setData(panelId, JSON.stringify(data));
copyNeuStorage(panelId);
const path = await dataPath();
if (!(await pathExists(path))) {
await filesystem.createDirectory(path);
}
try {
const filepath = `${path}/${panelId}.json`;
if (await pathExists(filepath)) {
await filesystem.remove(filepath);
}
saveQueue.push({path: `${path}/${panelId}.json`, data: JSON.stringify(data)});
} catch (err) {
console.error(err);
}
} catch (err) {
throw err;
}
}

/** Loads the data from the specified panelID */
export async function loadSettings(panelId: string): Promise<{[key: string]: Object} | undefined> {
export async function loadSettings(panelId: string): Promise<{ [key: string]: Object } | undefined> {
try {
const filepath = `${await dataPath()}/${panelId}.neustorage`;
const filepath = `${await dataPath()}/${panelId}.json`;
if (!(await pathExists(filepath))) {
return undefined
return undefined;
}
return JSON.parse(await filesystem.readFile(filepath));
} catch (err) {
console.error(err)
console.error(err);
}
}
2 changes: 1 addition & 1 deletion neutralino.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"exportAuthInfo": false,
"logging": {
"writeToLogFile": true,
"writeToLogFile": false,
"enabled": true
},
"tokenSecurity": "none",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "appleblox",
"version": "0.2.3",
"version": "0.2.4",
"description": "MacOS roblox launcher",
"main": "frontend/src/windows/main/main.ts",
"scripts": {
Expand Down

0 comments on commit 43098e9

Please sign in to comment.