bugs and performances

This commit is contained in:
Jean Ouina 2020-08-04 13:10:08 +02:00
parent 8f427e387d
commit 36545c4d09
7 changed files with 328 additions and 312 deletions

View File

@ -82,7 +82,7 @@ Core.prototype.init = async function() {
Utils.log("Startup", "Loading Themes");
await themeModule.loadThemes();
DOM.addStyle("customcss", atob(DataStore.getBDData("bdcustomcss")));
DOM.addStyle("customcss", Buffer.from(DataStore.getBDData("bdcustomcss"), "base64").toString("utf8"));
window.addEventListener("beforeunload", function() {
if (settingsCookie["bda-dc-0"]) document.querySelector(".btn.btn-disconnect").click();

View File

@ -22,8 +22,8 @@ export default new class DataStore {
initialize() {
try {
if (!fs.existsSync(this.BDFile)) fs.writeFileSync(this.BDFile, JSON.stringify(this.data, null, 4), "binary");
const data = JSON.parse(fs.readFileSync(this.BDFile, "binary"))
if (!fs.existsSync(this.BDFile)) fs.writeFileSync(this.BDFile, JSON.stringify(this.data, null, 4), "utf-8");
const data = JSON.parse(fs.readFileSync(this.BDFile, "utf-8"))
if (data.hasOwnProperty("settings")) this.data = data;
if (!fs.existsSync(this.settingsFile)) return;
let settings = __non_webpack_require__(this.settingsFile);
@ -62,7 +62,7 @@ export default new class DataStore {
setSettingGroup(key, data) {
this.data.settings[releaseChannel][key] = data;
fs.writeFileSync(this.BDFile, JSON.stringify(this.data, null, 4), "binary");
fs.writeFileSync(this.BDFile, JSON.stringify(this.data, null, 4), "utf-8");
}
getBDData(key) {
@ -71,7 +71,7 @@ export default new class DataStore {
setBDData(key, value) {
this.data[key] = value;
fs.writeFileSync(this.BDFile, JSON.stringify(this.data, null, 4), "binary");
fs.writeFileSync(this.BDFile, JSON.stringify(this.data, null, 4), "utf-8");
}
getPluginData(pluginName, key) {
@ -85,12 +85,12 @@ export default new class DataStore {
if (value === undefined) return;
if (this.pluginData[pluginName] === undefined) this.pluginData[pluginName] = {};
this.pluginData[pluginName][key] = value;
fs.writeFileSync(this.getPluginFile(pluginName), JSON.stringify(this.pluginData[pluginName], null, 4), "binary");
fs.writeFileSync(this.getPluginFile(pluginName), JSON.stringify(this.pluginData[pluginName], null, 4), "utf-8");
}
deletePluginData(pluginName, key) {
if (this.pluginData[pluginName] === undefined) this.pluginData[pluginName] = {};
delete this.pluginData[pluginName][key];
fs.writeFileSync(this.getPluginFile(pluginName), JSON.stringify(this.pluginData[pluginName], null, 4), "binary");
fs.writeFileSync(this.getPluginFile(pluginName), JSON.stringify(this.pluginData[pluginName], null, 4), "utf-8");
}
};

View File

@ -6,9 +6,6 @@ import webpackModules from "../modules/webpackModules"
import { remote } from "electron"
import MarginTop from "./margintop"
const keys = {
settingTitle: uuidv4()
}
let formModule
export default class ApiPreview extends React.PureComponent {
constructor(){
@ -32,7 +29,7 @@ export default class ApiPreview extends React.PureComponent {
These components are here for the plugin devs. They can quickly embed any component below with this panel.
<div style={{marginTop: "20px"}}></div>
<Lightcord.Api.Components.general.AlertBox type="info">All these components have error handling. If you want none, add `.original` after the component path.</Lightcord.Api.Components.general.AlertBox>
<Lightcord.Api.Components.general.AlertBox type="warn">We do not recommend modifying these component by a plugin. Only do this if you know what you are doing.</Lightcord.Api.Components.general.AlertBox>
<Lightcord.Api.Components.general.AlertBox type="warn">We do not recommend modifying these component with plugins. Only do this if you know what you are doing.</Lightcord.Api.Components.general.AlertBox>
</formModule.FormText>
<MarginTop></MarginTop>
<Lightcord.Api.Components.inputs.Button color="brand" look="outlined" size="medium" hoverColor="green" onClick={() => {
@ -42,27 +39,33 @@ export default class ApiPreview extends React.PureComponent {
</Lightcord.Api.Components.inputs.Button>
</formModule.FormSection>,
allComponents.map(comp => {
let AllPreviews = []
if(comp.AllPreviews)AllPreviews = comp.AllPreviews
let onChange = (tab) => {
setState({
tab
const compName = comp.displayName || comp.name
const compPath = `Lightcord.Api.Components.${Object.keys(window.Lightcord.Api.Components).find(e => window.Lightcord.Api.Components[e][compName])}.${compName}`
return <ComponentPreview key={compPath} comp={comp} />
})
]
}
let setState = (newState) => {
this.setState({
states: [Object.assign(state, newState)].concat(this.state.states.filter(e => e.elem !== comp))
})
get renders(){
}
let state = this.state.states.find(e => e.elem === comp)
if(!state){
state = {
}
class ComponentPreview extends React.Component {
constructor(props){
super(props)
this.state = {
tab: "preview",
elem: comp,
elem: props.comp,
options: {}
}
this.state.states.push(state)
}
render(){
const comp = this.props.comp
let AllPreviews = []
if(comp.AllPreviews)AllPreviews = comp.AllPreviews
let state = this.state
let getProps = () => {
let final = {}
AllPreviews.forEach(category => {
@ -94,12 +97,19 @@ export default class ApiPreview extends React.PureComponent {
<window.Lightcord.Api.Components.general.SettingSubTitle>
JSX
</window.Lightcord.Api.Components.general.SettingSubTitle>
<window.Lightcord.Api.Components.general.CodeBlock language="jsx" content={generateCode("jsx")}/>
<window.Lightcord.Api.Components.general.ErrorCatcher>
{React.createElement(() => {
return <window.Lightcord.Api.Components.general.CodeBlock language="jsx" content={generateCode("jsx")}/>
})}
</window.Lightcord.Api.Components.general.ErrorCatcher>
<window.Lightcord.Api.Components.general.SettingSubTitle>
React
</window.Lightcord.Api.Components.general.SettingSubTitle>
<window.Lightcord.Api.Components.general.CodeBlock language="js" content={generateCode("react")}/>
<window.Lightcord.Api.Components.general.ErrorCatcher>
{React.createElement(() => {
return <window.Lightcord.Api.Components.general.CodeBlock language="js" content={generateCode("react")}/>
})}
</window.Lightcord.Api.Components.general.ErrorCatcher>
</div>
</div>
}
@ -262,7 +272,7 @@ export default class ApiPreview extends React.PureComponent {
label: JSON.stringify(e[Object.keys(e)[0]])
}
})} value={"opt-"+(state.options[key] || "0")} onChange={(value) => {
setState({
this.setState({
options: Object.assign({}, state.options, {
[key]: (value.value || "0").replace("opt-", "")
})
@ -272,13 +282,11 @@ export default class ApiPreview extends React.PureComponent {
]
})}
<window.Lightcord.Api.Components.general.Tabs tabs={[{label: "Preview", id: "preview"}, {label: "Code", id: "code"}]}
active={state.tab} children={state.tab === "preview" ? renderPreview() : renderCode()} onChange={onChange}/>
</div>)
active={state.tab} children={state.tab === "preview" ? renderPreview() : renderCode()} onChange={(tab) => {
this.setState({
tab
})
]
}
get renders(){
}}/>
</div>)
}
}

View File

@ -135,8 +135,8 @@ export default class CardList extends BDV2.reactComponent {
getAddons() {
const sortedAddons = this.list.sort((a, b) => {
const cap = this.state.sort.charAt(0).toUpperCase() + this.state.sort.slice(1);
const first = a.plugin && a.plugin[`get${cap}`] ? this.getString(a.plugin[`get${cap}`]()) : a[this.state.sort];
const second = b.plugin && b.plugin[`get${cap}`] ? this.getString(b.plugin[`get${cap}`]()) : b[this.state.sort];
const first = a.plugin && a.plugin[`get${cap}`] ? this.getString(a.plugin[`get${cap}`]()) : this.getString(a[this.state.sort]);
const second = b.plugin && b.plugin[`get${cap}`] ? this.getString(b.plugin[`get${cap}`]()) : this.getString(b[this.state.sort]);
if (typeof(first) == "string") return first.toLocaleLowerCase().localeCompare(second.toLocaleLowerCase());
if (first > second) return 1;
if (second > first) return -1;

View File

@ -72,7 +72,7 @@ export default class V2C_CssEditor extends BDV2.reactComponent {
const _ccss = DataStore.getBDData("bdcustomcss");
let ccss = "";
if (_ccss && _ccss !== "") {
ccss = atob(_ccss);
ccss = Buffer.from(_ccss, "base64").toString("utf8");
}
return ccss;
}
@ -193,7 +193,7 @@ export default class V2C_CssEditor extends BDV2.reactComponent {
}
saveCss() {
DataStore.setBDData("bdcustomcss", btoa(this.editor.session.getValue()));
DataStore.setBDData("bdcustomcss", Buffer.from(this.editor.session.getValue(), "utf-8").toString("base64"));
}
detach() {

View File

@ -62,7 +62,7 @@ export default class V2C_CssEditorDetached extends BDV2.reactComponent {
const _ccss = DataStore.getBDData("bdcustomcss");
let ccss = "";
if (_ccss && _ccss !== "") {
ccss = atob(_ccss);
ccss = Buffer.from(_ccss, "base64").toString("utf8");
}
return ccss;
}
@ -169,6 +169,6 @@ export default class V2C_CssEditorDetached extends BDV2.reactComponent {
}
saveCss() {
DataStore.setBDData("bdcustomcss", btoa(this.editor.session.getValue()));
DataStore.setBDData("bdcustomcss", Buffer.from(this.editor.session.getValue(), "utf-8").toString("base64"));
}
}

View File

@ -43,6 +43,14 @@ export default class Settings {
this.settings[key] = value;
}
delete(key){
delete this.settings[key]
}
exists(key){
return key in this.settings
}
save() {
if (this.lastModified && this.lastModified !== this._lastModified()) {
console.warn('Not saving settings, it has been externally modified.');