win_webview2 1.1.20 → 1.1.22
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/dist/browser/runVirtualDirBrowser.d.ts +7 -1
- package/dist/browser/runVirtualDirBrowser.js +9 -34
- package/dist/node/tsExport/downloadModule.d.ts +14 -4
- package/dist/node/tsExport/downloadModule.js +1 -1
- package/dist/node/tsExport/runVirtualDir/checkFile.d.ts +2 -0
- package/dist/node/tsExport/runVirtualDir/checkFile.js +23 -0
- package/dist/node/tsExport/runVirtualDir/checkMapFunction.d.ts +9 -0
- package/dist/node/tsExport/runVirtualDir/checkMapFunction.js +40 -0
- package/dist/node/tsExport/runVirtualDir/checkWW2.d.ts +8 -0
- package/dist/node/tsExport/runVirtualDir/checkWW2.js +74 -0
- package/dist/node/tsExport/runVirtualDir/runVirtualDir.d.ts +7 -0
- package/dist/node/tsExport/runVirtualDir/runVirtualDir.js +69 -0
- package/dist/node/tsExport/runVirtualDir/runVirtualDirCheckWW2.d.ts +1 -0
- package/dist/node/tsExport/runVirtualDir/runVirtualDirCheckWW2.js +2 -0
- package/dist/node/tsExport/runVirtualDir/runVirtualDirUtil.d.ts +1 -0
- package/dist/node/tsExport/runVirtualDir/runVirtualDirUtil.js +2 -0
- package/dist/node/tsExport/runVirtualDir/util.d.ts +8 -0
- package/dist/node/tsExport/runVirtualDir/util.js +31 -0
- package/dist/node/tsExport/runVirtualDir.d.ts +2 -2
- package/dist/node/tsExport/runVirtualDir.js +88 -16
- package/dist/node/tsExport/runVirtualDirCheckWW2.d.ts +1 -0
- package/dist/node/tsExport/runVirtualDirCheckWW2.js +2 -0
- package/dist/node/tsExport/runVirtualDirUtil.d.ts +1 -0
- package/dist/node/tsExport/runVirtualDirUtil.js +2 -0
- package/dist/node/tsExport/winwebview2.d.ts +1 -1
- package/dist/node/tsExport/winwebview2.js +1 -1
- package/dist/node/tsExport/ww2_server.js +3 -6
- package/package.json +1 -1
|
@@ -1,36 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
let
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
let data = event.data;
|
|
9
|
-
try {
|
|
10
|
-
let jobj = JSON.parse(data);
|
|
11
|
-
funRegistred[jobj.replyFun](jobj.data);
|
|
12
|
-
}
|
|
13
|
-
catch (error) {
|
|
14
|
-
console.log("messageError ", error);
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
registerListenerReady = true;
|
|
18
|
-
}
|
|
19
|
-
export function callVirtualDirFunction(funName, param) {
|
|
20
|
-
let ranNumber = Date.now();
|
|
21
|
-
let replyFun = funName + ranNumber;
|
|
22
|
-
registerListener();
|
|
23
|
-
let jsonPost = {
|
|
24
|
-
funName: funName,
|
|
25
|
-
data: param,
|
|
26
|
-
replyFun: replyFun
|
|
27
|
-
};
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
window.chrome.webview.postMessage(JSON.stringify(jsonPost));
|
|
30
|
-
return new Promise((r, x) => {
|
|
31
|
-
funRegistred[replyFun] = (msg) => {
|
|
32
|
-
delete funRegistred[replyFun];
|
|
33
|
-
r(msg);
|
|
34
|
-
};
|
|
1
|
+
export async function callVirtualDirFunction(arg) {
|
|
2
|
+
let response = await fetch("/ww2_postmethod", {
|
|
3
|
+
method: "POST",
|
|
4
|
+
body: JSON.stringify(arg),
|
|
5
|
+
headers: {
|
|
6
|
+
"Content-Type": "application/json"
|
|
7
|
+
},
|
|
35
8
|
});
|
|
9
|
+
let result = await response.json();
|
|
10
|
+
return result;
|
|
36
11
|
}
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { WwvPlatFrom } from "./ww2_config";
|
|
2
|
+
interface ResourceRequest {
|
|
3
|
+
uri: string;
|
|
4
|
+
method: string;
|
|
5
|
+
body: Uint8Array;
|
|
6
|
+
}
|
|
7
|
+
interface ResourceResponse {
|
|
8
|
+
status: number;
|
|
9
|
+
contentType: string;
|
|
10
|
+
body: Uint8Array;
|
|
11
|
+
}
|
|
2
12
|
export interface Ww2WebConfig {
|
|
3
|
-
|
|
13
|
+
onClose: (err: any, data: any) => void;
|
|
4
14
|
wclassname: string;
|
|
5
15
|
url: string;
|
|
6
16
|
title: string;
|
|
@@ -9,8 +19,8 @@ export interface Ww2WebConfig {
|
|
|
9
19
|
isKiosk: boolean;
|
|
10
20
|
isMaximize: boolean;
|
|
11
21
|
isDebug: boolean;
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
virtualHostName?: string;
|
|
23
|
+
onVirtualHostRequested?: (req: ResourceRequest, reply: (res: ResourceResponse) => void) => void;
|
|
14
24
|
}
|
|
15
25
|
interface WW2FileDialogArg {
|
|
16
26
|
callback: (err: any, data: any) => void;
|
|
@@ -25,7 +35,7 @@ export interface WW2ControlWindowsArg {
|
|
|
25
35
|
height?: number;
|
|
26
36
|
width?: number;
|
|
27
37
|
}
|
|
28
|
-
interface Ww2Module {
|
|
38
|
+
export interface Ww2Module {
|
|
29
39
|
openWeb: (arg: Ww2WebConfig) => void;
|
|
30
40
|
openFileDialog: (arg: WW2FileDialogArg) => void;
|
|
31
41
|
openFolderDialog: (arg: WW2FileDialogArg) => void;
|
|
@@ -22,7 +22,7 @@ function extractZip(zipPath, targetDir) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
;
|
|
25
|
-
const binFileVersion = "1.1.
|
|
25
|
+
const binFileVersion = "1.1.21";
|
|
26
26
|
async function downloadModuleFile(platform) {
|
|
27
27
|
let modulePath = (0, dirnameTool_1.getWWVNodeModuleFolder)();
|
|
28
28
|
let winlibPath = node_path_1.default.join(modulePath, "win_lib");
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.checkFileFromVirtualFolder = checkFileFromVirtualFolder;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const util_1 = require("./util");
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const promises_1 = require("node:fs/promises");
|
|
11
|
+
async function checkFileFromVirtualFolder(htmlFolderPath, currentPath) {
|
|
12
|
+
let contentType = (0, util_1.getContentType)(currentPath);
|
|
13
|
+
let filePath = node_path_1.default.join(htmlFolderPath, currentPath);
|
|
14
|
+
if (!(0, node_fs_1.existsSync)(filePath)) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
let fileContent = await (0, promises_1.readFile)(filePath);
|
|
18
|
+
let uint8 = new Uint8Array(fileContent);
|
|
19
|
+
return {
|
|
20
|
+
content: uint8,
|
|
21
|
+
contentType
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InternalFunctionResultPromise } from "./util";
|
|
2
|
+
export declare function checkMapFunction(arg: {
|
|
3
|
+
mapfunction: {
|
|
4
|
+
[key: string]: (msg: object) => Promise<object>;
|
|
5
|
+
};
|
|
6
|
+
body: Uint8Array;
|
|
7
|
+
method: string;
|
|
8
|
+
path: string;
|
|
9
|
+
}): InternalFunctionResultPromise;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkMapFunction = checkMapFunction;
|
|
4
|
+
const util_1 = require("./util");
|
|
5
|
+
async function checkMapFunction(arg) {
|
|
6
|
+
if (arg.path != "/ww2_postmethod")
|
|
7
|
+
return null;
|
|
8
|
+
if (arg.method != "POST")
|
|
9
|
+
return null;
|
|
10
|
+
if (arg.body == null)
|
|
11
|
+
return null;
|
|
12
|
+
let jsonResponse = {
|
|
13
|
+
data: null,
|
|
14
|
+
error: null
|
|
15
|
+
};
|
|
16
|
+
try {
|
|
17
|
+
let bodyString = (0, util_1.byteArrayToString)(arg.body);
|
|
18
|
+
let bodyObject = JSON.parse(bodyString);
|
|
19
|
+
if (bodyObject.funName == null || bodyObject.funName == "")
|
|
20
|
+
throw "no method name";
|
|
21
|
+
if (!arg.mapfunction[bodyObject.funName])
|
|
22
|
+
throw "no method match";
|
|
23
|
+
jsonResponse.data = await arg.mapfunction[bodyObject.funName](bodyObject.params);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
jsonResponse.error = error;
|
|
27
|
+
}
|
|
28
|
+
let serverResponse = null;
|
|
29
|
+
try {
|
|
30
|
+
let responseText = JSON.stringify(jsonResponse);
|
|
31
|
+
serverResponse = {
|
|
32
|
+
content: (0, util_1.byteArrayFromString)(responseText),
|
|
33
|
+
contentType: "application/json"
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.log(error);
|
|
38
|
+
}
|
|
39
|
+
return serverResponse;
|
|
40
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Ww2Module } from "../downloadModule";
|
|
2
|
+
import { InternalFunctionResultPromise } from "./util";
|
|
3
|
+
export declare function checkWw2BrowserFunction(arg: {
|
|
4
|
+
path: string;
|
|
5
|
+
method: string;
|
|
6
|
+
body: Uint8Array;
|
|
7
|
+
ww2Module: Ww2Module;
|
|
8
|
+
}): InternalFunctionResultPromise;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkWw2BrowserFunction = checkWw2BrowserFunction;
|
|
4
|
+
const util_1 = require("./util");
|
|
5
|
+
async function checkWw2BrowserFunction(arg) {
|
|
6
|
+
if (arg.path != "/ww2_post")
|
|
7
|
+
return null;
|
|
8
|
+
if (arg.method != "POST")
|
|
9
|
+
return null;
|
|
10
|
+
if (arg.body == null)
|
|
11
|
+
return null;
|
|
12
|
+
let result = null;
|
|
13
|
+
try {
|
|
14
|
+
let resultText = "";
|
|
15
|
+
let bodyString = (0, util_1.byteArrayToString)(arg.body);
|
|
16
|
+
let body = JSON.parse(bodyString);
|
|
17
|
+
let ww2Module = arg.ww2Module;
|
|
18
|
+
if (body.openWeb) {
|
|
19
|
+
let openWebArg = body.openWeb;
|
|
20
|
+
ww2Module.openWeb({
|
|
21
|
+
onClose: () => {
|
|
22
|
+
},
|
|
23
|
+
height: openWebArg.height,
|
|
24
|
+
wclassname: openWebArg.wclassname,
|
|
25
|
+
isDebug: openWebArg.isDebug,
|
|
26
|
+
isKiosk: openWebArg.isKiosk,
|
|
27
|
+
isMaximize: openWebArg.isMaximize,
|
|
28
|
+
title: openWebArg.title,
|
|
29
|
+
url: openWebArg.url,
|
|
30
|
+
width: openWebArg.width
|
|
31
|
+
});
|
|
32
|
+
resultText = "open web";
|
|
33
|
+
}
|
|
34
|
+
else if (body.controlWindow) {
|
|
35
|
+
ww2Module.controlWindow(body.controlWindow);
|
|
36
|
+
resultText = "controlWindow";
|
|
37
|
+
}
|
|
38
|
+
else if (body.openFileDialog) {
|
|
39
|
+
let openFileDialogArg = body.openFileDialog;
|
|
40
|
+
resultText = await new Promise((r, x) => {
|
|
41
|
+
ww2Module.openFileDialog({
|
|
42
|
+
callback: (err, d) => {
|
|
43
|
+
r(d);
|
|
44
|
+
},
|
|
45
|
+
filter: openFileDialogArg.filter,
|
|
46
|
+
ownerClassName: openFileDialogArg.ownerClassName
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
else if (body.openFolderDialog) {
|
|
51
|
+
let ofArg = body.openFolderDialog;
|
|
52
|
+
resultText = await new Promise((r, x) => {
|
|
53
|
+
ww2Module.openFolderDialog({
|
|
54
|
+
callback: (err, data) => {
|
|
55
|
+
r(data);
|
|
56
|
+
},
|
|
57
|
+
filter: ofArg.filter,
|
|
58
|
+
ownerClassName: ofArg.ownerClassName
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
let jsonStrResponse = JSON.stringify({
|
|
63
|
+
error: null,
|
|
64
|
+
result: resultText
|
|
65
|
+
});
|
|
66
|
+
result = {
|
|
67
|
+
content: (0, util_1.byteArrayFromString)(jsonStrResponse),
|
|
68
|
+
contentType: "application/json"
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Ww2WebConfig } from "../downloadModule";
|
|
2
|
+
export declare function runVirtualDir(config: Omit<Ww2WebConfig, "onVirtualHostRequested" | "url" | "virtualHostName"> & {
|
|
3
|
+
mapFunction: {
|
|
4
|
+
[key: string]: (msg: object) => Promise<object>;
|
|
5
|
+
};
|
|
6
|
+
htmlFolderPath: string;
|
|
7
|
+
}): void;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runVirtualDir = runVirtualDir;
|
|
4
|
+
const downloadModule_1 = require("../downloadModule");
|
|
5
|
+
const winwebview2_1 = require("../winwebview2");
|
|
6
|
+
const util_1 = require("./util");
|
|
7
|
+
const checkFile_1 = require("./checkFile");
|
|
8
|
+
const checkWW2_1 = require("./checkWW2");
|
|
9
|
+
const checkMapFunction_1 = require("./checkMapFunction");
|
|
10
|
+
function runVirtualDir(config) {
|
|
11
|
+
(0, downloadModule_1.getModule)().then((wwvModule) => {
|
|
12
|
+
(0, winwebview2_1.closeSplash)();
|
|
13
|
+
let hostname = "https://myapp.local";
|
|
14
|
+
let wwvConfig = {
|
|
15
|
+
onClose: config.onClose,
|
|
16
|
+
height: config.height,
|
|
17
|
+
width: config.width,
|
|
18
|
+
wclassname: config.wclassname,
|
|
19
|
+
isDebug: config.isDebug,
|
|
20
|
+
isKiosk: config.isKiosk,
|
|
21
|
+
isMaximize: config.isMaximize,
|
|
22
|
+
virtualHostName: hostname,
|
|
23
|
+
url: hostname,
|
|
24
|
+
onVirtualHostRequested: async (req, response) => {
|
|
25
|
+
try {
|
|
26
|
+
let parsedUrl = new URL(req.uri, hostname);
|
|
27
|
+
let cleanPath = parsedUrl.pathname;
|
|
28
|
+
if (cleanPath == "/" || cleanPath == "")
|
|
29
|
+
cleanPath = "index.html";
|
|
30
|
+
console.log(cleanPath);
|
|
31
|
+
let serverResponse = await (0, checkFile_1.checkFileFromVirtualFolder)(config.htmlFolderPath, cleanPath);
|
|
32
|
+
if (serverResponse == null) {
|
|
33
|
+
serverResponse = await (0, checkWW2_1.checkWw2BrowserFunction)({
|
|
34
|
+
body: req.body,
|
|
35
|
+
method: req.method,
|
|
36
|
+
path: cleanPath,
|
|
37
|
+
ww2Module: wwvModule
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (serverResponse == null) {
|
|
41
|
+
serverResponse = await (0, checkMapFunction_1.checkMapFunction)({
|
|
42
|
+
body: req.body,
|
|
43
|
+
mapfunction: config.mapFunction,
|
|
44
|
+
method: req.method,
|
|
45
|
+
path: cleanPath
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (serverResponse != null) {
|
|
49
|
+
response({
|
|
50
|
+
body: serverResponse.content,
|
|
51
|
+
contentType: serverResponse.contentType,
|
|
52
|
+
status: 200
|
|
53
|
+
});
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
response({
|
|
57
|
+
body: (0, util_1.byteArrayFromString)("no response"),
|
|
58
|
+
contentType: "text/plain",
|
|
59
|
+
status: 404
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
title: config.title,
|
|
66
|
+
};
|
|
67
|
+
wwvModule.openWeb(wwvConfig);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function byteArrayFromString(txt: string): Uint8Array<ArrayBuffer>;
|
|
2
|
+
export declare function byteArrayToString(body: Uint8Array): string;
|
|
3
|
+
export declare function getContentType(url: string): string;
|
|
4
|
+
export interface InternalFunctionResult {
|
|
5
|
+
content: Uint8Array;
|
|
6
|
+
contentType: string;
|
|
7
|
+
}
|
|
8
|
+
export type InternalFunctionResultPromise = Promise<InternalFunctionResult | null>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.byteArrayFromString = byteArrayFromString;
|
|
4
|
+
exports.byteArrayToString = byteArrayToString;
|
|
5
|
+
exports.getContentType = getContentType;
|
|
6
|
+
function byteArrayFromString(txt) {
|
|
7
|
+
const encoder = new TextEncoder();
|
|
8
|
+
const uint8Array = encoder.encode(txt);
|
|
9
|
+
return uint8Array;
|
|
10
|
+
}
|
|
11
|
+
function byteArrayToString(body) {
|
|
12
|
+
const decoder = new TextDecoder('utf-8');
|
|
13
|
+
const str = decoder.decode(body);
|
|
14
|
+
return str;
|
|
15
|
+
}
|
|
16
|
+
const mimeTypes = {
|
|
17
|
+
'.html': 'text/html',
|
|
18
|
+
'.js': 'application/javascript',
|
|
19
|
+
'.css': 'text/css',
|
|
20
|
+
'.json': 'application/json',
|
|
21
|
+
'.png': 'image/png',
|
|
22
|
+
'.jpg': 'image/jpeg',
|
|
23
|
+
'.gif': 'image/gif',
|
|
24
|
+
'.svg': 'image/svg+xml',
|
|
25
|
+
'.pdf': 'application/pdf',
|
|
26
|
+
'.zip': 'application/zip'
|
|
27
|
+
};
|
|
28
|
+
function getContentType(url) {
|
|
29
|
+
const ext = url.substring(url.lastIndexOf('.')).toLowerCase();
|
|
30
|
+
return mimeTypes[ext] || 'application/octet-stream';
|
|
31
|
+
}
|
|
@@ -4,9 +4,9 @@ export interface JsonMsg {
|
|
|
4
4
|
data: string;
|
|
5
5
|
replyFun: string;
|
|
6
6
|
}
|
|
7
|
-
export declare function runVirtualDir(config: Omit<Ww2WebConfig, "
|
|
7
|
+
export declare function runVirtualDir(config: Omit<Ww2WebConfig, "onVirtualHostRequested" | "url" | "virtualHostName"> & {
|
|
8
8
|
mapFunction: {
|
|
9
9
|
[key: string]: (msg: string) => Promise<string>;
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
htmlFolderPath: string;
|
|
12
12
|
}): void;
|
|
@@ -1,38 +1,110 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.runVirtualDir = runVirtualDir;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
4
8
|
const downloadModule_1 = require("./downloadModule");
|
|
5
9
|
const winwebview2_1 = require("./winwebview2");
|
|
10
|
+
const node_fs_1 = require("node:fs");
|
|
11
|
+
const promises_1 = require("node:fs/promises");
|
|
12
|
+
function byteArrayFromString(txt) {
|
|
13
|
+
const encoder = new TextEncoder();
|
|
14
|
+
const uint8Array = encoder.encode(txt);
|
|
15
|
+
return uint8Array;
|
|
16
|
+
}
|
|
17
|
+
function byteArrayToString(body) {
|
|
18
|
+
const decoder = new TextDecoder('utf-8');
|
|
19
|
+
const str = decoder.decode(body);
|
|
20
|
+
return str;
|
|
21
|
+
}
|
|
22
|
+
const mimeTypes = {
|
|
23
|
+
'.html': 'text/html',
|
|
24
|
+
'.js': 'application/javascript',
|
|
25
|
+
'.css': 'text/css',
|
|
26
|
+
'.json': 'application/json',
|
|
27
|
+
'.png': 'image/png',
|
|
28
|
+
'.jpg': 'image/jpeg',
|
|
29
|
+
'.gif': 'image/gif',
|
|
30
|
+
'.svg': 'image/svg+xml',
|
|
31
|
+
'.pdf': 'application/pdf',
|
|
32
|
+
'.zip': 'application/zip'
|
|
33
|
+
};
|
|
34
|
+
function getContentType(url) {
|
|
35
|
+
const ext = url.substring(url.lastIndexOf('.')).toLowerCase();
|
|
36
|
+
return mimeTypes[ext] || 'application/octet-stream';
|
|
37
|
+
}
|
|
38
|
+
async function getFile(htmlFolderPath, currentPath) {
|
|
39
|
+
let contentType = getContentType(currentPath);
|
|
40
|
+
let filePath = node_path_1.default.join(htmlFolderPath, currentPath);
|
|
41
|
+
if (!(0, node_fs_1.existsSync)(filePath)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
let fileContent = await (0, promises_1.readFile)(filePath);
|
|
45
|
+
let uint8 = new Uint8Array(fileContent);
|
|
46
|
+
return {
|
|
47
|
+
content: uint8,
|
|
48
|
+
contentType
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
async function checkWw2BrowserFunction(arg) {
|
|
52
|
+
if (arg.path != "/ww2_post")
|
|
53
|
+
return null;
|
|
54
|
+
if (arg.method != "POST")
|
|
55
|
+
return null;
|
|
56
|
+
if (arg.body == null)
|
|
57
|
+
return null;
|
|
58
|
+
let result = null;
|
|
59
|
+
try {
|
|
60
|
+
let bodyString = byteArrayToString(arg.body);
|
|
61
|
+
let jsonObj = JSON.parse(bodyString);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
6
67
|
function runVirtualDir(config) {
|
|
7
68
|
(0, downloadModule_1.getModule)().then((wwv) => {
|
|
8
69
|
(0, winwebview2_1.closeSplash)();
|
|
9
|
-
|
|
10
|
-
|
|
70
|
+
let hostname = "https://myapp.local";
|
|
71
|
+
let wwvConfig = {
|
|
72
|
+
onClose: config.onClose,
|
|
11
73
|
height: config.height,
|
|
12
74
|
width: config.width,
|
|
13
75
|
wclassname: config.wclassname,
|
|
14
76
|
isDebug: config.isDebug,
|
|
15
77
|
isKiosk: config.isKiosk,
|
|
16
78
|
isMaximize: config.isMaximize,
|
|
17
|
-
|
|
79
|
+
virtualHostName: hostname,
|
|
80
|
+
url: hostname,
|
|
81
|
+
onVirtualHostRequested: async (req, response) => {
|
|
18
82
|
try {
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
83
|
+
let parsedUrl = new URL(req.uri, hostname);
|
|
84
|
+
let cleanPath = parsedUrl.pathname;
|
|
85
|
+
if (cleanPath == "/")
|
|
86
|
+
cleanPath = "index.html";
|
|
87
|
+
console.log(cleanPath);
|
|
88
|
+
let file = await getFile(config.htmlFolderPath, cleanPath);
|
|
89
|
+
if (file != null) {
|
|
90
|
+
response({
|
|
91
|
+
body: file.content,
|
|
92
|
+
contentType: file.contentType,
|
|
93
|
+
status: 200
|
|
94
|
+
});
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
response({
|
|
98
|
+
body: byteArrayFromString("test dulu"),
|
|
99
|
+
contentType: "text/plain",
|
|
100
|
+
status: 200
|
|
101
|
+
});
|
|
29
102
|
}
|
|
30
103
|
catch (error) {
|
|
31
104
|
}
|
|
32
105
|
},
|
|
33
106
|
title: config.title,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
107
|
+
};
|
|
108
|
+
wwv.openWeb(wwvConfig);
|
|
37
109
|
});
|
|
38
110
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getWWVNodeModuleFolder } from "./dirnameTool";
|
|
2
2
|
import { readConfig } from "./ww2_config";
|
|
3
3
|
import { downloadModuleAndExtract } from "./downloadModule";
|
|
4
|
-
import { runVirtualDir } from "./runVirtualDir";
|
|
4
|
+
import { runVirtualDir } from "./runVirtualDir/runVirtualDir";
|
|
5
5
|
export declare function closeSplash(): Promise<void>;
|
|
6
6
|
export * from "./downloadModule";
|
|
7
7
|
export * from "./ww2_server";
|
|
@@ -22,7 +22,7 @@ const ww2_config_1 = require("./ww2_config");
|
|
|
22
22
|
Object.defineProperty(exports, "readConfig", { enumerable: true, get: function () { return ww2_config_1.readConfig; } });
|
|
23
23
|
const downloadModule_1 = require("./downloadModule");
|
|
24
24
|
Object.defineProperty(exports, "downloadModuleAndExtract", { enumerable: true, get: function () { return downloadModule_1.downloadModuleAndExtract; } });
|
|
25
|
-
const runVirtualDir_1 = require("./runVirtualDir");
|
|
25
|
+
const runVirtualDir_1 = require("./runVirtualDir/runVirtualDir");
|
|
26
26
|
Object.defineProperty(exports, "runVirtualDir", { enumerable: true, get: function () { return runVirtualDir_1.runVirtualDir; } });
|
|
27
27
|
function closeSplash() {
|
|
28
28
|
return (0, downloadModule_1.getModule)().then((module) => {
|
|
@@ -21,7 +21,7 @@ async function ww2_CreateServer(arg) {
|
|
|
21
21
|
if (body.openWeb) {
|
|
22
22
|
let openWebArg = body.openWeb;
|
|
23
23
|
ww2Module.openWeb({
|
|
24
|
-
|
|
24
|
+
onClose: () => {
|
|
25
25
|
},
|
|
26
26
|
height: openWebArg.height,
|
|
27
27
|
wclassname: openWebArg.wclassname,
|
|
@@ -30,8 +30,7 @@ async function ww2_CreateServer(arg) {
|
|
|
30
30
|
isMaximize: openWebArg.isMaximize,
|
|
31
31
|
title: openWebArg.title,
|
|
32
32
|
url: openWebArg.url,
|
|
33
|
-
width: openWebArg.width
|
|
34
|
-
onPostMessage: (m, r) => { }
|
|
33
|
+
width: openWebArg.width
|
|
35
34
|
});
|
|
36
35
|
result = openWebArg.url;
|
|
37
36
|
}
|
|
@@ -85,7 +84,7 @@ async function ww2_CreateServer(arg) {
|
|
|
85
84
|
console.log("open UI");
|
|
86
85
|
let uiConfig = arg.uiConfig;
|
|
87
86
|
ww2Module.openWeb({
|
|
88
|
-
|
|
87
|
+
onClose: (err, data) => {
|
|
89
88
|
process.exit();
|
|
90
89
|
},
|
|
91
90
|
wclassname: uiConfig.wclassname,
|
|
@@ -96,8 +95,6 @@ async function ww2_CreateServer(arg) {
|
|
|
96
95
|
title: uiConfig.title,
|
|
97
96
|
width: uiConfig.width,
|
|
98
97
|
url: url,
|
|
99
|
-
onPostMessage: (msg, r) => {
|
|
100
|
-
},
|
|
101
98
|
});
|
|
102
99
|
});
|
|
103
100
|
}
|