autoLaunch on startup

This commit is contained in:
Jessop 2019-11-18 10:30:15 -08:00 committed by Sean Yesmunt
parent 30270f2df9
commit 8cb4208282
14 changed files with 176 additions and 12 deletions

View file

@ -17,6 +17,8 @@ export default appState => {
defaultHeight: height,
});
const startMinimized = (process.argv || []).includes('--hidden');
const windowConfiguration = {
backgroundColor: '#270f34', // Located in src/scss/init/_vars.scss `--color-background--splash`
minWidth: 950,
@ -126,9 +128,13 @@ export default appState => {
});
window.once('ready-to-show', () => {
window.show();
startMinimized ? window.hide() : window.show();
});
window.webContents.once('dom-ready', () => {
startMinimized && window.hide()
})
window.webContents.on('did-finish-load', () => {
window.webContents.session.setUserAgent(`LBRY/${app.getVersion()}`);

View file

@ -43,6 +43,7 @@
"postinstall:warning": "echo '\n\nWARNING\n\nNot all node modules were installed because NODE_ENV is set to \"production\".\nThis should only be set after installing dependencies with \"yarn\". The app will not work.\n\n'"
},
"dependencies": {
"auto-launch": "^5.0.5",
"electron-dl": "^1.11.0",
"electron-log": "^2.2.12",
"electron-notarize": "^0.1.1",

View file

@ -24,7 +24,6 @@ export default function EmbedArea(props: Props) {
function copyToClipboard() {
const topRef = input.current;
console.log(topRef);
if (topRef && topRef.input && topRef.input.current) {
topRef.input.current.select();
document.execCommand('copy');

View file

@ -0,0 +1,20 @@
import { connect } from 'react-redux';
import * as SETTINGS from 'constants/settings';
import { doSetAutoLaunch } from 'redux/actions/settings';
import { makeSelectClientSetting } from 'redux/selectors/settings';
import { doToast } from 'lbry-redux';
import SettingAutoLaunch from './view';
const select = state => ({
autoLaunch: makeSelectClientSetting(SETTINGS.AUTO_LAUNCH)(state),
});
const perform = dispatch => ({
showToast: options => dispatch(doToast(options)),
setAutoLaunch: value => dispatch(doSetAutoLaunch(value)),
});
export default connect(
select,
perform
)(SettingAutoLaunch);

View file

@ -0,0 +1,33 @@
// @flow
import React from 'react';
import { FormField } from 'component/common/form';
type Props = {
autoLaunch: string,
showToast: ({}) => void,
setAutoLaunch: boolean => void,
};
function SettingAutoLaunch(props: Props) {
const { autoLaunch, setAutoLaunch } = props;
return (
<React.Fragment>
<FormField
type="checkbox"
name="autolaunch"
onChange={e => {
setAutoLaunch(e.target.checked);
}}
checked={autoLaunch}
label={__('Start minimized')}
helper={__(
'Improve view speed and help the LBRY network by allowing the app to cuddle up in your system tray.'
)}
/>
</React.Fragment>
);
}
export default SettingAutoLaunch;

View file

@ -16,6 +16,7 @@ export const AUTOMATIC_DARK_MODE_ENABLED = 'automatic_dark_mode_enabled';
export const AUTOPLAY = 'autoplay';
export const OS_NOTIFICATIONS_ENABLED = 'os_notifications_enabled';
export const AUTO_DOWNLOAD = 'auto_download';
export const AUTO_LAUNCH = 'auto_launch';
export const SUPPORT_OPTION = 'support_option';
export const HIDE_BALANCE = 'hide_balance';
export const HIDE_SPLASH_ANIMATION = 'hide_splash_animation';

View file

@ -228,8 +228,9 @@ document.addEventListener('click', event => {
});
function AppWrapper() {
const haveLaunched = window.sessionStorage.getItem('loaded') === 'y';
const [readyToLaunch, setReadyToLaunch] = useState(haveLaunched || IS_WEB);
// Splash screen and sdk setup not needed on web
const [readyToLaunch, setReadyToLaunch] = useState(IS_WEB);
const [persistDone, setPersistDone] = useState(false);
useEffect(() => {
// @if TARGET='app'
@ -255,22 +256,25 @@ function AppWrapper() {
}, []);
useEffect(() => {
if (readyToLaunch) {
if (readyToLaunch && persistDone) {
app.store.dispatch(doUpdateIsNightAsync());
app.store.dispatch(doDaemonReady());
app.store.dispatch(doBlackListedOutpointsSubscribe());
app.store.dispatch(doFilteredOutpointsSubscribe());
window.sessionStorage.setItem('loaded', 'y');
const appReadyTime = Date.now();
const timeToStart = appReadyTime - startTime;
analytics.readyEvent(timeToStart);
}
}, [readyToLaunch, haveLaunched]);
}, [readyToLaunch, persistDone]);
return (
<Provider store={store}>
<PersistGate persistor={persistor} loading={<div className="main--launching" />}>
<PersistGate
persistor={persistor}
onBeforeLift={() => setPersistDone(true)}
loading={<div className="main--launching" />}
>
<Fragment>
{readyToLaunch ? (
<ConnectedRouter history={history}>

View file

@ -195,13 +195,11 @@ class HelpPage extends React.PureComponent<Props, State> {
<header className="table__header">
<h2 className="section__title">{__('About')}</h2>
{this.state.upgradeAvailable !== null && this.state.upgradeAvailable ? (
{this.state.upgradeAvailable !== null && this.state.upgradeAvailable && (
<p className="section__subtitle">
{__('A newer version of LBRY is available.')}{' '}
<Button button="link" href={newVerLink} label={__('Download now!')} />
</p>
) : (
<p className="section__subtitle">{__('Your LBRY app is up to date.')}</p>
)}
</header>

View file

@ -11,10 +11,16 @@ import Button from 'component/button';
import I18nMessage from 'component/i18nMessage';
import Page from 'component/page';
import SettingLanguage from 'component/settingLanguage';
import SettingAutoLaunch from 'component/settingAutoLaunch';
import FileSelector from 'component/common/file-selector';
import SyncToggle from 'component/syncToggle';
import Card from 'component/common/card';
import { getSavedPassword } from 'util/saved-passwords';
// @if TARGET='app'
export const IS_MAC = process.platform === 'darwin';
// @endif
type Price = {
currency: string,
amount: number,
@ -632,6 +638,11 @@ 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 />} />}
{/* @endif */}
<Card
title={__('Application Cache')}
subtitle={

View file

@ -22,7 +22,7 @@ import {
doClearSupport,
} from 'lbry-redux';
import Native from 'native';
import { doFetchDaemonSettings } from 'redux/actions/settings';
import { doFetchDaemonSettings, doSetAutoLaunch } from 'redux/actions/settings';
import {
selectIsUpgradeSkipped,
selectUpdateUrl,
@ -323,6 +323,7 @@ export function doDaemonReady() {
// @if TARGET='app'
dispatch(doBalanceSubscribe());
dispatch(doSetAutoLaunch());
dispatch(doFetchDaemonSettings());
dispatch(doFetchFileInfosAndPublishedClaims());
if (!selectIsUpgradeSkipped(state)) {

View file

@ -3,7 +3,10 @@ import * as SETTINGS from 'constants/settings';
import * as LOCAL_ACTIONS from 'constants/action_types';
import analytics from 'analytics';
import SUPPORTED_LANGUAGES from 'constants/supported_languages';
import { launcher } from 'util/autoLaunch';
import { makeSelectClientSetting } from 'redux/selectors/settings';
export const IS_MAC = process.platform === 'darwin';
const UPDATE_IS_NIGHT_INTERVAL = 5 * 60 * 1000;
export function doFetchDaemonSettings() {
@ -120,3 +123,54 @@ export function doSetLanguage(language) {
}
};
}
export function doSetAutoLaunch(value) {
return (dispatch, getState) => {
const state = getState();
const autoLaunch = makeSelectClientSetting(SETTINGS.AUTO_LAUNCH)(state);
if (IS_MAC) {
launcher.disable();
return;
}
if (value === undefined) {
launcher.isEnabled().then(isEnabled => {
if (isEnabled) {
if (!autoLaunch) {
launcher.disable().then(() => {
dispatch(doSetClientSetting(SETTINGS.AUTO_LAUNCH, false));
});
}
} else {
if (autoLaunch || autoLaunch === null || autoLaunch === undefined) {
launcher.enable().then(() => {
dispatch(doSetClientSetting(SETTINGS.AUTO_LAUNCH, true));
});
}
}
});
} else if (value === true) {
launcher.isEnabled().then(function(isEnabled) {
if (!isEnabled) {
launcher.enable().then(() => {
dispatch(doSetClientSetting(SETTINGS.AUTO_LAUNCH, true));
});
} else {
dispatch(doSetClientSetting(SETTINGS.AUTO_LAUNCH, true));
}
});
} else {
// value = false
launcher.isEnabled().then(function(isEnabled) {
if (isEnabled) {
launcher.disable().then(() => {
dispatch(doSetClientSetting(SETTINGS.AUTO_LAUNCH, false));
});
} else {
dispatch(doSetClientSetting(SETTINGS.AUTO_LAUNCH, false));
}
});
}
};
}

View file

@ -23,6 +23,7 @@ const defaultState = {
[SETTINGS.HIDE_BALANCE]: false,
[SETTINGS.OS_NOTIFICATIONS_ENABLED]: true,
[SETTINGS.AUTOMATIC_DARK_MODE_ENABLED]: false,
[SETTINGS.DARK_MODE_TIMES]: {
from: { hour: '21', min: '00', formattedTime: '21:00' },
to: { hour: '8', min: '00', formattedTime: '8:00' },
@ -40,6 +41,9 @@ const defaultState = {
[SETTINGS.AUTOPLAY]: true,
[SETTINGS.FLOATING_PLAYER]: true,
[SETTINGS.AUTO_DOWNLOAD]: true,
// OS
[SETTINGS.AUTO_LAUNCH]: true,
},
};

6
ui/util/autoLaunch.js Normal file
View file

@ -0,0 +1,6 @@
const AutoLaunch = require('auto-launch');
export const launcher = new AutoLaunch({
name: 'LBRY',
isHidden: true,
});

View file

@ -1577,6 +1577,11 @@ app-builder-lib@21.2.0, app-builder-lib@~21.2.0:
semver "^6.3.0"
temp-file "^3.3.4"
applescript@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/applescript/-/applescript-1.0.0.tgz#bb87af568cad034a4e48c4bdaf6067a3a2701317"
integrity sha1-u4evVoytA0pOSMS9r2Bno6JwExc=
aproba@^1.0.3, aproba@^1.1.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a"
@ -1766,6 +1771,17 @@ atob@^2.1.1:
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==
auto-launch@^5.0.5:
version "5.0.5"
resolved "https://registry.yarnpkg.com/auto-launch/-/auto-launch-5.0.5.tgz#d14bd002b1ef642f85e991a6195ff5300c8ad3c0"
integrity sha512-ppdF4mihhYzMYLuCcx9H/c5TUOCev8uM7en53zWVQhyYAJrurd2bFZx3qQVeJKF2jrc7rsPRNN5cD+i23l6PdA==
dependencies:
applescript "^1.0.0"
mkdirp "^0.5.1"
path-is-absolute "^1.0.0"
untildify "^3.0.2"
winreg "1.2.4"
autoprefixer@^6.3.1:
version "6.7.7"
resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-6.7.7.tgz#1dbd1c835658e35ce3f9984099db00585c782014"
@ -12222,6 +12238,11 @@ unset-value@^1.0.0:
has-value "^0.3.1"
isobject "^3.0.0"
untildify@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/untildify/-/untildify-3.0.3.tgz#1e7b42b140bcfd922b22e70ca1265bfe3634c7c9"
integrity sha512-iSk/J8efr8uPT/Z4eSUywnqyrQU7DSdMfdqK4iWEaUVVmcP5JcnpRqmVMwcwcnmI1ATFNgC5V90u09tBynNFKA==
unused-filename@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unused-filename/-/unused-filename-1.0.0.tgz#d340880f71ae2115ebaa1325bef05cc6684469c6"
@ -12804,6 +12825,11 @@ windows-release@^3.1.0:
dependencies:
execa "^1.0.0"
winreg@1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/winreg/-/winreg-1.2.4.tgz#ba065629b7a925130e15779108cf540990e98d1b"
integrity sha1-ugZWKbepJRMOFXeRCM9UCZDpjRs=
wordwrap@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"