1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
define.class(function(require){
var path = require('path')
var fs = require('fs')
var ExternalApps = require('$system/server/externalapps')
var FileWatcher = require('$system/server/filewatcher')
var BusServer = require('$system/rpc/busserver')
var HTMLParser = require('$system/parse/htmlparser')
var ScriptError = require('$system/parse/scripterror')
var legacy_support = 0
this.atConstructor = function(
args,
compname,
rootserver){
this.width = parseInt(args['-width']) || 1920;
this.height = parseInt(args['-height']) || 1080;
this.name = args['-name'] || 'dreemgl';
this.verbose = ('-verbose' in args);
if ('-dumpstate' in args) {
var ds = args['-dumpstate'];
this.dumpstate = (ds.length > 0) ? args['-dumpstate'] : 'stdout';
}
this.duration = parseInt(args['-duration']) || 0;
if (this.verbose)
console.log('Loading environment', define.$environment);
this.args = args
this.compname = compname
this.rootserver = rootserver
this.busserver = new BusServer()
this.session = Math.random() * 1000000
this.slow_watcher = new FileWatcher()
this.slow_watcher.atChange = function(){
this.reload()
}.bind(this)
this.components = {}
this.paths = ""
for(var key in define.paths){
if(this.paths) this.paths += ',\n\t\t'
this.paths += '$'+key+':"$root/'+key+'"'
}
define.atRequire = function(filename){
this.slow_watcher.watch(filename)
}.bind(this)
this.reload()
}
this.atChange = function(){
}
this.destroy = function(){
if(this.mycomposition && this.mycomposition.destroy) this.mycomposition.destroy()
this.mycomposition = undefined
}
this.loadComposition = function(){
if (this.verbose)
console.log("Reloading composition "+this.filename)
require.clearCache()
this.HeadlessApi = require('./headless_api');
this.HeadlessApi.initialize({width: this.width, height: this.height, name: this.name, duration: this.duration, verbose: this.verbose, dumpstate: this.dumpstate});
var Composition = require(define.expandVariables(this.filename))
this.composition = new Composition(this.busserver, this.session)
}
this.reload = function(){
this.destroy()
require.clearCache()
var dir = '$root/'
var jsname = dir + this.compname+'.js'
try{
if(fs.existsSync(define.expandVariables(jsname))){
this.filename = jsname
return this.loadComposition()
}
else{
var jsname = dir + this.compname + '/index.js'
if(fs.existsSync(define.expandVariables(jsname))){
this.filename = jsname
return this.loadComposition()
}
}
}
finally{
}
this.screenname = this.compname;
console.log('bootheadless.reload: Unable to load', jsname);
}
this.loadHTML = function(title, boot){
return '';
}
this.loadTemplate = function(title, boot){
console.warn('warning: bootheadless.loadTemplate not written');
return '';
}
})
|