Refactoring how preferences classes provide access to fields inside

Instead of constantly implementing these weird methods to read or update
values, there will be fields inside the preferences which contain
methods to read or update them.
This commit is contained in:
koloml committed 2026-03-07 06:41:28 +04:00
1 parent dc29c6ca69
commit 9024883949
14 files changed
+188 -112

No files matched your search

+2 -2
View File
@@ -17,8 +17,8 @@ export class BlockCommunication extends BaseComponent {
protected init() {
Promise.all([
BlockCommunication.#preferences.resolveReplaceLinks(),
BlockCommunication.#preferences.resolveReplaceLinkText(),
BlockCommunication.#preferences.replaceLinks.get(),
BlockCommunication.#preferences.replaceLinkText.get(),
]).then(([replaceLinks, replaceLinkText]) => {
this.#onReplaceLinkSettingResolved(
replaceLinks,
+2 -2
View File
@@ -54,7 +54,7 @@ export class FullscreenViewer extends BaseComponent {
this.#sizeSelectorElement.addEventListener('click', event => event.stopPropagation());
FullscreenViewer.#preferences
.resolveFullscreenViewerPreviewSize()
.fullscreenViewerSize.get()
.then(this.#onSizeResolved.bind(this))
.then(this.#watchForSizeSelectionChanges.bind(this));
}
@@ -202,7 +202,7 @@ export class FullscreenViewer extends BaseComponent {
}
lastActiveSize = targetSize;
void FullscreenViewer.#preferences.setFullscreenViewerPreviewSize(targetSize);
void FullscreenViewer.#preferences.fullscreenViewerSize.set(targetSize as FullscreenViewerSize);
});
}
@@ -26,7 +26,7 @@ export class ImageShowFullscreenButton extends BaseComponent {
this.on('click', this.#onButtonClicked.bind(this));
if (ImageShowFullscreenButton.#preferences) {
ImageShowFullscreenButton.#preferences.resolveFullscreenViewerEnabled()
ImageShowFullscreenButton.#preferences.fullscreenViewer.get()
.then(isEnabled => {
this.#isFullscreenButtonEnabled = isEnabled;
this.#updateFullscreenButtonVisibility();
+3 -5
View File
@@ -214,7 +214,7 @@ export class MaintenancePopup extends BaseComponent {
let maybeTagsAndAliasesAfterUpdate;
const shouldAutoRemove = await MaintenancePopup.#preferences.resolveStripBlacklistedTags();
const shouldAutoRemove = await MaintenancePopup.#preferences.stripBlacklistedTags.get();
try {
maybeTagsAndAliasesAfterUpdate = await MaintenancePopup.#scrapedAPI.updateImageTags(
@@ -359,13 +359,11 @@ export class MaintenancePopup extends BaseComponent {
lastActiveProfileId = settings.activeProfile;
this.#preferences
.resolveActiveProfileAsObject()
this.#preferences.activeProfile.asObject()
.then(callback);
});
this.#preferences
.resolveActiveProfileAsObject()
this.#preferences.activeProfile.asObject()
.then(profileOrNull => {
if (profileOrNull) {
lastActiveProfileId = profileOrNull.id;
+3 -3
View File
@@ -179,7 +179,7 @@ export class TagDropdownWrapper extends BaseComponent {
});
await profile.save();
await TagDropdownWrapper.#preferences.setActiveProfileId(profile.id);
await TagDropdownWrapper.#preferences.activeProfile.set(profile.id);
}
async #onToggleInExistingClicked() {
@@ -219,7 +219,7 @@ export class TagDropdownWrapper extends BaseComponent {
lastActiveProfile = settings.activeProfile ?? null;
this.#preferences
.resolveActiveProfileAsObject()
.activeProfile.asObject()
.then(onActiveProfileChange);
});
@@ -232,7 +232,7 @@ export class TagDropdownWrapper extends BaseComponent {
});
this.#preferences
.resolveActiveProfileAsObject()
.activeProfile.asObject()
.then(activeProfile => {
lastActiveProfile = activeProfile?.id ?? null;
onActiveProfileChange(activeProfile);
+2 -2
View File
@@ -44,7 +44,7 @@ export class TagsListBlock extends BaseComponent {
}
init() {
this.#preferences.resolveGroupSeparation().then(this.#onTagSeparationChange.bind(this));
this.#preferences.groupSeparation.get().then(this.#onTagSeparationChange.bind(this));
this.#preferences.subscribe(settings => {
this.#onTagSeparationChange(Boolean(settings.groupSeparation))
});
@@ -103,7 +103,7 @@ export class TagsListBlock extends BaseComponent {
#onToggleGroupingClicked(event: Event) {
event.preventDefault();
void this.#preferences.setGroupSeparation(!this.#shouldDisplaySeparation);
void this.#preferences.groupSeparation.set(!this.#shouldDisplaySeparation);
}
#handleTagGroupChanges(tagGroup: TagGroup) {