2020-10-20 23:25:34 +02:00
/ * *
* @ name OldTitleBar
* @ authorId 278543574059057154
* @ invite Jx3TjNS
* @ donate https : //www.paypal.me/MircoWittrien
* @ patreon https : //www.patreon.com/MircoWittrien
* @ website https : //github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/OldTitleBar
* @ source https : //raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/OldTitleBar/OldTitleBar.plugin.js
2020-11-12 17:30:48 +01:00
* @ updateUrl https : //raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/OldTitleBar/OldTitleBar.plugin.js
2020-10-20 23:25:34 +02:00
* /
2019-03-22 20:54:11 +01:00
2020-09-19 20:49:33 +02:00
module . exports = ( _ => {
2020-10-09 21:09:35 +02:00
const config = {
2020-09-19 20:49:33 +02:00
"info" : {
"name" : "OldTitleBar" ,
"author" : "DevilBro" ,
"version" : "1.6.7" ,
2020-10-16 10:25:30 +02:00
"description" : "Revert the title bar back to its former self"
2020-02-11 12:43:04 +01:00
}
2020-09-19 20:49:33 +02:00
} ;
2020-11-13 19:47:44 +01:00
2020-10-09 21:09:35 +02:00
return ! window . BDFDB _Global || ( ! window . BDFDB _Global . loaded && ! window . BDFDB _Global . started ) ? class {
2021-01-06 12:38:36 +01:00
getName ( ) { return config . info . name ; }
getAuthor ( ) { return config . info . author ; }
getVersion ( ) { return config . info . version ; }
2021-02-01 17:13:13 +01:00
getDescription ( ) { return ` The Library Plugin needed for ${ config . info . name } is missing. Open the Plugin Settings to download it. \n \n ${ config . info . description } ` ; }
downloadLibrary ( ) {
require ( "request" ) . get ( "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js" , ( e , r , b ) => {
2021-02-02 11:22:26 +01:00
if ( ! e && b && b . indexOf ( ` * @name BDFDB ` ) > - 1 ) require ( "fs" ) . writeFile ( require ( "path" ) . join ( BdApi . Plugins . folder , "0BDFDB.plugin.js" ) , b , _ => BdApi . showToast ( "Finished downloading BDFDB Library" , { type : "success" } ) ) ;
2021-02-01 17:13:13 +01:00
else BdApi . alert ( "Error" , "Could not download BDFDB Library Plugin, try again later or download it manually from GitHub: https://github.com/mwittrien/BetterDiscordAddons/tree/master/Library/" ) ;
} ) ;
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
load ( ) {
2020-11-19 16:51:14 +01:00
if ( ! window . BDFDB _Global || ! Array . isArray ( window . BDFDB _Global . pluginQueue ) ) window . BDFDB _Global = Object . assign ( { } , window . BDFDB _Global , { pluginQueue : [ ] } ) ;
2020-09-19 20:49:33 +02:00
if ( ! window . BDFDB _Global . downloadModal ) {
window . BDFDB _Global . downloadModal = true ;
2021-01-14 16:14:44 +01:00
BdApi . showConfirmationModal ( "Library Missing" , ` The Library Plugin needed for ${ config . info . name } is missing. Please click "Download Now" to install it. ` , {
2020-09-19 20:49:33 +02:00
confirmText : "Download Now" ,
cancelText : "Cancel" ,
onCancel : _ => { delete window . BDFDB _Global . downloadModal ; } ,
2020-09-20 08:15:13 +02:00
onConfirm : _ => {
delete window . BDFDB _Global . downloadModal ;
2021-02-01 17:13:13 +01:00
this . downloadLibrary ( ) ;
2020-09-20 08:15:13 +02:00
}
2020-09-19 20:49:33 +02:00
} ) ;
}
if ( ! window . BDFDB _Global . pluginQueue . includes ( config . info . name ) ) window . BDFDB _Global . pluginQueue . push ( config . info . name ) ;
2020-10-09 21:09:35 +02:00
}
2021-01-06 12:38:36 +01:00
start ( ) { this . load ( ) ; }
stop ( ) { }
getSettingsPanel ( ) {
2020-11-28 23:12:09 +01:00
let template = document . createElement ( "template" ) ;
2021-01-14 16:14:44 +01:00
template . innerHTML = ` <div style="color: var(--header-primary); font-size: 16px; font-weight: 300; white-space: pre; line-height: 22px;">The Library Plugin needed for ${ config . info . name } is missing. \n Please click <a style="font-weight: 500;">Download Now</a> to install it.</div> ` ;
2021-02-01 17:13:13 +01:00
template . content . firstElementChild . querySelector ( "a" ) . addEventListener ( "click" , this . downloadLibrary ) ;
2020-11-28 23:12:09 +01:00
return template . content . firstElementChild ;
}
2020-10-09 21:09:35 +02:00
} : ( ( [ Plugin , BDFDB ] ) => {
2021-02-03 12:27:13 +01:00
var patched , lastWindowRects ;
2020-09-19 20:49:33 +02:00
var settings = { } ;
2020-10-09 21:09:35 +02:00
return class OldTitleBar extends Plugin {
2021-01-06 12:38:36 +01:00
onLoad ( ) {
2020-09-19 20:49:33 +02:00
patched = false ;
this . defaults = {
settings : {
2020-11-19 16:51:14 +01:00
displayNative : { value : ! ! document . querySelector ( ".platform-linux" ) , description : "Display the native title bar" } ,
addOldBar : { value : true , description : "Display the title bar in the old fashion" } ,
addToSettings : { value : true , description : "Add a title bar to settings windows" } ,
reloadButton : { value : false , description : "Add a reload button to the title bar" }
2020-09-19 20:49:33 +02:00
}
} ;
2019-11-12 15:42:23 +01:00
2020-09-19 20:49:33 +02:00
this . patchedModules = {
after : {
App : "render" ,
AppSkeleton : "render" ,
HeaderBarContainer : "render" ,
StandardSidebarView : "render" ,
AuthWrapper : "render"
}
} ;
2020-02-11 12:43:04 +01:00
2020-09-19 20:49:33 +02:00
this . css = `
$ { BDFDB . dotCNS . _oldtitlebarenabled + BDFDB . dotCN . titlebar } ,
$ { BDFDB . dotCNS . _oldtitlebarenabled + BDFDB . dotCN . splashbackground } : before {
display : none ! important ;
}
. platform - osx $ { BDFDB . dotCNS . _oldtitlebarenabled + BDFDB . dotCN . guildswrapper } {
margin - top : 0 ;
padding - top : 0 ;
}
. platform - osx $ { BDFDB . dotCNS . _oldtitlebarenabled + BDFDB . dotCN . guildsscroller } {
padding - top : 4 px ;
}
. platform - osx $ { BDFDB . dotCNS . _oldtitlebarenabled + BDFDB . dotCN . settingswindowstandardsidebarview } : before {
display : none ;
}
$ { BDFDB . dotCN . _oldtitlebartoolbar } {
flex : 1 1 auto ;
justify - content : flex - end ;
}
$ { BDFDB . dotCN . _oldtitlebarsettingstoolbar } {
position : absolute ;
top : 0 ;
right : 0 ;
padding : 10 px ;
z - index : 2 ;
- webkit - app - region : drag ! important ;
}
$ { BDFDB . dotCNS . _oldtitlebarenabled + BDFDB . dotCNS . splashbackground + BDFDB . dotCN . _oldtitlebarsettingstoolbar } {
background : rgba ( 0 , 0 , 0 , 0.3 ) ;
border - radius : 0 0 0 5 px ;
}
$ { BDFDB . dotCN . channelheaderheaderbar } {
- webkit - app - region : drag ! important ;
}
$ { BDFDB . dotCNS . stopanimations + BDFDB . dotCN . channelheaderheaderbar } ,
$ { BDFDB . dotCN . channelheaderheaderbar } * {
- webkit - app - region : no - drag ! important ;
}
` ;
2020-02-11 12:43:04 +01:00
}
2021-01-06 12:38:36 +01:00
onStart ( ) {
2020-02-11 12:43:04 +01:00
BDFDB . ListenerUtils . add ( this , window , "resize" , e => {
2020-09-11 19:31:36 +02:00
BDFDB . PatchUtils . forceAllUpdates ( this , [ "HeaderBarContainer" , "StandardSidebarView" ] ) ;
2020-02-11 12:43:04 +01:00
} ) ;
2019-01-26 22:45:19 +01:00
2020-02-11 12:43:04 +01:00
BDFDB . DOMUtils . addClass ( document . body , BDFDB . disCN . _oldtitlebarenabled ) ;
2019-01-26 22:45:19 +01:00
2020-06-09 10:10:08 +02:00
this . forceUpdateAll ( ) ;
this . patchMainScreen ( settings . displayNative ) ;
2020-02-11 12:43:04 +01:00
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
onStop ( ) {
2020-06-09 10:10:08 +02:00
this . forceUpdateAll ( ) ;
2019-01-26 22:45:19 +01:00
2020-02-11 12:43:04 +01:00
BDFDB . DOMUtils . removeClassFromDOM ( BDFDB . disCN . _oldtitlebarenabled ) ;
2020-09-19 20:49:33 +02:00
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
getSettingsPanel ( collapseStates = { } ) {
let settingsPanel , settingsItems = [ ] ;
let isLinux = ! ! document . querySelector ( ".platform-linux" ) ;
for ( let key in settings ) {
let isNativeTitlebarSetting = key == "displayNative" ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "Switch" ,
plugin : this ,
keys : [ "settings" , key ] ,
label : this . defaults . settings [ key ] . description ,
value : isLinux && isNativeTitlebarSetting || settings [ key ] ,
disabled : isLinux && isNativeTitlebarSetting ,
2021-02-02 12:45:38 +01:00
note : isLinux && isNativeTitlebarSetting && "This is disabled on Linux, because Discord/BD forces the Titlebar on Linux Systems!" ,
2020-09-19 20:49:33 +02:00
onChange : isNativeTitlebarSetting ? value => {
if ( this . patchMainScreen ( value ) ) {
patched = ! patched ;
2021-01-28 16:24:52 +01:00
let notifybar = document . querySelector ( "#OldTitleBarNotifyBar" ) ;
if ( notifybar ) notifybar . querySelector ( BDFDB . dotCN . noticedismiss ) . click ( ) ;
if ( patched ) {
2021-02-02 12:45:38 +01:00
notifybar = BDFDB . NotificationUtils . notice ( "Changed native Titlebar Settings. Please relaunch now:" , {
type : "danger" ,
id : "OldTitleBarNotifyBar" ,
buttons : [ {
contents : "Relaunch" ,
2021-02-02 13:02:27 +01:00
onClick : _ => { BDFDB . LibraryModules . WindowUtils . relaunch ( ) ; }
2021-02-02 12:45:38 +01:00
} ]
2021-01-28 16:24:52 +01:00
} ) ;
}
2020-09-19 20:49:33 +02:00
}
} : null
} ) ) ;
}
return settingsPanel = BDFDB . PluginUtils . createSettingsPanel ( this , settingsItems ) ;
2020-02-11 12:43:04 +01:00
}
2018-10-11 10:21:26 +02:00
2021-01-06 12:38:36 +01:00
onSettingsClosed ( ) {
2020-09-19 20:49:33 +02:00
if ( this . SettingsUpdated ) {
delete this . SettingsUpdated ;
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
this . forceUpdateAll ( ) ;
}
}
2021-01-06 12:38:36 +01:00
forceUpdateAll ( ) {
2020-09-19 20:49:33 +02:00
settings = BDFDB . DataUtils . get ( this , "settings" ) ;
BDFDB . PatchUtils . forceAllUpdates ( this ) ;
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
processApp ( e ) {
2020-11-19 16:51:14 +01:00
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . instance , { props : [ [ "type" , [ "WINDOWS" , "MACOS" ] ] ] } ) ;
2020-09-19 20:49:33 +02:00
if ( index > - 1 ) children [ index ] = null ;
}
2020-06-09 10:10:08 +02:00
2020-09-19 20:49:33 +02:00
processAppSkeleton ( e ) {
this . processApp ( e ) ;
2020-02-11 12:43:04 +01:00
}
2019-04-23 12:59:14 +02:00
2020-09-19 20:49:33 +02:00
processHeaderBarContainer ( e ) {
if ( ! settings . addOldBar ) return ;
let children = BDFDB . ObjectUtils . get ( e . returnvalue , "props.toolbar.props.children" ) ;
if ( ! children ) {
let [ oldToolbarParent , oldToolbarIndex ] = BDFDB . ReactUtils . findParent ( e . returnvalue , { key : "OldTitleBar-toolbar" } ) ;
if ( oldToolbarIndex > - 1 ) oldToolbarParent . splice ( oldToolbarIndex , 1 ) ;
let toolbar = BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCNS . channelheadertoolbar + BDFDB . disCN . _oldtitlebartoolbar ,
key : "OldTitleBar-toolbar" ,
children : [ ]
} ) ;
e . returnvalue . props . children . push ( toolbar ) ;
children = toolbar . props . children ;
}
this . injectButtons ( children , true ) ;
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
processStandardSidebarView ( e ) {
if ( ! BDFDB . ArrayUtils . is ( e . returnvalue . props . children ) ) e . returnvalue . props . children = [ e . returnvalue . props . children ] ;
this . injectSettingsToolbar ( e . returnvalue . props . children ) ;
}
2019-12-11 00:45:18 +01:00
2020-09-19 20:49:33 +02:00
processAuthWrapper ( e ) {
if ( ! BDFDB . ArrayUtils . is ( e . returnvalue . props . children ) ) e . returnvalue . props . children = [ e . returnvalue . props . children ] ;
this . injectSettingsToolbar ( e . returnvalue . props . children , true ) ;
}
injectSettingsToolbar ( children , fixed ) {
if ( ! settings . addToSettings ) return ;
2020-02-11 12:43:04 +01:00
let toolbar = BDFDB . ReactUtils . createElement ( "div" , {
2020-09-19 20:49:33 +02:00
className : BDFDB . disCNS . channelheadertoolbar + BDFDB . disCN . _oldtitlebarsettingstoolbar ,
children : [ ] ,
style : fixed ? { position : "fixed" } : null
2020-02-11 12:43:04 +01:00
} ) ;
2020-09-19 20:49:33 +02:00
this . injectButtons ( toolbar . props . children ) ;
children . push ( toolbar ) ;
2020-02-11 12:43:04 +01:00
}
2020-09-19 20:49:33 +02:00
injectButtons ( children , addFirstDivider ) {
if ( addFirstDivider ) children . push ( BDFDB . ReactUtils . createElement ( "div" , { className : BDFDB . disCN . channelheaderdivider } ) )
if ( settings . reloadButton ) {
children . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TooltipContainer , {
text : BDFDB . LanguageUtils . LanguageStrings . ERRORS _RELOAD ,
tooltipConfig : { type : "bottom" } ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Clickable , {
className : BDFDB . disCNS . channelheadericonwrapper + BDFDB . disCN . channelheadericonclickable ,
2021-02-04 16:44:02 +01:00
onClick : _ => { location . reload ( ) ; } ,
2020-09-19 20:49:33 +02:00
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . channelheadericon ,
iconSVG : ` <svg><path fill="currentColor" stroke="none" transform="translate(3,4)" d="M 17.061, 7.467 V 0 l -2.507, 2.507 C 13.013, 0.96, 10.885, 0, 8.528, 0 C 3.813, 0, 0.005, 3.819, 0.005, 8.533 s 3.808, 8.533, 8.523, 8.533 c 3.973, 0, 7.301 -2.72, 8.245 -6.4 h -2.219 c -0.88, 2.485 -3.237, 4.267 -6.027, 4.267 c -3.536, 0 -6.4 -2.864 -6.4 -6.4 s 2.864 -6.4, 6.4 -6.4 c 1.765, 0, 3.349, 0.736, 4.507, 1.893 l -3.44, 3.44 H 17.061 z"/></svg> `
} )
2020-02-11 12:43:04 +01:00
} )
2020-09-19 20:49:33 +02:00
} ) ) ;
children . push ( BDFDB . ReactUtils . createElement ( "div" , { className : BDFDB . disCN . channelheaderdivider } ) ) ;
} ;
children . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Clickable , {
className : BDFDB . disCNS . channelheadericonwrapper + BDFDB . disCN . channelheadericonclickable ,
2021-02-02 13:02:27 +01:00
onClick : _ => { BDFDB . LibraryModules . WindowUtils . minimize ( ) ; } ,
2020-09-19 20:49:33 +02:00
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . channelheadericon ,
iconSVG : ` <svg width="26" height="26"><path stroke-width="2" stroke="currentColor" fill="none" d="M6 18 l13 0"/></svg> `
2019-11-05 21:16:39 +01:00
} )
2020-02-11 12:43:04 +01:00
} ) ) ;
2020-09-19 20:49:33 +02:00
children . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Clickable , {
className : BDFDB . disCNS . channelheadericonwrapper + BDFDB . disCN . channelheadericonclickable ,
2021-02-03 12:27:13 +01:00
onClick : _ => { this . maximize ( ) ; } ,
2020-09-19 20:49:33 +02:00
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . channelheadericon ,
2021-02-02 12:45:38 +01:00
iconSVG : this . isMaximized ( ) ? ` <svg width="26" height="26"><path stroke-width="2" stroke="currentColor" fill="none" d="M6 9 l10 0 l0 10 l-10 0 l0 -10 m3 -3 l10 0 l0 10"/></svg> ` : ` <svg width="26" height="26"><path stroke-width="2" stroke="currentColor" fill="none" d="M6 6 l13 0 l0 13 l-13 0 l0 -13"/></svg> `
2020-09-19 20:49:33 +02:00
} )
} ) ) ;
children . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Clickable , {
className : BDFDB . disCNS . channelheadericonwrapper + BDFDB . disCN . channelheadericonclickable ,
2021-02-02 13:02:27 +01:00
onClick : _ => { BDFDB . LibraryModules . WindowUtils . close ( ) ; } ,
2020-09-19 20:49:33 +02:00
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . channelheadericon ,
iconSVG : ` <svg width="26" height="26"><path stroke-width="2" stroke="currentColor" fill="none" d="M6 6 l13 13 m0 -13 l-13 13"/></svg> `
} )
} ) ) ;
}
2021-02-02 12:45:38 +01:00
isMaximized ( ) {
2021-02-03 12:27:13 +01:00
let rects = this . getWindowRects ( ) ;
return rects . x == 0 && rects . y == 0 && this . isScreenSize ( rects ) ;
}
isScreenSize ( rects ) {
return screen . availWidth - rects . width == 0 && screen . availHeight - rects . height == 0 ;
}
maximize ( ) {
if ( ! this . isMaximized ( ) ) {
lastWindowRects = this . getWindowRects ( ) ;
BDFDB . LibraryModules . WindowUtils . maximize ( ) ;
}
else {
if ( ! lastWindowRects || this . isScreenSize ( lastWindowRects ) ) {
let rects = this . getWindowRects ( ) ;
window . resizeTo ( rects . width / 2 , rects . height / 2 ) ;
window . moveTo ( rects . width / 4 , rects . height / 4 ) ;
}
else {
window . resizeTo ( lastWindowRects . width , lastWindowRects . height ) ;
window . moveTo ( lastWindowRects . x , lastWindowRects . y ) ;
}
}
}
getWindowRects ( ) {
return { x : window . screenX , y : window . screenY , width : window . outerWidth , height : window . outerHeight } ;
2021-02-02 12:45:38 +01:00
}
2019-09-04 12:34:02 +02:00
2020-09-19 20:49:33 +02:00
patchMainScreen ( enable ) {
try {
if ( BdApi . getWindowPreference ( "frame" ) != enable ) {
BdApi . setWindowPreference ( "frame" , enable ) ;
return true ;
}
return false ;
}
catch ( err ) {
return false ;
2020-03-24 09:07:53 +01:00
}
2020-02-11 12:43:04 +01:00
}
2020-09-19 20:49:33 +02:00
} ;
2020-10-09 21:09:35 +02:00
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( config ) ) ;
2020-09-19 20:49:33 +02:00
} ) ( ) ;