From 3ea09973577808efc1ef194a912c2a73f761a31c Mon Sep 17 00:00:00 2001 From: "bach.le" Date: Tue, 29 Jun 2021 12:13:31 +0700 Subject: [PATCH] C2-11081 Let the user setting his zoom value from the General Settings menu --- src/app/main-api-handler.ts | 8 ++++- src/common/api-interface.ts | 2 ++ src/renderer/preload-main.ts | 2 ++ src/renderer/ssf-api.ts | 57 ++++++++++++++++++++++++++++-------- 4 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/app/main-api-handler.ts b/src/app/main-api-handler.ts index 2fd42b4e..fffbfb4c 100644 --- a/src/app/main-api-handler.ts +++ b/src/app/main-api-handler.ts @@ -1,5 +1,4 @@ import { BrowserWindow, ipcMain } from 'electron'; - import { apiCmds, apiName, @@ -285,6 +284,13 @@ ipcMain.on( case apiCmds.closeAllWrapperWindows: windowHandler.closeAllWindows(); break; + case apiCmds.setZoomLevel: + if (typeof arg.zoomLevel === 'number') { + windowHandler + .getMainWindow() + ?.webContents.setZoomFactor(arg.zoomLevel as number); + } + break; default: break; } diff --git a/src/common/api-interface.ts b/src/common/api-interface.ts index 7d1685e6..0167df1a 100644 --- a/src/common/api-interface.ts +++ b/src/common/api-interface.ts @@ -46,6 +46,7 @@ export enum apiCmds { setIsMana = 'set-is-mana', showNotification = 'show-notification', closeAllWrapperWindows = 'close-all-windows', + setZoomLevel = 'set-zoom-level', } export enum apiName { @@ -85,6 +86,7 @@ export interface IApiArgs { notificationOpts: object; notificationId: number; theme: Themes; + zoomLevel: number; } export type Themes = 'light' | 'dark'; diff --git a/src/renderer/preload-main.ts b/src/renderer/preload-main.ts index 54423bca..2cc384cd 100644 --- a/src/renderer/preload-main.ts +++ b/src/renderer/preload-main.ts @@ -87,6 +87,8 @@ if (ssfWindow.ssf) { closeNotification: ssfWindow.ssf.closeNotification, restartApp: ssfWindow.ssf.restartApp, closeAllWrapperWindows: ssfWindow.ssf.closeAllWrapperWindows, + setZoomLevel: ssfWindow.ssf.setZoomLevel, + getZoomLevel: ssfWindow.ssf.getZoomLevel, }); } diff --git a/src/renderer/ssf-api.ts b/src/renderer/ssf-api.ts index df26a323..3e691be1 100644 --- a/src/renderer/ssf-api.ts +++ b/src/renderer/ssf-api.ts @@ -1,5 +1,4 @@ -import { ipcRenderer, remote } from 'electron'; -const os = remote.require('os'); +import { ipcRenderer, remote, webFrame } from 'electron'; import { buildNumber, searchAPIVersion } from '../../package.json'; import { IDownloadItem } from '../app/download-handler'; import { ICustomBrowserWindow } from '../app/window-handler'; @@ -26,6 +25,7 @@ import { throttle } from '../common/utils'; import { getSource } from './desktop-capturer'; import SSFNotificationHandler from './notification-ssf-hendler'; import { ScreenSnippetBcHandler } from './screen-snippet-bc-handler'; +const os = remote.require('os'); let isAltKey: boolean = false; let isMenuOpen: boolean = false; @@ -69,27 +69,29 @@ const notificationActionCallbacks = new Map< NotificationActionCallback >(); +const DEFAULT_THROTTLE = 1000; + // Throttle func const throttledSetBadgeCount = throttle((count) => { local.ipcRenderer.send(apiName.symphonyApi, { cmd: apiCmds.setBadgeCount, count, }); -}, 1000); +}, DEFAULT_THROTTLE); const throttledSetLocale = throttle((locale) => { local.ipcRenderer.send(apiName.symphonyApi, { cmd: apiCmds.setLocale, locale, }); -}, 1000); +}, DEFAULT_THROTTLE); const throttledActivate = throttle((windowName) => { local.ipcRenderer.send(apiName.symphonyApi, { cmd: apiCmds.activate, windowName, }); -}, 1000); +}, DEFAULT_THROTTLE); const throttledBringToFront = throttle((windowName, reason) => { local.ipcRenderer.send(apiName.symphonyApi, { @@ -97,7 +99,7 @@ const throttledBringToFront = throttle((windowName, reason) => { windowName, reason, }); -}, 1000); +}, DEFAULT_THROTTLE); const throttledCloseScreenShareIndicator = throttle((streamId) => { ipcRenderer.send(apiName.symphonyApi, { @@ -105,47 +107,54 @@ const throttledCloseScreenShareIndicator = throttle((streamId) => { windowType: 'screen-sharing-indicator', winKey: streamId, }); -}, 1000); +}, DEFAULT_THROTTLE); const throttledSetIsInMeetingStatus = throttle((isInMeeting) => { local.ipcRenderer.send(apiName.symphonyApi, { cmd: apiCmds.setIsInMeeting, isInMeeting, }); -}, 1000); +}, DEFAULT_THROTTLE); const throttledSetCloudConfig = throttle((data) => { ipcRenderer.send(apiName.symphonyApi, { cmd: apiCmds.setCloudConfig, cloudConfig: data, }); -}, 1000); +}, DEFAULT_THROTTLE); const throttledOpenDownloadedItem = throttle((id: string) => { ipcRenderer.send(apiName.symphonyApi, { cmd: apiCmds.openDownloadedItem, id, }); -}, 1000); +}, DEFAULT_THROTTLE); const throttledShowDownloadedItem = throttle((id: string) => { ipcRenderer.send(apiName.symphonyApi, { cmd: apiCmds.showDownloadedItem, id, }); -}, 1000); +}, DEFAULT_THROTTLE); const throttledClearDownloadedItems = throttle(() => { ipcRenderer.send(apiName.symphonyApi, { cmd: apiCmds.clearDownloadedItems, }); -}, 1000); +}, DEFAULT_THROTTLE); const throttledRestart = throttle(() => { ipcRenderer.send(apiName.symphonyApi, { cmd: apiCmds.restartApp, }); -}, 1000); +}, DEFAULT_THROTTLE); + +const throttledSetZoomLevel = throttle((zoomLevel) => { + local.ipcRenderer.send(apiName.symphonyApi, { + cmd: apiCmds.setZoomLevel, + zoomLevel, + }); +}, DEFAULT_THROTTLE); let cryptoLib: ICryptoLib | null; try { @@ -674,6 +683,28 @@ export class SSFApi { notificationId, }); } + + /** + * Get zoom level + * + */ + public getZoomLevel(): Promise { + return new Promise((resolve) => { + resolve(webFrame.getZoomFactor()); + }); + } + + /** + * Sets zoom level + * + * @param {string} zoomLevel - language identifier and a region identifier + * @example: setZoomLevel(0.9) + */ + public setZoomLevel(zoomLevel): void { + if (typeof zoomLevel === 'number') { + throttledSetZoomLevel(zoomLevel); + } + } } /**