Popout window themes
This commit is contained in:
parent
11d80445a4
commit
2d42789c44
BetterDiscordApp
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -116,7 +116,6 @@ Core.prototype.init = async function() {
|
|||
Utils.suppressErrors(this.patchMessageHeader.bind(this), "BD Badge Chat Patch")();
|
||||
Utils.suppressErrors(this.patchMemberList.bind(this), "BD Badge Member List Patch")();
|
||||
Utils.suppressErrors(this.patchAttachment.bind(this), "LC Plugin Certifier Patch")();
|
||||
Utils.suppressErrors(this.patchPopoutWindow.bind(this), "BD Popout Window Patch")();
|
||||
|
||||
if(bdConfig.haveInstalledDefault){
|
||||
let alert = Utils.alert("First Installation", "As it is the first time you install Lightcord, We added two default themes and one default plugin in your plugin/theme folder. Check it in the Plugin/Theme settings.")
|
||||
|
@ -135,49 +134,6 @@ Core.prototype.init = async function() {
|
|||
}
|
||||
};
|
||||
|
||||
Core.prototype.patchPopoutWindow = async function() {
|
||||
let canceled = false
|
||||
this.cancelPatchPopoutWindow = () => {
|
||||
canceled = true
|
||||
}
|
||||
|
||||
window.Lightcord.Api.ensureExported(e => e.default && e.default.getWindow)
|
||||
.then(popoutModule => {
|
||||
if(canceled)return
|
||||
|
||||
/*
|
||||
// Not a good idea to do it like that.
|
||||
const interceptor = window.Lightcord.DiscordModules.dispatcher._interceptor
|
||||
window.Lightcord.DiscordModules.dispatcher.setInterceptor(function(action){
|
||||
if(action && action.type === "POPOUT_WINDOW_OPEN"){
|
||||
const render = action.render
|
||||
action.render = function(){
|
||||
const render1 = render.call(this, ...arguments)
|
||||
const type1 = render1.type
|
||||
render1.type = function(props){
|
||||
const render2 = type1(props)
|
||||
console.log(props, render2)
|
||||
return render2
|
||||
}
|
||||
console.log(render1)
|
||||
return render1
|
||||
}
|
||||
}
|
||||
return interceptor.call(this, action)
|
||||
})
|
||||
window.Lightcord.DiscordModules.dispatcher.subscribe("POPOUT_WINDOW_OPEN", (ev) => {
|
||||
if(!settingsCookie["lightcord-9"])return
|
||||
if(canceled)return
|
||||
Utils.log("POPOUT THEME", "Popout opened, Adding theme")
|
||||
setImmediate(() => {
|
||||
console.log(ev)
|
||||
const window = popoutModule.default.getWindow(ev.key)
|
||||
console.log(window)
|
||||
})
|
||||
})*/
|
||||
})
|
||||
};
|
||||
|
||||
Core.prototype.patchAttributes = async function() {
|
||||
let attribsPatchs = []
|
||||
this.cancelPatchAttributes = function() {
|
||||
|
|
|
@ -0,0 +1,130 @@
|
|||
import { themeCookie } from "../0globals"
|
||||
import bdEvents from "./bdEvents"
|
||||
import DOM from "./domtools"
|
||||
|
||||
export default new class popoutWindow {
|
||||
constructor(){
|
||||
/**
|
||||
* @type {Map<string, Window>}
|
||||
*/
|
||||
this.windows = new Map()
|
||||
this.enabled = false
|
||||
this.init()
|
||||
}
|
||||
|
||||
async init(){
|
||||
let popoutModule = await window.Lightcord.Api.ensureExported(e => e.default && e.default.getWindow)
|
||||
window.Lightcord.DiscordModules.dispatcher.subscribe("POPOUT_WINDOW_OPEN", (ev) => {
|
||||
setImmediate(() => {
|
||||
/**
|
||||
* @type {Window}
|
||||
*/
|
||||
const window = popoutModule.default.getWindow(ev.key)
|
||||
this.windows.set(ev.key, window)
|
||||
|
||||
let classList = window.document.body.classList
|
||||
classList.add("window-popout")
|
||||
classList.add("lightcord")
|
||||
classList.add("lightcord")
|
||||
|
||||
this.update(ev.key)
|
||||
})
|
||||
})
|
||||
window.Lightcord.DiscordModules.dispatcher.subscribe("POPOUT_WINDOW_CLOSE", (ev) => {
|
||||
setImmediate(() => {
|
||||
this.windows.delete(ev.key)
|
||||
})
|
||||
})
|
||||
bdEvents.on("theme-enabled", () => {
|
||||
this.update()
|
||||
})
|
||||
bdEvents.on("theme-disabled", () => {
|
||||
this.update()
|
||||
})
|
||||
bdEvents.on("theme-reloaded", () => {
|
||||
this.update()
|
||||
})
|
||||
bdEvents.on("theme-unloaded", () => {
|
||||
this.update()
|
||||
})
|
||||
bdEvents.on("theme-loaded", () => {
|
||||
this.update()
|
||||
})
|
||||
}
|
||||
|
||||
enable(){
|
||||
this.enabled = true
|
||||
this.update()
|
||||
}
|
||||
|
||||
disable(){
|
||||
this.enabled = false
|
||||
this.update()
|
||||
}
|
||||
|
||||
update(key){
|
||||
if(!this.windows.size)return
|
||||
if(!this.enabled){
|
||||
return this.removeThemes(key)
|
||||
}else{
|
||||
return this.applyThemes(key)
|
||||
}
|
||||
}
|
||||
|
||||
removeThemes(key){
|
||||
if(this.enabled)return
|
||||
if(key){
|
||||
let window = this.windows.get(key)
|
||||
if(!window)return
|
||||
let document = window.document
|
||||
|
||||
for(let style of document.querySelectorAll("style[data-lightcord-theme=true]")){
|
||||
style.remove()
|
||||
}
|
||||
}else{
|
||||
for(let key of this.windows.keys()){
|
||||
this.removeThemes(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
applyThemes(key){
|
||||
if(!this.enabled)return
|
||||
if(key){
|
||||
let window = this.windows.get(key)
|
||||
if(!window)return
|
||||
let document = window.document
|
||||
|
||||
for(let style of document.querySelectorAll("style[data-lightcord-theme=true]")){
|
||||
style.setAttribute("will-remove", "true")
|
||||
}
|
||||
|
||||
Object.keys(bdthemes)
|
||||
.forEach(themeName => {
|
||||
if(!themeCookie[themeName])return // theme disabled
|
||||
const theme = bdthemes[themeName]
|
||||
if(!theme)return //:shrug:
|
||||
|
||||
let existing = document.querySelector("style[data-lightcord-theme=true]#"+DOM.escapeID(theme.id))
|
||||
if(existing){
|
||||
existing.innerHTML = unescape(theme.css)
|
||||
existing.removeAttribute("will-remove")
|
||||
}else{
|
||||
const style = document.createElement("style")
|
||||
style.id = DOM.escapeID(theme.id)
|
||||
style.innerHTML = unescape(theme.css)
|
||||
style.setAttribute("data-lightcord-theme", "true")
|
||||
document.head.append(style)
|
||||
}
|
||||
})
|
||||
|
||||
for(let style of document.querySelectorAll("style[will-remove=true]")){
|
||||
style.remove()
|
||||
}
|
||||
}else{
|
||||
for(let key of this.windows.keys()){
|
||||
this.applyThemes(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,6 +30,7 @@ import webpackModules from "./webpackModules";
|
|||
import tooltipWrap from "../ui/tooltipWrap";
|
||||
import History from "../ui/icons/history";
|
||||
import core from "./core";
|
||||
import popoutWindow from "./popoutWindow";
|
||||
|
||||
class BDSidebarHeader extends React.PureComponent {
|
||||
render(){
|
||||
|
@ -236,6 +237,9 @@ export default new class V2_SettingsPanel {
|
|||
remote.app.relaunch()
|
||||
remote.app.exit()
|
||||
}
|
||||
if (id === "lightcord-9") {
|
||||
popoutWindow[enabled ? "enable" : "disable"]()
|
||||
}
|
||||
if (id === "lightcord-10"){
|
||||
core.methods.NotificationsUseShim(enabled)
|
||||
return
|
||||
|
@ -280,6 +284,7 @@ export default new class V2_SettingsPanel {
|
|||
if (settingsCookie["lightcord-4"]) AntiAdDM.enable()
|
||||
if (settingsCookie["lightcord-6"]) blurPrivate.enable()
|
||||
if (settingsCookie["lightcord-7"]) disableTyping.enable()
|
||||
if (settingsCookie["lightcord-9"]) popoutWindow.enable()
|
||||
|
||||
if (settingsCookie["fork-ps-5"]) {
|
||||
ContentManager.watchContent("plugin");
|
||||
|
|
|
@ -4,6 +4,7 @@ import DataStore from "./dataStore";
|
|||
import BDEvents from "./bdEvents";
|
||||
import Utils from "./utils";
|
||||
import DOM from "./domtools";
|
||||
import bdEvents from "./bdEvents";
|
||||
|
||||
class ThemeModule {
|
||||
constructor(){
|
||||
|
@ -36,6 +37,7 @@ ThemeModule.prototype.enableTheme = function(name, reload = false) {
|
|||
this.saveThemeData();
|
||||
const theme = bdthemes[name];
|
||||
DOM.addStyle(DOM.escapeID(theme.id), unescape(theme.css));
|
||||
bdEvents.dispatch("theme-enabled")
|
||||
if (settingsCookie["fork-ps-2"] && !reload) Utils.showToast(`${theme.name} v${theme.version} has been applied.`);
|
||||
};
|
||||
|
||||
|
@ -48,6 +50,7 @@ ThemeModule.prototype.disableTheme = function(name, reload = false) {
|
|||
this.saveThemeData();
|
||||
const theme = bdthemes[name];
|
||||
DOM.removeStyle(DOM.escapeID(theme.id));
|
||||
bdEvents.dispatch("theme-disabled")
|
||||
if (settingsCookie["fork-ps-2"] && !reload) Utils.showToast(`${theme.name} v${theme.version} has been disabled.`);
|
||||
};
|
||||
|
||||
|
@ -60,8 +63,8 @@ ThemeModule.prototype.toggleTheme = function(theme) {
|
|||
else this.enableTheme(theme);
|
||||
};
|
||||
|
||||
ThemeModule.prototype.toggle = function (name, reload = false) {
|
||||
return this.toggleTheme(name, reload);
|
||||
ThemeModule.prototype.toggle = function (name) {
|
||||
return this.toggleTheme(name);
|
||||
};
|
||||
|
||||
ThemeModule.prototype.loadTheme = async function(filename) {
|
||||
|
|
Loading…
Reference in New Issue