Skip to content

Commit

Permalink
linting + documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
komplexb committed Dec 15, 2016
1 parent 8907f1d commit 853792a
Show file tree
Hide file tree
Showing 16 changed files with 256 additions and 199 deletions.
3 changes: 0 additions & 3 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
app/node_modules/**
app/src/static/**
app/src/main/**
app/src/components/**
app/dist/**
app/electron.js
test/unit/coverage/**
test/unit/*.js
test/e2e/*.js
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module.exports = {
'no-unused-vars': 1,
'spaced-comment': 1,
'no-mixed-spaces-and-tabs': 1,
'indent': 1
'indent': 1,
'brace-style': 1,
'no-trailing-spaces': 1
}
}
30 changes: 30 additions & 0 deletions app/.app.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module'
},
env: {
browser: true,
node: true
},
extends: 'standard',
plugins: [
'html'
],
'rules': {
// allow paren-less arrow functions
'arrow-parens': 0,
// allow async-await
'generator-star-spacing': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
'camelcase': 0,
'no-unused-vars': 1,
'spaced-comment': 1,
'no-mixed-spaces-and-tabs': 1,
'indent': 1,
'brace-style': 0,
'curly': 0
}
}
96 changes: 44 additions & 52 deletions app/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const path = require('path')
const schedule = require('node-schedule')
const is = require('./src/main/is')
const {URLS, WINDOW, DEFAULT_SETTINGS} = require('./app.config')
const {ONENOTE} = require('./onenote.config')

const storeSettings = require('node-persist')
storeSettings.initSync({
Expand All @@ -16,7 +15,7 @@ storeSettings.initSync({

let mainWindow
let config = {}
let scheduleInstance;
let scheduleInstance

if (is.dev()) {
config = require('../config')
Expand All @@ -27,10 +26,8 @@ if (is.dev()) {
}

function createWindow () {
/**
* Initial window options
*/
const demo = {
// window config for pre build demos
const demoWindow = {
height: WINDOW.height,
width: WINDOW.width,
resizable: true,
Expand All @@ -44,6 +41,7 @@ function createWindow () {
maximizable: false
}

// default window config
const defaultWindow = {
height: WINDOW.height,
width: WINDOW.width,
Expand All @@ -58,8 +56,7 @@ function createWindow () {
maximizable: false
}

mainWindow = new BrowserWindow(defaultWindow)

mainWindow = new BrowserWindow(defaultWindow) // put demoWindow here
mainWindow.loadURL(config.url)

if (is.dev()) {
Expand All @@ -73,16 +70,15 @@ function createWindow () {
installExtension.default(installExtension.VUEJS_DEVTOOLS)
.then((name) => mainWindow.webContents.openDevTools())
.catch((err) => console.log('An error occurred: ', err))
}
else {
} else {
// allow dev tools in prod
mainWindow.webContents.on('devtools-opened', (event, deviceList, callback) => {
mainWindow.setSize(1200, 600)
mainWindow.setResizable(true)
})

mainWindow.webContents.on('devtools-closed', (event, deviceList, callback) => {
mainWindow.setSize(WINDOW.width,WINDOW.height)
mainWindow.setSize(WINDOW.width, WINDOW.height)
mainWindow.setResizable(false)
})

Expand All @@ -98,11 +94,10 @@ function createWindow () {
}

app.on('ready', () => {
settings()
scheduleInstance = scheduleRandomNote();
loadSettings()
createWindow()
setGlobalShortcuts();
// console.log('path', app.getPath('userData'))
scheduleInstance = scheduleRandomNote()
setGlobalShortcuts()
})

app.on('window-all-closed', () => {
Expand All @@ -125,35 +120,35 @@ ipc.on('set-global-shortcuts', () => {
setGlobalShortcuts()
})

function setGlobalShortcuts() {
globalShortcut.unregisterAll();
function setGlobalShortcuts () {
globalShortcut.unregisterAll()

globalShortcut.register(storeSettings.getItemSync('shortcutKey'), () => {
mainWindow.webContents.send('trigger-random-note');
mainWindow.webContents.send('trigger-random-note')
})
}

function initMenu () {
var template = [{
label: 'Edit',
submenu: [
{
label: 'Copy',
accelerator: 'Command+C',
selector: 'copy:'
},
{
label: 'Paste',
accelerator: 'Command+V',
selector: 'paste:'
},
{
label: 'Select All',
accelerator: 'Command+A',
selector: 'selectAll:'
}
]
},
var template = [{
label: 'Edit',
submenu: [
{
label: 'Copy',
accelerator: 'Command+C',
selector: 'copy:'
},
{
label: 'Paste',
accelerator: 'Command+V',
selector: 'paste:'
},
{
label: 'Select All',
accelerator: 'Command+A',
selector: 'selectAll:'
}
]
},
{
label: 'Developer',
submenu: [
Expand All @@ -169,18 +164,16 @@ function initMenu () {
]
}]

var menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
}
var menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
}

/**
* settings - Description
*
* @returns {type} Description
* loadSettings - persist default settings
*/
function settings() {
function loadSettings () {
for (const [key, value] of DEFAULT_SETTINGS) {
if(storeSettings.getItemSync(key) === undefined || null || '') {
if (storeSettings.getItemSync(key) === undefined || null || '') {
storeSettings.setItemSync(key, value)
}
}
Expand All @@ -189,22 +182,21 @@ function settings() {
/**
* If we did not explicitly set minute to 0,
* the message would have instead been logged at 5:00pm, 5:01pm, ..., 5:59pm.
*
* @returns {type} Description
*/
function scheduleRandomNote () {
let rule;
let rule

if(storeSettings.getItemSync('schedule') === '*/5 * * * *') {
if (storeSettings.getItemSync('schedule') === '*/5 * * * *') {
rule = '*/5 * * * *' // every 5 minutes
}
else {
} else {
rule = new schedule.RecurrenceRule()
rule.dayOfWeek = [0, new schedule.Range(0, 7)]
rule.hour = storeSettings.getItemSync('schedule')
rule.minute = 0
}

// return job instance so we can cancel it when schedule is updated
// via settings
return schedule.scheduleJob(rule, function () {
mainWindow.webContents.send('trigger-random-note')
})
Expand Down
4 changes: 3 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"vue-electron": "^1.0.0",
"vue-resource": "^1.0.3"
},
"devDependencies": {},
"devDependencies": {
"standard": "^8.6.0"
},
"author": "Byron Buckley <byronbuckley@live.com>"
}
12 changes: 4 additions & 8 deletions app/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ import Login from './components/Login.vue'
import Note from './components/Note.vue'
import Settings from './components/Settings.vue'
import is from './main/is'
const { shell } = require('electron')
const auth = require('./main/auth')
const {setNoteSection} = require('./main/onenote')
const {shell} = require('electron')
const {app} = require('electron').remote
const path = require('path')
const auth = require('./main/auth')
const {setNoteSection} = require('./main/onenote')
const {URLS, WINDOW} = require('../app.config')
const storeSettings = require('node-persist')
storeSettings.initSync({dir: path.join(app.getPath('userData'), URLS.SETTINGS)})
Expand All @@ -59,7 +60,6 @@ window.onload = function () {
console.log('loaded')
}
// export default $rootVm
export default {
data: function () {
return {
Expand Down Expand Up @@ -90,10 +90,6 @@ export default {
}
},
watch: {
},
components: {
Login,
Note,
Expand Down
28 changes: 14 additions & 14 deletions app/src/components/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
</template>

<script>
const {app, BrowserWindow, ipcMain, ipcRenderer} = require('electron').remote
/* global $ */
const {app, BrowserWindow} = require('electron').remote
const path = require('path')
const {URLS} = require('../../app.config')
const {ONENOTE} = require('../../onenote.config')
const {requestOneNoteToken, refreshOneNoteToken, hasAccessToken} = require('../main/auth')
const {setNoteSection, getRandomNote} = require('../main/onenote')
const {requestOneNoteToken, hasAccessToken} = require('../main/auth')
const {setNoteSection} = require('../main/onenote')
const storeSettings = require('node-persist')
storeSettings.initSync({dir: path.join(app.getPath('userData'), URLS.SETTINGS)})
Expand All @@ -47,7 +48,7 @@
},
handleLogin: function () {
if(hasAccessToken()) {
if (hasAccessToken()) {
this.onAuth()
this.$emit('toggleLogon')
}
Expand Down Expand Up @@ -76,13 +77,13 @@
})
let handleCallback = (url) => {
var raw_code = /code=([^&]*)/.exec(url) || null
var code = (raw_code && raw_code.length > 1) ? raw_code[1] : null
var error = /\?error=(.+)$/.exec(url)
let raw_code = /code=([^&]*)/.exec(url) || null
let code = (raw_code && raw_code.length > 1) ? raw_code[1] : null
let error = /\?error=(.+)$/.exec(url)
// Close the browser if code found or error
if (code || error) {
// Close the browser if code found or error
this.$emit('toggleLogon')
this.$emit('toggleLogon') // based on login state
authWindow.destroy()
}
Expand All @@ -95,7 +96,7 @@
client_secret: ONENOTE.client_secret,
redirect_uri: ONENOTE.redirect_uri
})
.then(() => {
.then(() => {
this.onAuth()
this.$emit('toggleLogon') // hide login, show main window
})
Expand All @@ -106,16 +107,15 @@
else if (error) {
console.log('authOneNote', decodeURIComponent(error.toString()))
/** TODO: update error state and display on login **/
// ('Oops! Something went wrong and we couldn\'t ' +'log you in using OneNote. Please try again.')
}
}
// If "Done" button is pressed, hide "Loading"
// If "Done" button is pressed
authWindow.on('close', () => {
authWindow.destroy()
})
// handle the response from OneNote
// handle the response from OneNote
authWindow.webContents.on('will-navigate', (event, url) => {
handleCallback(url)
})
Expand All @@ -124,7 +124,7 @@
handleCallback(newUrl)
})
// reset the authWindow on close
// reset the authWindow on close
authWindow.on('close', () => {
authWindow = null
}, false)
Expand Down
Loading

0 comments on commit 853792a

Please sign in to comment.