Skip to content

Commit

Permalink
Revert settings new saving system & fix switches not working
Browse files Browse the repository at this point in the history
  • Loading branch information
OrigamingWasTaken committed Jul 14, 2024
1 parent 4cc33b1 commit d351cd8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 24 deletions.
12 changes: 2 additions & 10 deletions frontend/src/windows/main/pages/Integrations.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,7 @@
type: "boolean",
state: true,
},
},
/*{
label: "See current place when teleporting",
description: "When you teleport (or join) a place, you will be notified of its name and other informations",
id: "notify_place",
options: {
type: "boolean",
state: false,
},
},*/
}
],
},
{
Expand Down Expand Up @@ -154,5 +145,6 @@
panel={panelOpts}
on:settingsChanged={(e) => {
settingsChanged(e.detail);
console.log(e.detail)
}}
/>
1 change: 1 addition & 0 deletions frontend/src/windows/main/pages/Settings/Panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
{: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] });
}}
Expand Down
50 changes: 37 additions & 13 deletions frontend/src/windows/main/ts/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,50 @@ export async function dataPath(): Promise<string> {
}

/** Saves the data provided to the Application Support folder */
let saveQueue: { panelId: string; data: string }[] = [];
let saveQueue: { [key: string]: string } = {};
let hasInterval = false;
if (!hasInterval) {
hasInterval = true;
setInterval(async () => {
const savePath = await dataPath();
// Create the directory if it doesn't exist
await os.execCommand(`mkdir -p "${savePath}"`);
for (const { panelId, data } of saveQueue) {
const filePath = path.join(savePath, panelId + ".json");
await os.execCommand(`rm -f "${filePath}"`);
await filesystem.writeFile(filePath, data).catch(console.error);
saveQueue = saveQueue.filter((q) => q.panelId !== panelId);
setInterval(() => {
for (const [path, data] of Object.entries(saveQueue)) {
filesystem.writeFile(path, data).catch(console.error);
delete saveQueue[path];
}
}, 100);
}, 1000);
}

// Keeps track of the debounces
const lastSaveTime = new Map<string, number>();
/** Saves the settings of a panel by its ID. Can only save a panel once every 100ms */
export async function saveSettings(panelId: string, data: Object): Promise<void> {
saveQueue.push({ panelId, data: JSON.stringify(data) });
const now = Date.now();
const lastSave = lastSaveTime.get(panelId);

// ignore save requests if they don't wait 100ms
if (lastSave && (now - lastSave) < 100) {
return;
}

// update the last save time
lastSaveTime.set(panelId, now);

try {
const savePath = await dataPath();
if (!(await pathExists(savePath))) {
await filesystem.createDirectory(savePath);
}
try {
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);
}
} catch (err) {
throw err;
}
}

/** Loads the data from the specified panelID */
Expand All @@ -40,4 +64,4 @@ export async function loadSettings(panelId: string): Promise<{ [key: string]: an
} catch (err) {
console.error(err);
}
}
}
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.5.3",
"version": "0.5.4",
"description": "MacOS roblox launcher",
"main": "frontend/src/windows/main/main.ts",
"scripts": {
Expand Down

0 comments on commit d351cd8

Please sign in to comment.