1+ import appSettings from "lib/settings" ;
12import Sponsors from "pages/sponsors" ;
23import SidebarApp from "./sidebarApp" ;
34
@@ -11,6 +12,8 @@ let $sidebar;
1112let currentSection = localStorage . getItem ( SIDEBAR_APPS_LAST_SECTION ) ;
1213/**@type {SidebarApp[] } */
1314const apps = [ ] ;
15+ /**@type {HTMLSpanElement | null } */
16+ let $sponsorIcon = null ;
1417
1518/**
1619 * @param {string } icon icon of the app
@@ -68,6 +71,10 @@ function init($el) {
6871 $apps = $sidebar . get ( ".app-icons-container" ) ;
6972 $apps . addEventListener ( "click" , onclick ) ;
7073 SidebarApp . init ( $el , $apps ) ;
74+ appSettings . on (
75+ "update:showSponsorSidebarApp" ,
76+ setSponsorSidebarAppVisibility ,
77+ ) ;
7178}
7279
7380/**
@@ -78,7 +85,33 @@ async function loadApps() {
7885 add ( ...( await import ( "./searchInFiles" ) ) . default ) ;
7986 add ( ...( await import ( "./extensions" ) ) . default ) ;
8087 add ( ...( await import ( "./notification" ) ) . default ) ;
81- $apps . append ( < span className = "icon favorite" onclick = { Sponsors } /> ) ;
88+ setSponsorSidebarAppVisibility ( appSettings . value . showSponsorSidebarApp ) ;
89+ }
90+
91+ /**
92+ * Adds or removes the sponsor icon in sidebar based on settings.
93+ * @param {boolean } visible
94+ */
95+ function setSponsorSidebarAppVisibility ( visible ) {
96+ if ( ! $apps ) return ;
97+
98+ if ( visible ) {
99+ if ( $sponsorIcon ?. isConnected ) return ;
100+ $sponsorIcon = (
101+ < span
102+ className = "icon favorite"
103+ title = { strings . sponsor }
104+ onclick = { Sponsors }
105+ />
106+ ) ;
107+ $apps . append ( $sponsorIcon ) ;
108+ return ;
109+ }
110+
111+ if ( $sponsorIcon ) {
112+ $sponsorIcon . remove ( ) ;
113+ $sponsorIcon = null ;
114+ }
82115}
83116
84117/**
0 commit comments