diff --git a/src/main/index.js b/src/main/index.js index 8480887..23afb32 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -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)) /** @@ -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() diff --git a/src/renderer/components/Calendar/GoogleApi/api.js b/src/renderer/components/Calendar/GoogleApi/api.js index 983cd0e..7130224 100644 --- a/src/renderer/components/Calendar/GoogleApi/api.js +++ b/src/renderer/components/Calendar/GoogleApi/api.js @@ -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 diff --git a/src/renderer/components/Calendar/GoogleApi/event.vue b/src/renderer/components/Calendar/GoogleApi/event.vue index e1c9fc1..cb9c942 100644 --- a/src/renderer/components/Calendar/GoogleApi/event.vue +++ b/src/renderer/components/Calendar/GoogleApi/event.vue @@ -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) diff --git a/src/renderer/components/Settings/SettingCalendar.vue b/src/renderer/components/Settings/SettingCalendar.vue index 0d76e66..c3713f9 100644 --- a/src/renderer/components/Settings/SettingCalendar.vue +++ b/src/renderer/components/Settings/SettingCalendar.vue @@ -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 @@ -81,7 +81,7 @@ 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() @@ -89,8 +89,8 @@ export default { }, 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() }) diff --git a/src/renderer/components/Settings/SettingProgram.vue b/src/renderer/components/Settings/SettingProgram.vue index aca6288..bf29d4f 100644 --- a/src/renderer/components/Settings/SettingProgram.vue +++ b/src/renderer/components/Settings/SettingProgram.vue @@ -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) diff --git a/src/renderer/components/Setup/auth.vue b/src/renderer/components/Setup/auth.vue index 028eb48..c4e8862 100644 --- a/src/renderer/components/Setup/auth.vue +++ b/src/renderer/components/Setup/auth.vue @@ -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') }) diff --git a/src/renderer/main.js b/src/renderer/main.js index 3699a80..efeda89 100644 --- a/src/renderer/main.js +++ b/src/renderer/main.js @@ -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: {