Skip to content

Commit

Permalink
Merge pull request #1192 from jijojosephk/issue_1150
Browse files Browse the repository at this point in the history
Add support for electron CLI flags in config file
  • Loading branch information
jijojosephk authored Apr 13, 2024
2 parents baaf42b + 9ac632e commit c831f5a
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 33 deletions.
19 changes: 19 additions & 0 deletions app/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Here is the list of available arguments and its usage:
| useMutationTitleLogic | Use MutationObserver to update counter from title | false |
| version | Show the version number | false |
| webDebug | Enable web debugging | false |
| electronCLIFlags | Electron CLI flags to be added when the app starts | [] |


As an example, to disable the persistence, you can run the following command:
Expand All @@ -80,6 +81,24 @@ Example:

Information about how to get the custom CA Certs fingerprints is now available under the [certificate README.md file](../certificate/README.md)

## Electron CLI flags

Now the `config.json` can have electron CLI flags which will be added when the application starts.

Example:

```json
{
"electronCLIFlags": [
["ozone-platform","wayland"]
"disable-software-rasterizer"
]
}
```

As you can see from the above example, switches with values must be of array where the first entry will be the switch and the second one will be the value. It can be a simple string otherwise.


## Custom backgrounds

We added a feature to load custom background images during a video call. This is available from version `1.0.84`.
Expand Down
5 changes: 5 additions & 0 deletions app/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ function argv(configPath, appVersion) {
default: false,
describe: 'Enable debug at start',
type: 'boolean'
},
electronCLIFlags: {
default: [],
describe: "Electron CLI flags",
type: 'array'
}
})
.parse(process.argv.slice(1));
Expand Down
108 changes: 76 additions & 32 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ const { httpHelper } = require('./helpers');
const isDev = require('electron-is-dev');
const os = require('os');
const isMac = os.platform() === 'darwin';
if (app.commandLine.hasSwitch('customUserDir')) {
app.setPath('userData', app.commandLine.getSwitchValue('customUserDir'));
}

// This must be executed before loading the config file.
addCommandLineSwitchesBeforeConfigLoad();

// Load config file.
const { AppConfiguration } = require('./appConfiguration');
const appConfig = new AppConfiguration(app.getPath('userData'), app.getVersion());

Expand All @@ -20,6 +21,10 @@ const logger = new LucidLog({
levels: config.appLogLevels.split(',')
});

// This must only be executed after loading the config file and logger is initialized.
addCommandLineSwitchesAfterConfigLoad();


