Skip to content

Commit

Permalink
Merge pull request #2 from IsmaelMartinez/0.1.5
Browse files Browse the repository at this point in the history
arguments, asar and not persisting the session by default
  • Loading branch information
IsmaelMartinez authored Oct 19, 2018
2 parents e641eae + 4a428fb commit 081c64f
Show file tree
Hide file tree
Showing 9 changed files with 464 additions and 82 deletions.
40 changes: 37 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,52 @@
[![Build Status](https://travis-ci.org/IsmaelMartinez/teams-for-linux.svg?branch=master)](https://travis-ci.org/IsmaelMartinez/teams-for-linux)

Unofficial Microsoft Teams client for Linux using [Electron](https://electronjs.org/).
It uses the Web App and wrapps it as a standalone application using Electron.
It uses the Web App and wraps it as a standalone application using Electron.

## Install

You can download the tarball, rpm, deb or pacman from the [releases page](https://github.com/IsmaelMartinez/teams-for-linux/releases).
You can download the tarball, rpm or deb from the [releases page](https://github.com/IsmaelMartinez/teams-for-linux/releases).

## Run from source

```bash
yarn start
```

## Available starting arguments

The application uses [yargs](https://www.npmjs.com/package/yargs) to allow command line arguments.

Here is the list of available arguments and its usage:

| Option | Usage | Default Value |
|:-:|:-:|:-:|
| help | show the available commands | false |
| version | show the version number | false |
| partition | [BrowserWindow](https://electronjs.org/docs/api/browser-window) webpreferences partition | nopersist |
| webDebug | start with the browser developer tools open | false |
| url | url to open | https://teams.microsoft.com/ |
| config | config file location | ~/.config/teams.json |
| userAgent | select the user agent to use | chrome |
| edgeUserAgent | user agent string for edge | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134 |
| chromeUserAgent | user agent string for chrome | Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36 |


As an example:
```bash
yarn start --help
```

## Using video vs mentions

To be able to use video, the application needs to be started with the edgeUserAgent.

Unfortunately, this introduces a bug in the mentions that render them unusable.

For that reason, the default userAgent used is chrome at this moment in time.

> Note: Switching the userAgent with the persistence turn on sometimes have the side effect of "loosing" the channels history.
## License

GPLv3
[GPLv3](LICENSE.md)
100 changes: 44 additions & 56 deletions app/lib/config/index.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,46 @@
// 'use strict';
// // const yargs = require('yargs');
// const path = require('path');
'use strict';
const yargs = require('yargs');
const path = require('path');

// function argv(configPath) {
// return yargs
// .env(true)
// .config(path.join(configPath, 'teams.json'))
// .options({
// url: {
// demandOption: true,
// default: 'https://teams.microsoft.com/',
// describe: 'Microsoft Teams URL',
// type: 'string'
// },
// webDebug: {
// demandOption: false,
// default: false,
// describe: 'Enable debug',
// type: 'boolean'
// },
// firewallUsername: {
// alias: 'u',
// demandOption: false,
// describe: 'Username',
// type: 'string'
// },
// firewallPassword: {
// alias: 'p',
// demandOption: false,
// describe: 'Password',
// type: 'string'
// },
// userAgent: {
// demandOption: false,
// describe: 'HTTP User Agent',
// type: 'string',
// default: 'edge'
// },
// edgeUserAgent: {
// demandOption: false,
// describe: 'Microsoft Edge User Agent',
// type: 'string',
// default:
// 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134'
// },
// chromeUserAgent: {
// demandOption: false,
// describe: 'Google Chrome User Agent',
// type: 'string',
// default:
// 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'
// }
// })
// .implies('firewallUsername', 'firewallPassword').argv;
// }
function argv(configPath) {
return yargs
.env(true)
.config(path.join(configPath, 'teams.json'))
.options({
url: {
default: 'https://teams.microsoft.com/',
describe: 'Microsoft Teams URL',
type: 'string'
},
webDebug: {
default: false,
describe: 'Enable debug',
type: 'boolean'
},
partition: {
default: 'nopersist',
describe: 'BrowserWindow webpreferences partition',
type: 'string'
},
userAgent: {
describe: 'HTTP User Agent',
type: 'string',
default: 'chrome'
},
edgeUserAgent: {
describe: 'Microsoft Edge User Agent',
type: 'string',
default:
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134'
},
chromeUserAgent: {
describe: 'Google Chrome User Agent',
type: 'string',
default:
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'
}
})
.argv;
}

// exports = module.exports = argv;
exports = module.exports = argv;
31 changes: 16 additions & 15 deletions app/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ const { shell, app, ipcMain, BrowserWindow } = require('electron');
const login = require('./login');
const NativeNotification = require('electron-native-notification');
const Menus = require('./menus');
const configBuilder = require('./config');

const teamsUrl = 'https://teams.microsoft.com/'
const userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36';

function createWindow(iconPath) {
function createWindow(config, iconPath) {
// Load the previous state with fallback to defaults
let windowState = windowStateKeeper({
defaultWidth: 0,
Expand All @@ -30,7 +28,7 @@ function createWindow(iconPath) {
icon: path.join(__dirname, 'assets', 'icons', 'icon-96x96.png'),

webPreferences: {
partition: 'persist:teams-linux',
partition: config.partition,
preload: path.join(__dirname, 'browser', 'index.js'),
nativeWindowOpen: true,
plugins: true,
Expand All @@ -55,20 +53,15 @@ app.on('ready', () => {
'lib/assets/icons/icon-96x96.png'
);
let isFirstLoginTry = true;
var window = createWindow(iconPath);
let menus = new Menus(iconPath);
const config = configBuilder(app.getPath('userData'));
var window = createWindow(config, iconPath);
let menus = new Menus(config, iconPath);
menus.register(window);

window.on('page-title-updated', (event, title) => {
window.webContents.send('page-title', title)
});

// ipcMain.on('nativeNotificationClick', event => {
// console.log('nativeNotificationClick called');
// window.show();
// window.focus();
// });

ipcMain.on('notifications', async (e, msg) => {
if (msg.count > 0) {
const body = "You got " + msg.count + " notification(s). " + ((msg.text) ? " <i>" + msg.text + "</i> " : "");
Expand Down Expand Up @@ -106,7 +99,11 @@ app.on('ready', () => {
}
});

window.webContents.setUserAgent(userAgent);
if (config.userAgent === 'edge') {
window.webContents.setUserAgent(config.edgeUserAgent);
} else {
window.webContents.setUserAgent(config.chromeUserAgent);
}

window.once('ready-to-show', () => window.show());

Expand All @@ -117,5 +114,9 @@ app.on('ready', () => {

window.on('closed', () => window = null);

window.loadURL(teamsUrl);
window.loadURL(config.url);

if (config.webDebug) {
window.openDevTools();
}
});
2 changes: 1 addition & 1 deletion app/lib/login/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<form name="form" onSubmit="JavaScript:sendForm(event)">
<input type="text" name="username" id="username" value="" placeholder="email of/or domain\username" type="email"
style="width: 342px;">
autofocus style="width: 342px;">
<br><br>
<input type="password" name="password" id="password" value="" placeholder="Password" style="width: 342px;">
<br><br>
Expand Down
5 changes: 3 additions & 2 deletions app/lib/menus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ let shouldQuit = false;

class Menus {

constructor(iconPath) {
constructor(config, iconPath) {
this.iconPath = iconPath;
this.config = config;
}

static quit() {
Expand Down Expand Up @@ -61,7 +62,7 @@ class Menus {
label: 'File',
submenu: appMenu
},
preferences(window),
preferences(this.config, window),
help(app)
]));

Expand Down
22 changes: 21 additions & 1 deletion app/lib/menus/preferences.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
'use strict';
const webFrame = require('electron').webFrame;

exports = module.exports = (window) => {
exports = module.exports = (config, window) => {
return {
label: 'Preferences',
submenu: [
{
label: 'User-Agent',
submenu: [
{
label: 'Microsoft Edge',
type: 'radio',
checked: config.userAgent === 'edge',
click: () => {
window.webContents.setUserAgent(config.edgeUserAgent);
}
},
{
label: 'Google Chrome',
type: 'radio',
checked: config.userAgent !== 'edge',
click: () => {
window.webContents.setUserAgent(config.chromeUserAgent);
}
}
]
}, {
label: 'Zoom',
submenu: [
{ role: 'resetZoom' },
Expand Down
5 changes: 3 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "teams-for-linux",
"version": "0.1.4",
"version": "0.1.5",
"description": "Microsoft Teams for Linux",
"main": "lib/index.js",
"author": "Ivelin Velkov <[email protected]>",
"dependencies": {
"electron-window-state": "~4.1.1",
"electron-native-notification":"^1.2.1",
"opn": "5.3.0"
"opn": "5.3.0",
"yargs": "^12.0.1"
}
}
Loading

0 comments on commit 081c64f

Please sign in to comment.