Skip to content

Commit fff59ea

Browse files
committed
feat(settings): add toggle to show/hide sponsor sidebar icon (default enabled)
Closes: Acode-Foundation#1903
1 parent 9318510 commit fff59ea

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/lib/settings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class Settings {
176176
maxRetryCount: 3,
177177
showRetryToast: false,
178178
showSideButtons: true,
179+
showSponsorSidebarApp: true,
179180
showAnnotations: false,
180181
lintGutter: true,
181182
rainbowBrackets: true,

src/settings/appSettings.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ export default function otherSettings() {
176176
text: strings["show side buttons"],
177177
checkbox: values.showSideButtons,
178178
},
179+
{
180+
key: "showSponsorSidebarApp",
181+
text: `${strings.sponsor} (${strings.sidebar})`,
182+
checkbox: values.showSponsorSidebarApp,
183+
},
179184
{
180185
key: "excludeFolders",
181186
text: strings["exclude files"],

src/sidebarApps/index.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import appSettings from "lib/settings";
12
import Sponsors from "pages/sponsors";
23
import SidebarApp from "./sidebarApp";
34

@@ -11,6 +12,8 @@ let $sidebar;
1112
let currentSection = localStorage.getItem(SIDEBAR_APPS_LAST_SECTION);
1213
/**@type {SidebarApp[]} */
1314
const 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

Comments
 (0)