more cleanup
This commit is contained in:
parent
d365999efe
commit
f3a1d789c8
36
js/main.js
36
js/main.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,4 @@
|
|||
import Builtin from "../structs/builtin";
|
||||
import {State} from "data";
|
||||
import {DataStore, Utilities, Events} from "modules";
|
||||
|
||||
import EmoteModule from "./emotes";
|
||||
|
@ -83,9 +82,7 @@ export default new class EmoteMenu extends Builtin {
|
|||
});
|
||||
this.hideEmojiCancel = this.registerSetting(this.hideEmojisID, this.enableHideEmojis, this.disableHideEmojis);
|
||||
if (this.hideEmojis) this.enableHideEmojis();
|
||||
// await this.waitForEmotes();
|
||||
// this.updateTwitchEmotes();
|
||||
if (State.emotesLoaded) this.updateTwitchEmotes();
|
||||
if (EmoteModule.emotesLoaded) this.updateTwitchEmotes();
|
||||
Events.on("emotes-loaded", this.updateTwitchEmotes);
|
||||
}
|
||||
|
||||
|
@ -96,13 +93,6 @@ export default new class EmoteMenu extends Builtin {
|
|||
if (this.hideEmojiCancel) this.hideEmojiCancel();
|
||||
}
|
||||
|
||||
async waitForEmotes() {
|
||||
if (State.emotesLoaded) return;
|
||||
return new Promise(resolve => {
|
||||
Events.on("emotes-loaded", resolve);
|
||||
});
|
||||
}
|
||||
|
||||
enableHideEmojis() {
|
||||
$(".emojiPicker-3m1S-j").addClass("bda-qme-hidden");
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import Builtin from "../structs/builtin";
|
||||
|
||||
import {Config, EmoteInfo, State, EmoteConfig} from "data";
|
||||
import {Config, EmoteInfo, EmoteConfig} from "data";
|
||||
import {Utilities, WebpackModules, DataStore, DiscordModules, Events, Settings} from "modules";
|
||||
import BDEmote from "../ui/emote";
|
||||
import {Toasts} from "ui";
|
||||
|
@ -151,6 +151,7 @@ export default new class EmoteModule extends Builtin {
|
|||
}
|
||||
|
||||
async loadEmoteData(emoteInfo) {
|
||||
this.emotesLoaded = false;
|
||||
const _fs = require("fs");
|
||||
const emoteFile = "emote_data.json";
|
||||
const file = Config.dataPath + emoteFile;
|
||||
|
@ -177,7 +178,7 @@ export default new class EmoteModule extends Builtin {
|
|||
|
||||
if (isValid) {
|
||||
Toasts.show("Emotes successfully loaded.", {type: "success"});
|
||||
State.emotesLoaded = true;
|
||||
this.emotesLoaded = true;
|
||||
Events.dispatch("emotes-loaded");
|
||||
return;
|
||||
}
|
||||
|
@ -200,7 +201,7 @@ export default new class EmoteModule extends Builtin {
|
|||
try { _fs.writeFileSync(file, JSON.stringify(Emotes), "utf8"); }
|
||||
catch (err) { Utilities.err("Emotes", "Could not save emote data.", err); }
|
||||
|
||||
State.emotesLoaded = true;
|
||||
this.emotesLoaded = true;
|
||||
Events.dispatch("emotes-loaded");
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
import Builtin from "../structs/builtin";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
export default new class WindowPrefs extends Builtin {
|
||||
get name() {return "WindowPrefs";}
|
||||
get category() {return "window";}
|
||||
get id() {return "transparency";}
|
||||
|
||||
get WindowConfigFile() {
|
||||
if (this._windowConfigFile) return this._windowConfigFile;
|
||||
const electron = require("electron").remote.app;
|
||||
const base = electron.getAppPath();
|
||||
const roamingBase = electron.getPath("userData");
|
||||
const roamingLocation = path.resolve(roamingBase, electron.getVersion(), "modules", "discord_desktop_core", "injector", "config.json");
|
||||
const location = path.resolve(base, "..", "app", "config.json");
|
||||
const realLocation = fs.existsSync(location) ? location : fs.existsSync(roamingLocation) ? roamingLocation : null;
|
||||
if (!realLocation) return this._windowConfigFile = null;
|
||||
return this._windowConfigFile = realLocation;
|
||||
}
|
||||
|
||||
enabled() {
|
||||
this.setWindowPreference("transparency", true);
|
||||
this.setWindowPreference("backgroundColor", null);
|
||||
}
|
||||
|
||||
disabled() {
|
||||
this.setWindowPreference("transparency", false);
|
||||
this.setWindowPreference("backgroundColor", "#2f3136");
|
||||
}
|
||||
|
||||
getAllWindowPreferences() {
|
||||
if (!this.WindowConfigFile) return {};
|
||||
return __non_webpack_require__(this.WindowConfigFile);
|
||||
}
|
||||
|
||||
getWindowPreference(key) {
|
||||
if (!this.WindowConfigFile) return undefined;
|
||||
return this.getAllWindowPreferences()[key];
|
||||
}
|
||||
|
||||
setWindowPreference(key, value) {
|
||||
if (!this.WindowConfigFile) return;
|
||||
const prefs = this.getAllWindowPreferences();
|
||||
prefs[key] = value;
|
||||
delete require.cache[this.WindowConfigFile];
|
||||
fs.writeFileSync(this.WindowConfigFile, JSON.stringify(prefs, null, 4));
|
||||
}
|
||||
};
|
|
@ -1,9 +1,6 @@
|
|||
import State from "./state";
|
||||
import Config from "./config";
|
||||
import EmoteInfo from "./emotes/info";
|
||||
import EmoteConfig from "./emotes/config";
|
||||
|
||||
import SettingsConfig from "./settings/config";
|
||||
import SettingsState from "./settings/state";
|
||||
|
||||
export {State, Config, EmoteInfo, EmoteConfig, SettingsConfig, SettingsState};
|
||||
export {Config, EmoteInfo, EmoteConfig, SettingsConfig};
|
|
@ -1 +0,0 @@
|
|||
export default {};
|
|
@ -1,3 +0,0 @@
|
|||
export default {
|
||||
emotesLoaded: false
|
||||
};
|
|
@ -46,6 +46,6 @@ export default function() {
|
|||
}
|
||||
});
|
||||
|
||||
window.localStorage = lsProxy;
|
||||
window.localStorage = null;
|
||||
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
import {SettingsConfig, SettingsState} from "data";
|
||||
import {SettingsConfig} from "data";
|
||||
import DataStore from "./datastore";
|
||||
import BdApi from "./pluginapi";
|
||||
import Events from "./emitter";
|
||||
import WebpackModules, {DiscordModules} from "./webpackmodules";
|
||||
|
||||
|
@ -11,8 +10,7 @@ import {Toasts} from "ui";
|
|||
export default new class SettingsManager {
|
||||
|
||||
constructor() {
|
||||
this.config = SettingsConfig;
|
||||
this.state = SettingsState;
|
||||
this.state = {};
|
||||
this.collections = [];
|
||||
this.panels = [];
|
||||
this.registerCollection("settings", "Settings", SettingsConfig);
|
||||
|
@ -101,7 +99,6 @@ export default new class SettingsManager {
|
|||
data.returnValue.splice(location, 0, section);
|
||||
location++;
|
||||
};
|
||||
console.log(data); /* eslint-disable-line no-console */
|
||||
insert({section: "DIVIDER"});
|
||||
insert({section: "HEADER", label: "BandagedBD"});
|
||||
for (const collection of this.collections) {
|
||||
|
@ -109,7 +106,7 @@ export default new class SettingsManager {
|
|||
insert({
|
||||
section: collection.name,
|
||||
label: collection.name,
|
||||
element: () => SettingsRenderer.buildSettingsPanel(collection.name, collection.settings, SettingsState[collection.id], this.onSettingChange.bind(this, collection.id), collection.button ? collection.button : null)
|
||||
element: () => SettingsRenderer.buildSettingsPanel(collection.name, collection.settings, this.state[collection.id], this.onSettingChange.bind(this, collection.id), collection.button ? collection.button : null)
|
||||
});
|
||||
}
|
||||
for (const panel of this.panels) insert(panel);
|
||||
|
@ -188,15 +185,4 @@ export default new class SettingsManager {
|
|||
Events.on("setting-updated", handler);
|
||||
return () => {Events.off("setting-updated", handler);};
|
||||
}
|
||||
|
||||
updateSettings(collection, category, id, enabled) {
|
||||
|
||||
if (id == "fork-wp-1") {
|
||||
BdApi.setWindowPreference("transparent", enabled);
|
||||
if (enabled) BdApi.setWindowPreference("backgroundColor", null);
|
||||
else BdApi.setWindowPreference("backgroundColor", "#2f3136");
|
||||
}
|
||||
|
||||
// this.saveSettings();
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue