Settings Fix

This commit is contained in:
Jean Ouina 2020-10-14 00:50:42 +02:00
parent b86df9a17e
commit 55208fd4d3
21 changed files with 245 additions and 304 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -119,7 +119,7 @@ class LightcordError extends Error {
} }
export const Constants = { export const Constants = {
SERVER_URL: "https://lightcord.deroku.xyz", SERVER_URL: "https://lightcord.org",
badges: [ // TODO: Add more badges + server side svg badges: [ // TODO: Add more badges + server side svg
{ {
name: "Lightcord Bug Hunter", name: "Lightcord Bug Hunter",

View File

@ -3,5 +3,9 @@ const {useState} = BDV2.react
export function useForceUpdate(){ export function useForceUpdate(){
return useState()[1]; const [,setValue] = useState(0)
return function forceUpdate(){
setValue(e => e+1)
}
} }

View File

@ -32,6 +32,7 @@ import History from "../ui/icons/history";
import core from "./core"; import core from "./core";
import popoutWindow from "./popoutWindow"; import popoutWindow from "./popoutWindow";
import TextInputSetting from "../ui/TextInputSetting"; import TextInputSetting from "../ui/TextInputSetting";
import { useForceUpdate } from "./hooks";
class BDSidebarHeader extends React.PureComponent { class BDSidebarHeader extends React.PureComponent {
render(){ render(){
@ -327,90 +328,94 @@ export default new class V2_SettingsPanel {
(i === 0 ? null : BDV2.react.createElement(MarginTop)), (i === 0 ? null : BDV2.react.createElement(MarginTop)),
BDV2.react.createElement("h2", {className: "ui-form-title h2 margin-reset margin-bottom-20"}, section.title), BDV2.react.createElement("h2", {className: "ui-form-title h2 margin-reset margin-bottom-20"}, section.title),
section.settings.map(setting => { section.settings.map(setting => {
let isChecked = settingsCookie[setting.id] return React.createElement(() => {
let value = appSettings.get("BD_"+setting.id, setting.default || "") const forceUpdate = useForceUpdate()
if(setting.id === "lightcord-8")isChecked = appSettings.get("isTabs", false); let isChecked = settingsCookie[setting.id]
if(setting.id === "no_window_bound")isChecked = appSettings.get("NO_WINDOWS_BOUND", false) if(setting.id === "lightcord-8")isChecked = appSettings.get("isTabs", false);
if(setting.id === "enable_glasstron")isChecked = appSettings.get("GLASSTRON", true) if(setting.id === "no_window_bound")isChecked = appSettings.get("NO_WINDOWS_BOUND", false)
if(setting.id === "lightcord-10")isChecked = !appSettings.get("DEFAULT_NOTIFICATIONS", true) if(setting.id === "enable_glasstron")isChecked = appSettings.get("GLASSTRON", true)
let returnValue if(setting.id === "lightcord-10")isChecked = !appSettings.get("DEFAULT_NOTIFICATIONS", true)
if(["lightcord-11"].includes(setting.id)){ let returnValue
returnValue = BDV2.react.createElement(TextInputSetting, {id: setting.id, key: setting.id, data: setting, value, placeholder: setting.default || null, onChange: (id, value) => { if(["lightcord-11"].includes(setting.id)){
this.onChange(id, value, sidebar); let value = appSettings.get("BD_"+setting.id, setting.default || "")
}}) returnValue = BDV2.react.createElement(TextInputSetting, {id: setting.id, key: setting.id, data: setting, value, placeholder: setting.default || null, onChange: (id, value) => {
}else{ this.onChange(id, value, sidebar);
returnValue = BDV2.react.createElement(Switch, {id: setting.id, key: setting.id, data: setting, checked: isChecked, onChange: (id, checked) => { }})
this.onChange(id, checked, sidebar); }else{
}}) returnValue = BDV2.react.createElement(Switch, {id: setting.id, key: setting.id, data: setting, checked: isChecked, onChange: (id, checked) => {
} this.onChange(id, checked, sidebar);
if(setting.id == "lightcord-8" && isChecked){ forceUpdate()
return [ }})
returnValue, }
React.createElement(Lightcord.Api.Components.inputs.Button, { if(setting.id == "lightcord-8" && isChecked){
color: "green",
look: "outlined",
size: "small",
hoverColor: "brand",
onClick: () => {
DiscordNative.ipc.send("NEW_TAB")
},
wrapper: false,
disabled: false
}, "Open a new Tab")
]
}
if(setting.id === "enable_glasstron" && isChecked){
if(process.platform !== "linux"){
let choices = []
let actual = null
if(process.platform === "win32"){
choices.push("blurbehind", "acrylic", "transparent")
actual = appSettings.get("GLASSTRON_BLUR", "blurbehind")
}else if(process.platform === "darwin"){
choices.push("titlebar",
"selection",
"menu",
"popover",
"sidebar",
"header",
"sheet",
"window",
"hud",
"fullscreen-ui",
"tooltip",
"content",
"under-window",
"under-page",
"none"
)
actual = appSettings.get("GLASSTRON_VIBRANCY", "fullscreen-ui")
}
return [ return [
returnValue, returnValue,
React.createElement(Lightcord.Api.Components.general.SettingSubTitle, {}, "Glasstron Blur"), React.createElement(Lightcord.Api.Components.inputs.Button, {
React.createElement(Lightcord.Api.Components.inputs.Dropdown, { color: "green",
options: choices.map(e => { look: "outlined",
return { size: "small",
value: e, hoverColor: "brand",
label: e onClick: () => {
} DiscordNative.ipc.send("NEW_TAB")
}), },
value: actual, wrapper: false,
disabled: false, disabled: false
searchable: true, }, "Open a new Tab")
clearable: false,
onChange: (value) => {
if(process.platform === "win32"){
ipcRenderer.invoke("LIGHTCORD_SET_BLUR_TYPE", value)
}else{
ipcRenderer.invoke("LIGHTCORD_SET_VIBRANCY", value)
}
}
}, null)
] ]
} }
} if(setting.id === "enable_glasstron" && isChecked){
return returnValue if(process.platform !== "linux"){
let choices = []
let actual = null
if(process.platform === "win32"){
choices.push("blurbehind", "acrylic", "transparent")
actual = appSettings.get("GLASSTRON_BLUR", "blurbehind")
}else if(process.platform === "darwin"){
choices.push("titlebar",
"selection",
"menu",
"popover",
"sidebar",
"header",
"sheet",
"window",
"hud",
"fullscreen-ui",
"tooltip",
"content",
"under-window",
"under-page",
"none"
)
actual = appSettings.get("GLASSTRON_VIBRANCY", "fullscreen-ui")
}
return [
returnValue,
React.createElement(Lightcord.Api.Components.general.SettingSubTitle, {}, "Glasstron Blur"),
React.createElement(Lightcord.Api.Components.inputs.Dropdown, {
options: choices.map(e => {
return {
value: e,
label: e
}
}),
value: actual,
disabled: false,
searchable: true,
clearable: false,
onChange: (value) => {
if(process.platform === "win32"){
ipcRenderer.invoke("LIGHTCORD_SET_BLUR_TYPE", value)
}else{
ipcRenderer.invoke("LIGHTCORD_SET_VIBRANCY", value)
}
}
}, null)
]
}
}
return returnValue
})
}) })
] ]
}), }),

View File

@ -33,7 +33,7 @@ export default class ApiPreview extends React.PureComponent {
</formModule.FormText> </formModule.FormText>
<MarginTop></MarginTop> <MarginTop></MarginTop>
<Lightcord.Api.Components.inputs.Button color="brand" look="outlined" size="medium" hoverColor="green" onClick={() => { <Lightcord.Api.Components.inputs.Button color="brand" look="outlined" size="medium" hoverColor="green" onClick={() => {
remote.shell.openExternal("https://lightcord.deroku.xyz/LightcordApi/") remote.shell.openExternal("https://lightcord.org/LightcordApi/")
}} wrapper={false}> }} wrapper={false}>
Documentation Documentation
</Lightcord.Api.Components.inputs.Button> </Lightcord.Api.Components.inputs.Button>

View File

@ -7,7 +7,6 @@ export default class Switch extends React.Component {
super(props); super(props);
this.state = {checked: this.props.checked}; this.state = {checked: this.props.checked};
this.onChange = this.onChange.bind(this); this.onChange = this.onChange.bind(this);
this.switch = <Lightcord.Api.Components.inputs.Switch onChange={this.onChange} value={this.state.checked} />
} }
onChange(value) { onChange(value) {
@ -17,6 +16,6 @@ export default class Switch extends React.Component {
} }
render() { render() {
return this.switch return <Lightcord.Api.Components.inputs.Switch onChange={this.onChange} value={this.state.checked} />
} }
} }

View File

@ -155,7 +155,7 @@ export default class V2C_PresenceSettings extends React.Component {
DiscordNative.clipboard.copy(Date.now()+"") DiscordNative.clipboard.copy(Date.now()+"")
}} />) }} />)
}*/ }*/
return array return array[0]
}else if(e.type === "choice"){ }else if(e.type === "choice"){
if(["assets.small", "assets.large"].includes(e.id)){ if(["assets.small", "assets.large"].includes(e.id)){
return <InputChoice setting={e} manager={this} id={e.id} choices={[{value: "none", label: "No assets"}].concat(this.state.assets.map(e => { return <InputChoice setting={e} manager={this} id={e.id} choices={[{value: "none", label: "No assets"}].concat(this.state.assets.map(e => {

View File

@ -4,6 +4,7 @@ import BDV2 from "../modules/v2";
import SettingsTitle from "./settingsTitle"; import SettingsTitle from "./settingsTitle";
import Switch from "./switch"; import Switch from "./switch";
import MarginTop from "./margintop"; import MarginTop from "./margintop";
import { useForceUpdate } from "../modules/hooks";
let formModule let formModule
let switchItem let switchItem
@ -26,6 +27,7 @@ export default class V2C_SettingsGroup extends BDV2.reactComponent {
settings.map(setting => { settings.map(setting => {
return BDV2.react.createElement(Switch, {id: setting.id, key: setting.id, data: setting, checked: settingsCookie[setting.id], onChange: (id, checked) => { return BDV2.react.createElement(Switch, {id: setting.id, key: setting.id, data: setting, checked: settingsCookie[setting.id], onChange: (id, checked) => {
this.props.onChange(id, checked); this.props.onChange(id, checked);
this.forceUpdate()
}}); }});
})]; })];
} }
@ -64,15 +66,18 @@ export default class V2C_SettingsGroup extends BDV2.reactComponent {
if(setting.experimental){ if(setting.experimental){
info.push(<sup className={betaClassNames.beta}>(EXPERIMENTAL)</sup>) info.push(<sup className={betaClassNames.beta}>(EXPERIMENTAL)</sup>)
} }
return <switchItem.default onChange={(ev) => { return React.createElement(() => {
this.props.onChange(setting.id, ev.target.checked); const forceUpdate = useForceUpdate()
this.forceUpdate() return <switchItem.default onChange={(val) => {
}} key={setting.id} value={settingsCookie[setting.id]} className={__SECRET_EMOTION__.css({ this.props.onChange(setting.id, val);
marginBottom: "20px" forceUpdate()
})} disabled={false} hideBorder={false} }} key={setting.id} value={settingsCookie[setting.id]} className={__SECRET_EMOTION__.css({
size={switchItem.default.Sizes.DEFAULT} theme={switchItem.default.Themes.DEFAULT} note={setting.info}> marginBottom: "20px"
{info} })} disabled={false} hideBorder={false}
</switchItem.default> note={setting.info} tooltipNote={null}>
{info}
</switchItem.default>
})
})) }))
return <formModule.FormSection tag="h2" title={this.props.title}> return <formModule.FormSection tag="h2" title={this.props.title}>
{children} {children}

View File

@ -4,4 +4,4 @@ Welcome to LightcordApi's Documentation !
The api is mainly written here. The api is mainly written here.
The main's module documentation can be found [here](https://lightcord.deroku.xyz/LightcordApi/interfaces/_index_.lightcordglobal.html) The main's module documentation can be found [here](https://lightcord.org/LightcordApi/interfaces/_index_.lightcordglobal.html)

View File

@ -165,7 +165,7 @@
</a> </a>
<p>Welcome to LightcordApi&#39;s Documentation !</p> <p>Welcome to LightcordApi&#39;s Documentation !</p>
<p>The api is mainly written here.</p> <p>The api is mainly written here.</p>
<p>The main&#39;s module documentation can be found <a href="https://lightcord.deroku.xyz/LightcordApi/interfaces/_index_.lightcordglobal.html">here</a></p> <p>The main&#39;s module documentation can be found <a href="https://lightcord.org/LightcordApi/interfaces/_index_.lightcordglobal.html">here</a></p>
</div> </div>
<footer class="with-border-bottom"> <footer class="with-border-bottom">
<div class="tsd-legend-group"> <div class="tsd-legend-group">

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,29 +1,18 @@
import WebpackLoader from "../../modules/WebpackLoader" import WebpackLoader from "../../modules/WebpackLoader"
import uuid from "../../modules/uuid"
import NOOP from "../../modules/noop" import NOOP from "../../modules/noop"
import Utils from "../../modules/Utils"
type SwitchProps = { type SwitchProps = {
id?: string, id?: string,
onChange?: (checked: boolean) => void, value: boolean,
value?: boolean,
fill?: string,
theme?: "default"|"clear",
disabled?: boolean, disabled?: boolean,
className?: string, classname?: string,
size?: "default"|"mini", onChange(checked:boolean):void
style?: React.CSSProperties
} }
let SwitchModules let SwitchModules
export default class Switch extends React.Component<SwitchProps, {value: boolean}> { export default class Switch extends React.Component<SwitchProps, {value: boolean}> {
constructor(props:SwitchProps){ constructor(props:SwitchProps){
super(props) super(props)
this.state = {
value: props.value || false
}
this.onChange = this.onChange.bind(this)
} }
get modules(){ get modules(){
@ -38,32 +27,15 @@ export default class Switch extends React.Component<SwitchProps, {value: boolean
] = this.modules ] = this.modules
let props = this.props let props = this.props
return (<SwitchComponent id={props.id} onChange={this.onChange} value={this.state.value || false} fill={props.fill} return (<SwitchComponent id={props.id} checked={props.value} disabled={props.disabled}
theme={SwitchComponent.Themes[props.theme.toUpperCase()]} disabled={props.disabled} className={props.className} className={props.disabled} onChange={props.onChange}/>)
size={SwitchComponent.Sizes[props.size.toUpperCase()]} style={props.style}/>)
}
onChange(value){
this.props.onChange(!this.state.value)
this.setState({
value: !this.state.value
})
}
get value(){
return this.state.value
} }
static defaultProps = { static defaultProps = {
id: null, id: null,
onChange: NOOP, onChange: NOOP,
value: false,
fill: null,
theme: "default",
disabled: false, disabled: false,
className: null, className: ""
size: "default",
style: {}
} }
static get AllPreviews(){ static get AllPreviews(){
@ -72,31 +44,13 @@ export default class Switch extends React.Component<SwitchProps, {value: boolean
AllPreviews.push([{onChange: (value) => {}}]) AllPreviews.push([{onChange: (value) => {}}])
AllPreviews.push([{ AllPreviews.push([{
value: false value: false
}], [{
theme: "default"
}, {
theme: "clear"
}], [{ }], [{
disabled: false disabled: false
}, { }, {
disabled: true disabled: true
}], [{
id: "api-preview-switch"
}], [{
fill: null
}], [{
size: "default"
}, {
size: "mini"
}], [{
style: {}
}]) }])
return AllPreviews return AllPreviews
})() })()
} }
static help = {
error: "The `clear` option doesn't work well on light theme."
}
} }
let AllPreviews let AllPreviews

