@naanlang/naan 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +10 -10
- package/bin/index.js +25 -15
- package/dist/env_web.js +68 -73
- package/dist/naan.min.js +5 -5
- package/frameworks/browser/sworker.js +23 -23
- package/frameworks/browser/terminals.nlg +52 -3
- package/frameworks/client/psm_client.nlg +2 -0
- package/frameworks/client/relaycon.nlg +1 -1
- package/frameworks/common/common.nlg +10 -54
- package/frameworks/node/filesystem.nlg +5 -4
- package/frameworks/node/psm_server.nlg +1 -1
- package/frameworks/node/shell.nlg +134 -0
- package/frameworks/node/worker.nlg +1 -1
- package/frameworks/project/build.nlg +19 -5
- package/frameworks/project/projects.nlg +12 -1
- package/frameworks/running/debugnub.nlg +102 -12
- package/frameworks/running/debugutil.nlg +30 -13
- package/frameworks/running/executors.nlg +7 -3
- package/frameworks/running/running.nlg +26 -6
- package/frameworks/running/sourcecode.nlg +3 -1
- package/frameworks/running/taskexec.nlg +1 -1
- package/frameworks/storage/dbt_pouch.nlg +37 -19
- package/frameworks/storage/file_manager.nlg +1 -1
- package/frameworks/storage/psm_dbtables.nlg +23 -24
- package/frameworks/storage/resources.nlg +12 -4
- package/frameworks/storage/storage.nlg +2 -2
- package/lib/browser/env_web.js +73 -78
- package/lib/core/naanlib.js +5 -5
- package/package.json +1 -1
- package/plugins/gitClient/gitClient.nlg +3 -3
- package/plugins/openSearch/openSearch.nlg +2 -2
- package/plugins/serviceAws/aws_s3.nlg +17 -1
- package/plugins/serviceAws/psm_aws.nlg +4 -2
- package/plugins/serviceAws/serviceAws.nlg +1 -1
- package/plugins/serviceGC/gc_api.nlg +4 -4
- package/plugins/serviceGitHub/serviceGitHub.nlg +1 -1
- package/plugins/serviceGitLab/psm_gitlab.nlg +1 -1
- package/plugins/serviceGitLab/serviceGitLab.nlg +1 -1
- package/test/harness.nlg +9 -9
- package/test/test_01_core.nlg +24 -2
- package/test/test_02_context.nlg +1 -1
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
**
|
|
1
|
+
**NaaN**™
|
|
2
2
|
-----
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
NaaN is an async-first software platform for rapid development.
|
|
5
5
|
|
|
6
6
|
#### Release:
|
|
7
|
-
**
|
|
7
|
+
**NaaN for NPM** version **1.4.2+1**
|
|
8
8
|
Copyright (c) 2017-2024 Zulch Laboratories, Inc.
|
|
9
9
|
|
|
10
10
|
#### Features
|
|
11
|
-
- **
|
|
11
|
+
- **NaaN** runs in NodeJS and web browsers using JavaScript
|
|
12
12
|
- Based on an asynchronous LISP-2 engine with persistent execution
|
|
13
13
|
- The default **Lingo**™ surface language provides familiar Algol-style braces syntax
|
|
14
14
|
- Fiber-based concurrent execution without async or await declarations
|
|
@@ -37,18 +37,18 @@ For use as a library in the current project:
|
|
|
37
37
|
|
|
38
38
|
naan [options] [source file] [arguments]
|
|
39
39
|
|
|
40
|
-
With no arguments
|
|
40
|
+
With no arguments NaaN runs as an interactive REPL using the node.js terminal.
|
|
41
41
|
It can also evaluate an expression or execute a source file.
|
|
42
42
|
|
|
43
43
|
##### Command line usage
|
|
44
44
|
|
|
45
45
|
-e <expression> evaluate an expression
|
|
46
46
|
-i, --interactive use REPL with -e or [source file]
|
|
47
|
-
--version print
|
|
48
|
-
--buildno print
|
|
47
|
+
--version print NaaN version
|
|
48
|
+
--buildno print NaaN version with build number
|
|
49
49
|
-h, --help print usage information
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
NaaN prints the results of evaluating each expression with the REPL, but not
|
|
52
52
|
by default with an expression or source file. The interactive flag overrides
|
|
53
53
|
this to print the result of each expression in all cases.
|
|
54
54
|
|
|
@@ -72,7 +72,7 @@ Fetch your public IP from a website (NodeJS version 18 or later):
|
|
|
72
72
|
|
|
73
73
|
##### Shell scripting
|
|
74
74
|
|
|
75
|
-
When installed globally,
|
|
75
|
+
When installed globally, NaaN can be used for shell scripts with the [Shebang](https://en.wikipedia.org/wiki/Shebang_(Unix))
|
|
76
76
|
mechanism. For example, copy the following text to a file named helloworld:
|
|
77
77
|
|
|
78
78
|
#!/usr/bin/env naan
|
|
@@ -89,7 +89,7 @@ The [NaanIDE](https://www.npmjs.com/package/@naanlang/naanide) installation incl
|
|
|
89
89
|
Please email [Richard Zulch](mailto:naanlang@zulchlabs.com) with questions and comments.
|
|
90
90
|
|
|
91
91
|
#### Dependencies:
|
|
92
|
-
We gratefully acknowledge these software packages used with
|
|
92
|
+
We gratefully acknowledge these software packages used with NaaN:
|
|
93
93
|
- [jszip.js](http://stuartk.com/jszip) - read and write zip files
|
|
94
94
|
- [NodeJS-path](https://nodejs.org/) - NodeJS path utilities
|
|
95
95
|
- [PouchDB](https://pouchdb.com/) - synchronizing database
|
package/bin/index.js
CHANGED
|
@@ -7,20 +7,24 @@
|
|
|
7
7
|
*
|
|
8
8
|
* column positioning: // // !
|
|
9
9
|
*
|
|
10
|
-
* Copyright (c) 2021-
|
|
10
|
+
* Copyright (c) 2021-2024 by Richard C. Zulch
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
"use strict";
|
|
15
15
|
|
|
16
16
|
/*
|
|
17
|
-
* imports
|
|
17
|
+
* imports & environment
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
var path = require("path");
|
|
22
22
|
var fs = require("fs");
|
|
23
23
|
var naanOptions = {};
|
|
24
|
+
var jspath = require("path");
|
|
25
|
+
var naanpath = path.join(__dirname, ".."); // path to naan, which is us
|
|
26
|
+
var rootpath = naanpath; // path to us, which is naan
|
|
27
|
+
var envpath = jspath.resolve(naanpath, 'lib/env_node.js'); // path to Naan loader
|
|
24
28
|
|
|
25
29
|
/*
|
|
26
30
|
* Process command-line arguments
|
|
@@ -30,7 +34,12 @@ var naanOptions = {};
|
|
|
30
34
|
var cmd_file;
|
|
31
35
|
var eval_text;
|
|
32
36
|
var do_interactive;
|
|
33
|
-
var cmd_text = "
|
|
37
|
+
var cmd_text = ""
|
|
38
|
+
+ `App.naanpath = '${ naanpath.replace(/\\/g, "\\\\") }';;\n` // path/to/our naan library
|
|
39
|
+
+ `App.rootpath = '${ rootpath.replace(/\\/g, "\\\\") }';;\n` // path/to/our package.json
|
|
40
|
+
+ "Naan.module.defineLoc('naanlib', App.naanpath);;\n" // defines "naanlib:" prefix for require
|
|
41
|
+
+ "nodeparse('lib/node_repl_init.nlg');;\n" // REPL utility functions
|
|
42
|
+
+ "App.shell = require('naanlib:frameworks/node/shell.nlg').ShellConnect({ cwd: js.d });;\n";
|
|
34
43
|
|
|
35
44
|
process.argv.every((val, index) => {
|
|
36
45
|
if (index < 2)
|
|
@@ -58,11 +67,11 @@ process.argv.every((val, index) => {
|
|
|
58
67
|
return (true);
|
|
59
68
|
}
|
|
60
69
|
if (val == "--version") {
|
|
61
|
-
console.log("1.4.
|
|
70
|
+
console.log("1.4.2");
|
|
62
71
|
process.exit(0);
|
|
63
72
|
}
|
|
64
73
|
if (val == "--buildno") {
|
|
65
|
-
console.log("1.4.
|
|
74
|
+
console.log("1.4.2+1");
|
|
66
75
|
process.exit(0);
|
|
67
76
|
}
|
|
68
77
|
if (val.substring(0,1) == "-") {
|
|
@@ -97,10 +106,10 @@ if (eval_text) {
|
|
|
97
106
|
naanOptions.noWelcome = true;
|
|
98
107
|
if (!do_interactive)
|
|
99
108
|
naanOptions.replDisable = true;
|
|
100
|
-
cmd_text =
|
|
109
|
+
cmd_text = cmd_text.concat(
|
|
101
110
|
"closure NodeREPL(local input, error, expr) {\n" +
|
|
102
111
|
|
|
103
|
-
(do_interactive ?
|
|
112
|
+
(do_interactive ? "" :
|
|
104
113
|
" sudo(putproc(`exception, false))\n") +
|
|
105
114
|
|
|
106
115
|
" input = new(textstream, js.expr)\n" +
|
|
@@ -114,15 +123,16 @@ if (eval_text) {
|
|
|
114
123
|
" } else\n" +
|
|
115
124
|
|
|
116
125
|
(cmd_file && !do_interactive ?
|
|
117
|
-
"
|
|
126
|
+
" $(evalactive(expr))\n" :
|
|
118
127
|
|
|
119
128
|
" {\n" +
|
|
120
|
-
"
|
|
121
|
-
"
|
|
129
|
+
" $(evalactive(expr))\n" +
|
|
130
|
+
" if input.tokenlast().atom == `;; || $ === Naan.local.mu\n" +
|
|
131
|
+
" { }\n" +
|
|
122
132
|
" else if input.tokenlast().atom == `;>\n" +
|
|
123
|
-
" printline(
|
|
133
|
+
" printline($)\n" +
|
|
124
134
|
" else\n" +
|
|
125
|
-
" printline(Dialect.print(
|
|
135
|
+
" printline(Dialect.print($))\n" +
|
|
126
136
|
" }\n") +
|
|
127
137
|
|
|
128
138
|
" }\n" +
|
|
@@ -138,7 +148,7 @@ if (eval_text) {
|
|
|
138
148
|
" exec(quote(js.g.process.exit(if error 1 else 0)))\n") +
|
|
139
149
|
|
|
140
150
|
" }\n" +
|
|
141
|
-
"}();;\n";
|
|
151
|
+
"}();;\n");
|
|
142
152
|
} else if (!process.stdin.isTTY) {
|
|
143
153
|
console.log("naan: nothing specified and no TTY; exiting");
|
|
144
154
|
process.exit(1);
|
|
@@ -150,9 +160,9 @@ if (eval_text) {
|
|
|
150
160
|
*
|
|
151
161
|
*/
|
|
152
162
|
|
|
153
|
-
var NaanNodeREPL = require(
|
|
163
|
+
var NaanNodeREPL = require(envpath);
|
|
154
164
|
var naanrepl = new NaanNodeREPL(naanOptions);
|
|
155
|
-
naanrepl.setDirectory(
|
|
165
|
+
naanrepl.setDirectory(rootpath);
|
|
156
166
|
if (eval_text)
|
|
157
167
|
naanrepl.setGlobal("expr", eval_text + "\n");
|
|
158
168
|
naanrepl.textCommand(cmd_text);
|
package/dist/env_web.js
CHANGED
|
@@ -34,7 +34,7 @@ exports.NaanControllerWeb = function() {
|
|
|
34
34
|
"use strict";
|
|
35
35
|
/*jshint -W024 */
|
|
36
36
|
var undefined; // JavaScript should make this a keyword
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
//
|
|
39
39
|
// Persistent
|
|
40
40
|
//
|
|
@@ -43,17 +43,11 @@ exports.NaanControllerWeb = function() {
|
|
|
43
43
|
kStateFirstVersion = 200, // increment when losing backwards compatbility
|
|
44
44
|
kStateCurrentVersion = 200; // increment when adding features
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
//
|
|
48
48
|
// Environment
|
|
49
49
|
//
|
|
50
|
-
|
|
51
|
-
var pageLoading = true; // assume we are loading the page
|
|
52
50
|
|
|
53
|
-
window.addEventListener("load", function (e) {
|
|
54
|
-
pageLoading = false;
|
|
55
|
-
});
|
|
56
|
-
|
|
57
51
|
var querystrings = (function(a) {
|
|
58
52
|
if (a === "") return {};
|
|
59
53
|
var b = {};
|
|
@@ -67,12 +61,12 @@ exports.NaanControllerWeb = function() {
|
|
|
67
61
|
}
|
|
68
62
|
return b;
|
|
69
63
|
})(window.location.search.substr(1).split('&'));
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
|
|
65
|
+
|
|
72
66
|
//
|
|
73
67
|
// Initialization
|
|
74
68
|
//
|
|
75
|
-
|
|
69
|
+
|
|
76
70
|
var naanlib = new exports.Naanlib();
|
|
77
71
|
var dontSaveUntilWorking; // true when state loaded, must be reset to save state again
|
|
78
72
|
var contSelf = this; // this is us, for access within nested functions
|
|
@@ -129,7 +123,7 @@ exports.NaanControllerWeb = function() {
|
|
|
129
123
|
//
|
|
130
124
|
// Read any pending Naan output and send to terminal.
|
|
131
125
|
//
|
|
132
|
-
|
|
126
|
+
|
|
133
127
|
function takePending() {
|
|
134
128
|
var outputq = replqueue;
|
|
135
129
|
replqueue = false;
|
|
@@ -145,13 +139,13 @@ exports.NaanControllerWeb = function() {
|
|
|
145
139
|
//==========================================================================
|
|
146
140
|
// New Terminal Interface
|
|
147
141
|
//--------------------------------------------------------------------------
|
|
148
|
-
|
|
142
|
+
|
|
149
143
|
//
|
|
150
144
|
// StateGet
|
|
151
145
|
//
|
|
152
146
|
// Report the saved state we are keeping for the terminal.
|
|
153
147
|
//
|
|
154
|
-
|
|
148
|
+
|
|
155
149
|
this.StateGet = function StateGet() {
|
|
156
150
|
termlist.every(function(term) {
|
|
157
151
|
var state;
|
|
@@ -170,20 +164,20 @@ exports.NaanControllerWeb = function() {
|
|
|
170
164
|
//
|
|
171
165
|
// Attach a terminal to our interpreter and immediately start sending it messages.
|
|
172
166
|
//
|
|
173
|
-
|
|
167
|
+
|
|
174
168
|
this.Attach = function Attach(terminal) {
|
|
175
169
|
var repdex = termlist.indexOf(terminal);
|
|
176
170
|
if (repdex < 0)
|
|
177
171
|
termlist.push(terminal);
|
|
178
172
|
takePending(); // output all pending terminal messages
|
|
179
173
|
};
|
|
180
|
-
|
|
174
|
+
|
|
181
175
|
//
|
|
182
176
|
// Detach
|
|
183
177
|
//
|
|
184
178
|
// Detach the terminal from the interpreter.
|
|
185
179
|
//
|
|
186
|
-
|
|
180
|
+
|
|
187
181
|
this.Detach = function Detach(terminal) {
|
|
188
182
|
var repdex = termlist.indexOf(terminal);
|
|
189
183
|
if (repdex >= 0)
|
|
@@ -191,17 +185,17 @@ exports.NaanControllerWeb = function() {
|
|
|
191
185
|
if (termlist.length === 0)
|
|
192
186
|
replstate = terminal.StateSave(); // save ultimate repl state
|
|
193
187
|
};
|
|
194
|
-
|
|
188
|
+
|
|
195
189
|
//
|
|
196
190
|
// Interrupt
|
|
197
191
|
//
|
|
198
192
|
// Interrupt the interpreter in response to a user request.
|
|
199
193
|
//
|
|
200
|
-
|
|
194
|
+
|
|
201
195
|
this.Interrupt = function Interrupt(terminal) {
|
|
202
|
-
|
|
196
|
+
Promise.resolve().then(function () {
|
|
203
197
|
naanlib.escape();
|
|
204
|
-
}
|
|
198
|
+
});
|
|
205
199
|
};
|
|
206
200
|
|
|
207
201
|
//
|
|
@@ -209,7 +203,7 @@ exports.NaanControllerWeb = function() {
|
|
|
209
203
|
//
|
|
210
204
|
// Enter line of text to instance.
|
|
211
205
|
//
|
|
212
|
-
|
|
206
|
+
|
|
213
207
|
this.Return = function Return(text, terminal) {
|
|
214
208
|
termlist.forEach(function(term) {
|
|
215
209
|
if (term !== terminal)
|
|
@@ -240,13 +234,13 @@ exports.NaanControllerWeb = function() {
|
|
|
240
234
|
});
|
|
241
235
|
return (data);
|
|
242
236
|
};
|
|
243
|
-
|
|
237
|
+
|
|
244
238
|
var nideListener;
|
|
245
239
|
this.OnMessage = function OnMessage(proc) {
|
|
246
240
|
nideListener = proc;
|
|
247
241
|
return (proc);
|
|
248
242
|
};
|
|
249
|
-
|
|
243
|
+
|
|
250
244
|
this.DispatchMessage = function DispatchMessage(data) { // "local" -> "remote"
|
|
251
245
|
if (nideListener)
|
|
252
246
|
setTimeout(function() {
|
|
@@ -267,7 +261,7 @@ exports.NaanControllerWeb = function() {
|
|
|
267
261
|
debugListener = proc;
|
|
268
262
|
return (proc);
|
|
269
263
|
};
|
|
270
|
-
|
|
264
|
+
|
|
271
265
|
this.DispatchDebugger = function DispatchDebugger(data) { // "local" -> "remote"
|
|
272
266
|
if (debugListener)
|
|
273
267
|
setTimeout(function() {
|
|
@@ -280,7 +274,7 @@ exports.NaanControllerWeb = function() {
|
|
|
280
274
|
//
|
|
281
275
|
// Report status to the terminal.
|
|
282
276
|
//
|
|
283
|
-
|
|
277
|
+
|
|
284
278
|
setInterval(function() {
|
|
285
279
|
var samples = naanlib.status(1);
|
|
286
280
|
if (samples.length > 0)
|
|
@@ -297,29 +291,30 @@ exports.NaanControllerWeb = function() {
|
|
|
297
291
|
//
|
|
298
292
|
// Enter keystroke to instance.
|
|
299
293
|
//
|
|
300
|
-
|
|
294
|
+
|
|
301
295
|
this.Keystroke = function Keystroke(text, keycode) {
|
|
302
296
|
console.log("Naan keystroke mode not implemented");
|
|
303
297
|
};
|
|
304
|
-
|
|
298
|
+
|
|
305
299
|
//
|
|
306
300
|
// Dimensions
|
|
307
301
|
//
|
|
308
302
|
// Report terminal dimensions to instance.
|
|
309
303
|
//
|
|
310
|
-
|
|
304
|
+
|
|
311
305
|
this.Dimensions = function Dimensions(rows, cols) {
|
|
312
306
|
console.log("Naan terminal dimensions now (" + rows + ", " + cols + ")");
|
|
313
307
|
};
|
|
314
|
-
|
|
308
|
+
|
|
315
309
|
//
|
|
316
310
|
// VsiteRefresh
|
|
317
311
|
//
|
|
318
312
|
// Check if our underlying data has changed, and reload if needed.
|
|
319
313
|
//
|
|
320
|
-
|
|
314
|
+
|
|
321
315
|
this.VsiteRefresh = function VsiteRefresh(url_origin) {
|
|
322
316
|
if (vsiteName && window.location.href.startsWith(url_origin)) {
|
|
317
|
+
virtualClose();
|
|
323
318
|
window.location.reload(); // we have changed underneath
|
|
324
319
|
window.scroll(0,0); // Chrome 106 had flood pants 🤓
|
|
325
320
|
return (true);
|
|
@@ -330,7 +325,7 @@ exports.NaanControllerWeb = function() {
|
|
|
330
325
|
//==========================================================================
|
|
331
326
|
// Browser Console Terminal
|
|
332
327
|
//--------------------------------------------------------------------------
|
|
333
|
-
|
|
328
|
+
|
|
334
329
|
// Commands:
|
|
335
330
|
// Naanlang.debug(<text>) -- command line text entry
|
|
336
331
|
// Naanlang.int() -- interrupt and enter debugger
|
|
@@ -373,7 +368,7 @@ exports.NaanControllerWeb = function() {
|
|
|
373
368
|
return (false);
|
|
374
369
|
};
|
|
375
370
|
}
|
|
376
|
-
|
|
371
|
+
|
|
377
372
|
//
|
|
378
373
|
// debug
|
|
379
374
|
//
|
|
@@ -429,7 +424,7 @@ exports.NaanControllerWeb = function() {
|
|
|
429
424
|
debugListener(msg.data); // target received a message
|
|
430
425
|
}
|
|
431
426
|
});
|
|
432
|
-
|
|
427
|
+
|
|
433
428
|
//
|
|
434
429
|
// report messages back to opener
|
|
435
430
|
//
|
|
@@ -437,7 +432,7 @@ exports.NaanControllerWeb = function() {
|
|
|
437
432
|
window.opener.postMessage(msg, window.origin);
|
|
438
433
|
return (msg);
|
|
439
434
|
};
|
|
440
|
-
|
|
435
|
+
|
|
441
436
|
//
|
|
442
437
|
// report messages back to opener
|
|
443
438
|
//
|
|
@@ -459,7 +454,7 @@ exports.NaanControllerWeb = function() {
|
|
|
459
454
|
};
|
|
460
455
|
return (termSelf.OnMessage(msg));
|
|
461
456
|
};
|
|
462
|
-
|
|
457
|
+
|
|
463
458
|
//
|
|
464
459
|
// report status back to opener
|
|
465
460
|
//
|
|
@@ -471,64 +466,47 @@ exports.NaanControllerWeb = function() {
|
|
|
471
466
|
return (termSelf.OnMessage(msg));
|
|
472
467
|
};
|
|
473
468
|
}
|
|
474
|
-
|
|
469
|
+
|
|
475
470
|
//==========================================================================
|
|
476
471
|
// Host Environment
|
|
477
472
|
//--------------------------------------------------------------------------
|
|
478
|
-
|
|
473
|
+
|
|
479
474
|
//
|
|
480
475
|
// SavePref
|
|
481
476
|
//
|
|
482
477
|
// Save a persistent preference object that can be retrieved in the future.
|
|
483
478
|
//
|
|
484
|
-
|
|
479
|
+
|
|
485
480
|
this.SavePref = function SavePref(key, value) {
|
|
486
481
|
return (prefs[key] = value);
|
|
487
482
|
};
|
|
488
|
-
|
|
483
|
+
|
|
489
484
|
//
|
|
490
485
|
// LoadPref
|
|
491
486
|
//
|
|
492
487
|
// Load a previously-saved preference object for future retrieval.
|
|
493
488
|
//
|
|
494
|
-
|
|
489
|
+
|
|
495
490
|
this.LoadPref = function LoadPref(key) {
|
|
496
491
|
return (prefs[key]);
|
|
497
492
|
};
|
|
498
|
-
|
|
493
|
+
|
|
499
494
|
//
|
|
500
495
|
// Working
|
|
501
496
|
//
|
|
502
497
|
// The application is working, so it is safe to save state.
|
|
503
498
|
//
|
|
504
|
-
|
|
499
|
+
|
|
505
500
|
this.Working = function Working() {
|
|
506
501
|
dontSaveUntilWorking = false;
|
|
507
502
|
};
|
|
508
|
-
|
|
509
|
-
var saveEvent = new Event("NaanSave");
|
|
510
|
-
|
|
511
|
-
window.document.addEventListener("visibilitychange", function (e) {
|
|
512
|
-
if (window.document.visibilityState != "hidden")
|
|
513
|
-
return;
|
|
514
|
-
window.dispatchEvent(saveEvent);
|
|
515
|
-
saveLocal();
|
|
516
|
-
});
|
|
517
503
|
|
|
518
|
-
window.addEventListener("
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
window.dispatchEvent(saveEvent);
|
|
525
|
-
saveLocal();
|
|
526
|
-
virtualClose();
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
window.addEventListener("beforeunload", function (e) {
|
|
530
|
-
window.dispatchEvent(saveEvent);
|
|
531
|
-
saveLocal();
|
|
504
|
+
window.document.addEventListener("visibilitychange", function (e) {
|
|
505
|
+
virtualVisibilityChange();
|
|
506
|
+
if (window.document.visibilityState == "hidden") {
|
|
507
|
+
window.dispatchEvent(new Event("NaanSave"));
|
|
508
|
+
saveLocal();
|
|
509
|
+
}
|
|
532
510
|
});
|
|
533
511
|
|
|
534
512
|
function makeState() {
|
|
@@ -548,24 +526,24 @@ exports.NaanControllerWeb = function() {
|
|
|
548
526
|
statedoc.replstate = replstate;
|
|
549
527
|
return (statedoc);
|
|
550
528
|
}
|
|
551
|
-
|
|
529
|
+
|
|
552
530
|
function loadState(statedoc) {
|
|
553
531
|
if (statedoc===undefined || statedoc.naan === undefined
|
|
554
532
|
|| statedoc.firstver > kStateCurrentVersion
|
|
555
533
|
|| statedoc.curversion < kStateFirstVersion
|
|
556
534
|
|| statedoc.licensee != "$Licensee$"
|
|
557
|
-
|| statedoc.verstring != "$Version$"
|
|
535
|
+
|| statedoc.verstring != "$Version$"
|
|
536
|
+
|| !(naanstate = statedoc.naan))
|
|
558
537
|
{
|
|
559
538
|
localStorage.removeItem("NaanState_Hosted");
|
|
560
539
|
return (false);
|
|
561
540
|
}
|
|
562
|
-
naanstate = statedoc.naan;
|
|
563
541
|
replstate = statedoc.replstate; // get terminal state, if any
|
|
564
542
|
if (typeof(statedoc.prefs) == "object")
|
|
565
543
|
prefs = statedoc.prefs;
|
|
566
544
|
return (true);
|
|
567
545
|
}
|
|
568
|
-
|
|
546
|
+
|
|
569
547
|
function saveLocal() {
|
|
570
548
|
/*jshint sub:true */
|
|
571
549
|
if (dontSaveUntilWorking) { // saved state is problematic
|
|
@@ -588,7 +566,7 @@ exports.NaanControllerWeb = function() {
|
|
|
588
566
|
}
|
|
589
567
|
return (false);
|
|
590
568
|
}
|
|
591
|
-
|
|
569
|
+
|
|
592
570
|
function loadLocal() {
|
|
593
571
|
try {
|
|
594
572
|
/*jshint sub:true */
|
|
@@ -604,7 +582,7 @@ exports.NaanControllerWeb = function() {
|
|
|
604
582
|
}
|
|
605
583
|
return (false);
|
|
606
584
|
}
|
|
607
|
-
|
|
585
|
+
|
|
608
586
|
function virtualOpen() {
|
|
609
587
|
try {
|
|
610
588
|
if (window.opener && window.opener.Naanlang) {
|
|
@@ -619,7 +597,7 @@ exports.NaanControllerWeb = function() {
|
|
|
619
597
|
} catch (e) {
|
|
620
598
|
}
|
|
621
599
|
}
|
|
622
|
-
|
|
600
|
+
|
|
623
601
|
function virtualClose() {
|
|
624
602
|
try {
|
|
625
603
|
if (window.opener && window.opener.Naanlang) {
|
|
@@ -636,6 +614,22 @@ exports.NaanControllerWeb = function() {
|
|
|
636
614
|
vsiteName = false; // window is going away
|
|
637
615
|
}
|
|
638
616
|
|
|
617
|
+
function virtualVisibilityChange() {
|
|
618
|
+
try {
|
|
619
|
+
if (window.opener && window.opener.Naanlang) {
|
|
620
|
+
window.opener.Naanlang.naancon.DispatchMessage({
|
|
621
|
+
op: "VsiteVisibilityChange",
|
|
622
|
+
name: vsiteName,
|
|
623
|
+
naancont: contSelf,
|
|
624
|
+
title: vsiteName + " $Version$",
|
|
625
|
+
hidden: window.document.visibilityState == "hidden",
|
|
626
|
+
window: window
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
} catch (e) {
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
639
633
|
/*jshint sub:true */
|
|
640
634
|
if (querystrings["restart"] || !loadLocal())
|
|
641
635
|
{ // don't load state or can't load state
|
|
@@ -656,6 +650,7 @@ exports.NaanControllerWeb = function() {
|
|
|
656
650
|
localStorage.removeItem("NaanState_Hosted");
|
|
657
651
|
window.location.reload();
|
|
658
652
|
}
|
|
653
|
+
naanstate = false; // reclaim memory
|
|
659
654
|
}
|
|
660
655
|
|
|
661
656
|
if (window.opener) {
|