Skip to content

Commit

Permalink
start stop working
Browse files Browse the repository at this point in the history
  • Loading branch information
BitHighlander committed Oct 19, 2021
1 parent 4b78066 commit 467c958
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
25 changes: 17 additions & 8 deletions src-electron/main-process/electron-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ const adapter = NodeWebUSBKeepKeyAdapter.useKeyring(new core.Keyring())
const express = require( "express" );
const bodyParser = require("body-parser");
const cors = require('cors')
const server = express();
server.use(cors())
server.use(bodyParser.urlencoded({ extended: false }));
server.use(bodyParser.json());
const appExpress = express();
appExpress.use(cors())
appExpress.use(bodyParser.urlencoded({ extended: false }));
appExpress.use(bodyParser.json());
let server

const EVENT_LOG = []

Expand Down Expand Up @@ -213,7 +214,7 @@ const start_bridge = async function(event){

let API_PORT = process.env["API_PORT_BRIDGE"] || "1646"
//bridge
server.all('/exchange/device', async function (req, res, next) {
appExpress.all('/exchange/device', async function (req, res, next) {
try{
if(req.method === 'GET'){
let resp = await transport.readChunk()
Expand All @@ -239,15 +240,15 @@ const start_bridge = async function(event){
});

//catchall
server.use((err, req, res, next) => {
appExpress.use((err, req, res, next) => {
const { status = 500, message = 'something went wrong. ', data = {} } = err
log.error(message)
res.status(status).json({ message, data })
})

//port
try{
server.listen( API_PORT, () => {
server = appExpress.listen( API_PORT, () => {
event.sender.send('playSound',{ sound:'success' })
console.log( `server started at http://localhost:${ API_PORT }` );
STATE = 3
Expand Down Expand Up @@ -277,7 +278,15 @@ ipcMain.on('onStopBridge', async (event, data) => {
const tag = TAG + ' | onStartBridge | '
try {
event.sender.send('playSound',{ sound:'fail' })
server.close(function() { console.log('shutdown server'); });
console.log("server: ",server)
server.close(() => {
console.log('Closed out remaining connections');
STATE = 2
STATUS = 'device connected'
event.sender.send('setKeepKeyState',{ state:STATE })
event.sender.send('setKeepKeyStatus',{ status:STATUS })
});

} catch (e) {
console.error(tag, e)
}
Expand Down
28 changes: 25 additions & 3 deletions src/pages/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
<div align="center">
status: {{status}}
<br/>
code: {{code}}
state: {{state}}
<br/>
url: {{bridgeUrl}}
<!-- <div></div>-->
<!-- url: {{bridgeUrl}}-->
<br/>
<q-btn @click="startBridge" color="primary" label="Start Bridge" />
<br/>
Expand Down Expand Up @@ -59,6 +60,7 @@
<script>
import { mapMutations, mapGetters } from 'vuex'
import { copyToClipboard } from 'quasar'
import {ipcRenderer} from "electron";
export default {
Expand All @@ -79,7 +81,7 @@
devMode:false,
installing: [],
status:"unknown",
code:0,
state:0,
draggable: true,
resizable: true,
responsive: true,
Expand All @@ -90,7 +92,27 @@
},
mounted() {
try{
ipcRenderer.on('attach', (event, data) => {
console.log('attach', data)
})
ipcRenderer.on('detach', (event, data) => {
console.log('detach', data)
})
ipcRenderer.on('setKeepKeyState', (event, data) => {
console.log('setKeepKeyState', data)
this.state = data.state
})
ipcRenderer.on('setKeepKeyStatus', (event, data) => {
console.log('setKeepKeyStatus', data)
this.status = data.status
})
ipcRenderer.on('setDevice', (event, data) => {
console.log('setDevice', data)
})
}catch(e){
console.error(e)
Expand Down

0 comments on commit 467c958

Please sign in to comment.