Skip to content

Commit

Permalink
fix: zoom level on servers (#2770)
Browse files Browse the repository at this point in the history
* fix zoom level shortcuts

* Merge branch 'master' into fix/zoom-level

* remove log
  • Loading branch information
jeanfbrito authored Nov 10, 2023
1 parent fe0c103 commit 4de6a75
Showing 1 changed file with 18 additions and 33 deletions.
51 changes: 18 additions & 33 deletions src/ui/main/menuBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,21 @@ 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;
}
return getWebContentsByServerUrl(url);
};

const createViewMenu = createSelector(
selectViewDeps,
({
Expand Down Expand Up @@ -376,17 +391,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 +400,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 +417,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 4de6a75

Please sign in to comment.