-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappmainRun.js
More file actions
171 lines (136 loc) · 5.4 KB
/
appmainRun.js
File metadata and controls
171 lines (136 loc) · 5.4 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
const FILENAME_LAYOUT = 'layout.htm';
const FILENAME_MAINCSS = 'main.css';
const FILENAME_JSBACKEND = 'appmainNext.js'
const FILENAME_MAINCSS_PLUS = 'plus.css';
const ID_MAINCSS_PLUS = 'mainCSSPlus';
const FILENAME_JSBACKEND_PLUS = 'plus.js';
const FILENAME_LIST_JS = 'js.lst';
const FILENAME_LIST_CSS = 'css.lst';
const FILENAME_LIST_JS_PLUGINS = 'plugins.lst';
const SUBDIR_BASE = 'base/';
const EVT_PluginsLoadingFinished = 'PluginsLoadingFinished';
var FILENAME_DEFAULT_HELPFILE = 'hlp/Help-.zip';
var srcJSOverride = null;
var srcMainCSSPlus = null;
var srcJSOverridePlus = null;
async function initLayout(store) {
const srcLayout = await _Storage.search(store, (store == STO_DATA ? SUBDIR_BASE : '') + FILENAME_LAYOUT);
if (srcLayout)
document.body.innerHTML = srcLayout;
const srcMainCSS = await _Storage.search(store, (store == STO_DATA ? SUBDIR_BASE : '') + FILENAME_MAINCSS);
if (!srcMainCSS) return
const mainCSSAlias = 'mainCSS';
$(mainCSSAlias)?.remove();
appendCSS(mainCSSAlias, srcMainCSS);
}
async function runApp() {
var listData = await _Storage.search(STO_DATA, FILENAME_LIST_CSS);
const sequenceCSS = rowsToArray(listData.trim());
if (sequenceCSS) {
for (const one of sequenceCSS) {
const srcCSS = await _Storage.search(STO_DATA, one);
appendCSS(one, srcCSS);
}
}
initLayout(STO_DATA);
listData = await _Storage.search(STO_DATA, FILENAME_LIST_JS);
const sequence = rowsToArray(listData.trim());
for (const one of sequence) {
const srcMarkedJs = await _Storage.search(STO_DATA, one);
appendJavaScript(one, srcMarkedJs, document.head);
}
const loadedList = await loadPluginList(FILENAME_LIST_JS_PLUGINS, STO_DATA);
if (!srcJSOverride)
srcJSOverride = await _Storage.search(STO_DATA, FILENAME_JSBACKEND);
appendJavaScript(FILENAME_JSBACKEND, srcJSOverride, document.head);
if (srcMainCSSPlus)
appendCSS(ID_MAINCSS_PLUS, srcMainCSSPlus);
if (srcJSOverridePlus)
appendJavaScript('mainJSPlus', srcJSOverridePlus, document.head);
sendEvent(EVT_PluginsLoadingFinished, (x) => {
x.result = loadedList;
x.source = STO_DATA;
});
const loadedListH = await loadPluginList(FILENAME_LIST_JS_PLUGINS, STO_HELP);
sendEvent(EVT_PluginsLoadingFinished, (x) => {
x.result = loadedListH;
x.source = STO_HELP;
});
}
const loadPluginListBasePath = (name) => `plugins/${name}.js`;
async function loadPluginList(listFileName, storage, basePath = loadPluginListBasePath) {
if (!basePath) {
log('E No basePath function specified. This is not correct and it has been wantedly (function provides default). Specify this!')
return;
}
var listData = await _Storage.search(storage, listFileName);
const sequencePlugins = rowsToArray(listData.trim());
const activatedPluginsList = [];
for (const one of sequencePlugins) {
const names = one.split(':');
const name = names[0];
var aliases = [];
if (names.length > 1)
aliases = names[1].split(';');
if (aliases.length == 0)
//aliases.push('');
log(`W Plugin: ${name} will be loaded only ... no aliases defined`);
try {
await loadPlugin(name, basePath(name), storage);
for (const oneAlias of aliases) {
await activatePlugin(name, oneAlias, storage);
activatedPluginsList.push([name, oneAlias]);
}
} catch (error) {
log('E Error during loading plugin: ', name, aliases);
}
}
return activatedPluginsList;
}
function getNoDotPath(path) {
const base = 'http://a.com/'
const reply = new URL(path, base).href.substring(base.length);
return reply;
}
async function lc_loadPlugin(name, file, source = STO_DATA) {
const appendingAlias = name.replaceAll('/', '_');
log(`Plugins: loading from file '${file}' under internal alias ${appendingAlias} ...'`);
const srcMarkedJs = await _Storage.search(source, getNoDotPath(file));
appendJavaScript(`plugins-${appendingAlias}.js`, srcMarkedJs, document.head);
const pluginPureName = name.split('/').pop();
const foundP = Plugins.pluginsClasses.get(pluginPureName);
if (foundP)
foundP._fileLength = new TextEncoder().encode(srcMarkedJs).length;
return pluginPureName;
}
async function lc_activatePlugin(name, alias, source = STO_DATA) {
const pluginPureName = name.split('/').pop();
const cfgFile = `plugins-config/${pluginPureName}_${alias}.cfg`;
log(`Plugins: loading configuration for plugin ${pluginPureName} (${name}) from file '${cfgFile}' ...`);
const configFileRaw = await _Storage.search(source, cfgFile);
const configFileStruct = parseConfigFile(configFileRaw || '|');
log(`Plugins: loading configuration for plugin ${pluginPureName} (${name}) from file '${cfgFile}' ... results:`, configFileStruct);
const plugin = Plugins.activate(pluginPureName, alias, configFileStruct || {});
plugin[1].storageName = source;
return plugin;
}
function lc_deactivatePlugin(pluginName, alias = '') {
log(`Plugins: requested deactivation for plugin ${pluginName} (${alias})`);
return Plugins.deactivate(pluginName, alias);
}
var loadPlugin = lc_loadPlugin;
var activatePlugin = lc_activatePlugin;
var deactivatePlugin = lc_deactivatePlugin;
function parseConfigFile(data) {
var rows = rowsToArray(data.trim());
const obj = rows
.reduce((acc, line) => {
const [key, value] = line.split('|');
acc[key] = value;
return acc;
}, {});
return obj;
}
function getObjectCopy(obj) {
return JSON.parse(JSON.stringify(obj));
}