Skip to content

Commit

Permalink
[ADD] 파일 저장 경로를 localappdata로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
tbvjaos510 committed Oct 30, 2018
1 parent 8b2f63d commit cc6e075
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 21 deletions.
26 changes: 14 additions & 12 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import electron, { Menu } from 'electron'
import fs from 'fs'
import path from 'path'
const { app, BrowserWindow, Tray, Notification, ipcMain } = electron

// Set Path to Exe
process.chdir(path.dirname(process.execPath))
/**
Expand Down Expand Up @@ -49,18 +48,21 @@ function createWindow () {
})
}
function setupWindow () {
fs.stat('calendar.json', (err, stat) => {
fs.stat(process.env.LOCALAPPDATA + '/DesktopCalendar/calendar.json', (err, stat) => {
if (err) {
startWindow = new BrowserWindow({
title: 'Desktop Calendar 시작'
})
// startWindow.setMenuBarVisibility(false)
startWindow.loadURL(setupURL)
// startWindow.webContents.openDevTools({
// mode: 'undocked'
// })
startWindow.on('close', () => {
startWindow = null
fs.mkdir(process.env.LOCALAPPDATA + '/DesktopCalendar', (errs, res) => {
if (errs) console.log('fileExists')
startWindow = new BrowserWindow({
title: 'Desktop Calendar 시작'
})
// startWindow.setMenuBarVisibility(false)
startWindow.loadURL(setupURL)
// startWindow.webContents.openDevTools({
// mode: 'undocked'
// })
startWindow.on('close', () => {
startWindow = null
})
})
} else {
createWindow()
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/Calendar/GoogleApi/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fs from 'fs'
import { remote } from 'electron'
// import { OAuth2Client } from 'google-auth-library'

const TOKEN_PATH = './token.json'
const TOKEN_PATH = process.env.LOCALAPPDATA + '/DesktopCalendar/token.json'
const SCOPES = ['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.events']
var APIKEY = null
let Popup
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/Calendar/GoogleApi/event.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default {
this.$http.defaults.headers.common['Authorization'] = 'Bearer ' + key
api.colors((color) => {
this.gcolor = color.data
fs.readFile('calendar.json', (err, res) => {
fs.readFile(this.appdata + '/calendar.json', (err, res) => {
if (err) return console.error(err)
const calendars = JSON.parse(res)
console.log(calendars)
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/components/Settings/SettingCalendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default {
'chrome-picker': Chrome
},
mounted () {
fs.readFile('calendar.json', (err, res) => {
fs.readFile(this.appdata + '/calendar.json', (err, res) => {
if (err) return console.error(err)
res = JSON.parse(res)
this.calendarList = res
Expand All @@ -81,16 +81,16 @@ export default {
})
},
saveCalendar () {
fs.writeFile('./calendar.json', JSON.stringify(this.calendarList), (err) => {
fs.writeFile(this.appdata + '/calendar.json', JSON.stringify(this.calendarList), (err) => {
if (err) console.error(err)
console.log('calendar save success')
this.parents.webContents.reload()
})
},
deleteToken () {
this.calendarList = []
if (fs.existsSync('token.json')) {
fs.unlink('token.json', (err) => {
if (fs.existsSync(this.appdata + '/token.json')) {
fs.unlink(this.appdata + '/token.json', (err) => {
if (err) return console.error(err)
this.auth()
})
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/Settings/SettingProgram.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export default {
}
},
restartApp () {
fs.unlink('calendar.json', (e) => {
fs.unlink(this.appdata + '/calendar.json', (e) => {
if (e) console.log(e)
fs.unlink('token.json', (e) => {
fs.unlink(this.appdata + '/token.json', (e) => {
if (e) console.log(e)
remote.app.relaunch()
remote.app.exit(0)
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/Setup/auth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default {
})
},
save () {
fs.writeFile('./calendar.json', JSON.stringify(this.calendarList), function (err) {
fs.writeFile(this.appdata + '/calendar.json', JSON.stringify(this.calendarList), function (err) {
if (err) console.error(err)
console.log('calendar save success')
})
Expand Down
1 change: 1 addition & 0 deletions src/renderer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Vue.config.productionTip = false
Vue.DevMode = Vue.prototype.DevMode = () => process.env.NODE_ENV === 'development'
Vue.setIgnore = Vue.prototype.setIgnore = enableMouse
Vue.disableIgnore = Vue.prototype.disableIgnore = disableMouse
Vue.appdata = Vue.prototype.appdata = process.env.LOCALAPPDATA + '/DesktopCalendar'
/* eslint-disable no-new */
new Vue({
components: {
Expand Down

0 comments on commit cc6e075

Please sign in to comment.