mirror of https://github.com/Kylart/KawAnime.git
Put electron in devDependencies.
This commit is contained in:
parent
9d6fe5b503
commit
02d454806c
|
@ -80,14 +80,14 @@ const local = require('./local.js')
|
|||
const wl = require('./watchList.js')
|
||||
const history = require('./history')
|
||||
|
||||
exports.route = (nuxt) => {
|
||||
exports.route = (nuxt, window) => {
|
||||
return (req, res) => {
|
||||
const url = new URL(req.url)
|
||||
|
||||
switch (url.pathname)
|
||||
{
|
||||
case '/openThis':
|
||||
openExternal(url, res)
|
||||
openExternal(url, res, window)
|
||||
break
|
||||
|
||||
case '/seasons.json':
|
||||
|
|
|
@ -5,10 +5,22 @@
|
|||
const {join} = require('path')
|
||||
|
||||
const shell = require('electron').shell
|
||||
const {dialog, BrowserWindow} = require('electron')
|
||||
const fs = require('fs')
|
||||
const qs = require('querystring')
|
||||
|
||||
exports.openExternal = (url, res) => {
|
||||
const sendEmptyRes = (res) => {
|
||||
res.writeHead(200, {})
|
||||
res.end()
|
||||
}
|
||||
|
||||
const sendRes = (res, data) => {
|
||||
res.writeHead(200, {"Content-Type": "application/json"})
|
||||
res.write(JSON.stringify(data))
|
||||
res.end()
|
||||
}
|
||||
|
||||
exports.openExternal = (url, res, window = null) => {
|
||||
const query = qs.parse(url.query.replace('?', ''))
|
||||
|
||||
const type = query.type
|
||||
|
@ -21,11 +33,26 @@ exports.openExternal = (url, res) => {
|
|||
break
|
||||
|
||||
case 'video':
|
||||
shell.openItem(join(query.dir, query.path))
|
||||
shell.openItem(join(query.dir, query.path));
|
||||
sendEmptyRes(res)
|
||||
break
|
||||
|
||||
case 'link':
|
||||
shell.openExternal(query.link)
|
||||
sendEmptyRes(res)
|
||||
break
|
||||
|
||||
case 'insideLink':
|
||||
const win = new BrowserWindow({
|
||||
parent: process.win,
|
||||
x: 50,
|
||||
y: 50,
|
||||
minimizable: false,
|
||||
maximizable: false,
|
||||
resizable: false
|
||||
})
|
||||
|
||||
win.loadURL(query.link)
|
||||
break
|
||||
|
||||
case 'delete':
|
||||
|
@ -34,12 +61,23 @@ exports.openExternal = (url, res) => {
|
|||
|
||||
console.log('[Open-External] Deleted file successfully.')
|
||||
})
|
||||
sendEmptyRes(res)
|
||||
break
|
||||
|
||||
case 'dialog':
|
||||
dialog.showOpenDialog({properties: ['openDirectory']}, (dirPath) => {
|
||||
if (dirPath !== undefined)
|
||||
{
|
||||
const result = {
|
||||
path: dirPath[0]
|
||||
}
|
||||
|
||||
sendRes(res, result)
|
||||
}
|
||||
})
|
||||
break
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
res.writeHead(200, {})
|
||||
res.end()
|
||||
}
|
13
main.js
13
main.js
|
@ -21,7 +21,7 @@ config.rootDir = __dirname // for electron-packager
|
|||
const nuxt = new Nuxt(config)
|
||||
|
||||
// Initiate routes.
|
||||
const route = initFile.route(nuxt)
|
||||
const route = initFile.route(nuxt, win)
|
||||
const server = http.createServer(route)
|
||||
|
||||
// Build only in dev mode
|
||||
|
@ -64,8 +64,8 @@ const menu = Menu.buildFromTemplate(template)
|
|||
|
||||
const newWin = () => {
|
||||
win = new bw({
|
||||
width: config.electron.width || 800,
|
||||
height: config.electron.height || 600,
|
||||
width: config.electron.width,
|
||||
height: config.electron.height,
|
||||
titleBarStyle: 'hidden',
|
||||
show: false
|
||||
})
|
||||
|
@ -91,6 +91,11 @@ const newWin = () => {
|
|||
}
|
||||
|
||||
app.on('ready', () => {
|
||||
app.setAboutPanelOptions({
|
||||
applicationName: 'KawAnime',
|
||||
applicationVersion: '0.3.0',
|
||||
copyright: 'Kylart 2016-2017'
|
||||
})
|
||||
|
||||
Menu.setApplicationMenu(menu)
|
||||
|
||||
|
@ -101,6 +106,8 @@ app.on('ready', () => {
|
|||
}
|
||||
|
||||
newWin()
|
||||
|
||||
process.win = win
|
||||
})
|
||||
|
||||
// Quit when all windows are closed.
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
"dependencies": {
|
||||
"axios": "^0.16.0",
|
||||
"cheerio": "^0.22.0",
|
||||
"cross-env": "^3.1.4",
|
||||
"electron": "^1.6.2",
|
||||
"mal-scraper": "^1.3.4",
|
||||
"nuxt": "latest",
|
||||
"nyaapi": "^1.0.1",
|
||||
|
@ -28,11 +26,12 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"colors": "^1.1.2",
|
||||
"cross-env": "^3.1.4",
|
||||
"devtron": "^1.4.0",
|
||||
"electron": "^1.6.2",
|
||||
"electron-installer-debian": "^0.5.1",
|
||||
"electron-installer-dmg": "^0.2.1",
|
||||
"electron-packager": "^8.6.0",
|
||||
"electron-winstaller": "^2.5.2",
|
||||
"stylus": "^0.54.5",
|
||||
"stylus-loader": "^3.0.1",
|
||||
"tar.gz": "^1.0.5",
|
||||
|
|
|
@ -6,7 +6,6 @@ import axios from 'axios'
|
|||
import {readFileSync, writeFileSync} from 'fs'
|
||||
import {join} from 'path'
|
||||
import {userInfo} from 'os'
|
||||
import {remote} from 'electron'
|
||||
|
||||
// Getting config.
|
||||
const configPath = join(userInfo().homedir, '.KawAnime', 'config.json')
|
||||
|
@ -231,44 +230,27 @@ const store = new Vuex.Store({
|
|||
})
|
||||
},
|
||||
async changePath({commit, dispatch}) {
|
||||
remote.dialog.showOpenDialog({properties: ['openDirectory']}, (dirPath) => {
|
||||
if (dirPath !== undefined)
|
||||
{
|
||||
commit('emptyLocals')
|
||||
commit('setCurrentDir', dirPath[0])
|
||||
dispatch('refreshLocal')
|
||||
}
|
||||
})
|
||||
const {data} = await axios.get('openThis?type=dialog')
|
||||
|
||||
commit('emptyLocals')
|
||||
commit('setCurrentDir', data.path)
|
||||
dispatch('refreshLocal')
|
||||
},
|
||||
async changePathWithConfig({commit, dispatch}) {
|
||||
remote.dialog.showOpenDialog({properties: ['openDirectory']}, (dirPath) => {
|
||||
if (dirPath !== undefined)
|
||||
{
|
||||
commit('emptyLocals')
|
||||
commit('setCurrentDir', dirPath[0])
|
||||
commit('setConfigDir', dirPath[0])
|
||||
dispatch('refreshLocal')
|
||||
}
|
||||
})
|
||||
const {data} = await axios.get('openThis?type=dialog')
|
||||
|
||||
commit('emptyLocals')
|
||||
commit('setCurrentDir', data.path)
|
||||
commit('setConfigDir', data.path)
|
||||
dispatch('refreshLocal')
|
||||
},
|
||||
async openNewsLink({state}, link) {
|
||||
console.log('[News] Opening a link')
|
||||
console.log(`[${(new Date()).toLocaleTimeString()}]: Opening a link`)
|
||||
|
||||
if ((state.config.inside === 'true' ) === false)
|
||||
await axios.get(`openThis?type=link&link=${link}`)
|
||||
else
|
||||
{
|
||||
let win = new remote.BrowserWindow({
|
||||
parent: remote.getCurrentWindow(),
|
||||
x: 50,
|
||||
y: 50,
|
||||
minimizable: false,
|
||||
maximizable: false,
|
||||
resizable: false
|
||||
})
|
||||
|
||||
win.loadURL(link)
|
||||
}
|
||||
await axios.get(`openThis?type=insideLink&link=${link}`)
|
||||
},
|
||||
async download({state, commit}) {
|
||||
const name = state.downloaderForm.name.replace(' ', '_')
|
||||
|
|
Loading…
Reference in New Issue