Skip to content

Commit 8615f84

Browse files
authored
feat: support zoom in out (#123)
1 parent 22d95f0 commit 8615f84

File tree

2 files changed

+111
-1
lines changed

2 files changed

+111
-1
lines changed

src/main/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ const createWindow = async () => {
195195
preload: path.join(__dirname, "preload.js"),
196196
},
197197
});
198+
webAppWindow.webContents.setVisualZoomLevelLimits(1, 3)
199+
198200
new AutoUpdate(webAppWindow);
199201
remote.enable(webAppWindow.webContents);
200202

src/main/menu.ts

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,33 @@ export default class MenuBuilder {
124124
this.mainWindow.webContents.toggleDevTools();
125125
},
126126
},
127+
{
128+
type: "separator",
129+
},
130+
{
131+
label: "Zoom In",
132+
accelerator: "Command+Plus",
133+
click: () => {
134+
this.mainWindow.webContents.setZoomLevel(
135+
this.mainWindow.webContents.getZoomLevel() + 1
136+
);
137+
},
138+
},
139+
{
140+
label: "Zoom Out",
141+
accelerator: "Command+-",
142+
click: () => {
143+
this.mainWindow.webContents.setZoomLevel(
144+
this.mainWindow.webContents.getZoomLevel() - 1
145+
);
146+
},
147+
},
148+
{
149+
label: "Reset Zoom",
150+
click: () => {
151+
this.mainWindow.webContents.setZoomLevel(0);
152+
},
153+
},
127154
],
128155
};
129156
const subMenuViewProd: MenuItemConstructorOptions = {
@@ -143,6 +170,33 @@ export default class MenuBuilder {
143170
this.enableBGWindowDebug();
144171
},
145172
},
173+
{
174+
type: "separator",
175+
},
176+
{
177+
label: "Zoom In",
178+
accelerator: "Command+Plus",
179+
click: () => {
180+
this.mainWindow.webContents.setZoomLevel(
181+
this.mainWindow.webContents.getZoomLevel() + 1
182+
);
183+
},
184+
},
185+
{
186+
label: "Zoom Out",
187+
accelerator: "Command+-",
188+
click: () => {
189+
this.mainWindow.webContents.setZoomLevel(
190+
this.mainWindow.webContents.getZoomLevel() - 1
191+
);
192+
},
193+
},
194+
{
195+
label: "Reset Zoom",
196+
click: () => {
197+
this.mainWindow.webContents.setZoomLevel(0);
198+
},
199+
},
146200
],
147201
};
148202
const subMenuWindow: DarwinMenuItemConstructorOptions = {
@@ -200,7 +254,7 @@ export default class MenuBuilder {
200254
}
201255

202256
buildDefaultTemplate() {
203-
const templateDefault = [
257+
const templateDefault: MenuItemConstructorOptions[] = [
204258
{
205259
label: "&File",
206260
submenu: [
@@ -245,6 +299,33 @@ export default class MenuBuilder {
245299
this.mainWindow.webContents.toggleDevTools();
246300
},
247301
},
302+
{
303+
type: "separator",
304+
},
305+
{
306+
label: "Zoom In",
307+
accelerator: "Ctrl+Plus",
308+
click: () => {
309+
this.mainWindow.webContents.setZoomLevel(
310+
this.mainWindow.webContents.getZoomLevel() + 1
311+
);
312+
},
313+
},
314+
{
315+
label: "Zoom Out",
316+
accelerator: "Ctrl+-",
317+
click: () => {
318+
this.mainWindow.webContents.setZoomLevel(
319+
this.mainWindow.webContents.getZoomLevel() - 1
320+
);
321+
},
322+
},
323+
{
324+
label: "Reset Zoom",
325+
click: () => {
326+
this.mainWindow.webContents.setZoomLevel(0);
327+
},
328+
},
248329
]
249330
: [
250331
{
@@ -263,6 +344,33 @@ export default class MenuBuilder {
263344
this.mainWindow.webContents.toggleDevTools();
264345
},
265346
},
347+
{
348+
type: "separator",
349+
},
350+
{
351+
label: "Zoom In",
352+
accelerator: "Ctrl+Plus",
353+
click: () => {
354+
this.mainWindow.webContents.setZoomLevel(
355+
this.mainWindow.webContents.getZoomLevel() + 1
356+
);
357+
},
358+
},
359+
{
360+
label: "Zoom Out",
361+
accelerator: "Ctrl+-",
362+
click: () => {
363+
this.mainWindow.webContents.setZoomLevel(
364+
this.mainWindow.webContents.getZoomLevel() - 1
365+
);
366+
},
367+
},
368+
{
369+
label: "Reset Zoom",
370+
click: () => {
371+
this.mainWindow.webContents.setZoomLevel(0);
372+
},
373+
},
266374
],
267375
},
268376
{

0 commit comments

Comments
 (0)