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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "win_webview2",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/nnttoo/win_webview2"
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
- /** @type {string | null} */
8
- let resultDataFromWebview2 = "";
9
- let resultInUse = false;
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
- * @param {object } arg
19
+ * @returns {Promise<import("./ww2_builder_type").ConfigWW2> }
21
20
  */
22
- async function waitingResult(arg) {
23
- if (resultInUse) return "";
24
- resultInUse = true;
25
-
26
- resultDataFromWebview2 = null;
21
+ async function readConfig() {
22
+ let str = await readFile(jsonConfigFilePath);
23
+ let jsonObj = JSON.parse(str.toString());
27
24
 
28
- var objstr = JSON.stringify(arg);
29
- sendToPipe(`${prefixWebview}JSON` + objstr);
25
+ return jsonObj;
26
+ }
30
27
 
31
- while (resultDataFromWebview2 == null) {
32
- await sleep(200);
33
- }
28
+ async function getExecPath() {
29
+ let jsonConfig = await readConfig();
30
+ let exeFilePath = jsonConfig.appname + ".exe";
34
31
 
35
- resultInUse = false;
36
- return resultDataFromWebview2;
32
+ return exeFilePath;
37
33
 
38
34
  }
39
35
 
40
-
41
-
42
- async function createPipe() {
43
-
44
- // ini akan terhubung terus menerus
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
- /** @type {string} */
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
- let client = net.createConnection(PIPE_CPLUS_SENDER, () => {
52
- console.log('Anak terhubung ke Named Pipe!');
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
- // while(true){
66
- // await sleep();
67
- // sendToPipe("ping");
68
- // }
72
+ execFile(exeFilePath, arrOpen, (err, data) => {
73
+ console.log("error yaaa" + err)
74
+ })
69
75
  }
70
76
 
71
- /**
72
- * @param {string} msg
77
+
78
+
79
+ /**
80
+ *
81
+ * @param {import("./argtype").OpenDialogFileArg} arg
82
+ * @returns {Promise<string>}
73
83
  */
74
- function sendToPipe(msg) {
75
-
76
- /** @type {any} */
77
- var PIPE_CPLUS_Reader = process.env.PIPE_PATH;
78
- let client = net.createConnection(PIPE_CPLUS_Reader, () => {
79
- console.log("PIPE_CPLUS_Reader terhubung")
80
- client.write(msg);
81
- });
82
- client.on("error",(e)=>{
83
- console.log("errornya apa : ", e );
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").OpenWebArg } arg
90
- */
91
- export function openWeb(arg) {
92
- if (!isOncloseSetted) {
93
- isOncloseSetted = true;
94
- createPipe();
95
- }
96
-
97
- arg["fun"] = "OpenWeb";
98
- var objstr = JSON.stringify(arg);
99
- sendToPipe(`${prefixWebview}JSON` + objstr);
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").OpenDialogFileArg} arg
105
- * @returns {Promise<string>}
140
+ * @param {import("./argtype").OpenDialogArg} arg
141
+ * @returns
106
142
  */
107
- export function openDialogFile(arg) {
108
- arg["fun"] = "OpenDialogFIle";
109
- return waitingResult(arg);
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
@@ -0,0 +1,3 @@
1
+ @echo off
2
+ set exeFileDir=%cd%
3
+ CmdWebview2.exe fun=openwebview url=https://google.com width=900 height=600 title=auto wndClassName=aplikasiWebView
Binary file
@@ -0,0 +1,3 @@
1
+ @echo off
2
+ set exeFileDir=%cd%
3
+ CmdWebview2.exe fun=openwebview url=https://google.com width=900 height=600 title=auto wndClassName=aplikasiWebView
package/ww2_builder.mjs CHANGED
@@ -43,6 +43,8 @@ async function askWhitList(msg, list) {
43
43
 
44
44
 
45
45
  async function run() {
46
+ console.log("v-22");
47
+
46
48
  let p = await askWhitList("menu", [
47
49
  "init_webview2",
48
50
  "deploy",
@@ -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 sharpsToIco from "sharp-ico"
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, "WebView2Loader.dll");
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.conf");
145
+ let oututFileConf = path.join(obj.outdir, "index.bat");
137
146
 
138
- let configCtn = `./lib/node.exe ./${obj.entry_point}`
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
 
@@ -1 +0,0 @@
1
- node ../../../../example/express_dev/index.mjs
@@ -1 +0,0 @@
1
- node ../../../../example/express_dev/index.mjs
@@ -1,3 +0,0 @@
1
- export class WW2Deploy {
2
- static startDeploy(): Promise<void>;
3
- }