win_webview2 1.0.8 → 1.0.9
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/argtype.ts +8 -1
- package/package.json +1 -1
- package/winWebview2.d.ts +3 -2
- package/winWebview2.mjs +124 -80
- package/win_lib/Win32/CmdWebview2.exe +0 -0
- package/win_lib/Win32/index.bat +3 -0
- package/win_lib/x64/CmdWebview2.exe +0 -0
- package/win_lib/x64/index.bat +3 -0
- package/ww2_builder.mjs +2 -0
- package/ww2_builder_deploy.mjs +27 -18
- package/win_lib/Win32/index.conf +0 -1
- package/win_lib/x64/index.conf +0 -1
- package/ww2_builder_deploy.d.ts +0 -3
package/argtype.ts
CHANGED
|
@@ -8,8 +8,15 @@ export type OpenWebArg = {
|
|
|
8
8
|
maximize: boolean
|
|
9
9
|
title: string
|
|
10
10
|
isDebugMode : boolean
|
|
11
|
+
winClassName : string
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
export type OpenDialogFileArg = {
|
|
14
|
+
export type OpenDialogFileArg = {
|
|
15
|
+
winClassName : string
|
|
14
16
|
filter : string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export type OpenDialogArg = {
|
|
21
|
+
winClassName : string
|
|
15
22
|
}
|
package/package.json
CHANGED
package/winWebview2.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OpenDialogFileArg, OpenWebArg } from "./argtype";
|
|
1
|
+
import { OpenDialogArg, OpenDialogFileArg, OpenWebArg } from "./argtype";
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -14,5 +14,6 @@ export function openDialogFile(arg: OpenDialogFileArg): Promise<string>;
|
|
|
14
14
|
/**
|
|
15
15
|
* Open folder dialog and return selected folder path
|
|
16
16
|
*/
|
|
17
|
-
export function openDialogFolder(): Promise<string>;
|
|
17
|
+
export function openDialogFolder(arg : OpenDialogArg): Promise<string>;
|
|
18
|
+
export function closeWindowWebView(arg : OpenDialogArg): Promise<string>;
|
|
18
19
|
|
package/winWebview2.mjs
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import net from "net"
|
|
3
|
-
let isOncloseSetted = false;
|
|
4
|
-
const prefixWebview = "WINWEBVIEW_";
|
|
5
|
-
const prefixWebviewResult = "WIN_WEBVIEW2_RESULT";
|
|
1
|
+
//@ts-check
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
import { exec, execFile } from "child_process";
|
|
4
|
+
import { readFile } from "fs/promises";
|
|
5
|
+
|
|
6
|
+
import { arch } from "os";
|
|
7
|
+
const arc = arch();
|
|
10
8
|
|
|
11
9
|
function sleep(n = 1000) {
|
|
12
10
|
return new Promise((r, x) => {
|
|
@@ -14,105 +12,151 @@ function sleep(n = 1000) {
|
|
|
14
12
|
})
|
|
15
13
|
}
|
|
16
14
|
|
|
15
|
+
const jsonConfigFilePath = "./win_webview2.json";
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
18
|
*
|
|
20
|
-
* @
|
|
19
|
+
* @returns {Promise<import("./ww2_builder_type").ConfigWW2> }
|
|
21
20
|
*/
|
|
22
|
-
async function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
resultDataFromWebview2 = null;
|
|
21
|
+
async function readConfig() {
|
|
22
|
+
let str = await readFile(jsonConfigFilePath);
|
|
23
|
+
let jsonObj = JSON.parse(str.toString());
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
return jsonObj;
|
|
26
|
+
}
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
async function getExecPath() {
|
|
29
|
+
let jsonConfig = await readConfig();
|
|
30
|
+
let exeFilePath = jsonConfig.appname + ".exe";
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
return resultDataFromWebview2;
|
|
32
|
+
return exeFilePath;
|
|
37
33
|
|
|
38
34
|
}
|
|
39
35
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @param {import("./argtype").OpenWebArg } arg
|
|
39
|
+
*/
|
|
40
|
+
export async function openWeb(arg) {
|
|
41
|
+
let jsonConfig = await readConfig();
|
|
42
|
+
let exeFilePath = jsonConfig.appname + ".exe";
|
|
43
|
+
|
|
44
|
+
let arrOpen = [
|
|
45
|
+
"fun=openwebview",
|
|
46
|
+
"wndClassName=" + arg.winClassName,
|
|
47
|
+
"url=" + arg.url,
|
|
48
|
+
"width=" + arg.width,
|
|
49
|
+
"height=" + arg.height,
|
|
50
|
+
//"kiosk=true",
|
|
51
|
+
//"maximize=true",
|
|
52
|
+
"title=auto",
|
|
53
|
+
//"isDebugMode=true"
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
if (arg.maximize) {
|
|
57
|
+
arrOpen.push("maximize=true");
|
|
58
|
+
}
|
|
45
59
|
|
|
46
|
-
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
let PIPE_CPLUS_SENDER = process.env.PIPE_PATH + "Sender";
|
|
60
|
+
if (arg.kiosk) {
|
|
49
61
|
|
|
62
|
+
arrOpen.push("kiosk=true");
|
|
63
|
+
}
|
|
50
64
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
65
|
+
if (arg.isDebugMode) {
|
|
66
|
+
arrOpen.push("isDebugMode=true");
|
|
67
|
+
}
|
|
54
68
|
|
|
55
|
-
|
|
56
69
|
|
|
57
|
-
client.on('data', (buff) => {
|
|
58
|
-
let data = buff.toString();
|
|
59
70
|
|
|
60
|
-
if (!data.startsWith(prefixWebviewResult)) return false;
|
|
61
|
-
let result = data.substring(prefixWebviewResult.length);
|
|
62
|
-
resultDataFromWebview2 = result;
|
|
63
|
-
});
|
|
64
71
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// }
|
|
72
|
+
execFile(exeFilePath, arrOpen, (err, data) => {
|
|
73
|
+
console.log("error yaaa" + err)
|
|
74
|
+
})
|
|
69
75
|
}
|
|
70
76
|
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
*
|
|
81
|
+
* @param {import("./argtype").OpenDialogFileArg} arg
|
|
82
|
+
* @returns {Promise<string>}
|
|
73
83
|
*/
|
|
74
|
-
function
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
export async function openDialogFile(arg) {
|
|
85
|
+
let exeFilePath = await getExecPath();
|
|
86
|
+
return new Promise((r, x) => {
|
|
87
|
+
execFile(exeFilePath,
|
|
88
|
+
[
|
|
89
|
+
"fun=openFileDialog",
|
|
90
|
+
"wndClassName="+arg.winClassName,
|
|
91
|
+
"filter=" + arg.filter,
|
|
92
|
+
|
|
93
|
+
], (/** @type {any} */ err, /** @type {string} */ data) => {
|
|
94
|
+
|
|
95
|
+
let filepath = "";
|
|
96
|
+
for (let l of data.split("\r\n")) {
|
|
97
|
+
if (l.startsWith("result:")) {
|
|
98
|
+
filepath = l.substring(7, l.length);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
r(filepath);
|
|
103
|
+
})
|
|
84
104
|
})
|
|
85
105
|
}
|
|
86
106
|
|
|
87
107
|
/**
|
|
88
|
-
*
|
|
89
|
-
* @param {import("./argtype").
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
108
|
+
*
|
|
109
|
+
* @param {import("./argtype").OpenDialogArg} arg
|
|
110
|
+
* @returns
|
|
111
|
+
*/
|
|
112
|
+
export async function openDialogFolder(arg) {
|
|
113
|
+
let exeFilePath = await getExecPath();
|
|
114
|
+
return new Promise((r, x) => {
|
|
115
|
+
execFile(exeFilePath,
|
|
116
|
+
[
|
|
117
|
+
"fun=openFolderDialog",
|
|
118
|
+
"wndClassName=" + arg.winClassName,
|
|
119
|
+
|
|
120
|
+
], (
|
|
121
|
+
/** @type {any} */
|
|
122
|
+
err,
|
|
123
|
+
/** @type {string} */
|
|
124
|
+
data
|
|
125
|
+
) => {
|
|
126
|
+
|
|
127
|
+
let filepath = "";
|
|
128
|
+
for (let l of data.split("\r\n")) {
|
|
129
|
+
if (l.startsWith("result:")) {
|
|
130
|
+
filepath = l.substring(7, l.length);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
r(filepath);
|
|
135
|
+
})
|
|
136
|
+
})
|
|
100
137
|
}
|
|
101
|
-
|
|
102
138
|
/**
|
|
103
139
|
*
|
|
104
|
-
* @param {import("./argtype").
|
|
105
|
-
* @returns
|
|
140
|
+
* @param {import("./argtype").OpenDialogArg} arg
|
|
141
|
+
* @returns
|
|
106
142
|
*/
|
|
107
|
-
export function
|
|
108
|
-
|
|
109
|
-
return
|
|
143
|
+
export async function closeWindowWebView(arg) {
|
|
144
|
+
let exeFilePath = await getExecPath();
|
|
145
|
+
return new Promise((r, x) => {
|
|
146
|
+
execFile(exeFilePath,
|
|
147
|
+
[
|
|
148
|
+
"fun=closewindow",
|
|
149
|
+
"wndClassName=" + arg.winClassName,
|
|
150
|
+
|
|
151
|
+
], (
|
|
152
|
+
/** @type {any} */
|
|
153
|
+
err,
|
|
154
|
+
/** @type {string} */
|
|
155
|
+
data) => {
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
r(data);
|
|
159
|
+
})
|
|
160
|
+
})
|
|
110
161
|
}
|
|
111
162
|
|
|
112
|
-
export async function openDialogFolder() {
|
|
113
|
-
let obj = {
|
|
114
|
-
fun: "OpenDialogFolder"
|
|
115
|
-
};
|
|
116
|
-
return waitingResult(obj);
|
|
117
|
-
}
|
|
118
|
-
|
|
Binary file
|
|
Binary file
|
package/ww2_builder.mjs
CHANGED
package/ww2_builder_deploy.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import path from "path";
|
|
|
9
9
|
import { logPrint } from "./ww2_builder_log.mjs";
|
|
10
10
|
import { fileURLToPath } from 'url';
|
|
11
11
|
import rcedit from "rcedit";
|
|
12
|
-
import
|
|
12
|
+
import sharpsToIco from "sharp-ico"
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
const jsonConfigFilePath = "./win_webview2.json";
|
|
@@ -39,7 +39,7 @@ export class WW2Deploy {
|
|
|
39
39
|
await fs.promises.mkdir(folderDist);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
let libFolder = path.join(folderDist,"lib");
|
|
42
|
+
let libFolder = path.join(folderDist, "lib");
|
|
43
43
|
if (!fs.existsSync(libFolder)) {
|
|
44
44
|
await fs.promises.mkdir(libFolder);
|
|
45
45
|
}
|
|
@@ -64,15 +64,15 @@ export class WW2Deploy {
|
|
|
64
64
|
const images = await Promise.all(sizes.map(size =>
|
|
65
65
|
sharp(iconPath)
|
|
66
66
|
.resize(size, size)
|
|
67
|
-
.toFormat('png')
|
|
67
|
+
.toFormat('png')
|
|
68
68
|
));
|
|
69
69
|
|
|
70
70
|
|
|
71
|
-
await sharpsToIco.sharpsToIco(images, outputIcon);
|
|
71
|
+
await sharpsToIco.sharpsToIco(images, outputIcon);
|
|
72
72
|
|
|
73
73
|
console.log('✅ Berhasil membuat icon.ico yang valid untuk rcedit!');
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
async copyExe() {
|
|
@@ -86,15 +86,24 @@ export class WW2Deploy {
|
|
|
86
86
|
logPrint(currentDir);
|
|
87
87
|
|
|
88
88
|
let inputFileExe = path.join(currentDir, "win_lib", this.platform, "CmdWebview2.exe");
|
|
89
|
-
|
|
90
|
-
let outFileExe = path.join(config.outdir, config.appname + ".exe");
|
|
91
|
-
this.outputExeFile = inputFileExe;
|
|
89
|
+
|
|
90
|
+
let outFileExe = path.join(config.outdir, config.appname + ".exe");
|
|
91
|
+
this.outputExeFile = inputFileExe;
|
|
92
92
|
await fs.promises.copyFile(inputFileExe, outFileExe);
|
|
93
93
|
|
|
94
94
|
let inputFileDll = path.join(currentDir, "win_lib", this.platform, "WebView2Loader.dll");
|
|
95
|
-
let outFileDll = path.join(config.outdir,
|
|
95
|
+
let outFileDll = path.join(config.outdir, "WebView2Loader.dll");
|
|
96
96
|
await fs.promises.copyFile(inputFileDll, outFileDll);
|
|
97
97
|
|
|
98
|
+
await (async () => {
|
|
99
|
+
let inputFileDll = jsonConfigFilePath;
|
|
100
|
+
let outFileDll = path.join(config.outdir, "win_webview2.json");
|
|
101
|
+
await fs.promises.copyFile(inputFileDll, outFileDll);
|
|
102
|
+
|
|
103
|
+
})();
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
98
107
|
logPrint("copy file success");
|
|
99
108
|
}
|
|
100
109
|
|
|
@@ -120,25 +129,25 @@ export class WW2Deploy {
|
|
|
120
129
|
this.configObjec = jsonObj;
|
|
121
130
|
}
|
|
122
131
|
|
|
123
|
-
async copyNodeExe(){
|
|
124
|
-
if(this.configObjec == null) return;
|
|
132
|
+
async copyNodeExe() {
|
|
133
|
+
if (this.configObjec == null) return;
|
|
125
134
|
let obj = this.configObjec;
|
|
126
135
|
|
|
127
136
|
let inputNodeExe = process.execPath;
|
|
128
|
-
let outNodeExe = path.join(obj.outdir,"lib","node.exe");
|
|
137
|
+
let outNodeExe = path.join(obj.outdir, "lib", "node.exe");
|
|
129
138
|
await fs.promises.copyFile(inputNodeExe, outNodeExe);
|
|
130
139
|
}
|
|
131
140
|
|
|
132
|
-
async createIndexConf(){
|
|
133
|
-
if(this.configObjec == null) return;
|
|
141
|
+
async createIndexConf() {
|
|
142
|
+
if (this.configObjec == null) return;
|
|
134
143
|
let obj = this.configObjec;
|
|
135
144
|
|
|
136
|
-
let oututFileConf = path.join(obj.outdir,"index.
|
|
145
|
+
let oututFileConf = path.join(obj.outdir, "index.bat");
|
|
137
146
|
|
|
138
|
-
let configCtn =
|
|
139
|
-
await fs.promises.writeFile(oututFileConf,configCtn);
|
|
147
|
+
let configCtn = `.\\\\lib\\\\node.exe ./${obj.entry_point}`
|
|
148
|
+
await fs.promises.writeFile(oututFileConf, configCtn);
|
|
140
149
|
}
|
|
141
|
-
|
|
150
|
+
|
|
142
151
|
static async initWW2() {
|
|
143
152
|
/** @type {ConfigWW2} */
|
|
144
153
|
|
package/win_lib/Win32/index.conf
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
node ../../../../example/express_dev/index.mjs
|
package/win_lib/x64/index.conf
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
node ../../../../example/express_dev/index.mjs
|
package/ww2_builder_deploy.d.ts
DELETED