Skip to content

Commit

Permalink
show logs
Browse files Browse the repository at this point in the history
  • Loading branch information
simon300000 committed Oct 20, 2019
1 parent 574192f commit 27758b1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
22 changes: 22 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,33 @@
<title>DD@Electron</title>
<link rel="stylesheet" href="./bulma/bulma.css">
<script src="./vue/vue.js"></script>
<style>
.fullheight {
height: calc(100vh + 24px);
width: 3000px;
position: absolute;
top: 0;
overflow: hidden;
font-family: monospace;
font-size: 12px;
color: grey;
opacity: 0.233;
padding-top: 2px;
padding-left: 2px;
}

</style>
</head>

<body style="-webkit-app-region: drag">

<div id="main" style="display: none;">
<div class="fullheight">
<p v-for="log in logs">
{{log}}
</p>
</div>

<section class="hero is-fullheight">
<div class="hero-body">
<div class="container">
Expand Down
14 changes: 13 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ new Vue({
update: undefined,
updateProgress: undefined,
updateDownloaded: undefined,
nickname: undefined
nickname: undefined,
log: undefined
},
logs: [],
uptime: undefined,
interval: undefined,
nickname: undefined
Expand All @@ -39,6 +41,12 @@ new Vue({
},
nickname(value) {
send('updateNickname', value)
},
'state.log'(log) {
this.logs.unshift(log)
if (this.logs.length > 233) {
this.logs.pop()
}
}
},
methods: {
Expand All @@ -55,6 +63,10 @@ new Vue({
}
},
async created() {
let logs = await get('logs')
logs.shift()
this.logs = logs

ipcRenderer.on('stateUpdate', (_events, key, value) => {
this.state[key] = value
})
Expand Down
1 change: 1 addition & 0 deletions src/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module.exports = ({ getWin, state, stateEmitter, getWs, updateInterval, autoUpda
subscribe('completeNum')
subscribe('completeNumNow')
subscribe('delay')
subscribe('log')
subscribe('INTERVAL')
subscribe('nickname')
subscribe('url')
Expand Down
10 changes: 9 additions & 1 deletion src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ const stateEmitter = new EventEmitter()

const state = new Proxy({
completeNum: 0,
completeNumNow: 0
completeNumNow: 0,
logs: []
}, {
set(target, key, value) {
target[key] = value
stateEmitter.emit(key, value)
}
})

stateEmitter.on('log', log => {
state.logs.unshift(log)
if (state.logs.length > 233) {
state.logs.pop()
}
})

module.exports = { state, stateEmitter }
5 changes: 5 additions & 0 deletions src/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = async ({ state, db }) => {
url.searchParams.set('name', nickname)
}

state.log = `using: ${url}`
console.log(`using: ${url}`)
state.nickname = nickname
state.url = url.href
Expand Down Expand Up @@ -85,6 +86,7 @@ module.exports = async ({ state, db }) => {
if (result) {
state.delay = Math.round(process.uptime() * 1000 / state.completeNumNow)
console.log(`job complete ${((Date.now() - time) / 1000).toFixed(2)}s`, state.delay, INTERVAL * PARALLEL - Date.now() + now)
state.log = url
state.completeNum++
state.completeNumNow++
}
Expand All @@ -93,15 +95,18 @@ module.exports = async ({ state, db }) => {
}

ws.on('open', () => {
state.log = 'DD@Home connected'
console.log('DD@Home connected')
Array(PARALLEL).fill().map(processer)
})

ws.on('error', e => {
state.log = `error: ${e.message}`
console.error(`error: ${e.message}`)
})

ws.on('close', (n, reason) => {
state.log = `closed, ${n}, ${reason}`
console.log('closed', n, reason)
if (reason === 'User Reload') {
resolve()
Expand Down

0 comments on commit 27758b1

Please sign in to comment.