diff --git a/src/browser/settings.jsx b/src/browser/settings.jsx index 224d9601..91cbbbc8 100644 --- a/src/browser/settings.jsx +++ b/src/browser/settings.jsx @@ -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(); + //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(); + } var options_row = (options.length > 0) ? ( diff --git a/src/main.js b/src/main.js index baa80e49..ecdcfa99 100644 --- a/src/main.js +++ b/src/main.js @@ -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; diff --git a/src/package.json b/src/package.json index bd17e5d6..6a1e2f77 100644 --- a/src/package.json +++ b/src/package.json @@ -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",