Skip to content

Commit

Permalink
Merge pull request #1082 from benterova/follow-system-theme
Browse files Browse the repository at this point in the history
Add followSystemTheme config option
  • Loading branch information
jijojosephk authored Jan 30, 2024
2 parents 60b2b1f + 4e28334 commit cc5e376
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ function initializeModules(config, ipcRenderer) {
require('./tools/chromeApi')(config);
require('./tools/settings').init(config, ipcRenderer);
require('./tools/customBackgrounds')(config, ipcRenderer);
require('./tools/theme').init(config, ipcRenderer);
}

23 changes: 23 additions & 0 deletions app/browser/tools/theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const instance = require('./instance');

class ThemeManager {
/**
* @param {object} config
* @param {Electron.IpcRenderer} ipcRenderer
*/
init(config, ipcRenderer) {
this.ipcRenderer = ipcRenderer;
this.config = config;
if (config.followSystemTheme) {
this.ipcRenderer.on('system-theme-changed', this.applyTheme);
}
}

applyTheme = async (event, ...args) => {
const theme = args[0] ? 'dark' : 'default';
const inst = await instance.whenReady();
inst.controller.layoutService.setTheme(theme);
}
}

module.exports = new ThemeManager();
7 changes: 6 additions & 1 deletion app/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ function argv(configPath, appVersion) {
describe: 'custom CSS styles file location',
type: 'string'
},
followSystemTheme: {
default: false,
describe: 'Follow system theme',
type: 'boolean'
},
customUserDir: {
default: null,
describe: 'Custom User Directory so that you can have multiple profiles',
Expand Down Expand Up @@ -126,7 +131,7 @@ function argv(configPath, appVersion) {
default: '',
describe: 'Default application to be used to open the HTTP URLs',
type: 'string'
},
},
disableAutogain: {
default: false,
describe: 'A flag indicates whether to disable mic auto gain or not',
Expand Down
18 changes: 15 additions & 3 deletions app/mainAppWindow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { execFile, spawn } = require('child_process');
const TrayIconChooser = require('../browser/tools/trayIconChooser');
// eslint-disable-next-line no-unused-vars
const { AppConfiguration } = require('../appConfiguration');
const connMgr = require('../connectionManager');
const connMgr = require('../connectionManager');

/**
* @type {TrayIconChooser}
Expand Down Expand Up @@ -71,7 +71,7 @@ exports.onAppReady = async function onAppReady(mainConfig) {
addEventHandlers();

const url = processArgs(process.argv);
connMgr.start(url,{
connMgr.start(url, {
window: window,
config: config
});
Expand Down Expand Up @@ -155,6 +155,18 @@ function onDidFinishLoad() {
tryAgainLink && tryAgainLink.click()
`);
customCSS.onDidFinishLoad(window.webContents, config);
initSystemThemeFollow(config);
}

function initSystemThemeFollow(config) {
if (config.followSystemTheme) {
nativeTheme.on('updated', () => {
window.webContents.send('system-theme-changed', nativeTheme.shouldUseDarkColors);
});
setTimeout(() => {
window.webContents.send('system-theme-changed', nativeTheme.shouldUseDarkColors);
}, 2500);
}
}

function onDidFrameFinishLoad(event, isMainFrame, frameProcessId, frameRoutingId) {
Expand Down Expand Up @@ -457,7 +469,7 @@ function assignEventHandlers(newWindow) {

function createNewBrowserWindow(windowState) {
return new BrowserWindow({
title:'Teams for Linux',
title: 'Teams for Linux',
x: windowState.x,
y: windowState.y,

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "teams-for-linux",
"version": "1.4.6",
"version": "1.4.7",
"main": "app/index.js",
"description": "Unofficial client for Microsoft Teams for Linux",
"homepage": "https://github.com/IsmaelMartinez/teams-for-linux",
Expand Down Expand Up @@ -126,4 +126,4 @@
},
"afterPack": "scripts/afterpack.js"
}
}
}

0 comments on commit cc5e376

Please sign in to comment.