Pref: start automatically on login
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"airplayer": "^2.0.0",
|
"airplayer": "^2.0.0",
|
||||||
"application-config": "^1.0.0",
|
"application-config": "^1.0.0",
|
||||||
|
"auto-launch": "^4.0.0",
|
||||||
"bitfield": "^1.0.2",
|
"bitfield": "^1.0.2",
|
||||||
"chromecasts": "^1.8.0",
|
"chromecasts": "^1.8.0",
|
||||||
"create-torrent": "^3.24.5",
|
"create-torrent": "^3.24.5",
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ const windows = require('./windows')
|
|||||||
|
|
||||||
let shouldQuit = false
|
let shouldQuit = false
|
||||||
let argv = sliceArgv(process.argv)
|
let argv = sliceArgv(process.argv)
|
||||||
|
const hidden = argv.includes('--hidden')
|
||||||
|
|
||||||
if (config.IS_PRODUCTION) {
|
if (config.IS_PRODUCTION) {
|
||||||
// When Electron is running in production mode (packaged app), then run React
|
// When Electron is running in production mode (packaged app), then run React
|
||||||
@@ -67,7 +68,7 @@ function init () {
|
|||||||
app.on('ready', function () {
|
app.on('ready', function () {
|
||||||
isReady = true
|
isReady = true
|
||||||
|
|
||||||
windows.main.init()
|
windows.main.init({hidden: hidden})
|
||||||
windows.webtorrent.init()
|
windows.webtorrent.init()
|
||||||
menu.init()
|
menu.init()
|
||||||
|
|
||||||
@@ -155,6 +156,8 @@ function processArgv (argv) {
|
|||||||
dialog.openTorrentFile()
|
dialog.openTorrentFile()
|
||||||
} else if (arg === '-u') {
|
} else if (arg === '-u') {
|
||||||
dialog.openTorrentAddress()
|
dialog.openTorrentAddress()
|
||||||
|
} else if (arg === '--hidden') {
|
||||||
|
// Igonre hidden argument, already being handled
|
||||||
} else if (arg.startsWith('-psn')) {
|
} else if (arg.startsWith('-psn')) {
|
||||||
// Ignore Mac launchd "process serial number" argument
|
// Ignore Mac launchd "process serial number" argument
|
||||||
// Issue: https://github.com/feross/webtorrent-desktop/issues/214
|
// Issue: https://github.com/feross/webtorrent-desktop/issues/214
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const shortcuts = require('./shortcuts')
|
|||||||
const externalPlayer = require('./external-player')
|
const externalPlayer = require('./external-player')
|
||||||
const windows = require('./windows')
|
const windows = require('./windows')
|
||||||
const thumbar = require('./thumbar')
|
const thumbar = require('./thumbar')
|
||||||
|
const startup = require('./startup')
|
||||||
|
|
||||||
// Messages from the main process, to be sent once the WebTorrent process starts
|
// Messages from the main process, to be sent once the WebTorrent process starts
|
||||||
const messageQueueMainToWebTorrent = []
|
const messageQueueMainToWebTorrent = []
|
||||||
@@ -102,6 +103,14 @@ function init () {
|
|||||||
else handlers.uninstall()
|
else handlers.uninstall()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Startup
|
||||||
|
*/
|
||||||
|
ipc.on('setStartup', (e, flag) => {
|
||||||
|
if (flag) startup.install()
|
||||||
|
else startup.uninstall()
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Windows: Main
|
* Windows: Main
|
||||||
*/
|
*/
|
||||||
|
|||||||
27
src/main/startup.js
Normal file
27
src/main/startup.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
module.exports = {
|
||||||
|
install,
|
||||||
|
uninstall
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = require('../config')
|
||||||
|
const AutoLaunch = require('auto-launch')
|
||||||
|
|
||||||
|
const appLauncher = new AutoLaunch({
|
||||||
|
name: config.APP_NAME,
|
||||||
|
isHidden: true
|
||||||
|
})
|
||||||
|
|
||||||
|
function install () {
|
||||||
|
return appLauncher.isEnabled()
|
||||||
|
.then(enabled => {
|
||||||
|
if (enabled) return
|
||||||
|
return appLauncher.enable()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function uninstall () {
|
||||||
|
return appLauncher.isEnabled()
|
||||||
|
.then(enabled => {
|
||||||
|
if (enabled) return appLauncher.disable()
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -26,7 +26,7 @@ const tray = require('../tray')
|
|||||||
const HEADER_HEIGHT = 38
|
const HEADER_HEIGHT = 38
|
||||||
const TORRENT_HEIGHT = 100
|
const TORRENT_HEIGHT = 100
|
||||||
|
|
||||||
function init () {
|
function init (options) {
|
||||||
if (main.win) {
|
if (main.win) {
|
||||||
return main.win.show()
|
return main.win.show()
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,8 @@ function init () {
|
|||||||
titleBarStyle: 'hidden-inset', // Hide title bar (Mac)
|
titleBarStyle: 'hidden-inset', // Hide title bar (Mac)
|
||||||
useContentSize: true, // Specify web page size without OS chrome
|
useContentSize: true, // Specify web page size without OS chrome
|
||||||
width: 500,
|
width: 500,
|
||||||
height: HEADER_HEIGHT + (TORRENT_HEIGHT * 6) // header height + 5 torrents
|
height: HEADER_HEIGHT + (TORRENT_HEIGHT * 6), // header height + 5 torrents
|
||||||
|
show: !options.hidden
|
||||||
})
|
})
|
||||||
|
|
||||||
win.loadURL(config.WINDOW_MAIN)
|
win.loadURL(config.WINDOW_MAIN)
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ module.exports = class PrefsController {
|
|||||||
setup: function (cb) {
|
setup: function (cb) {
|
||||||
// initialize preferences
|
// initialize preferences
|
||||||
state.window.title = 'Preferences'
|
state.window.title = 'Preferences'
|
||||||
state.unsaved = Object.assign(state.unsaved || {}, {prefs: state.saved.prefs || {}})
|
state.unsaved = Object.assign(state.unsaved || {}, {
|
||||||
|
prefs: Object.assign({}, state.saved.prefs)
|
||||||
|
})
|
||||||
ipcRenderer.send('setAllowNav', false)
|
ipcRenderer.send('setAllowNav', false)
|
||||||
cb()
|
cb()
|
||||||
},
|
},
|
||||||
@@ -50,6 +52,9 @@ module.exports = class PrefsController {
|
|||||||
if (state.unsaved.prefs.isFileHandler !== state.saved.prefs.isFileHandler) {
|
if (state.unsaved.prefs.isFileHandler !== state.saved.prefs.isFileHandler) {
|
||||||
ipcRenderer.send('setDefaultFileHandler', state.unsaved.prefs.isFileHandler)
|
ipcRenderer.send('setDefaultFileHandler', state.unsaved.prefs.isFileHandler)
|
||||||
}
|
}
|
||||||
|
if (state.unsaved.prefs.startup !== state.saved.prefs.startup) {
|
||||||
|
ipcRenderer.send('setStartup', state.unsaved.prefs.startup)
|
||||||
|
}
|
||||||
state.saved.prefs = Object.assign(state.saved.prefs || {}, state.unsaved.prefs)
|
state.saved.prefs = Object.assign(state.saved.prefs || {}, state.unsaved.prefs)
|
||||||
State.save(state)
|
State.save(state)
|
||||||
dispatch('checkDownloadPath')
|
dispatch('checkDownloadPath')
|
||||||
|
|||||||
@@ -108,7 +108,8 @@ function setupSavedState (cb) {
|
|||||||
downloadPath: config.DEFAULT_DOWNLOAD_PATH,
|
downloadPath: config.DEFAULT_DOWNLOAD_PATH,
|
||||||
isFileHandler: false,
|
isFileHandler: false,
|
||||||
openExternalPlayer: false,
|
openExternalPlayer: false,
|
||||||
externalPlayerPath: null
|
externalPlayerPath: null,
|
||||||
|
startup: false
|
||||||
},
|
},
|
||||||
torrents: config.DEFAULT_TORRENTS.map(createTorrentObject),
|
torrents: config.DEFAULT_TORRENTS.map(createTorrentObject),
|
||||||
version: config.APP_VERSION /* make sure we can upgrade gracefully later */
|
version: config.APP_VERSION /* make sure we can upgrade gracefully later */
|
||||||
|
|||||||
@@ -123,7 +123,9 @@ function onState (err, _state) {
|
|||||||
document.addEventListener('webkitvisibilitychange', onVisibilityChange)
|
document.addEventListener('webkitvisibilitychange', onVisibilityChange)
|
||||||
|
|
||||||
// Done! Ideally we want to get here < 500ms after the user clicks the app
|
// Done! Ideally we want to get here < 500ms after the user clicks the app
|
||||||
sound.play('STARTUP')
|
if (electron.remote.getCurrentWindow().isVisible()) {
|
||||||
|
sound.play('STARTUP')
|
||||||
|
}
|
||||||
console.timeEnd('init')
|
console.timeEnd('init')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ const Heading = require('../components/heading')
|
|||||||
const PathSelector = require('../components/path-selector')
|
const PathSelector = require('../components/path-selector')
|
||||||
|
|
||||||
const {dispatch} = require('../lib/dispatcher')
|
const {dispatch} = require('../lib/dispatcher')
|
||||||
|
const config = require('../../config')
|
||||||
|
|
||||||
class PreferencesPage extends React.Component {
|
class PreferencesPage extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
@@ -21,6 +22,9 @@ class PreferencesPage extends React.Component {
|
|||||||
|
|
||||||
this.handleExternalPlayerPathChange =
|
this.handleExternalPlayerPathChange =
|
||||||
this.handleExternalPlayerPathChange.bind(this)
|
this.handleExternalPlayerPathChange.bind(this)
|
||||||
|
|
||||||
|
this.handleStartupChange =
|
||||||
|
this.handleStartupChange.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadPathSelector () {
|
downloadPathSelector () {
|
||||||
@@ -107,6 +111,29 @@ class PreferencesPage extends React.Component {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleStartupChange (e, isChecked) {
|
||||||
|
dispatch('updatePreferences', 'startup', isChecked)
|
||||||
|
}
|
||||||
|
|
||||||
|
setStartupSection () {
|
||||||
|
if (config.IS_PORTABLE) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PreferencesSection title='Startup'>
|
||||||
|
<Preference>
|
||||||
|
<Checkbox
|
||||||
|
className='control'
|
||||||
|
checked={this.props.state.unsaved.prefs.startup}
|
||||||
|
label={'Open WebTorrent on startup.'}
|
||||||
|
onCheck={this.handleStartupChange}
|
||||||
|
/>
|
||||||
|
</Preference>
|
||||||
|
</PreferencesSection>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
handleSetDefaultApp () {
|
handleSetDefaultApp () {
|
||||||
dispatch('updatePreferences', 'isFileHandler', true)
|
dispatch('updatePreferences', 'isFileHandler', true)
|
||||||
}
|
}
|
||||||
@@ -129,6 +156,7 @@ class PreferencesPage extends React.Component {
|
|||||||
<PreferencesSection title='Default torrent app'>
|
<PreferencesSection title='Default torrent app'>
|
||||||
{this.setDefaultAppButton()}
|
{this.setDefaultAppButton()}
|
||||||
</PreferencesSection>
|
</PreferencesSection>
|
||||||
|
{this.setStartupSection()}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user