Add app closing behavior setting

This commit is contained in:
Franco Montenegro 2020-08-13 13:57:00 -03:00 committed by Sean Yesmunt
parent 907eb598e3
commit cbfed97853
8 changed files with 73 additions and 1 deletions

View file

@ -4,6 +4,7 @@ import isDev from 'electron-is-dev';
import windowStateKeeper from 'electron-window-state'; import windowStateKeeper from 'electron-window-state';
import SUPPORTED_LANGUAGES from 'constants/supported_languages'; import SUPPORTED_LANGUAGES from 'constants/supported_languages';
import { SUPPORTED_SUB_LANGUAGE_CODES, SUB_LANG_CODE_LEN } from 'constants/supported_sub_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 setupBarMenu from './menu/setupBarMenu';
import * as PAGES from 'constants/pages'; import * as PAGES from 'constants/pages';
@ -106,7 +107,11 @@ export default appState => {
window.loadURL(rendererURL + deepLinkingURI); window.loadURL(rendererURL + deepLinkingURI);
window.on('close', event => { window.on('close', event => {
if (!appState.isQuitting && !appState.autoUpdateAccepted) { if (appState.isQuitting) {
return;
}
if (!appState.autoUpdateAccepted) {
event.preventDefault(); event.preventDefault();
if (window.isFullScreen()) { if (window.isFullScreen()) {
window.once('leave-full-screen', () => { window.once('leave-full-screen', () => {
@ -117,6 +122,16 @@ export default appState => {
window.hide(); 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', () => { window.on('focus', () => {

View file

@ -249,6 +249,7 @@ app.on('will-quit', event => {
} }
appState.isQuitting = true; appState.isQuitting = true;
if (daemon) { if (daemon) {
daemon.quit(); daemon.quit();
event.preventDefault(); event.preventDefault();
@ -259,6 +260,7 @@ app.on('will-quit', event => {
} }
if (rendererWindow) { if (rendererWindow) {
tray.destroy();
rendererWindow = null; rendererWindow = null;
} }
}); });

View file

@ -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);

View file

@ -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 (
<React.Fragment>
<FormField
type="checkbox"
name="totraywhenclosed"
onChange={e => {
setToTrayWhenClosed(e.target.checked);
}}
checked={toTrayWhenClosed}
label={__('Leave app running in notification area when the window is closed')}
/>
</React.Fragment>
);
}
export default SettingClosingBehavior;

View file

@ -22,3 +22,4 @@ export const HIDE_SPLASH_ANIMATION = 'hide_splash_animation';
export const FLOATING_PLAYER = 'floating_player'; export const FLOATING_PLAYER = 'floating_player';
export const DARK_MODE_TIMES = 'dark_mode_times'; export const DARK_MODE_TIMES = 'dark_mode_times';
export const ENABLE_SYNC = 'enable_sync'; export const ENABLE_SYNC = 'enable_sync';
export const TO_TRAY_WHEN_CLOSED = 'to_tray_when_closed';

View file

@ -7,6 +7,7 @@ import I18nMessage from 'component/i18nMessage';
import Page from 'component/page'; import Page from 'component/page';
import SettingWalletServer from 'component/settingWalletServer'; import SettingWalletServer from 'component/settingWalletServer';
import SettingAutoLaunch from 'component/settingAutoLaunch'; import SettingAutoLaunch from 'component/settingAutoLaunch';
import SettingClosingBehavior from 'component/settingClosingBehavior';
import FileSelector from 'component/common/file-selector'; import FileSelector from 'component/common/file-selector';
import { SETTINGS } from 'lbry-redux'; import { SETTINGS } from 'lbry-redux';
import Card from 'component/common/card'; import Card from 'component/common/card';
@ -500,6 +501,7 @@ class SettingsPage extends React.PureComponent<Props, State> {
{/* @if TARGET='app' */} {/* @if TARGET='app' */}
{/* Auto launch in a hidden state doesn't work on mac https://github.com/Teamwork/node-auto-launch/issues/81 */} {/* Auto launch in a hidden state doesn't work on mac https://github.com/Teamwork/node-auto-launch/issues/81 */}
{!IS_MAC && <Card title={__('Startup Preferences')} actions={<SettingAutoLaunch />} />} {!IS_MAC && <Card title={__('Startup Preferences')} actions={<SettingAutoLaunch />} />}
<Card title={__('Closing Preferences')} actions={<SettingClosingBehavior />} />
{/* @endif */} {/* @endif */}
</div> </div>
)} )}

View file

@ -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));
};
}

View file

@ -63,6 +63,7 @@ const defaultState = {
// OS // OS
[SETTINGS.AUTO_LAUNCH]: true, [SETTINGS.AUTO_LAUNCH]: true,
[SETTINGS.TO_TRAY_WHEN_CLOSED]: true,
}, },
}; };