Add app closing behavior setting
This commit is contained in:
parent
907eb598e3
commit
cbfed97853
8 changed files with 73 additions and 1 deletions
|
@ -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', () => {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
|
15
ui/component/settingClosingBehavior/index.js
Normal file
15
ui/component/settingClosingBehavior/index.js
Normal 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);
|
29
ui/component/settingClosingBehavior/view.jsx
Normal file
29
ui/component/settingClosingBehavior/view.jsx
Normal 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;
|
|
@ -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';
|
||||
|
|
|
@ -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<Props, State> {
|
|||
{/* @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 && <Card title={__('Startup Preferences')} actions={<SettingAutoLaunch />} />}
|
||||
<Card title={__('Closing Preferences')} actions={<SettingClosingBehavior />} />
|
||||
{/* @endif */}
|
||||
</div>
|
||||
)}
|
||||
|
|
|
@ -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));
|
||||
};
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ const defaultState = {
|
|||
|
||||
// OS
|
||||
[SETTINGS.AUTO_LAUNCH]: true,
|
||||
[SETTINGS.TO_TRAY_WHEN_CLOSED]: true,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue