Merge pull request #213 from feross/magnet-focus
Show, unminimize, and focus window after opening magnet link (fix #210)
This commit is contained in:
@@ -18,15 +18,11 @@ var shouldQuit = app.makeSingleInstance(function (newArgv) {
|
|||||||
|
|
||||||
if (app.ipcReady) {
|
if (app.ipcReady) {
|
||||||
log('Second app instance attempted to open but was prevented')
|
log('Second app instance attempted to open but was prevented')
|
||||||
|
windows.focusMainWindow()
|
||||||
|
|
||||||
newArgv.forEach(function (torrentId) {
|
newArgv.forEach(function (torrentId) {
|
||||||
windows.main.send('dispatch', 'onOpen', torrentId)
|
windows.main.send('dispatch', 'onOpen', torrentId)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (windows.main.isMinimized()) {
|
|
||||||
windows.main.restore()
|
|
||||||
}
|
|
||||||
windows.main.focus()
|
|
||||||
} else {
|
} else {
|
||||||
argv.push(...newArgv)
|
argv.push(...newArgv)
|
||||||
}
|
}
|
||||||
@@ -89,6 +85,12 @@ function onOpen (e, torrentId) {
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (app.ipcReady) {
|
if (app.ipcReady) {
|
||||||
windows.main.send('dispatch', 'onOpen', torrentId)
|
windows.main.send('dispatch', 'onOpen', torrentId)
|
||||||
|
setTimeout(function () {
|
||||||
|
// Required for magnet links opened from Chrome otherwise the confirmation dialog
|
||||||
|
// that Chrome shows causes Chrome to steal back the focus.
|
||||||
|
// Electron issue: https://github.com/atom/electron/issues/4338
|
||||||
|
windows.focusMainWindow()
|
||||||
|
}, 100)
|
||||||
} else {
|
} else {
|
||||||
argv.push(torrentId)
|
argv.push(torrentId)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
var windows = module.exports = {
|
var windows = module.exports = {
|
||||||
main: null,
|
main: null,
|
||||||
createMainWindow: createMainWindow
|
createMainWindow: createMainWindow,
|
||||||
|
focusMainWindow: focusMainWindow
|
||||||
}
|
}
|
||||||
|
|
||||||
var electron = require('electron')
|
var electron = require('electron')
|
||||||
@@ -52,3 +53,10 @@ function createMainWindow () {
|
|||||||
windows.main = null
|
windows.main = null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function focusMainWindow () {
|
||||||
|
if (windows.main.isMinimized()) {
|
||||||
|
windows.main.restore()
|
||||||
|
}
|
||||||
|
windows.main.show() // shows and gives focus
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user