Skip to content

Commit

Permalink
Fix change text size
Browse files Browse the repository at this point in the history
Fix increasing, decreasing and resetting text size.
  • Loading branch information
dusansimic committed Jan 5, 2021
1 parent a6f90ca commit f03ba4d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
18 changes: 9 additions & 9 deletions source/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,23 +448,23 @@ ipc.answerMain('render-native-emoji', (emoji: string): string => {
return dataUrl;
});

ipc.answerMain('zoom-reset', () => {
setZoom(1);
ipc.answerMain('zoom-reset', ({isNewDesign}: INewDesign) => {
setZoom(isNewDesign, 1);
});

ipc.answerMain('zoom-in', () => {
ipc.answerMain('zoom-in', ({isNewDesign}: INewDesign) => {
const zoomFactor = config.get('zoomFactor') + 0.1;

if (zoomFactor < 1.6) {
setZoom(zoomFactor);
setZoom(isNewDesign, zoomFactor);
}
});

ipc.answerMain('zoom-out', () => {
ipc.answerMain('zoom-out', ({isNewDesign}: INewDesign) => {
const zoomFactor = config.get('zoomFactor') - 0.1;

if (zoomFactor >= 0.8) {
setZoom(zoomFactor);
setZoom(isNewDesign, zoomFactor);
}
});

Expand Down Expand Up @@ -537,9 +537,9 @@ function selectedConversationIndex(isNewDesign: boolean, offset = 0): number {
return ((index % list.length) + list.length) % list.length;
}

function setZoom(zoomFactor: number): void {
function setZoom(isNewDesign: boolean, zoomFactor: number): void {
const node = document.querySelector<HTMLElement>('#zoomFactor')!;
node.textContent = `${selectors.conversationSelector} {zoom: ${zoomFactor} !important}`;
node.textContent = `${isNewDesign ? selectors.conversationSelectorNewDesign : selectors.conversationSelector} {zoom: ${zoomFactor} !important}`;
config.set('zoomFactor', zoomFactor);
}

Expand Down Expand Up @@ -690,7 +690,7 @@ document.addEventListener('DOMContentLoaded', async () => {

// Set the zoom factor if it was set before quitting
const zoomFactor = config.get('zoomFactor');
setZoom(zoomFactor);
setZoom(await isNewDesign(), zoomFactor);

// Enable OS specific styles
document.documentElement.classList.add(`os-${process.platform}`);
Expand Down
1 change: 1 addition & 0 deletions source/browser/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export default {
conversationList: 'div[role="navigation"] > div > ul',
conversationListNewDesign: '[role=navigation] [role=grid]',
conversationSelector: '._4u-c._1wfr .__i_, ._4u-c._1wfr #conversationWindow',
conversationSelectorNewDesign: '[aria-label=Messages]',
notificationCheckbox: '._374b:nth-of-type(4) ._4ng2 input'
};
6 changes: 3 additions & 3 deletions source/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,21 +387,21 @@ Press Command/Ctrl+R in Caprine to see your changes.
label: 'Reset Text Size',
accelerator: 'CommandOrControl+0',
click() {
sendAction('zoom-reset');
sendAction('zoom-reset', {isNewDesign});
}
},
{
label: 'Increase Text Size',
accelerator: 'CommandOrControl+Plus',
click() {
sendAction('zoom-in');
sendAction('zoom-in', {isNewDesign});
}
},
{
label: 'Decrease Text Size',
accelerator: 'CommandOrControl+-',
click() {
sendAction('zoom-out');
sendAction('zoom-out', {isNewDesign});
}
},
{
Expand Down

0 comments on commit f03ba4d

Please sign in to comment.