Fixed crash on first start.

This commit is contained in:
Kylart 2017-03-31 15:16:12 +02:00
parent 9f655116fb
commit 4616899772
2 changed files with 48 additions and 45 deletions

72
main.js
View File

@ -20,29 +20,7 @@ const template = menuFile.template(() => {
})
const menu = Menu.buildFromTemplate(template)
// Checking if that config file already exists
fs.access(path.join(os.userInfo().homedir, '.KawAnime', 'config.json'), fs.constants.R_OK | fs.constants.W_OK, (err) => {
if (err) // This means the file does not exist
{
console.log('Creating initial config file.')
const initPath = path.join(os.userInfo().homedir, 'Downloads')
const initConf = {
config: {
fansub: 'HorribleSubs',
quality: '720p',
sound: 'Nyanpasu',
localPath: initPath,
inside: true,
}
}
const json = JSON.stringify(initConf)
fs.writeFileSync(path.join(os.userInfo().homedir, '.KawAnime', 'config.json'), json)
}
})
const animeLocalStoragePath = path.join(os.userInfo().homedir, '.KawAnime', 'anime.json')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
@ -104,6 +82,11 @@ app.on('ready', () => {
Menu.setApplicationMenu(menu)
const animeJSONCreated = self.createJSON()
// Checking if that config file already exists
self.createConfig()
// Dev tools
if (process.env.NODE_ENV === 'development')
{
@ -195,4 +178,45 @@ exports.openPreferences = () => {
// when you should delete the corresponding element.
preferencesWindow = null
})
}
}
exports.createJSON = () => {
fs.access(animeLocalStoragePath, fs.constants.R_OK | fs.constants.W_OK, (err) => {
if (err)
{
fs.appendFileSync(animeLocalStoragePath, '{}')
console.log('Local anime JSON file was created.')
return true
}
else
{
console.log('Local anime JSON file already exists.')
return false
}
})
}
exports.createConfig = () => {
fs.access(path.join(os.userInfo().homedir, '.KawAnime', 'config.json'), fs.constants.R_OK | fs.constants.W_OK, (err) => {
if (err) // This means the file does not exist
{
console.log('Creating initial config file.')
const initPath = path.join(os.userInfo().homedir, 'Downloads')
const initConf = {
config: {
fansub: 'HorribleSubs',
quality: '720p',
sound: 'Nyanpasu',
localPath: initPath,
inside: true,
}
}
const json = JSON.stringify(initConf)
fs.writeFileSync(path.join(os.userInfo().homedir, '.KawAnime', 'config.json'), json)
}
})
}

View File

@ -15,8 +15,6 @@ const fs = require('fs')
const os = require('os')
const path = require('path')
const animeLocalStoragePath = path.join(os.userInfo().homedir, '.KawAnime', 'anime.json')
exports.watcher = require(path.join(__dirname, 'watcher', 'watcher.js'))
exports.lastPage = 'releases'
@ -72,25 +70,6 @@ exports.shutAllPages = () => {
self.watchList.watchList.show = false
}
exports.createJSON = () => {
fs.access(animeLocalStoragePath, fs.constants.R_OK | fs.constants.W_OK, (err) => {
if (err)
{
fs.appendFileSync(animeLocalStoragePath, '{}')
console.log('Local anime JSON file was created.')
return true
}
else
{
console.log('Local anime JSON file already exists.')
return false
}
})
}
// Creates anime.json at rendering.
const animeJSONCreated = self.createJSON()
/* -------------------- END FUNCTIONS ----------------- */
/* ------------------- VUE.JS OBJECTS ----------------- */