Skip to content

Commit

Permalink
Issue 447 (#501)
Browse files Browse the repository at this point in the history
* Fix: #447

* Fix: #447

* Fix: #447
  • Loading branch information
jijojosephk authored Nov 2, 2021
1 parent 1bf6b88 commit d068804
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
if (config.rightClickWithSpellcheck) {
require('./rightClickMenuWithSpellcheck');
}
require('./zoom')();
require('./zoom')(config);

require('./desktopShare/chromeApi');

Expand Down
41 changes: 33 additions & 8 deletions app/browser/zoom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
const {webFrame} = require('electron');
const { webFrame, ipcRenderer } = require('electron');

exports = module.exports = () => {
const zoomLevels = {
'+': 1,
'-': -1,
'0': 0
};

exports = module.exports = (config) => {
restoreZoomLevel(config);
document.addEventListener('keydown', (event) => {
const keyName = event.key;

Expand All @@ -10,11 +17,29 @@ exports = module.exports = () => {
}

if (event.ctrlKey) {
if (keyName === '+') {
webFrame.setZoomLevel(webFrame.getZoomLevel() + 1);
} else if (keyName === '-') {
webFrame.setZoomLevel(webFrame.getZoomLevel() - 1);
}
setNextZoomLevel(keyName, config);
}
}, false);
};
};

function restoreZoomLevel(config) {
ipcRenderer.invoke('getZoomLevel', config.partition).then(zoomLevel => {
webFrame.setZoomLevel(zoomLevel);
});
}

function setNextZoomLevel(keyName, config) {
const zoomFactor = zoomLevels[keyName];
var zoomLevel = webFrame.getZoomLevel();
console.log(`Current zoom level: ${zoomLevel}`);
if (typeof (zoomFactor) !== 'number') {
return;
}

zoomLevel = zoomFactor == 0 ? 0 : zoomLevel + zoomFactor;
webFrame.setZoomLevel(zoomLevel);
ipcRenderer.invoke('saveZoomLevel', {
partition: config.partition,
zoomLevel: webFrame.getZoomLevel()
});
}
44 changes: 44 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const { app, ipcMain } = require('electron');
const config = require('./config')(app.getPath('userData'));
const Store = require('electron-store');
const store = new Store({
name: 'settings'
});
const certificateModule = require('./certificate');
const gotTheLock = app.requestSingleInstanceLock();
const mainAppWindow = require('./mainAppWindow');
Expand Down Expand Up @@ -34,6 +38,8 @@ if (!gotTheLock) {
app.on('will-quit', () => console.log('will-quit'));
app.on('certificate-error', handleCertificateError);
ipcMain.handle('getConfig', handleGetConfig);
ipcMain.handle('getZoomLevel', handleGetZoomLevel);
ipcMain.handle('saveZoomLevel', handleSaveZoomLevel);
}

function handleAppReady() {
Expand All @@ -44,6 +50,44 @@ async function handleGetConfig() {
return config;
}

async function handleGetZoomLevel(event, name) {
const partition = getPartition(name) || {};
return partition.zoomLevel ? partition.zoomLevel : 0;
}

async function handleSaveZoomLevel(event, args) {
let partition = getPartition(args.partition) || {};
partition.name = args.partition;
partition.zoomLevel = args.zoomLevel;
savePartition(partition);
return;
}

function getPartitions() {
return store.get('app.partitions') || [];
}

function getPartition(name) {
const partitions = getPartitions();
return partitions.filter(p => {
return p.name == name;
})[0];
}

function savePartition(arg) {
const partitions = getPartitions();
const partitionIndex = partitions.findIndex(p => {
return p.name == arg.name;
});

if (partitionIndex >= 0) {
partitions[partitionIndex] = arg;
} else {
partitions.push(arg);
}
store.set('app.partitions', partitions);
}

function handleCertificateError() {
const arg = {
event: arguments[0],
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "teams-for-linux",
"version": "1.0.19",
"version": "1.0.20",
"main": "app/index.js",
"description": "Unofficial client for Microsoft Teams for Linux",
"homepage": "https://github.com/IsmaelMartinez/teams-for-linux",
Expand Down Expand Up @@ -38,6 +38,7 @@
"electron-dl": "ismaelmartinez/electron-dl",
"electron-editor-context-menu": "1.1.1",
"electron-native-notification": "1.2.1",
"electron-store": "8.0.1",
"electron-window-state": "5.0.3",
"spellchecker": "3.7.1",
"yargs": "17.2.1"
Expand Down
Loading

0 comments on commit d068804

Please sign in to comment.