2022-03-29 10:25:25 +00:00
|
|
|
const m = require('mithril')
|
2020-09-08 07:53:42 +00:00
|
|
|
const defaults = require('./defaults')
|
|
|
|
const socket = require('./socket')
|
|
|
|
|
2022-03-29 10:25:25 +00:00
|
|
|
const core = {
|
|
|
|
name: '...loading...',
|
|
|
|
title: '',
|
|
|
|
apps: [],
|
|
|
|
db: {},
|
|
|
|
status: {},
|
|
|
|
}
|
|
|
|
|
|
|
|
socket.on('core.config', function(res) {
|
|
|
|
core.apps = []
|
|
|
|
let keys = Object.keys(res)
|
|
|
|
for (let key of keys) {
|
|
|
|
if (typeof(res[key]) !== 'object') {
|
|
|
|
core[key] = res[key]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (let appName of res.applications) {
|
|
|
|
core.apps.push({
|
|
|
|
name: appName,
|
|
|
|
config: res[appName],
|
|
|
|
})
|
|
|
|
}
|
|
|
|
m.redraw()
|
|
|
|
})
|
|
|
|
|
|
|
|
socket.on('core.status', function(res) {
|
|
|
|
core.status = res
|
|
|
|
m.redraw()
|
|
|
|
})
|
|
|
|
|
2020-09-08 07:53:42 +00:00
|
|
|
module.exports = function Module(module) {
|
|
|
|
return defaults(module, {
|
|
|
|
init: function() {},
|
|
|
|
|
|
|
|
oninit: function(vnode) {
|
|
|
|
this._listeners = []
|
2022-03-29 10:25:25 +00:00
|
|
|
this.core = core
|
2020-09-08 07:53:42 +00:00
|
|
|
this.init(vnode)
|
|
|
|
},
|
|
|
|
|
|
|
|
_listeners: null,
|
|
|
|
|
|
|
|
_socketOn: function(cb) {
|
|
|
|
socket.on('connect', () => cb())
|
|
|
|
|
|
|
|
if (socket.connected) {
|
|
|
|
cb()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
on: function(name, cb) {
|
2022-03-29 10:25:25 +00:00
|
|
|
for (let i = 0; i < this._listeners.length; i++) {
|
|
|
|
if (this._listeners[i][0] === name) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2020-09-08 07:53:42 +00:00
|
|
|
this._listeners.push([name, cb])
|
|
|
|
socket.on(name, cb)
|
|
|
|
},
|
|
|
|
|
|
|
|
remove: function() {},
|
|
|
|
|
|
|
|
onremove: function() {
|
|
|
|
this.remove()
|
|
|
|
if (!this._listeners) return
|
|
|
|
for (let i = 0; i < this._listeners.length; i++) {
|
2022-03-29 10:25:25 +00:00
|
|
|
socket.off(this._listeners[i][0], this._listeners[i][1])
|
2020-09-08 07:53:42 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|