From 75eeff516ff425491040c0d62dd302382fa2727d Mon Sep 17 00:00:00 2001 From: Kevin Bohinski Date: Sat, 4 Feb 2017 13:15:41 -0500 Subject: [PATCH] fixed localStorage --- app.js | 32 +++++++++++++++++++++----------- index.html | 4 ++-- localData.json | 1 - package.json | 7 ++++++- 4 files changed, 29 insertions(+), 15 deletions(-) delete mode 100644 localData.json diff --git a/app.js b/app.js index d12df72..381f441 100644 --- a/app.js +++ b/app.js @@ -4,8 +4,7 @@ const menubar = require('menubar') const electron = require('electron') const AutoLaunch = require('auto-launch') const ipcMain = require('electron').ipcMain -const fs = require('fs') -let localData = require('./localData.json') +const storage = require('electron-json-storage') const Menu = electron.Menu const BrowserWindow = electron.BrowserWindow @@ -73,29 +72,40 @@ const openAbout = () => { } mb.on('ready', () => { - console.log('server -- launching...') - console.log('server -- userData dir', mb.app.getPath('userData')) mb.tray.on('right-click', () => { mb.tray.popUpContextMenu(contextMenu) }) }) mb.on('after-create-window', () => { - mb.window.loadURL('file://' + __dirname + '/index.html#' + localData.schoolUrl) + storage.has('schoolUrl', (error, hasKey) => { + if (hasKey) { + storage.get('schoolUrl', (error, data) => { + mb.window.loadURL('file://' + __dirname + '/index.html#' + data) + }) + } else { + mb.window.loadURL('file://' + __dirname + '/index.html#') + } + }) // mb.window.openDevTools() }) mb.on('show', () => { - mb.window.loadURL('file://' + __dirname + '/index.html#' + localData.schoolUrl) - console.log('server -- requesting client refresh...') + storage.has('schoolUrl', (error, hasKey) => { + if (hasKey) { + storage.get('schoolUrl', (error, data) => { + mb.window.loadURL('file://' + __dirname + '/index.html#' + data) + }) + } else { + mb.window.loadURL('file://' + __dirname + '/index.html#') + } + }) }) ipcMain.on('schoolUrl', (e, data) => { - console.log('server -- saving url...', data) - localData.schoolUrl = data - fs.writeFileSync('./localData.json', JSON.stringify(localData)) + storage.set('schoolUrl', data) }) ipcMain.on('log', (e, data) => { - console.log(data) + // console.log(data) }) diff --git a/index.html b/index.html index 67281b8..5afc835 100644 --- a/index.html +++ b/index.html @@ -35,7 +35,7 @@

First time setup

We need to know how your school talks to Canvas.

We also need your permission to talk to Canvas.

On the next page please check 'Stay signed in'!

-

After you see your classes start to load
please close and reopen this window.

+

After you see your grades start to load
please close and reopen this window.

Please enter your school's Canvas url:

TCNJ's is provided as an example...

@@ -99,7 +99,7 @@ baseUrl = 'https://' + school.trim() + '/' document.getElementById('loading').style.visibility = 'visible' ipc.send('schoolUrl', toLoad) - window.location.href = baseUrl + window.location.href = baseUrl + '/grades' }) if (window.location.href.split('#')[1] !== '') { diff --git a/localData.json b/localData.json deleted file mode 100644 index 1adfb39..0000000 --- a/localData.json +++ /dev/null @@ -1 +0,0 @@ -{"schoolUrl":""} \ No newline at end of file diff --git a/package.json b/package.json index 83e1ba2..9d794e5 100644 --- a/package.json +++ b/package.json @@ -5,13 +5,18 @@ "main": "app.js", "dependencies": { "auto-launch": "latest", + "electron-json-storage": "^3.0.1", "menubar": "latest" }, "devDependencies": { + "electron-installer-dmg": "^0.2.0", "electron-prebuilt": "latest" }, "scripts": { - "test": "" + "package-mac": "electron-packager . --overwrite --asar=true --platform=darwin --arch=x64 --prune=true --out=releases", + "package-win": "electron-packager . --overwrite --asar=true --platform=win32 --arch=ia32 --prune=true --out=releases --version-string.CompanyName='KB' --version-string.FileDescription='KB' --version-string.ProductName='Canvasbar'", + "package-lin": "electron-packager . --overwrite --asar=true --platform=linux --arch=x64 --prune=true --out=releases", + "create-installer-mac": "electron-installer-dmg ./releases/Canvasbar-darwin-x64/ Canvasbar.app canvasbar-app --out=releases --overwrite" }, "repository": "https://github.com/kbohinski/canvasbar", "author": "https://github.com/kbohinski",