[Storage > Ext] Hybrid 2 (rewrite)

pull/55/head
Oj18 3 years ago
parent c918f67dbf
commit c38dd3bd1f

@ -1,6 +1,6 @@
# GooseMod Changelog
## v12.1-dev [2021-09-14]
## v12.1-dev [2021-09-15]
- ### Store
- **Ludicrous speed.** The Store should now be quite faster, especially on low-end hardware.
@ -8,6 +8,9 @@
- **Search text hints.** Now shows no results text for no results, and hints to go to an other category if there are results in that and not the current category.
- **Improved profile store.** Better and more reliable scrolling down to card and now highlight clears after a short time.
- ### Hybrid Storage
- **Heavy reduction in GooseMod wipes.** Sometimes when Discord updates (desktop) GooseMod settings and modules would get cleared due to a Discord client bug. This should now hopefully be eliminated or at least heavily reduced thanks to a new hybrid backup storage system.
- ### Tweaks Settings
- **Added tweaks setting section.** Includes new minor changes you can now toggle on or off. New settings (and more will likely be added in future updates):
- **Placeholder Image.** Use a placeholder image in the Store for modules without images.

@ -95,6 +95,8 @@ const importsToAssign = {
const init = async function () {
Object.assign(this, importsToAssign);
await this.storage.init();
this.cssCache.load();
while (document.querySelectorAll('.flex-1xMQg5.flex-1O1GKY.horizontal-1ae9ci.horizontal-2EEEnY.flex-1O1GKY.directionRow-3v3tfG.justifyStart-2NDFzi.alignStretch-DpGPf3.noWrap-3jynv6 > [type="button"]:last-child').length === 0 || window.webpackJsonp === undefined) {
@ -106,7 +108,7 @@ const init = async function () {
}
this.versioning = {
version: `12.1-dev (rc-1)`,
version: `12.1-dev (rc-2)`,
hash: '<hash>', // Hash of built final js file is inserted here via build script
lastUsedVersion: this.storage.get('goosemodLastVersion')

@ -1,23 +1,47 @@
import fixLocalStorage from '../../util/discord/fixLocalStorage';
import * as hybrid_localStorage from './hyrbid/localStorage';
import * as hybrid_userDataCache from './hyrbid/userDataCache';
let storageCache = {};
export const type = 'Extension';
export const init = () => {
export const init = async () => {
if (!window.localStorage) fixLocalStorage();
document.addEventListener('gmes_get_return', ({ detail }) => {
const returnPromise = new Promise((res) => document.addEventListener('gmes_get_return', async ({ detail }) => {
storageCache = detail;
}, { once: true });
if (Object.keys(storageCache).length < 5) { // Empty (less than expected pairs) extension storage, try restore
await restore();
}
res();
}, { once: true }));
document.dispatchEvent(new CustomEvent('gmes_get'));
backup();
await returnPromise;
await backup();
};
export const restore = async () => {
console.log('GooseMod', 'Restoring storage...');
await hybrid_localStorage.restore({ set });
await hybrid_userDataCache.restore({ set });
};
export const backup = () => {
for (const k of keys()) localStorage.setItem(k, get(k));
export const backup = async () => {
console.log('GooseMod', 'Backing up storage...');
await hybrid_localStorage.backup({ keys, get });
await hybrid_userDataCache.backup({ keys, get });
};
export const set = (key, value) => {

@ -0,0 +1,12 @@
export const backup = async ({ keys, get }) => {
if (!window.localStorage) return;
for (const k of keys()) localStorage.setItem(k, get(k));
};
export const restore = async ({ set }) => { // Extension migration should do this automatically, but try anyway?
if (!window.localStorage) return;
Object.keys(localStorage).filter((x) => x.toLowerCase().startsWith('goosemod')).forEach((x) => set(x, localStorage.getItem(x)));
};

@ -0,0 +1,18 @@
export const backup = async ({ keys, get }) => {
if (!window.DiscordNative?.userDataCache) return;
const cache = await DiscordNative.userDataCache.getCached();
for (const k of keys()) cache[k] = get(k);
DiscordNative.userDataCache.cacheUserData(JSON.stringify(cache));
};
export const restore = async ({ set }) => {
if (!window.DiscordNative?.userDataCache) return;
const cache = await DiscordNative.userDataCache.getCached();
Object.keys(cache).filter((x) => x.toLowerCase().startsWith('goosemod')).forEach((x) => set(x, cache[x]));
};

@ -4,6 +4,6 @@ import * as impl_extension from './impl/extension';
// If extension version isn't defined, use localStorage
const impl = !window.gmExtension ? impl_localstorage : impl_extension;
if (impl.init) impl.init();
// if (impl.init) impl.init();
export default impl;
Loading…
Cancel
Save