Skip to content

Commit

Permalink
Allow disabling the hidden preferences window.
Browse files Browse the repository at this point in the history
This gives an option under advanced settings allowing the user to
disable the hidden preferences window when applying settings (i.e.,
adding the hide-preferences-window class when caprine opens settings).
This will be disabled by default (current behavior). If enabled, you'll
very briefly see the settings window flash when caprine applies a
setting inside Messenger.
  • Loading branch information
stuckj committed Dec 22, 2024
1 parent 2ba6371 commit 06184ed
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
10 changes: 8 additions & 2 deletions source/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ ipc.answerMain('archive-conversation', async () => {

async function openHiddenPreferences(): Promise<boolean> {
if (!isPreferencesOpen()) {
document.documentElement.classList.add('hide-preferences-window');
const disableSettingsHiding = await ipc.callMain<undefined, boolean>('get-config-disableSettingsHiding');
if (!disableSettingsHiding) {
document.documentElement.classList.add('hide-preferences-window');
}

await openPreferences();

Expand Down Expand Up @@ -675,7 +678,10 @@ async function closePreferences(): Promise<void> {
// Get the parent of preferences, that's not getting deleted
const preferencesParent = preferencesOverlay.closest('div:not([class])')!;

preferencesOverlayObserver.observe(preferencesParent, {childList: true});
const disableSettingsHiding = await ipc.callMain<undefined, boolean>('get-config-disableSettingsHiding');
if (!disableSettingsHiding) {
preferencesOverlayObserver.observe(preferencesParent, {childList: true});
}

const closeButton = preferencesOverlay.querySelector(selectors.closePreferencesButton)!;
(closeButton as HTMLElement)?.click();
Expand Down
5 changes: 5 additions & 0 deletions source/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type StoreType = {
autoplayVideos: boolean;
isSpellCheckerEnabled: boolean;
spellCheckerLanguages: string[];
disableSettingsHiding: boolean;
};

const schema: Store.Schema<StoreType> = {
Expand Down Expand Up @@ -218,6 +219,10 @@ const schema: Store.Schema<StoreType> = {
},
default: [],
},
disableSettingsHiding: {
type: 'boolean',
default: false,
},
};

function updateVibrancySetting(store: Store<StoreType>): void {
Expand Down
1 change: 1 addition & 0 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,3 +680,4 @@ ipc.answerRenderer<undefined, StoreType['emojiStyle']>('get-config-emojiStyle',
ipc.answerRenderer<StoreType['emojiStyle'], void>('set-config-emojiStyle', async emojiStyle => {
config.set('emojiStyle', emojiStyle);
});
ipc.answerRenderer<undefined, StoreType['disableSettingsHiding']>('get-config-disableSettingsHiding', async () => config.get('disableSettingsHiding'));
8 changes: 8 additions & 0 deletions source/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ Press Command/Ctrl+R in Caprine to see your changes.
shell.openPath(filePath);
},
},
{
label: 'Disable Settings Hiding',
type: 'checkbox',
checked: config.get('disableSettingsHiding'),
click() {
config.set('disableSettingsHiding', !config.get('disableSettingsHiding'));
},
},
];

const preferencesSubmenu: MenuItemConstructorOptions[] = [
Expand Down

0 comments on commit 06184ed

Please sign in to comment.