Skip to content

Commit

Permalink
fix zoom level shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanfbrito committed Sep 29, 2023
1 parent df33261 commit be9ee04
Showing 1 changed file with 19 additions and 33 deletions.
52 changes: 19 additions & 33 deletions src/ui/main/menuBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ const selectViewDeps = createStructuredSelector<
rootWindowState: ({ rootWindowState }) => rootWindowState,
});

const getCurrentViewWebcontents = async () => {
const browserWindow = await getRootWindow();

if (!browserWindow.isVisible()) {
browserWindow.showInactive();
}
browserWindow.focus();
const currentView = select(({ currentView }) => currentView);
const url = typeof currentView === 'object' ? currentView.url : null;
if (!url) {
return null;
}
console.log('zoom url', url);
return getWebContentsByServerUrl(url);
};

const createViewMenu = createSelector(
selectViewDeps,
({
Expand Down Expand Up @@ -376,17 +392,7 @@ const createViewMenu = createSelector(
label: t('menus.resetZoom'),
accelerator: 'CommandOrControl+0',
click: async () => {
const browserWindow = await getRootWindow();

if (!browserWindow.isVisible()) {
browserWindow.showInactive();
}
browserWindow.focus();
const url = typeof currentView === 'object' ? currentView.url : null;
if (!url) {
return;
}
const guestWebContents = getWebContentsByServerUrl(url);
const guestWebContents = await getCurrentViewWebcontents();
guestWebContents?.setZoomLevel(0);
},
},
Expand All @@ -395,16 +401,7 @@ const createViewMenu = createSelector(
label: t('menus.zoomIn'),
accelerator: 'CommandOrControl+Plus',
click: async () => {
const browserWindow = await getRootWindow();
if (!browserWindow.isVisible()) {
browserWindow.showInactive();
}
browserWindow.focus();
const url = typeof currentView === 'object' ? currentView.url : null;
if (!url) {
return;
}
const guestWebContents = getWebContentsByServerUrl(url);
const guestWebContents = await getCurrentViewWebcontents();
if (!guestWebContents) {
return;
}
Expand All @@ -421,21 +418,10 @@ const createViewMenu = createSelector(
label: t('menus.zoomOut'),
accelerator: 'CommandOrControl+-',
click: async () => {
const browserWindow = await getRootWindow();
if (!browserWindow.isVisible()) {
browserWindow.showInactive();
}
browserWindow.focus();
const url = typeof currentView === 'object' ? currentView.url : null;
if (!url) {
return;
}

const guestWebContents = getWebContentsByServerUrl(url);
const guestWebContents = await getCurrentViewWebcontents();
if (!guestWebContents) {
return;
}

const zoomLevel = guestWebContents.getZoomLevel();
if (zoomLevel <= -9) {
return;
Expand Down

0 comments on commit be9ee04

Please sign in to comment.