From 8cb4208282d65f3dba85e44f726603b9e7ae92b1 Mon Sep 17 00:00:00 2001 From: Jessop Date: Mon, 18 Nov 2019 10:30:15 -0800 Subject: [PATCH] autoLaunch on startup --- electron/createWindow.js | 8 +++- package.json | 1 + ui/component/embedArea/view.jsx | 1 - ui/component/settingAutoLaunch/index.js | 20 +++++++++ ui/component/settingAutoLaunch/view.jsx | 33 +++++++++++++++ ui/constants/settings.js | 1 + ui/index.jsx | 16 +++++--- ui/page/help/view.jsx | 4 +- ui/page/settings/view.jsx | 11 +++++ ui/redux/actions/app.js | 3 +- ui/redux/actions/settings.js | 54 +++++++++++++++++++++++++ ui/redux/reducers/settings.js | 4 ++ ui/util/autoLaunch.js | 6 +++ yarn.lock | 26 ++++++++++++ 14 files changed, 176 insertions(+), 12 deletions(-) create mode 100644 ui/component/settingAutoLaunch/index.js create mode 100644 ui/component/settingAutoLaunch/view.jsx create mode 100644 ui/util/autoLaunch.js diff --git a/electron/createWindow.js b/electron/createWindow.js index b0b30c866..f190c9f11 100644 --- a/electron/createWindow.js +++ b/electron/createWindow.js @@ -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()}`); diff --git a/package.json b/package.json index 3be4906c1..8afff98bf 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/ui/component/embedArea/view.jsx b/ui/component/embedArea/view.jsx index 533938aae..058b25732 100644 --- a/ui/component/embedArea/view.jsx +++ b/ui/component/embedArea/view.jsx @@ -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'); diff --git a/ui/component/settingAutoLaunch/index.js b/ui/component/settingAutoLaunch/index.js new file mode 100644 index 000000000..5a08f94f9 --- /dev/null +++ b/ui/component/settingAutoLaunch/index.js @@ -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); diff --git a/ui/component/settingAutoLaunch/view.jsx b/ui/component/settingAutoLaunch/view.jsx new file mode 100644 index 000000000..4effdabf7 --- /dev/null +++ b/ui/component/settingAutoLaunch/view.jsx @@ -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 ( + + { + 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.' + )} + /> + + ); +} + +export default SettingAutoLaunch; diff --git a/ui/constants/settings.js b/ui/constants/settings.js index c9c7ddaeb..c3efa057f 100644 --- a/ui/constants/settings.js +++ b/ui/constants/settings.js @@ -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'; diff --git a/ui/index.jsx b/ui/index.jsx index d2c8a4969..52db88278 100644 --- a/ui/index.jsx +++ b/ui/index.jsx @@ -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 ( - }> + setPersistDone(true)} + loading={
} + > {readyToLaunch ? ( diff --git a/ui/page/help/view.jsx b/ui/page/help/view.jsx index 645c32251..04abd9a7b 100644 --- a/ui/page/help/view.jsx +++ b/ui/page/help/view.jsx @@ -195,13 +195,11 @@ class HelpPage extends React.PureComponent {

{__('About')}

- {this.state.upgradeAvailable !== null && this.state.upgradeAvailable ? ( + {this.state.upgradeAvailable !== null && this.state.upgradeAvailable && (

{__('A newer version of LBRY is available.')}{' '}

diff --git a/ui/page/settings/view.jsx b/ui/page/settings/view.jsx index e70630fa3..d1fc38ccf 100644 --- a/ui/page/settings/view.jsx +++ b/ui/page/settings/view.jsx @@ -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 { } /> + {/* @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 */} + { + 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)); + } + }); + } + }; +} diff --git a/ui/redux/reducers/settings.js b/ui/redux/reducers/settings.js index 683047810..4644867d0 100644 --- a/ui/redux/reducers/settings.js +++ b/ui/redux/reducers/settings.js @@ -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, }, }; diff --git a/ui/util/autoLaunch.js b/ui/util/autoLaunch.js new file mode 100644 index 000000000..210aedfe2 --- /dev/null +++ b/ui/util/autoLaunch.js @@ -0,0 +1,6 @@ +const AutoLaunch = require('auto-launch'); + +export const launcher = new AutoLaunch({ + name: 'LBRY', + isHidden: true, +}); diff --git a/yarn.lock b/yarn.lock index 39b67b044..5eaa8c408 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"