E596 fix(main): apply zoomFactor to active BrowserView only · Sync-in/desktop@228adb7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 228adb7

Browse files
committed
fix(main): apply zoomFactor to active BrowserView only
1 parent 4ae21ba commit 228adb7

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

main/components/events.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export class EventsManager {
4747
this.initIPC()
4848
}
4949

50+
async checkNativeTheme() {
51+
await this.switchTheme(nativeTheme.shouldUseDarkColors ? THEME.DARK : THEME.LIGHT)
52+
}
53+
5054
private initIPC() {
5155
powerMonitor.on('suspend', () => this.managePowerSuspension(true))
5256
powerMonitor.on('resume', () => this.managePowerSuspension(false))
@@ -94,6 +98,9 @@ export class EventsManager {
9498
ipcMain.handle(REMOTE_RENDERER.SYNC.TRANSFER_LOGS, async (ev: IpcMainInvokeEventServer, action: string, syncPathId: number, query: string) =>
9599
this.onSyncTransferLogs(ev, action, syncPathId, query)
96100
)
101+
appEvents.on(LOCAL_RENDERER.WINDOW.ZOOM.IN, () => this.windowZoomIn())
102+
appEvents.on(LOCAL_RENDERER.WINDOW.ZOOM.OUT, () => this.windowZoomOut())
103+
appEvents.on(LOCAL_RENDERER.WINDOW.ZOOM.RESET, () => this.windowZoomReset())
97104
appEvents.on(LOCAL_RENDERER.UPDATE.DOWNLOADED, (msg: string) => this.viewsManager.sendToWrapperRenderer(LOCAL_RENDERER.UPDATE.DOWNLOADED, msg))
98105
appEvents.on(LOCAL_RENDERER.POWER.PREVENT_APP_SUSPENSION, (state: boolean) => this.manageAppPreventSuspension(state))
99106
}
@@ -116,10 +123,6 @@ export class EventsManager {
116123
}
117124
}
118125

119-
async checkNativeTheme() {
120-
await this.switchTheme(nativeTheme.shouldUseDarkColors ? THEME.DARK : THEME.LIGHT)
121-
}
122-
123126
private serverAuthentication(ev: any): SyncClientAuth {
124127
const server = ServersManager.find(ev.sender.serverId)
125128
return { clientId: server.authID, token: server.authToken, info: genClientInfos() }
@@ -323,4 +326,21 @@ export class EventsManager {
323326
}
324327
appEvents.emit(LOCAL_RENDERER.POWER.SUSPENSION_EVENT, state)
325328
}
329+
330+
private windowZoomIn() {
331+
if (!this.viewsManager.currentView) return
332+
const zFactor = this.viewsManager.currentView.webContents.getZoomFactor()
333+
this.viewsManager.currentView.webContents.setZoomFactor(zFactor + 0.1)
334+
}
335+
336+
private windowZoomOut() {
337+
if (!this.viewsManager.currentView) return
338+
const zFactor = this.viewsManager.currentView.webContents.getZoomFactor()
339+
this.viewsManager.currentView.webContents.setZoomFactor(zFactor - 0.1)
340+
}
341+
342+
private windowZoomReset() {
343+
if (!this.viewsManager.currentView) return
344+
this.viewsManager.currentView.webContents.setZoomFactor(1)
345+
}
326346
}

main/components/menus.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,28 +140,18 @@ export function createTemplate() {
140140
separatorItem,
141141
{
142142
label: i18n.tr('Actual Size'),
143-
role: 'resetZoom',
144-
accelerator: 'CmdOrCtrl+0'
143+
accelerator: 'CmdOrCtrl+0',
144+
click: () => appEvents.emit(LOCAL_RENDERER.WINDOW.ZOOM.RESET)
145145
},
146146
{
147-
role: 'zoomIn',
148147
label: i18n.tr('Zoom In'),
149-
accelerator: 'CmdOrCtrl+='
148+
accelerator: 'CmdOrCtrl+=',
149+
click: () => appEvents.emit(LOCAL_RENDERER.WINDOW.ZOOM.IN)
150150
},
151151
{
152-
role: 'zoomIn',
153-
visible: false,
154-
accelerator: 'CmdOrCtrl+Shift+='
155-
},
156-
{
157-
role: 'zoomOut',
158152
label: i18n.tr('Zoom Out'),
159-
accelerator: 'CmdOrCtrl+-'
160-
},
161-
{
162-
role: 'zoomOut',
163-
visible: false,
164-
accelerator: 'CmdOrCtrl+Shift+-'
153+
accelerator: 'CmdOrCtrl+-',
154+
click: () => appEvents.emit(LOCAL_RENDERER.WINDOW.ZOOM.OUT)
165155
},
166156
separatorItem,
167157
{

main/constants/events.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export const LOCAL_RENDERER = {
2424
UNMAXIMIZE: 'window-unmaximize',
2525
IS_MAXIMIZED: 'window-is-maximized',
2626
IS_FULLSCREEN: 'window-is-fullscreen',
27-
CLOSE: 'window-close'
27+
CLOSE: 'window-close',
28+
ZOOM: { IN: 'window-zoom-in', OUT: 'window-zoom-out', RESET: 'window-zoom-reset' }
2829
},
2930
UPDATE: {
3031
DOWNLOADED: 'update-available',

0 commit comments

Comments
 (0)
0