Setup basic logic for default torrent client

This commit is contained in:
Kylart 2019-04-09 15:40:42 +02:00
parent 2daa626ced
commit eb4cb552aa
8 changed files with 56 additions and 17 deletions

17
src/background/events.js Normal file
View File

@ -0,0 +1,17 @@
import { BrowserWindow } from 'electron'
import { sendToWindows } from './server/externals'
import { eventsList } from '../vendor'
import { Logger } from './server/utils'
const logger = new Logger('External Open')
export default function (e, args) {
e && e.preventDefault()
logger.info('Opening', args)
sendToWindows(eventsList.externalOpen.success, Array.isArray(args) ? args : [args])
setTimeout(BrowserWindow.getAllWindows()[0].focus, 100)
}

View File

@ -12,6 +12,7 @@ import './startUp'
import './server'
import { dir } from './server/utils'
import { localFiles } from './server/externals'
import external from './events'
import menuTemplate from './menu'
const isDevelopment = process.env.NODE_ENV !== 'production'
@ -172,6 +173,11 @@ app.on('quit', () => {
})
})
if (process.argv.length) external(null, process.argv)
app.on('open-file', external)
app.on('open-url', external)
app.on('activate', () => {
win === null
? createWindow()

View File

@ -4,3 +4,4 @@ export { default as mal } from './mal'
export { default as localFiles } from './localFiles'
export { default as parseSubtitles } from './subtitles'
export { getCreds, setupCreds } from './vault'
export { default as sendToWindows } from './sendToWindows'

View File

@ -0,0 +1,8 @@
import { BrowserWindow } from 'electron'
export default function (eventName, data) {
BrowserWindow.getAllWindows()
.forEach((win) => {
win.webContents.send(eventName, data)
})
}

View File

@ -25,11 +25,14 @@ export default {
data: () => ({
isDefault: false,
defaultLoading: false
defaultLoading: false,
protocols: ['magnet', 'stream-magnet']
}),
async mounted () {
this.isDefault = (await this.$axios.get('protocols/isDefault')).data
mounted () {
const { app } = this.$electron.remote
this.isDefault = this.protocols.some((protocol) => app.isDefaultProtocolClient(protocol))
},
computed: {
@ -54,13 +57,16 @@ export default {
if (path) this.path = path
},
async setDefault () {
setDefault () {
this.$log('Registering as default torrent app...')
this.defaultLoading = true
const { app } = this.$electron.remote
const { status } = await this.$axios.post('protocols/register')
const isOk = this.protocols
.map((protocol) => app.setAsDefaultProtocolClient(protocol))
.every(Boolean)
if (status === 200) {
if (isOk) {
this.$log('Success!')
this.isDefault = true
} else {

View File

@ -50,13 +50,15 @@ export default {
torrents: [{ torrent: '', show: false }]
}),
mounted () {
const { torrent } = this.$route.query
created () {
this.$ipc.on(this.$eventsList.externalOpen.success, (e, args) => {
const toAdd = args.filter((e) => ['magnet', '.torrent'].includes(e))
if (torrent) {
this.addTorrentsFromPath([torrent])
this.show = true
}
if (toAdd.length) {
this.addTorrentsFromPath(toAdd)
this.show = true
}
})
},
computed: {

View File

@ -1,5 +1,3 @@
import { debounce } from 'lodash'
export default {
data: () => ({
hover: {
@ -21,7 +19,7 @@ export default {
},
methods: {
onMouseOver: debounce(function (e) {
onMouseOver (e) {
const { value, isInsideTrack } = this.parseMouseMove(e)
if (isInsideTrack) {
@ -31,7 +29,7 @@ export default {
} else {
this.hover.show = false
}
}, 50),
},
onMouseEnter () {
this.hover.show = true
},

View File

@ -19,7 +19,8 @@ const getOnly = [
// Internal
'env',
'isOnline'
'isOnline',
'externalOpen'
]
const updatable = [