This repository has been archived by the owner on Aug 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.js
69 lines (64 loc) · 1.74 KB
/
renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// vueではなくてvue/dist/vue.jsをrequireするとruntime + compilerとなる
// https://stackoverflow.com/questions/39488660/vue-js-2-0-not-rendering-anything
const Vue = require('vue/dist/vue.js')
const ipcRenderer = require('electron').ipcRenderer
const { RELOAD_ENTRIES, SUBMIT_ENTRY, FIX_ENTRY } = require('./lib/EventTypes')
const AppComponent = Vue.component('app', {
template: `
<div id="app">
<div class="panel panel-default selected-entry">
<div class="panel-body selected-entry-inner" v-bind:class="{ 'fix-entry-animation': fix_entry_flash }">
{{ selected_entry }}
</div>
</div>
<ul class="list-group entry-list">
<li class="list-group-item list-entry" v-for="entry in rest_entries" v-bind:key="entry">
{{ entry }}
</li>
</ul>
</div>
`,
props: {
selected_entry: {
default: ''
},
rest_entries: {
default: []
},
fix_entry_flash: {
default: false
}
}
})
const app = new Vue({
el: '#vue',
data: {
selectedEntry: '',
restEntries: [],
fix_entry_flash: false
},
components: { AppComponent },
methods: {
changeEntries (newEntries) {
const entries = [].concat(newEntries)
this.selectedEntry = entries.shift()
this.restEntries = entries
},
startFixEntryAnimation () {
this.fix_entry_flash = true
setTimeout(() => { this.fix_entry_flash = false }, 1000)
}
}
})
ipcRenderer.on(RELOAD_ENTRIES, (_event, entries) => {
app.changeEntries(entries)
})
ipcRenderer.on(FIX_ENTRY, (_event) => {
app.startFixEntryAnimation()
})
// submit when press Enter key
window.addEventListener('keyup', (event) => {
if (event.key === 'Enter') {
ipcRenderer.send(SUBMIT_ENTRY)
}
})