From 7eacf18fddf6da6acc1599f9a5f5a9bf935124fb Mon Sep 17 00:00:00 2001 From: Kylart Date: Thu, 27 Apr 2017 23:38:07 +0200 Subject: [PATCH] KawAnime now can be opened in the browser! --- assets/scripts/init/main.js | 14 ++++++++++++-- nuxt.config.js | 5 ----- package.json | 2 +- store/index.js | 15 ++++++--------- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/assets/scripts/init/main.js b/assets/scripts/init/main.js index b1b7a53..7fdd89b 100644 --- a/assets/scripts/init/main.js +++ b/assets/scripts/init/main.js @@ -87,8 +87,8 @@ exports.route = (nuxt) => { switch (url.pathname) { case '/getConf': - const configPath = join(dir, 'config.json') - const configFile = require(configPath).config + const configPath = join(dir, 'config.json'); + const configFile = JSON.parse(fs.readFileSync(configPath)); res.writeHead(200, {"Content-Type": "application/json"}); res.write(JSON.stringify(configFile)); @@ -135,6 +135,16 @@ exports.route = (nuxt) => { history.getHistory(res) break + case '/saveConfig': + req.on('data', (chunk) => { + const data = JSON.parse(chunk) + fs.writeFileSync(join(dir, 'config.json'), JSON.stringify(data)) + console.log('[Open-External]: Successfully saved config!') + }) + res.writeHead(200, {}); + res.end(); + break + default: nuxt.render(req, res) } diff --git a/nuxt.config.js b/nuxt.config.js index 05c0ecc..070da1b 100755 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -9,11 +9,6 @@ module.exports = { height: 800 }, build: { - extend (config, {isClient}) { - // Extend only webpack config for client-bundle - if (isClient) - config.target = 'electron-renderer' - }, vendor: ['vuetify', 'axios'] }, plugins: [ diff --git a/package.json b/package.json index 18e606a..9b9c8c2 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "KawAnime", - "version": "0.3.0", + "version": "0.4.0", "description": "A Software for Otaku Community.", "main": "main.js", "repository": "https://github.com/Kylart/KawAnime.git", diff --git a/store/index.js b/store/index.js index b27db43..32606af 100644 --- a/store/index.js +++ b/store/index.js @@ -3,7 +3,6 @@ import Vue from 'vue' //noinspection NpmUsedModulesInstalled import Vuex from 'vuex' import axios from 'axios' -import {writeFileSync} from 'fs' Vue.use(Vuex) @@ -297,17 +296,15 @@ const store = new Vuex.Store({ }) } else - { console.log(`[${(new Date()).toLocaleTimeString()}]: Opening torrents directly on preferred torrent client.`) - } }, - async saveConfig({}, data) { - const toSave = JSON.stringify({ - config: data + saveConfig({}, data) { + axios.post('saveConfig', JSON.stringify(data)).then((res) => { + if (res.status === 200) + console.log(`[${(new Date()).toLocaleTimeString()}]: Successfully updated config!`) + }).catch((err) => { + console.log(`[${(new Date()).toLocaleTimeString()}]: An error occurred while saving config: ${err}`) }) - - writeFileSync(configPath, toSave) - console.log(`[${(new Date()).toLocaleTimeString()}]: New config saved!`) }, async appendHistory({}, data) { const {status} = await axios.get(`appendHistory?type=${data.type}&text=${data.text}`)