diff --git a/electron/createWindow.js b/electron/createWindow.js
index 8c9799d16..154955973 100644
--- a/electron/createWindow.js
+++ b/electron/createWindow.js
@@ -4,6 +4,7 @@ import isDev from 'electron-is-dev';
import windowStateKeeper from 'electron-window-state';
import SUPPORTED_LANGUAGES from 'constants/supported_languages';
import { SUPPORTED_SUB_LANGUAGE_CODES, SUB_LANG_CODE_LEN } from 'constants/supported_sub_languages';
+import { TO_TRAY_WHEN_CLOSED } from 'constants/settings';
import setupBarMenu from './menu/setupBarMenu';
import * as PAGES from 'constants/pages';
@@ -106,7 +107,11 @@ export default appState => {
window.loadURL(rendererURL + deepLinkingURI);
window.on('close', event => {
- if (!appState.isQuitting && !appState.autoUpdateAccepted) {
+ if (appState.isQuitting) {
+ return;
+ }
+
+ if (!appState.autoUpdateAccepted) {
event.preventDefault();
if (window.isFullScreen()) {
window.once('leave-full-screen', () => {
@@ -117,6 +122,16 @@ export default appState => {
window.hide();
}
}
+
+ const getToTrayWhenClosedSetting = window.webContents.executeJavaScript(`localStorage.getItem('${TO_TRAY_WHEN_CLOSED}')`);
+
+ getToTrayWhenClosedSetting.then(toTrayWhenClosedSetting => {
+ const closeApp = toTrayWhenClosedSetting === 'false';
+
+ if (closeApp) {
+ app.quit();
+ }
+ });
});
window.on('focus', () => {
diff --git a/electron/index.js b/electron/index.js
index 16a613f5f..2348dcfb7 100644
--- a/electron/index.js
+++ b/electron/index.js
@@ -249,6 +249,7 @@ app.on('will-quit', event => {
}
appState.isQuitting = true;
+
if (daemon) {
daemon.quit();
event.preventDefault();
@@ -259,6 +260,7 @@ app.on('will-quit', event => {
}
if (rendererWindow) {
+ tray.destroy();
rendererWindow = null;
}
});
diff --git a/ui/component/settingClosingBehavior/index.js b/ui/component/settingClosingBehavior/index.js
new file mode 100644
index 000000000..e90759a99
--- /dev/null
+++ b/ui/component/settingClosingBehavior/index.js
@@ -0,0 +1,15 @@
+import { connect } from 'react-redux';
+import { SETTINGS } from 'lbry-redux';
+import { doSetAppToTrayWhenClosed } from 'redux/actions/settings';
+import { makeSelectClientSetting } from 'redux/selectors/settings';
+import SettingClosingBehavior from './view';
+
+const select = state => ({
+ toTrayWhenClosed: makeSelectClientSetting(SETTINGS.TO_TRAY_WHEN_CLOSED)(state),
+});
+
+const perform = dispatch => ({
+ setToTrayWhenClosed: value => dispatch(doSetAppToTrayWhenClosed(value)),
+});
+
+export default connect(select, perform)(SettingClosingBehavior);
diff --git a/ui/component/settingClosingBehavior/view.jsx b/ui/component/settingClosingBehavior/view.jsx
new file mode 100644
index 000000000..a8560aa57
--- /dev/null
+++ b/ui/component/settingClosingBehavior/view.jsx
@@ -0,0 +1,29 @@
+// @flow
+
+import React from 'react';
+import { FormField } from 'component/common/form';
+
+type Props = {
+ toTrayWhenClosed: boolean,
+ setToTrayWhenClosed: boolean => void,
+};
+
+function SettingClosingBehavior(props: Props) {
+ const { toTrayWhenClosed, setToTrayWhenClosed } = props;
+
+ return (
+
+ {
+ setToTrayWhenClosed(e.target.checked);
+ }}
+ checked={toTrayWhenClosed}
+ label={__('Leave app running in notification area when the window is closed')}
+ />
+
+ );
+}
+
+export default SettingClosingBehavior;
diff --git a/ui/constants/settings.js b/ui/constants/settings.js
index b2c83cfe0..56bfae976 100644
--- a/ui/constants/settings.js
+++ b/ui/constants/settings.js
@@ -22,3 +22,4 @@ export const HIDE_SPLASH_ANIMATION = 'hide_splash_animation';
export const FLOATING_PLAYER = 'floating_player';
export const DARK_MODE_TIMES = 'dark_mode_times';
export const ENABLE_SYNC = 'enable_sync';
+export const TO_TRAY_WHEN_CLOSED = 'to_tray_when_closed';
diff --git a/ui/page/settingsAdvanced/view.jsx b/ui/page/settingsAdvanced/view.jsx
index 221918387..2863f765e 100644
--- a/ui/page/settingsAdvanced/view.jsx
+++ b/ui/page/settingsAdvanced/view.jsx
@@ -7,6 +7,7 @@ import I18nMessage from 'component/i18nMessage';
import Page from 'component/page';
import SettingWalletServer from 'component/settingWalletServer';
import SettingAutoLaunch from 'component/settingAutoLaunch';
+import SettingClosingBehavior from 'component/settingClosingBehavior';
import FileSelector from 'component/common/file-selector';
import { SETTINGS } from 'lbry-redux';
import Card from 'component/common/card';
@@ -500,6 +501,7 @@ class SettingsPage extends React.PureComponent {
{/* @if TARGET='app' */}
{/* Auto launch in a hidden state doesn't work on mac https://github.com/Teamwork/node-auto-launch/issues/81 */}
{!IS_MAC && } />}
+ } />
{/* @endif */}
)}
diff --git a/ui/redux/actions/settings.js b/ui/redux/actions/settings.js
index 9815439fe..6b1f949a6 100644
--- a/ui/redux/actions/settings.js
+++ b/ui/redux/actions/settings.js
@@ -290,3 +290,10 @@ export function doSetAutoLaunch(value) {
}
};
}
+
+export function doSetAppToTrayWhenClosed(value) {
+ return dispatch => {
+ window.localStorage.setItem(SETTINGS.TO_TRAY_WHEN_CLOSED, value);
+ dispatch(doSetClientSetting(SETTINGS.TO_TRAY_WHEN_CLOSED, value));
+ };
+}
diff --git a/ui/redux/reducers/settings.js b/ui/redux/reducers/settings.js
index c9754e193..ea0a363b0 100644
--- a/ui/redux/reducers/settings.js
+++ b/ui/redux/reducers/settings.js
@@ -63,6 +63,7 @@ const defaultState = {
// OS
[SETTINGS.AUTO_LAUNCH]: true,
+ [SETTINGS.TO_TRAY_WHEN_CLOSED]: true,
},
};