win_webview2 1.0.13 → 1.1.5
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/README.md +164 -31
- 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,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getWw2Dirname = getWw2Dirname;
|
|
37
|
+
exports.findUserProjectRoot = findUserProjectRoot;
|
|
38
|
+
const node_url_1 = require("node:url");
|
|
39
|
+
const node_path_1 = __importStar(require("node:path"));
|
|
40
|
+
const node_fs_1 = require("node:fs");
|
|
41
|
+
function getWw2Dirname() {
|
|
42
|
+
// Trik deteksi lingkungan
|
|
43
|
+
const _filename = typeof __filename !== 'undefined'
|
|
44
|
+
? __filename
|
|
45
|
+
// @ts-ignore:
|
|
46
|
+
: (0, node_url_1.fileURLToPath)(eval('import.meta.url'));
|
|
47
|
+
const _dirname = typeof __dirname !== 'undefined'
|
|
48
|
+
? __dirname
|
|
49
|
+
: (0, node_path_1.dirname)(_filename);
|
|
50
|
+
let ww2ModulePath = node_path_1.default.join(_dirname, "../../../");
|
|
51
|
+
return { _dirname, _filename, ww2ModulePath };
|
|
52
|
+
}
|
|
53
|
+
function findUserProjectRoot(currentDir = process.cwd()) {
|
|
54
|
+
const packagePath = node_path_1.default.join(currentDir, 'package.json');
|
|
55
|
+
if ((0, node_fs_1.existsSync)(packagePath)) {
|
|
56
|
+
return currentDir;
|
|
57
|
+
}
|
|
58
|
+
const parentDir = node_path_1.default.dirname(currentDir);
|
|
59
|
+
if (parentDir === currentDir) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return findUserProjectRoot(parentDir);
|
|
63
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { getWw2Dirname } from "./dirnameTool";
|
|
2
|
+
import { readConfig } from "./ww2_config";
|
|
3
|
+
interface Ww2WebConfig {
|
|
4
|
+
callback: (err: any, data: any) => void;
|
|
5
|
+
wclassname: string;
|
|
6
|
+
url: string;
|
|
7
|
+
title: string;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
isKiosk: boolean;
|
|
11
|
+
isMaximize: boolean;
|
|
12
|
+
isDebug: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface WW2FileDialogArg {
|
|
15
|
+
callback: (err: any, data: any) => void;
|
|
16
|
+
filter: string;
|
|
17
|
+
ownerClassName: string;
|
|
18
|
+
}
|
|
19
|
+
export interface WW2ControlWindowsArg {
|
|
20
|
+
wndClassName: string;
|
|
21
|
+
controlcmd: "close" | "move" | "maximize" | "minimize" | "resize" | "check";
|
|
22
|
+
left?: number;
|
|
23
|
+
top?: number;
|
|
24
|
+
height?: number;
|
|
25
|
+
width?: number;
|
|
26
|
+
}
|
|
27
|
+
interface Ww2Module {
|
|
28
|
+
openWeb: (arg: Ww2WebConfig) => void;
|
|
29
|
+
openFileDialog: (arg: WW2FileDialogArg) => void;
|
|
30
|
+
openFolderDialog: (arg: WW2FileDialogArg) => void;
|
|
31
|
+
controlWindow: (arg: WW2ControlWindowsArg) => void;
|
|
32
|
+
}
|
|
33
|
+
export declare function getModule(): Promise<Ww2Module>;
|
|
34
|
+
export declare function closeSplash(): Promise<void>;
|
|
35
|
+
export * from "./ww2_server";
|
|
36
|
+
export { findUserProjectRoot } from "./dirnameTool";
|
|
37
|
+
export { readConfig };
|
|
38
|
+
export { getWw2Dirname };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.getWw2Dirname = exports.readConfig = exports.findUserProjectRoot = void 0;
|
|
21
|
+
exports.getModule = getModule;
|
|
22
|
+
exports.closeSplash = closeSplash;
|
|
23
|
+
const node_fs_1 = require("node:fs");
|
|
24
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
25
|
+
const dirnameTool_1 = require("./dirnameTool");
|
|
26
|
+
Object.defineProperty(exports, "getWw2Dirname", { enumerable: true, get: function () { return dirnameTool_1.getWw2Dirname; } });
|
|
27
|
+
const ww2_config_1 = require("./ww2_config");
|
|
28
|
+
Object.defineProperty(exports, "readConfig", { enumerable: true, get: function () { return ww2_config_1.readConfig; } });
|
|
29
|
+
async function getModule() {
|
|
30
|
+
let dirname = (0, dirnameTool_1.getWw2Dirname)();
|
|
31
|
+
let filepath = node_path_1.default.join(dirname._dirname, "./ww2_addon.node");
|
|
32
|
+
if (!(0, node_fs_1.existsSync)(filepath)) {
|
|
33
|
+
let config = await (0, ww2_config_1.readConfig)();
|
|
34
|
+
if (config == null)
|
|
35
|
+
throw "user config null";
|
|
36
|
+
filepath = node_path_1.default.join(dirname._dirname, `../../../win_lib/${config.platform}/ww2_addon.node`);
|
|
37
|
+
}
|
|
38
|
+
let myAddon = require(filepath);
|
|
39
|
+
return myAddon;
|
|
40
|
+
}
|
|
41
|
+
function closeSplash() {
|
|
42
|
+
return getModule().then((module) => {
|
|
43
|
+
module.controlWindow({
|
|
44
|
+
controlcmd: "close",
|
|
45
|
+
wndClassName: "mysplashclassname"
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
__exportStar(require("./ww2_server"), exports);
|
|
50
|
+
var dirnameTool_2 = require("./dirnameTool");
|
|
51
|
+
Object.defineProperty(exports, "findUserProjectRoot", { enumerable: true, get: function () { return dirnameTool_2.findUserProjectRoot; } });
|
|
@@ -0,0 +1,18 @@
|
|
|
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.readConfig = readConfig;
|
|
7
|
+
const promises_1 = require("node:fs/promises");
|
|
8
|
+
const dirnameTool_1 = require("./dirnameTool");
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const jsonConfigFilePath = "./win_webview2.json";
|
|
11
|
+
async function readConfig() {
|
|
12
|
+
let userDir = (0, dirnameTool_1.findUserProjectRoot)();
|
|
13
|
+
if (userDir == null)
|
|
14
|
+
return null;
|
|
15
|
+
let str = await (0, promises_1.readFile)(node_path_1.default.join(userDir, jsonConfigFilePath));
|
|
16
|
+
let jsonObj = JSON.parse(str.toString());
|
|
17
|
+
return jsonObj;
|
|
18
|
+
}
|
|
@@ -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.5",
|
|
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
|
+
}
|