Adds a setting to launch the app on system login

This commit is contained in:
Kolja Lampe
2016-06-11 02:17:18 +02:00
committed by Kolja Lampe
parent c6d91e7ae4
commit 447f6ec41d
3 changed files with 49 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ const settings = require('../common/settings');
const React = require('react');
const ReactDOM = require('react-dom');
const ReactBootstrap = require('react-bootstrap');
var AutoLaunch = require('auto-launch');
const Grid = ReactBootstrap.Grid;
const Row = ReactBootstrap.Row;
@@ -16,6 +17,10 @@ const ListGroup = ReactBootstrap.ListGroup;
const ListGroupItem = ReactBootstrap.ListGroupItem;
const Glyphicon = ReactBootstrap.Glyphicon;
var appLauncher = new AutoLaunch({
name: 'Mattermost'
});
function backToIndex() {
remote.getCurrentWindow().loadURL('file://' + __dirname + '/index.html');
}
@@ -35,6 +40,16 @@ var SettingsPage = React.createClass({
return config;
},
componentDidMount: function() {
if (process.platform === 'win32' || process.platform === 'linux') {
var self = this;
appLauncher.isEnabled().then(function(enabled) {
self.setState({
autostart: enabled
});
});
}
},
handleTeamsChange: function(teams) {
this.setState({
teams: teams
@@ -56,6 +71,15 @@ var SettingsPage = React.createClass({
var currentWindow = remote.getCurrentWindow();
currentWindow.setAutoHideMenuBar(config.hideMenuBar);
currentWindow.setMenuBarVisibility(!config.hideMenuBar);
var autostart = this.state.autostart;
appLauncher.isEnabled().then(function(enabled) {
if (enabled && !autostart) {
appLauncher.disable();
} else if (!enabled && autostart) {
appLauncher.enable();
}
});
}
if (typeof toIndex == 'undefined' || toIndex) {
@@ -85,6 +109,11 @@ var SettingsPage = React.createClass({
trayIconTheme: this.refs.trayIconTheme.getValue()
});
},
handleChangeAutoStart: function() {
this.setState({
autostart: this.refs.autostart.getChecked()
});
},
handleShowTeamForm: function() {
if (!this.state.showAddTeamForm) {
this.setState({
@@ -127,6 +156,10 @@ var SettingsPage = React.createClass({
}
options.push(<Input key="inputDisableWebSecurity" ref="disablewebsecurity" type="checkbox" label="Allow mixed content (Enabling allows both secure and insecure content, images and scripts to render and execute. Disabling allows only secure content.)"
checked={ this.state.disablewebsecurity } onChange={ this.handleChangeDisableWebSecurity } />);
//OSX has an option in the tray, to set the app to autostart, so we choose to not support this option for OSX
if (process.platform === 'win32' || process.platform === 'linux') {
options.push(<Input key="inputAutoStart" ref="autostart" type="checkbox" label="Start app on login." checked={ this.state.autostart } onChange={ this.handleChangeAutoStart } />);
}
var options_row = (options.length > 0) ? (
<Row>
<Col md={ 12 }>

View File

@@ -3,7 +3,21 @@
const electron = require('electron');
const app = electron.app; // Module to control application life.
if (require('electron-squirrel-startup')) app.quit();
if (process.platform === 'win32') {
var cmd = process.argv[1];
if (cmd === '--squirrel-uninstall') {
var AutoLaunch = require('auto-launch');
var appLauncher = new AutoLaunch({
name: 'Mattermost'
});
appLauncher.isEnabled().then(function(enabled) {
if (enabled)
appLauncher.disable();
});
}
}
require('electron-squirrel-startup');
const BrowserWindow = electron.BrowserWindow; // Module to create native browser window.
const Menu = electron.Menu;

View File

@@ -13,6 +13,7 @@
"electron-connect": "^0.3.3"
},
"dependencies": {
"auto-launch": "^2.0.1",
"bootstrap": "^3.3.6",
"os-locale": "^1.4.0",
"react": "^15.0.1",