const notificationSounds = [{
type: 'new-message',
file: path.join(config.appPath, 'assets/sounds/new_message.wav')
Expand Down Expand Up @@ -49,30 +54,8 @@ const certificateModule = require('./certificate');
const gotTheLock = app.requestSingleInstanceLock();
const mainAppWindow = require('./mainAppWindow');

if (config.proxyServer) app.commandLine.appendSwitch('proxy-server', config.proxyServer);
app.commandLine.appendSwitch('auth-server-whitelist', config.authServerWhitelist);
app.commandLine.appendSwitch('enable-ntlm-v2', config.ntlmV2enabled);
app.commandLine.appendSwitch('try-supported-channel-layouts');

const disabledFeatures = app.commandLine.hasSwitch('disable-features') ? app.commandLine.getSwitchValue('disable-features').split(',') : ['HardwareMediaKeyHandling'];

if (!disabledFeatures.includes('HardwareMediaKeyHandling'))
disabledFeatures.push('HardwareMediaKeyHandling');

app.commandLine.appendSwitch('disable-features', disabledFeatures.join(','));

if (isMac) {
requestMediaAccess();

} else if (process.env.XDG_SESSION_TYPE === 'wayland') {
logger.info('Running under Wayland, switching to PipeWire...');

const features = app.commandLine.hasSwitch('enable-features') ? app.commandLine.getSwitchValue('enable-features').split(',') : [];
if (!features.includes('WebRTCPipeWireCapturer'))
features.push('WebRTCPipeWireCapturer');

app.commandLine.appendSwitch('enable-features', features.join(','));
app.commandLine.appendSwitch('use-fake-ui-for-media-stream');
}

const protocolClient = 'msteams';
Expand All @@ -82,12 +65,6 @@ if (!app.isDefaultProtocolClient(protocolClient, process.execPath)) {

app.allowRendererProcessReuse = false;

if (config.disableGpu) {
logger.info('Disabling GPU support...');
app.commandLine.appendSwitch('disable-gpu');
app.commandLine.appendSwitch('disable-software-rasterizer');
}

if (!gotTheLock) {
logger.info('App already running');
app.quit();
Expand All @@ -110,6 +87,73 @@ if (!gotTheLock) {
ipcMain.handle('set-badge-count', setBadgeCountHandler);
}

function addCommandLineSwitchesBeforeConfigLoad() {
// Custom user data directory
if (app.commandLine.hasSwitch('customUserDir')) {
app.setPath('userData', app.commandLine.getSwitchValue('customUserDir'));
}

app.commandLine.appendSwitch('try-supported-channel-layouts');

// Disabled features
const disabledFeatures = app.commandLine.hasSwitch('disable-features') ? app.commandLine.getSwitchValue('disable-features').split(',') : ['HardwareMediaKeyHandling'];

if (!disabledFeatures.includes('HardwareMediaKeyHandling'))
disabledFeatures.push('HardwareMediaKeyHandling');

app.commandLine.appendSwitch('disable-features', disabledFeatures.join(','));
}

function addCommandLineSwitchesAfterConfigLoad() {
// Wayland
if (process.env.XDG_SESSION_TYPE === 'wayland') {
logger.info('Running under Wayland, switching to PipeWire...');

const features = app.commandLine.hasSwitch('enable-features') ? app.commandLine.getSwitchValue('enable-features').split(',') : [];
if (!features.includes('WebRTCPipeWireCapturer'))
features.push('WebRTCPipeWireCapturer');

app.commandLine.appendSwitch('enable-features', features.join(','));
app.commandLine.appendSwitch('use-fake-ui-for-media-stream');
}

// Proxy
if (config.proxyServer) {
app.commandLine.appendSwitch('proxy-server', config.proxyServer);
}

app.commandLine.appendSwitch('auth-server-whitelist', config.authServerWhitelist);
app.commandLine.appendSwitch('enable-ntlm-v2', config.ntlmV2enabled);

// GPU
if (config.disableGpu) {
logger.info('Disabling GPU support...');
app.commandLine.appendSwitch('disable-gpu');
app.commandLine.appendSwitch('disable-software-rasterizer');
}

addElectronCLIFlagsFromConfig();
}

function addElectronCLIFlagsFromConfig() {
if (Array.isArray(config.electronCLIFlags)) {
for (const flag of config.electronCLIFlags) {
if (typeof (flag) === 'string') {
logger.debug(`Adding electron CLI flag '${flag}'`);
app.commandLine.appendSwitch(flag);
} else if (Array.isArray(flag) && typeof (flag[0]) === 'string') {
if (!(typeof (flag[1]) === 'undefined' || typeof (flag[1]) === 'object' || typeof (flag[1]) === 'function')) {
logger.debug(`Adding electron CLI flag '${flag[0]}' with value '${flag[1]}'`);
app.commandLine.appendSwitch(flag[0], flag[1]);
} else {
logger.debug(`Adding electron CLI flag '${flag[0]}'`);
app.commandLine.appendSwitch(flag[0]);
}
}
}
}
}

// eslint-disable-next-line no-unused-vars
async function playNotificationSound(event, options) {
logger.debug(`Notificaion => Type: ${options.type}, Audio: ${options.audio}, Title: ${options.title}, Body: ${options.body}`);
Expand Down Expand Up @@ -186,7 +230,7 @@ async function handleGetSystemIdleState() {
if (systemIdleState === 'active') {
idleTimeUserStatus = -1
}

return state;
}

Expand Down
7 changes: 7 additions & 0 deletions com.github.IsmaelMartinez.teams_for_linux.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
<url type="bugtracker">https://github.com/IsmaelMartinez/teams-for-linux/issues</url>
<launchable type="desktop-id">com.github.IsmaelMartinez.teams_for_linux.desktop</launchable>
<releases>
<release version="1.4.24" date="2024-04-13">
<description>
<ul>
<li>Support for electron CLI flags in config file</li>
</ul>
</description>
</release>
<release version="1.4.23" date="2024-04-12">
<description>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "teams-for-linux",
"version": "1.4.23",
"version": "1.4.24",
"main": "app/index.js",
"description": "Unofficial client for Microsoft Teams for Linux",
"homepage": "https://github.com/IsmaelMartinez/teams-for-linux",
Expand Down

0 comments on commit c831f5a

Please sign in to comment.