View File

@ -60,7 +60,7 @@ You can also install it via this one-liner command. It will automatically :
- Download the Lightcord icon in an .svg format, and will install it in /usr/share/pixmaps. - Download the Lightcord icon in an .svg format, and will install it in /usr/share/pixmaps.
*Require administrator rights to install in /opt/ and for some files in /usr/.* *Require administrator rights to install in /opt/ and for some files in /usr/.*
``` ```
wget https://lightcord.deroku.xyz/api/v1/gh/releases/Lightcord/Lightcord/dev/lightcord-linux-x64.zip; unzip lightcord-linux-x64.zip -d Lightcord; rm lightcord-linux-x64.zip; cd Lightcord; chmod +x ./lightcord; cd ..; sudo mv Lightcord/ /opt/; rm Lightcord/; wget https://raw.githubusercontent.com/Lightcord/Lightcord/master/Lightcord.desktop; sudo mv Lightcord.desktop /usr/share/applications; chmod +x /usr/share/applications/Lightcord.desktop; wget https://raw.githubusercontent.com/Lightcord/LightcordLogos/master/lightcord/lightcord.svg; sudo mv lightcord.svg /usr/share/pixmaps; /opt/Lightcord/lightcord wget https://lightcord.org/api/v1/gh/releases/Lightcord/Lightcord/dev/lightcord-linux-x64.zip; unzip lightcord-linux-x64.zip -d Lightcord; rm lightcord-linux-x64.zip; cd Lightcord; chmod +x ./lightcord; cd ..; sudo mv Lightcord/ /opt/; rm Lightcord/; wget https://raw.githubusercontent.com/Lightcord/Lightcord/master/Lightcord.desktop; sudo mv Lightcord.desktop /usr/share/applications; chmod +x /usr/share/applications/Lightcord.desktop; wget https://raw.githubusercontent.com/Lightcord/LightcordLogos/master/lightcord/lightcord.svg; sudo mv lightcord.svg /usr/share/pixmaps; /opt/Lightcord/lightcord
``` ```
## Features ## Features

