Skip to content

Commit

Permalink
fixed localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
kbohinski committed Feb 4, 2017
1 parent d7d892d commit 75eeff5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
32 changes: 21 additions & 11 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
})
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h2>First time setup</h2>
<p>We need to know how your school talks to Canvas.</p>
<p>We also need your permission to talk to Canvas.</p>
<p>On the next page please check 'Stay signed in'!</p>
<p>After you see your classes start to load<br> please close and reopen this window.</p>
<p>After you see your grades start to load<br> please close and reopen this window.</p>

<h3 style="margin-top: 3em;">Please enter your school's Canvas url:</h3>
<p><i>TCNJ's is provided as an example...</i></p>
Expand Down Expand Up @@ -99,7 +99,7 @@ <h4 style="visibility: hidden;" id="loading">Thanks, loading Canvas...</h4>
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] !== '') {
Expand Down
1 change: 0 additions & 1 deletion localData.json

This file was deleted.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 75eeff5

Please sign in to comment.