win_webview2 1.0.13 → 1.1.3
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/buildtools/copyDll.ts +71 -0
- package/{tsconfig.json → buildtools/tsconfig.json} +12 -12
- package/dist/browser/ww2_browser.d.ts +32 -0
- package/dist/browser/ww2_browser.js +11 -0
- package/{tsDist/srcBuilder → dist/node/builder}/build_copyDir.d.ts +1 -1
- package/{tsDist/srcBuilder → dist/node/builder}/build_copyDir.js +24 -24
- package/dist/node/builder/builder_deploy.d.ts +2 -0
- package/{tsDist/srcBuilder/builder_tp.js → dist/node/builder/builder_deploy.js} +2 -2
- package/dist/node/builder/builder_init.d.ts +9 -0
- package/dist/node/builder/builder_init.js +52 -0
- package/dist/node/builder/builder_promps.d.ts +9 -0
- package/dist/node/builder/builder_promps.js +68 -0
- package/dist/node/builder/dirnameTool.d.ts +4 -0
- package/dist/node/builder/dirnameTool.js +16 -0
- package/dist/node/builder/tools.d.ts +4 -0
- package/dist/node/builder/tools.js +15 -0
- package/dist/node/builder/userExec.d.ts +2 -0
- package/dist/node/builder/userExec.js +45 -0
- package/{tsDist/srcBuilder/builder_tp.d.ts → dist/node/tsExport/config.d.ts} +7 -7
- package/dist/node/tsExport/config.js +2 -0
- package/dist/node/tsExport/dirnameTool.d.ts +6 -0
- package/dist/node/tsExport/dirnameTool.js +63 -0
- package/dist/node/tsExport/winwebview2.d.ts +38 -0
- package/dist/node/tsExport/winwebview2.js +51 -0
- package/dist/node/tsExport/ww2_config.d.ts +7 -0
- package/dist/node/tsExport/ww2_config.js +18 -0
- package/dist/node/tsExport/ww2_server.d.ts +36 -0
- package/dist/node/tsExport/ww2_server.js +100 -0
- package/package.json +21 -7
- package/srcBrowser/tsconfig.json +13 -0
- package/srcBrowser/ww2_browser.ts +47 -0
- package/srcNode/builder/builder_init.ts +78 -0
- package/srcNode/builder/builder_promps.ts +93 -0
- package/srcNode/builder/userExec.ts +54 -0
- package/srcNode/tsExport/dirnameTool.ts +34 -0
- package/srcNode/tsExport/winwebview2.ts +78 -0
- package/srcNode/tsExport/ww2_config.ts +24 -0
- package/srcNode/tsExport/ww2_server.ts +157 -0
- package/srcNode/tsconfig.json +13 -0
- package/tsDistRun.js +5 -5
- package/win_lib/Win32/WebView2Loader.dll +0 -0
- package/win_lib/Win32/exeOpenner.exe +0 -0
- package/win_lib/Win32/ww2_addon.node +0 -0
- package/win_lib/x64/WebView2Loader.dll +0 -0
- package/win_lib/x64/exeOpenner.exe +0 -0
- package/win_lib/x64/ww2_addon.node +0 -0
- package/tsDist/logprint.d.ts +0 -1
- package/tsDist/logprint.js +0 -6
- package/tsDist/srcBuilder/ww2_build_promp.d.ts +0 -1
- package/tsDist/srcBuilder/ww2_build_promp.js +0 -31
- package/tsDist/srcBuilder/ww2_buildercore.d.ts +0 -14
- package/tsDist/srcBuilder/ww2_buildercore.js +0 -124
- package/tsDist/tsExport/winwebview2.d.ts +0 -28
- package/tsDist/tsExport/winwebview2.js +0 -105
- package/tsSrc/logprint.ts +0 -3
- package/tsSrc/srcBuilder/build_copyDir.ts +0 -32
- package/tsSrc/srcBuilder/builder_tp.ts +0 -7
- package/tsSrc/srcBuilder/ww2_build_promp.ts +0 -30
- package/tsSrc/srcBuilder/ww2_buildercore.ts +0 -182
- package/tsSrc/tsExport/winwebview2.ts +0 -160
- package/win_lib/Win32/CmdWebview2.exe +0 -0
- package/win_lib/Win32/icon.ico +0 -0
- package/win_lib/Win32/index.bat +0 -3
- package/win_lib/x64/CmdWebview2.exe +0 -0
- package/win_lib/x64/icon.ico +0 -0
- package/win_lib/x64/index.bat +0 -3
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { WW2ControlWindowsArg } from './winwebview2';
|
|
3
|
+
interface WW2FileDialogArg {
|
|
4
|
+
filter: string;
|
|
5
|
+
ownerClassName: string;
|
|
6
|
+
}
|
|
7
|
+
export type PostData = {
|
|
8
|
+
openWeb?: {
|
|
9
|
+
wclassname: string;
|
|
10
|
+
url: string;
|
|
11
|
+
title: string;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
isKiosk: boolean;
|
|
15
|
+
isMaximize: boolean;
|
|
16
|
+
isDebug: boolean;
|
|
17
|
+
};
|
|
18
|
+
openFileDialog?: WW2FileDialogArg;
|
|
19
|
+
openFolderDialog?: WW2FileDialogArg;
|
|
20
|
+
controlWindow?: WW2ControlWindowsArg;
|
|
21
|
+
};
|
|
22
|
+
export declare function ww2_CreateServer(arg: {
|
|
23
|
+
port: number;
|
|
24
|
+
onExpressCreate: (app: express.Express) => void;
|
|
25
|
+
uiConfig: {
|
|
26
|
+
wclassname: string;
|
|
27
|
+
title: string;
|
|
28
|
+
width: number;
|
|
29
|
+
height: number;
|
|
30
|
+
isKiosk: boolean;
|
|
31
|
+
isMaximize: boolean;
|
|
32
|
+
isDebug: boolean;
|
|
33
|
+
};
|
|
34
|
+
htmlfolder: string;
|
|
35
|
+
}): Promise<void>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
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.ww2_CreateServer = ww2_CreateServer;
|
|
7
|
+
const express_1 = __importDefault(require("express"));
|
|
8
|
+
const winwebview2_1 = require("./winwebview2");
|
|
9
|
+
async function ww2_CreateServer(arg) {
|
|
10
|
+
let port = arg.port ? arg.port : 0;
|
|
11
|
+
let app = (0, express_1.default)();
|
|
12
|
+
app.use(express_1.default.json());
|
|
13
|
+
app.use(express_1.default.static(arg.htmlfolder));
|
|
14
|
+
arg.onExpressCreate(app);
|
|
15
|
+
app.post("/ww2_post", async (req, res) => {
|
|
16
|
+
let body = req.body;
|
|
17
|
+
console.log("ww2_post", body);
|
|
18
|
+
let result = "";
|
|
19
|
+
let err = "";
|
|
20
|
+
try {
|
|
21
|
+
if (body.openWeb) {
|
|
22
|
+
let openWebArg = body.openWeb;
|
|
23
|
+
ww2Module.openWeb({
|
|
24
|
+
callback: () => {
|
|
25
|
+
},
|
|
26
|
+
height: openWebArg.height,
|
|
27
|
+
wclassname: openWebArg.wclassname,
|
|
28
|
+
isDebug: openWebArg.isDebug,
|
|
29
|
+
isKiosk: openWebArg.isKiosk,
|
|
30
|
+
isMaximize: openWebArg.isMaximize,
|
|
31
|
+
title: openWebArg.title,
|
|
32
|
+
url: openWebArg.url,
|
|
33
|
+
width: openWebArg.width
|
|
34
|
+
});
|
|
35
|
+
result = openWebArg.url;
|
|
36
|
+
}
|
|
37
|
+
else if (body.controlWindow) {
|
|
38
|
+
ww2Module.controlWindow(body.controlWindow);
|
|
39
|
+
}
|
|
40
|
+
else if (body.openFileDialog) {
|
|
41
|
+
let openFileDialogArg = body.openFileDialog;
|
|
42
|
+
result = await new Promise((r, x) => {
|
|
43
|
+
ww2Module.openFileDialog({
|
|
44
|
+
callback: (err, d) => {
|
|
45
|
+
r(d);
|
|
46
|
+
},
|
|
47
|
+
filter: openFileDialogArg.filter,
|
|
48
|
+
ownerClassName: openFileDialogArg.ownerClassName
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else if (body.openFolderDialog) {
|
|
53
|
+
let ofArg = body.openFolderDialog;
|
|
54
|
+
result = await new Promise((r, x) => {
|
|
55
|
+
ww2Module.openFolderDialog({
|
|
56
|
+
callback: (err, data) => {
|
|
57
|
+
r(data);
|
|
58
|
+
},
|
|
59
|
+
filter: ofArg.filter,
|
|
60
|
+
ownerClassName: ofArg.ownerClassName
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
err = error + "";
|
|
67
|
+
}
|
|
68
|
+
res.json({
|
|
69
|
+
error: err,
|
|
70
|
+
result: result
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
let ww2Module = await (0, winwebview2_1.getModule)();
|
|
74
|
+
let server = app.listen(port, async (err) => {
|
|
75
|
+
let add = server.address();
|
|
76
|
+
if (add == null) {
|
|
77
|
+
console.log("build server failed : " + err);
|
|
78
|
+
process.exit();
|
|
79
|
+
}
|
|
80
|
+
let addr = add;
|
|
81
|
+
let resultPort = addr.port;
|
|
82
|
+
let url = `http://localhost:${resultPort}`;
|
|
83
|
+
console.log(url);
|
|
84
|
+
console.log("open UI");
|
|
85
|
+
let uiConfig = arg.uiConfig;
|
|
86
|
+
ww2Module.openWeb({
|
|
87
|
+
callback: (err, data) => {
|
|
88
|
+
process.exit();
|
|
89
|
+
},
|
|
90
|
+
wclassname: uiConfig.wclassname,
|
|
91
|
+
height: uiConfig.height,
|
|
92
|
+
isDebug: uiConfig.isDebug,
|
|
93
|
+
isKiosk: uiConfig.isKiosk,
|
|
94
|
+
isMaximize: uiConfig.isMaximize,
|
|
95
|
+
title: uiConfig.title,
|
|
96
|
+
width: uiConfig.width,
|
|
97
|
+
url: url,
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "win_webview2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/nnttoo/win_webview2"
|
|
@@ -8,25 +8,39 @@
|
|
|
8
8
|
"description": "",
|
|
9
9
|
"main": "./tsDist/tsExport/winwebview2.js",
|
|
10
10
|
"types": "./tsDist/tsExport/winwebview2.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
"./browser": {
|
|
13
|
+
"types": "./dist/browser/ww2_browser.d.ts",
|
|
14
|
+
"default": "./dist/browser/ww2_browser.js"
|
|
15
|
+
},
|
|
16
|
+
"./node": {
|
|
17
|
+
"types": "./dist/node/tsExport/winwebview2.dt.ts",
|
|
18
|
+
"default": "./dist/node/tsExport/winwebview2.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
11
21
|
"bin": {
|
|
12
22
|
"win_webview2": "tsDistRun.js"
|
|
13
23
|
},
|
|
14
24
|
"type": "commonjs",
|
|
15
25
|
"scripts": {
|
|
16
|
-
"build": "tsc",
|
|
17
|
-
"build_watch": "
|
|
26
|
+
"build": "tsc -p ./srcNode/tsconfig.json",
|
|
27
|
+
"build_watch": "npm run build -- --watch",
|
|
28
|
+
"build_browser": "tsc -p ./srcBrowser/tsconfig.json",
|
|
29
|
+
"build_browser_watch": "npm run build_browser -- --watch",
|
|
30
|
+
"copy_dll": "tsx ./buildtools/copyDll.ts"
|
|
18
31
|
},
|
|
19
32
|
"author": "",
|
|
20
33
|
"license": "ISC",
|
|
21
34
|
"dependencies": {
|
|
35
|
+
"comment-json": "^4.6.2",
|
|
36
|
+
"degit": "^2.8.4",
|
|
37
|
+
"express": "^5.2.1",
|
|
22
38
|
"prompts": "^2.4.2",
|
|
23
|
-
"rcedit": "^4.0.1",
|
|
24
|
-
"sharp": "^0.33.5",
|
|
25
|
-
"sharp-ico": "^0.1.5",
|
|
26
39
|
"tsx": "^4.21.0"
|
|
27
40
|
},
|
|
28
41
|
"devDependencies": {
|
|
29
|
-
"@types/
|
|
42
|
+
"@types/express": "^5.0.6",
|
|
43
|
+
"@types/node": "^25.5.2",
|
|
30
44
|
"@types/prompts": "^2.4.9",
|
|
31
45
|
"typescript": "^6.0.2"
|
|
32
46
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
interface WW2FileDialogArg {
|
|
2
|
+
filter: string;
|
|
3
|
+
ownerClassName: string;
|
|
4
|
+
}
|
|
5
|
+
interface WW2ControlWindowsArg {
|
|
6
|
+
wndClassName: string;
|
|
7
|
+
controlcmd: "close" | "move" | "maximize" | "minimize" | "resize" | "check",
|
|
8
|
+
left?: number;
|
|
9
|
+
top?: number;
|
|
10
|
+
height?: number;
|
|
11
|
+
width?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type PostData = {
|
|
15
|
+
openWeb?: {
|
|
16
|
+
wclassname: string,
|
|
17
|
+
url: string,
|
|
18
|
+
title: string,
|
|
19
|
+
|
|
20
|
+
width: number,
|
|
21
|
+
height: number,
|
|
22
|
+
isKiosk: boolean,
|
|
23
|
+
isMaximize: boolean,
|
|
24
|
+
isDebug: boolean,
|
|
25
|
+
},
|
|
26
|
+
openFileDialog?: WW2FileDialogArg,
|
|
27
|
+
openFolderDialog?: WW2FileDialogArg,
|
|
28
|
+
controlWindow?: WW2ControlWindowsArg,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function callWw2(arg : PostData){
|
|
32
|
+
let response = await fetch("/ww2_post",{
|
|
33
|
+
method : "POST",
|
|
34
|
+
body : JSON.stringify(arg),
|
|
35
|
+
headers: {
|
|
36
|
+
"Content-Type": "application/json"
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
let result = await response.json() as {
|
|
41
|
+
err : string,
|
|
42
|
+
result : string,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return result;
|
|
46
|
+
|
|
47
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { existsSync } from "fs";
|
|
2
|
+
import { copyFile, mkdir, readFile, writeFile } from "fs/promises";
|
|
3
|
+
import { getWw2Dirname } from "../tsExport/dirnameTool";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { exec, execSync } from "child_process";
|
|
6
|
+
import { ConfigWW2 } from "../tsExport/ww2_config";
|
|
7
|
+
import prompts from "prompts";
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
function runCommand(command : string) {
|
|
11
|
+
try {
|
|
12
|
+
const currentShell = process.platform === 'win32' ? 'cmd.exe' : '/bin/sh';
|
|
13
|
+
execSync(command, { stdio: 'inherit', shell: currentShell, killSignal : "SIGINT" });
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.error(`Command Error: ${command}`);
|
|
16
|
+
process.exit();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const jsonConfigFilePath = "./win_webview2.json";
|
|
21
|
+
let mdirname = getWw2Dirname();
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
interface ChoiseItem {
|
|
25
|
+
fun: () => any;
|
|
26
|
+
description: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type WW2Choise = { [key: string]: ChoiseItem }
|
|
30
|
+
|
|
31
|
+
let ww2Choise: WW2Choise = {
|
|
32
|
+
|
|
33
|
+
"ww2_typescript": {
|
|
34
|
+
description: "init win_webview2",
|
|
35
|
+
fun: async () => {
|
|
36
|
+
runCommand('npx degit nnttoo/win_webview2/example/ww2_typescript#master ww2_typescript')
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
type promChoise = {
|
|
43
|
+
title: string,
|
|
44
|
+
value: () => any,
|
|
45
|
+
description: string,
|
|
46
|
+
disable? :boolean
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function ww2Init() {
|
|
50
|
+
const response = await prompts({
|
|
51
|
+
type: 'select',
|
|
52
|
+
name: 'menu',
|
|
53
|
+
message: 'Pick one example',
|
|
54
|
+
instructions: '(Use arrow keys to navigate, press enter to select)',
|
|
55
|
+
choices: (() => {
|
|
56
|
+
let result: promChoise[] = [];
|
|
57
|
+
|
|
58
|
+
for (let item in ww2Choise) {
|
|
59
|
+
let val = ww2Choise[item];
|
|
60
|
+
|
|
61
|
+
result.push({
|
|
62
|
+
title: item,
|
|
63
|
+
value: val.fun,
|
|
64
|
+
description : val.description,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
})(),
|
|
71
|
+
});
|
|
72
|
+
if (response && response.menu) {
|
|
73
|
+
|
|
74
|
+
await response.menu();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
|
|
2
|
+
import prompts from 'prompts';
|
|
3
|
+
import { ww2Init } from './builder_init';
|
|
4
|
+
import { readUserScripts } from './userExec';
|
|
5
|
+
|
|
6
|
+
interface ChoiseItem {
|
|
7
|
+
fun: () => any;
|
|
8
|
+
description: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type WW2Choise = { [key: string]: ChoiseItem }
|
|
12
|
+
|
|
13
|
+
let ww2Choise: WW2Choise = {
|
|
14
|
+
|
|
15
|
+
"init_win_webview2": {
|
|
16
|
+
description: "init win_webview2",
|
|
17
|
+
fun: async () => {
|
|
18
|
+
await ww2Init();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type promChoise = {
|
|
24
|
+
title: string,
|
|
25
|
+
value: () => any,
|
|
26
|
+
description: string,
|
|
27
|
+
disable? :boolean
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function buildForServer() {
|
|
31
|
+
let userChoise = await readUserScripts();
|
|
32
|
+
if(userChoise != null){
|
|
33
|
+
ww2Choise = {
|
|
34
|
+
...ww2Choise,
|
|
35
|
+
...userChoise
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const response = await prompts({
|
|
40
|
+
type: 'select',
|
|
41
|
+
name: 'menu',
|
|
42
|
+
message: 'Pick one',
|
|
43
|
+
instructions: '(Use arrow keys to navigate, press enter to select)',
|
|
44
|
+
choices: (() => {
|
|
45
|
+
let result: promChoise[] = [];
|
|
46
|
+
|
|
47
|
+
for (let item in ww2Choise) {
|
|
48
|
+
let val = ww2Choise[item];
|
|
49
|
+
|
|
50
|
+
result.push({
|
|
51
|
+
title: item,
|
|
52
|
+
value: val.fun,
|
|
53
|
+
description : val.description,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
})(),
|
|
60
|
+
});
|
|
61
|
+
if (response && response.menu) {
|
|
62
|
+
|
|
63
|
+
await response.menu();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
console.log("ww2 version : v6 \n\n");
|
|
67
|
+
const args = process.argv.slice(2);
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
if (args.length > 0) {
|
|
71
|
+
|
|
72
|
+
let argument = args[0] as string;
|
|
73
|
+
if (argument.startsWith("--")) {
|
|
74
|
+
argument = argument.substring(2);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
console.log(argument);
|
|
78
|
+
if (ww2Choise[argument]) {
|
|
79
|
+
ww2Choise[argument].fun();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
} else {
|
|
83
|
+
|
|
84
|
+
buildForServer();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
process.on('SIGINT', () => {
|
|
88
|
+
console.log('\n[Sinyal SIGINT Terdeteksi]');
|
|
89
|
+
console.log('User menekan Ctrl+C. Membersihkan data...');
|
|
90
|
+
|
|
91
|
+
// Anda harus memanggil exit secara manual jika menggunakan listener ini
|
|
92
|
+
process.exit(0);
|
|
93
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { findUserProjectRoot } from "../tsExport/dirnameTool";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { parse } from "comment-json";
|
|
5
|
+
import { WW2Choise } from "./builder_promps";
|
|
6
|
+
import { execSync } from "node:child_process";
|
|
7
|
+
|
|
8
|
+
interface MyPkg{
|
|
9
|
+
name? : string,
|
|
10
|
+
scripts? : {[key : string] : string}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function runNpm(command : string) {
|
|
14
|
+
try {
|
|
15
|
+
const currentShell = process.platform === 'win32' ? 'cmd.exe' : '/bin/sh';
|
|
16
|
+
let cmd = `npm run ${command}`;
|
|
17
|
+
console.log(cmd);
|
|
18
|
+
execSync(cmd, { stdio: 'inherit', shell: currentShell, killSignal : "SIGINT" });
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error(`Command Error: ${command}`);
|
|
21
|
+
process.exit();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function readUserScripts(){
|
|
26
|
+
let dirUser = findUserProjectRoot();
|
|
27
|
+
if(dirUser == null) return;
|
|
28
|
+
|
|
29
|
+
let pkgJson = path.join(dirUser, "package.json");
|
|
30
|
+
let pkgTxt = await readFile(pkgJson,"utf-8");
|
|
31
|
+
|
|
32
|
+
let obj = parse(pkgTxt) as MyPkg;
|
|
33
|
+
|
|
34
|
+
if(obj.scripts == null) return;
|
|
35
|
+
|
|
36
|
+
let ww2Choise : WW2Choise = {};
|
|
37
|
+
|
|
38
|
+
let name = obj.name? obj.name : "";
|
|
39
|
+
|
|
40
|
+
for(let kscript in obj.scripts){
|
|
41
|
+
let cmd = obj.scripts[kscript];
|
|
42
|
+
|
|
43
|
+
ww2Choise["--"+kscript] = {
|
|
44
|
+
description : name + " : " + cmd,
|
|
45
|
+
fun : ()=>{
|
|
46
|
+
runNpm(kscript);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return ww2Choise;
|
|
53
|
+
|
|
54
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import path, { dirname } from 'node:path';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export function getWw2Dirname() {
|
|
7
|
+
// Trik deteksi lingkungan
|
|
8
|
+
const _filename = typeof __filename !== 'undefined'
|
|
9
|
+
? __filename
|
|
10
|
+
// @ts-ignore:
|
|
11
|
+
: fileURLToPath(eval('import.meta.url'));
|
|
12
|
+
|
|
13
|
+
const _dirname = typeof __dirname !== 'undefined'
|
|
14
|
+
? __dirname
|
|
15
|
+
: dirname(_filename);
|
|
16
|
+
|
|
17
|
+
let ww2ModulePath = path.join(_dirname,"../../../")
|
|
18
|
+
|
|
19
|
+
return { _dirname, _filename , ww2ModulePath};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function findUserProjectRoot(currentDir : string = process.cwd()) {
|
|
23
|
+
|
|
24
|
+
const packagePath = path.join(currentDir, 'package.json');
|
|
25
|
+
if (existsSync(packagePath)) {
|
|
26
|
+
return currentDir;
|
|
27
|
+
}
|
|
28
|
+
const parentDir = path.dirname(currentDir);
|
|
29
|
+
if (parentDir === currentDir) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return findUserProjectRoot(parentDir);
|
|
33
|
+
}
|
|
34
|
+
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { getWw2Dirname } from "./dirnameTool";
|
|
6
|
+
import { ConfigWW2, readConfig } from "./ww2_config";
|
|
7
|
+
|
|
8
|
+
interface Ww2WebConfig {
|
|
9
|
+
callback: (err: any, data: any) => void;
|
|
10
|
+
wclassname: string;
|
|
11
|
+
url: string;
|
|
12
|
+
title: string;
|
|
13
|
+
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
isKiosk: boolean;
|
|
17
|
+
isMaximize: boolean;
|
|
18
|
+
isDebug: boolean;
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface WW2FileDialogArg {
|
|
23
|
+
callback: (err: any, data: any) => void;
|
|
24
|
+
filter: string;
|
|
25
|
+
ownerClassName: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface WW2ControlWindowsArg {
|
|
29
|
+
wndClassName: string;
|
|
30
|
+
controlcmd: "close" | "move" | "maximize" | "minimize" | "resize" | "check",
|
|
31
|
+
left?: number;
|
|
32
|
+
top?: number;
|
|
33
|
+
height?: number;
|
|
34
|
+
width?: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface Ww2Module {
|
|
38
|
+
openWeb: (arg: Ww2WebConfig) => void;
|
|
39
|
+
openFileDialog: (arg: WW2FileDialogArg) => void;
|
|
40
|
+
openFolderDialog: (arg: WW2FileDialogArg) => void;
|
|
41
|
+
controlWindow: (arg: WW2ControlWindowsArg) => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
export async function getModule() {
|
|
47
|
+
let dirname = getWw2Dirname();
|
|
48
|
+
|
|
49
|
+
let filepath = path.join(
|
|
50
|
+
dirname._dirname,
|
|
51
|
+
"./ww2_addon.node"
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
if (!existsSync(filepath)) {
|
|
55
|
+
|
|
56
|
+
let config = await readConfig();
|
|
57
|
+
if(config == null) throw "user config null";
|
|
58
|
+
filepath = path.join(dirname._dirname, `../../../win_lib/${config.platform}/ww2_addon.node`);
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let myAddon = require(filepath) as Ww2Module;
|
|
63
|
+
return myAddon;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function closeSplash(){
|
|
67
|
+
return getModule().then((module)=>{
|
|
68
|
+
module.controlWindow({
|
|
69
|
+
controlcmd : "close",
|
|
70
|
+
wndClassName : "mysplashclassname"
|
|
71
|
+
})
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export * from "./ww2_server"
|
|
76
|
+
export {findUserProjectRoot } from "./dirnameTool"
|
|
77
|
+
export {readConfig} ;
|
|
78
|
+
export {getWw2Dirname}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { findUserProjectRoot } from "./dirnameTool";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
export type ConfigWW2 = {
|
|
6
|
+
appname: string;
|
|
7
|
+
entry_point: string;
|
|
8
|
+
outdir: string;
|
|
9
|
+
platform: 'Win32' | 'x64'
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const jsonConfigFilePath = "./win_webview2.json";
|
|
14
|
+
export async function readConfig() {
|
|
15
|
+
let userDir = findUserProjectRoot();
|
|
16
|
+
if (userDir == null) return null;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
let str = await readFile(path.join(userDir, jsonConfigFilePath));
|
|
21
|
+
let jsonObj = JSON.parse(str.toString());
|
|
22
|
+
|
|
23
|
+
return jsonObj as ConfigWW2;
|
|
24
|
+
}
|