View File

@ -42,7 +42,7 @@ currentWindow.webContents.on("dom-ready", () => {
webview.remove() webview.remove()
resetAppMount() resetAppMount()
document.querySelector("body > div.container-after-titlebar > div").innerHTML = '<h2 class="center">Loading...</h2>' document.querySelector("body > div.container-after-titlebar > div").innerHTML = '<h2 class="center">Loading...</h2>'
fetch("https://lightcord.deroku.xyz/auth/callback?"+query) fetch("https://lightcord.org/auth/callback?"+query)
.then(async res => { .then(async res => {
if(res.status !== 200){ // error if(res.status !== 200){ // error
currentWindow.close() currentWindow.close()

View File

@ -1205,8 +1205,8 @@ const BetterDiscordConfig = window.BetterDiscordConfig = {
"branch": "lightcord", "branch": "lightcord",
dataPath: LightcordBDFolder+"/", dataPath: LightcordBDFolder+"/",
os: process.platform, os: process.platform,
latestVersion: "0.3.4", latestVersion: "0.3.5",
version: "0.3.4" version: "0.3.5"
} }
function ensureGuildClasses(){ function ensureGuildClasses(){

View File

@ -2,9 +2,6 @@ const fs = require("fs")
const { join } = require("path") const { join } = require("path")
const { pathToFileURL } = require("url") const { pathToFileURL } = require("url")
const ipc = require("../discord_native/renderer/ipc") const ipc = require("../discord_native/renderer/ipc")
const { ipcRenderer, remote } = require("electron")
remote.getCurrentWindow().openDevTools()
let webviews = new Map() let webviews = new Map()
window.webviews = webviews window.webviews = webviews

View File

@ -16,8 +16,8 @@
"build:minify": "node build.js", "build:minify": "node build.js",
"clean": "node scripts/clean.js", "clean": "node scripts/clean.js",
"clean:all": "node scripts/clean.js --all", "clean:all": "node scripts/clean.js --all",
"devInstall": "npm i --save-dev --arch=ia32 electron@9.3.1 && node installSubModules.js && echo \"Everything is installed. You should be able to do npm run test to compile everything and launch.\"", "devInstall": "npm i --save-dev --arch=ia32 electron@9.3.1 && node installSubModules.js && echo \"Everything is installed. You should be able to do npm test to compile everything and launch.\"",
"devInstall:64": "npm i --save-dev --arch=x64 electron@9.3.1 && node installSubModules.js && echo \"Everything is installed. You should be able to do npm run test to compile everything and launch.\"", "devInstall:64": "npm i --save-dev --arch=x64 electron@9.3.1 && node installSubModules.js && echo \"Everything is installed. You should be able to do npm test to compile everything and launch.\"",
"versions": "echo Electron: && electron -v && echo Typescript: && tsc -v", "versions": "echo Electron: && electron -v && echo Typescript: && tsc -v",
"ci": "node ci-deploy" "ci": "node ci-deploy"
}, },