Fix various bugs
- Fix an issue removing settings collection - Fix bugs related to opening in system editor - Check for guild glasses (in webpack) a little bit later to allow for slower loading - Add addition try..catch around file operations in DataStore
This commit is contained in:
parent
fd43ebf7b8
commit
01941c1178
|
@ -16,6 +16,8 @@ const React = DiscordModules.React;
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const Module = require("module").Module;
|
const Module = require("module").Module;
|
||||||
|
const shell = require("electron").shell;
|
||||||
|
const openItem = shell.openItem || shell.openPath;
|
||||||
|
|
||||||
const splitRegex = /[^\S\r\n]*?\r?(?:\r\n|\n)[^\S\r\n]*?\*[^\S\r\n]?/;
|
const splitRegex = /[^\S\r\n]*?\r?(?:\r\n|\n)[^\S\r\n]*?\*[^\S\r\n]?/;
|
||||||
const escapedAtRegex = /^\\@/;
|
const escapedAtRegex = /^\\@/;
|
||||||
|
@ -205,10 +207,6 @@ export default class AddonManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
const addon = __non_webpack_require__(path.resolve(this.addonFolder, filename));
|
const addon = __non_webpack_require__(path.resolve(this.addonFolder, filename));
|
||||||
// console.log(addon);
|
|
||||||
// await Promise.resolve(addon);
|
|
||||||
// addon = __non_webpack_require__(path.resolve(this.addonFolder, filename));
|
|
||||||
// console.log(addon);
|
|
||||||
if (this.addonList.find(c => c.id == addon.id)) return new AddonError(addon.name, filename, Strings.Addons.alreadyExists.format({type: this.prefix, name: addon.name}), this.prefix);
|
if (this.addonList.find(c => c.id == addon.id)) return new AddonError(addon.name, filename, Strings.Addons.alreadyExists.format({type: this.prefix, name: addon.name}), this.prefix);
|
||||||
|
|
||||||
const error = this.initializeAddon(addon);
|
const error = this.initializeAddon(addon);
|
||||||
|
@ -343,7 +341,7 @@ export default class AddonManager {
|
||||||
const addon = typeof(idOrFileOrAddon) == "string" ? this.addonList.find(c => c.id == idOrFileOrAddon || c.filename == idOrFileOrAddon) : idOrFileOrAddon;
|
const addon = typeof(idOrFileOrAddon) == "string" ? this.addonList.find(c => c.id == idOrFileOrAddon || c.filename == idOrFileOrAddon) : idOrFileOrAddon;
|
||||||
const fullPath = path.resolve(this.addonFolder, addon.filename);
|
const fullPath = path.resolve(this.addonFolder, addon.filename);
|
||||||
if (typeof(system) == "undefined") system = Settings.get("settings", "addons", "editAction") == "system";
|
if (typeof(system) == "undefined") system = Settings.get("settings", "addons", "editAction") == "system";
|
||||||
if (system) return require("electron").shell.openItem(`${fullPath}`);
|
if (system) return openItem(`${fullPath}`);
|
||||||
return this.openDetached(addon);
|
return this.openDetached(addon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,6 @@ import IPC from "./ipc";
|
||||||
import LoadingIcon from "../loadingicon";
|
import LoadingIcon from "../loadingicon";
|
||||||
import Styles from "../styles/index.css";
|
import Styles from "../styles/index.css";
|
||||||
|
|
||||||
const GuildClasses = DiscordModules.GuildClasses;
|
|
||||||
|
|
||||||
export default new class Core {
|
export default new class Core {
|
||||||
async startup() {
|
async startup() {
|
||||||
if (this.hasStarted) return;
|
if (this.hasStarted) return;
|
||||||
|
@ -89,6 +87,8 @@ export default new class Core {
|
||||||
}
|
}
|
||||||
|
|
||||||
waitForGuilds() {
|
waitForGuilds() {
|
||||||
|
// TODO: experiment with waiting for CONNECTION_OPEN event instead
|
||||||
|
const GuildClasses = DiscordModules.GuildClasses;
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
const checkForGuilds = function () {
|
const checkForGuilds = function () {
|
||||||
if (document.readyState != "complete") setTimeout(checkForGuilds, 100);
|
if (document.readyState != "complete") setTimeout(checkForGuilds, 100);
|
||||||
|
|
|
@ -37,18 +37,24 @@ export default new class DataStore {
|
||||||
|
|
||||||
if (!fs.existsSync(this.dataFolder)) fs.mkdirSync(this.dataFolder);
|
if (!fs.existsSync(this.dataFolder)) fs.mkdirSync(this.dataFolder);
|
||||||
// if (!fs.existsSync(this.localeFolder)) fs.mkdirSync(this.localeFolder);
|
// if (!fs.existsSync(this.localeFolder)) fs.mkdirSync(this.localeFolder);
|
||||||
if (!fs.existsSync(this.emoteFolder)) fs.mkdirSync(this.emoteFolder);
|
// if (!fs.existsSync(this.emoteFolder)) fs.mkdirSync(this.emoteFolder);
|
||||||
|
|
||||||
if (!fs.existsSync(this.cacheFile)) fs.writeFileSync(this.cacheFile, JSON.stringify({}));
|
// if (!fs.existsSync(this.cacheFile)) fs.writeFileSync(this.cacheFile, JSON.stringify({}));
|
||||||
if (!fs.existsSync(this.customCSS)) fs.writeFileSync(this.customCSS, "");
|
if (!fs.existsSync(this.customCSS)) fs.writeFileSync(this.customCSS, "");
|
||||||
|
|
||||||
const dataFiles = fs.readdirSync(this.dataFolder).filter(f => !fs.statSync(path.resolve(this.dataFolder, f)).isDirectory() && f.endsWith(".json"));
|
const dataFiles = fs.readdirSync(this.dataFolder).filter(f => !fs.statSync(path.resolve(this.dataFolder, f)).isDirectory() && f.endsWith(".json"));
|
||||||
for (const file of dataFiles) {
|
for (const file of dataFiles) {
|
||||||
this.data[file.split(".")[0]] = __non_webpack_require__(path.resolve(this.dataFolder, file));
|
let data = {};
|
||||||
|
try {data = __non_webpack_require__(path.resolve(this.dataFolder, file));}
|
||||||
|
catch (e) {Logger.stacktrace("DataStore", `Could not load file ${file}`, e);}
|
||||||
|
this.data[file.split(".")[0]] = data;
|
||||||
}
|
}
|
||||||
this.cacheData = Utilities.testJSON(fs.readFileSync(this.cacheFile).toString()) || {};
|
// this.cacheData = Utilities.testJSON(fs.readFileSync(this.cacheFile).toString()) || {};
|
||||||
|
|
||||||
if (!newStorageExists) this.convertOldData(); // Convert old data if it exists (routine checks existence and removes existence)
|
if (newStorageExists) return;
|
||||||
|
|
||||||
|
try {this.convertOldData();} // Convert old data if it exists (routine checks existence and removes existence)
|
||||||
|
catch (e) {Logger.stacktrace("DataStore", `Could not convert old data.`, e);}
|
||||||
}
|
}
|
||||||
|
|
||||||
convertOldData() {
|
convertOldData() {
|
||||||
|
@ -109,9 +115,9 @@ export default new class DataStore {
|
||||||
get customCSS() {return this._customCSS || (this._customCSS = path.resolve(this.dataFolder, "custom.css"));}
|
get customCSS() {return this._customCSS || (this._customCSS = path.resolve(this.dataFolder, "custom.css"));}
|
||||||
get baseFolder() {return this._baseFolder || (this._baseFolder = path.resolve(Config.dataPath, "data"));}
|
get baseFolder() {return this._baseFolder || (this._baseFolder = path.resolve(Config.dataPath, "data"));}
|
||||||
get dataFolder() {return this._dataFolder || (this._dataFolder = path.resolve(this.baseFolder, `${releaseChannel}`));}
|
get dataFolder() {return this._dataFolder || (this._dataFolder = path.resolve(this.baseFolder, `${releaseChannel}`));}
|
||||||
get localeFolder() {return this._localeFolder || (this._localeFolder = path.resolve(this.baseFolder, `locales`));}
|
// get localeFolder() {return this._localeFolder || (this._localeFolder = path.resolve(this.baseFolder, `locales`));}
|
||||||
get emoteFolder() {return this._emoteFolder || (this._emoteFolder = path.resolve(this.baseFolder, `emotes`));}
|
// get emoteFolder() {return this._emoteFolder || (this._emoteFolder = path.resolve(this.baseFolder, `emotes`));}
|
||||||
get cacheFile() {return this._cacheFile || (this._cacheFile = path.resolve(this.baseFolder, `.cache`));}
|
// get cacheFile() {return this._cacheFile || (this._cacheFile = path.resolve(this.baseFolder, `.cache`));}
|
||||||
getPluginFile(pluginName) {return path.resolve(Config.dataPath, "plugins", pluginName + ".config.json");}
|
getPluginFile(pluginName) {return path.resolve(Config.dataPath, "plugins", pluginName + ".config.json");}
|
||||||
|
|
||||||
|
|
||||||
|
@ -139,37 +145,37 @@ export default new class DataStore {
|
||||||
fs.writeFileSync(path.resolve(this.localeFolder, `${locale}.json`), JSON.stringify(strings, null, 4));
|
fs.writeFileSync(path.resolve(this.localeFolder, `${locale}.json`), JSON.stringify(strings, null, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
getCacheHash(category, key) {
|
// getCacheHash(category, key) {
|
||||||
if (!this.cacheData[category]) return "";
|
// if (!this.cacheData[category]) return "";
|
||||||
if (!fs.existsSync(path.resolve(this.baseFolder, category, `${key}.json`))) return "";
|
// if (!fs.existsSync(path.resolve(this.baseFolder, category, `${key}.json`))) return "";
|
||||||
return this.cacheData[category][key] || "";
|
// return this.cacheData[category][key] || "";
|
||||||
}
|
// }
|
||||||
|
|
||||||
setCacheHash(category, key, hash) {
|
// setCacheHash(category, key, hash) {
|
||||||
if (!this.cacheData[category]) this.cacheData[category] = {};
|
// if (!this.cacheData[category]) this.cacheData[category] = {};
|
||||||
this.cacheData[category][key] = hash;
|
// this.cacheData[category][key] = hash;
|
||||||
fs.writeFileSync(this.cacheFile, JSON.stringify(this.cacheData));
|
// fs.writeFileSync(this.cacheFile, JSON.stringify(this.cacheData));
|
||||||
}
|
// }
|
||||||
|
|
||||||
invalidateCache(category, key) {
|
// invalidateCache(category, key) {
|
||||||
if (!this.cacheData[category]) return;
|
// if (!this.cacheData[category]) return;
|
||||||
delete this.cacheData[category][key];
|
// delete this.cacheData[category][key];
|
||||||
fs.writeFileSync(this.cacheFile, JSON.stringify(this.cacheData));
|
// fs.writeFileSync(this.cacheFile, JSON.stringify(this.cacheData));
|
||||||
}
|
// }
|
||||||
|
|
||||||
emotesExist(category) {
|
// emotesExist(category) {
|
||||||
return fs.existsSync(path.resolve(this.emoteFolder, `${category}.json`));
|
// return fs.existsSync(path.resolve(this.emoteFolder, `${category}.json`));
|
||||||
}
|
// }
|
||||||
|
|
||||||
getEmoteData(category) {
|
// getEmoteData(category) {
|
||||||
const file = path.resolve(this.emoteFolder, `${category}.json`);
|
// const file = path.resolve(this.emoteFolder, `${category}.json`);
|
||||||
if (!fs.existsSync(file)) return null;
|
// if (!fs.existsSync(file)) return null;
|
||||||
return Utilities.testJSON(fs.readFileSync(file).toString());
|
// return Utilities.testJSON(fs.readFileSync(file).toString());
|
||||||
}
|
// }
|
||||||
|
|
||||||
saveEmoteData(category, data) {
|
// saveEmoteData(category, data) {
|
||||||
fs.writeFileSync(path.resolve(this.emoteFolder, `${category}.json`), JSON.stringify(data));
|
// fs.writeFileSync(path.resolve(this.emoteFolder, `${category}.json`), JSON.stringify(data));
|
||||||
}
|
// }
|
||||||
|
|
||||||
getData(key) {
|
getData(key) {
|
||||||
return this.data[key] || "";
|
return this.data[key] || "";
|
||||||
|
|
|
@ -36,7 +36,7 @@ export default new class SettingsManager {
|
||||||
|
|
||||||
removeCollection(id) {
|
removeCollection(id) {
|
||||||
const location = this.collections.findIndex(c => c.id == id);
|
const location = this.collections.findIndex(c => c.id == id);
|
||||||
if (!location < 0) return Logger.error("Settings", "No collection with id " + id);
|
if (location < 0) return Logger.error("Settings", "No collection with id " + id);
|
||||||
this.collections.splice(location, 1);
|
this.collections.splice(location, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue