Skip to content

Commit

Permalink
Merge pull request #25 from copios-jp/master
Browse files Browse the repository at this point in the history
Patched USB and visible version
  • Loading branch information
copios authored Dec 14, 2018
2 parents c4796b9 + 075fcda commit 7734c98
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
6 changes: 2 additions & 4 deletions app/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ app.on('ready', async () => {
titleBarStyle: 'hiddenInset',
})

mainWindow.on('close', () => {
scanner.deactivate()
})
mainWindow.loadFile(path.resolve(path.join(__dirname, '../renderer/index.html')))

// show window once on first load
Expand All @@ -49,6 +46,8 @@ app.on('ready', async () => {
mainWindow.show()
autoUpdater.checkForUpdatesAndNotify()
PowerSaveBlocker.activate()
mainWindow.webContents.send('version', app.getVersion())

app.on('activate', () => {
mainWindow.show()
})
Expand All @@ -72,7 +71,6 @@ app.on('ready', async () => {

app.on('before-quit', () => {
PowerSaveBlocker.deactivate()
scanner.deactivate()
})

ipcMain.on('activate', () => {
Expand Down
3 changes: 1 addition & 2 deletions app/main/services/ant/Receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ class Receiver extends events.EventEmitter {
})
try {
this.stick.close()
// this.stick.reset()
} catch (e) {
if (this.stick) {
this.stick.emit('shutdown')
this.stick.emit('shutdown', this)
}
/* noop */
}
Expand Down
14 changes: 10 additions & 4 deletions app/main/services/ant/Scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ class Scanner extends events.EventEmitter {
}
}

close(stick) {
try {
stick.close()
} catch (err) {
/* noop */
}
}

open = (stick) => {
stick.startupTimeout = 1
stick.once('startup', () => {
Expand All @@ -64,15 +72,13 @@ class Scanner extends events.EventEmitter {
} else {
setTimeout(() => {
if (stick.startupTimeout) {
console.log('Scanner#open stick opened but no startup received')
stick.close()
this.close(stick)
}
}, 500)
}
} catch (e) {
if (e.message !== "Cannot read property 'transfer' of undefined") {
console.log('Scanner#open stick open errored', e)
stick.close()
this.close(stick)
}
stick.removeAllListeners('startup')
}
Expand Down
10 changes: 8 additions & 2 deletions app/renderer/components/status_bar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@ export class StatusBar extends Component {
mainEvents = {
onTransmitter: ['transmitter-added', 'transmitter-removed'],
onReceiver: ['receiver-added', 'receiver-removed'],
onVersion: ['version'],
}

onVersion = (event, version) => {
this.setState({ ...this.state, version })
}

render = () => {
const { classes } = this.props
const { receivers, transmitters } = this.state
const { receivers, transmitters, version } = this.state
return (
<div className={classes.statusBar}>
<Typography variant="caption" className={classes.copyright}>
&copy; COPIOS
&copy; COPIOS v{version}
</Typography>
<Typography className={classes.bottomBarItem} variant="caption">
受信機数: {receivers.length}
Expand All @@ -41,6 +46,7 @@ export class StatusBar extends Component {
state = {
receivers: [],
transmitters: [],
version: '-',
}
}

Expand Down

0 comments on commit 7734c98

Please sign in to comment.