Skip to content
This repository has been archived by the owner on Jan 9, 2019. It is now read-only.

Commit

Permalink
- Add DApps file watcher, for autoreload dapp in browser when their
Browse files Browse the repository at this point in the history
 files update
  • Loading branch information
alexstep committed Dec 6, 2017
1 parent a138448 commit 62167b2
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DApps/dicedapp_v2/bankroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//(function(){
window.MultDApp = (function(){
let DApp = new DCLib.DApp({slug : 'dicegame_v3'})

return DApp
})()

1 change: 1 addition & 0 deletions DApps/dicedapp_v2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name="HandheldFriendly" content="True"/>
<title>Dice Game Channels</title>


<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/min/1.5/min.min.css">
<link rel="stylesheet" type="text/css" href="./styles.css">

Expand Down
2 changes: 1 addition & 1 deletion DApps/dicedapp_v2/lib/DC.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions DApps/dicedapp_v2/lib/DC.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion DApps/dicedapp_v2/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ html, body {
font-size: 14px;
text-align: left;
padding: 20px 30px;

user-select: none;
}

Expand Down
Binary file modified DApps/example.zip
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@
"highcharts": "^5.0.14",
"jquery": "^3.2.1",
"node-fetch": "^1.7.3",
"node-watch": "^0.5.5",
"qrcode-svg": "^0.9.0",
"riot": "^3.7.0",
"riot-route": "^3.1.2",
"rtc-mesh": "^1.0.0",
"rtc-quickconnect": "^5.8.0",
"socket.io": "^2.0.4",
"toastr": "^2.1.2",
"utf-8-validate": "^3.0.3",
"web3": "git://github.com/ethereum/web3.js.git#1.0ES6",
Expand Down
16 changes: 15 additions & 1 deletion public/server.electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ const queryp = require('querystring')
const fs = require('fs')
const Gun = require('gun')
const fse = require('fs-extra')
const watch = require('node-watch')
const {app} = require('electron')


const filetypes = {
'.js': 'text/javascript',
'.css': 'text/css',
Expand Down Expand Up @@ -83,6 +85,8 @@ const DApps = {
setInterval(()=>{
this.readDirs()
}, 5000)

this.watchChanges()
},

readDirs(){
Expand Down Expand Up @@ -176,6 +180,17 @@ const DApps = {
})
},

watchChanges: function(){
var io = require('socket.io')({origins:'http://localhost:*'})
io.on('connection', function(client){})
io.listen(9997)
console.log('watchChanges in', dapps_path)
watch(dapps_path, { recursive: true }, function(evt, name) {
console.log(evt+' '+name)
io.emit('reload_page', 'filechanged '+name+'')
})
},

serve: function(request, response){

// Upload game folder
Expand Down Expand Up @@ -321,7 +336,6 @@ const server = http.createServer(function (request, response) {

server.listen(_config.http_port)


global.GunDB = Gun({file: _config.database, web: server })
global.fetch = require('node-fetch')
global.window = {}
Expand Down
16 changes: 15 additions & 1 deletion src/server.electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ const queryp = require('querystring')
const fs = require('fs')
const Gun = require('gun')
const fse = require('fs-extra')
const watch = require('node-watch')
const {app} = require('electron')


const filetypes = {
'.js': 'text/javascript',
'.css': 'text/css',
Expand Down Expand Up @@ -83,6 +85,8 @@ const DApps = {
setInterval(()=>{
this.readDirs()
}, 5000)

this.watchChanges()
},

readDirs(){
Expand Down Expand Up @@ -176,6 +180,17 @@ const DApps = {
})
},

watchChanges: function(){
var io = require('socket.io')({origins:'http://localhost:*'})
io.on('connection', function(client){})
io.listen(9997)
console.log('watchChanges in', dapps_path)
watch(dapps_path, { recursive: true }, function(evt, name) {
console.log(evt+' '+name)
io.emit('reload_page', 'filechanged '+name+'')
})
},

serve: function(request, response){

// Upload game folder
Expand Down Expand Up @@ -321,7 +336,6 @@ const server = http.createServer(function (request, response) {

server.listen(_config.http_port)


global.GunDB = Gun({file: _config.database, web: server })
global.fetch = require('node-fetch')
global.window = {}
Expand Down

0 comments on commit 62167b2

Please sign in to comment.