win_webview2 1.0.9 → 1.0.13

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.
@@ -1,162 +1,160 @@
1
- //@ts-check
2
-
3
- import { exec, execFile } from "child_process";
4
- import { readFile } from "fs/promises";
5
-
6
- import { arch } from "os";
7
- const arc = arch();
8
-
9
- function sleep(n = 1000) {
10
- return new Promise((r, x) => {
11
- setTimeout(r, n);
12
- })
13
- }
14
-
15
- const jsonConfigFilePath = "./win_webview2.json";
16
-
17
- /**
18
- *
19
- * @returns {Promise<import("./ww2_builder_type").ConfigWW2> }
20
- */
21
- async function readConfig() {
22
- let str = await readFile(jsonConfigFilePath);
23
- let jsonObj = JSON.parse(str.toString());
24
-
25
- return jsonObj;
26
- }
27
-
28
- async function getExecPath() {
29
- let jsonConfig = await readConfig();
30
- let exeFilePath = jsonConfig.appname + ".exe";
31
-
32
- return exeFilePath;
33
-
34
- }
35
-
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
- }
59
-
60
- if (arg.kiosk) {
61
-
62
- arrOpen.push("kiosk=true");
63
- }
64
-
65
- if (arg.isDebugMode) {
66
- arrOpen.push("isDebugMode=true");
67
- }
68
-
69
-
70
-
71
-
72
- execFile(exeFilePath, arrOpen, (err, data) => {
73
- console.log("error yaaa" + err)
74
- })
75
- }
76
-
77
-
78
-
79
- /**
80
- *
81
- * @param {import("./argtype").OpenDialogFileArg} arg
82
- * @returns {Promise<string>}
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
- })
104
- })
105
- }
106
-
107
- /**
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
- })
137
- }
138
- /**
139
- *
140
- * @param {import("./argtype").OpenDialogArg} arg
141
- * @returns
142
- */
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
- })
161
- }
162
-
1
+ import { execFile } from "node:child_process";
2
+ import { readFile } from "node:fs/promises";
3
+
4
+ export type OpenWebArg = {
5
+ url: string
6
+ width: number
7
+ height: number
8
+ kiosk: boolean
9
+ maximize: boolean
10
+ title: string
11
+ isDebugMode : boolean
12
+ winClassName : string
13
+ }
14
+
15
+ export type OpenDialogFileArg = {
16
+ winClassName : string
17
+ filter : string
18
+ }
19
+
20
+
21
+ export type OpenDialogArg = {
22
+ winClassName : string
23
+ }
24
+
25
+ const jsonConfigFilePath = "./win_webview2.json";
26
+ async function readConfig() {
27
+ let str = await readFile(jsonConfigFilePath);
28
+ let jsonObj = JSON.parse(str.toString());
29
+
30
+ return jsonObj;
31
+ }
32
+
33
+ async function getExecPath() {
34
+ let jsonConfig = await readConfig();
35
+ let exeFilePath = jsonConfig.appname + ".exe";
36
+
37
+ return exeFilePath;
38
+
39
+ }
40
+
41
+ export async function openWeb(arg : OpenWebArg) {
42
+ let jsonConfig = await readConfig();
43
+ let exeFilePath = jsonConfig.appname + ".exe";
44
+
45
+ let arrOpen = [
46
+ "fun=openwebview",
47
+ "wndClassName=" + arg.winClassName,
48
+ "url=" + arg.url,
49
+ "width=" + arg.width,
50
+ "height=" + arg.height,
51
+ //"kiosk=true",
52
+ //"maximize=true",
53
+ "title=auto",
54
+ //"isDebugMode=true"
55
+ ];
56
+
57
+ if (arg.maximize) {
58
+ arrOpen.push("maximize=true");
59
+ }
60
+
61
+ if (arg.kiosk) {
62
+
63
+ arrOpen.push("kiosk=true");
64
+ }
65
+
66
+ if (arg.isDebugMode) {
67
+ arrOpen.push("isDebugMode=true");
68
+ }
69
+
70
+
71
+
72
+
73
+ execFile(exeFilePath, arrOpen, (err, data) => {
74
+ console.log( err)
75
+ })
76
+ }
77
+
78
+ export async function openDialogFile(arg : OpenDialogFileArg) {
79
+ let exeFilePath = await getExecPath();
80
+ return new Promise((r, x) => {
81
+ execFile(exeFilePath,
82
+ [
83
+ "fun=openFileDialog",
84
+ "wndClassName="+arg.winClassName,
85
+ "filter=" + arg.filter,
86
+
87
+ ], (/** @type {any} */ err, /** @type {string} */ data) => {
88
+
89
+ let filepath = "";
90
+ for (let l of data.split("\r\n")) {
91
+ if (l.startsWith("result:")) {
92
+ filepath = l.substring(7, l.length);
93
+ }
94
+ }
95
+
96
+ r(filepath);
97
+ })
98
+ })
99
+ }
100
+
101
+ export async function openDialogFolder(arg : OpenDialogArg) {
102
+ let exeFilePath = await getExecPath();
103
+ return new Promise((r, x) => {
104
+ execFile(exeFilePath,
105
+ [
106
+ "fun=openFolderDialog",
107
+ "wndClassName=" + arg.winClassName,
108
+
109
+ ], (
110
+ /** @type {any} */
111
+ err,
112
+ /** @type {string} */
113
+ data
114
+ ) => {
115
+
116
+ let filepath = "";
117
+ for (let l of data.split("\r\n")) {
118
+ if (l.startsWith("result:")) {
119
+ filepath = l.substring(7, l.length);
120
+ }
121
+ }
122
+
123
+ r(filepath);
124
+ })
125
+ })
126
+ }
127
+
128
+ export async function controlWindow(arg : {
129
+ winClassName: string,
130
+ controlcmd : "close" | "maximize" | "minimize" | "move" | "resize",
131
+ left : number,
132
+ top : number,
133
+ width : number,
134
+ height : number,
135
+ }) {
136
+ let exeFilePath = await getExecPath();
137
+ return new Promise((r, x) => {
138
+ execFile(exeFilePath,
139
+ [
140
+ "fun=controlwindow",
141
+ "wndClassName=" + arg.winClassName,
142
+ "controlcmd="+arg.controlcmd,
143
+
144
+ "left="+arg.left,
145
+ "top="+arg.top,
146
+ "width="+arg.width,
147
+ "height="+arg.height,
148
+
149
+
150
+ ], (
151
+ /** @type {any} */
152
+ err,
153
+ /** @type {string} */
154
+ data) => {
155
+
156
+
157
+ r(data);
158
+ })
159
+ })
160
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "CommonJS",
5
+ "declaration": true,
6
+ "rootDir": "./tsSrc",
7
+ "outDir": "./tsDist",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true
11
+ },
12
+ "include": ["tsSrc"]
13
+ }
Binary file
Binary file
Binary file
Binary file
package/argtype.ts DELETED
@@ -1,22 +0,0 @@
1
-
2
-
3
- export type OpenWebArg = {
4
- url: string
5
- width: number
6
- height: number
7
- kiosk: boolean
8
- maximize: boolean
9
- title: string
10
- isDebugMode : boolean
11
- winClassName : string
12
- }
13
-
14
- export type OpenDialogFileArg = {
15
- winClassName : string
16
- filter : string
17
- }
18
-
19
-
20
- export type OpenDialogArg = {
21
- winClassName : string
22
- }
package/winWebview2.d.ts DELETED
@@ -1,19 +0,0 @@
1
- import { OpenDialogArg, OpenDialogFileArg, OpenWebArg } from "./argtype";
2
-
3
-
4
- /**
5
- * Open WebView window via IPC
6
- */
7
- export function openWeb(arg: OpenWebArg): void;
8
-
9
- /**
10
- * Open file dialog and return selected file path
11
- */
12
- export function openDialogFile(arg: OpenDialogFileArg): Promise<string>;
13
-
14
- /**
15
- * Open folder dialog and return selected folder path
16
- */
17
- export function openDialogFolder(arg : OpenDialogArg): Promise<string>;
18
- export function closeWindowWebView(arg : OpenDialogArg): Promise<string>;
19
-
package/ww2_builder.mjs DELETED
@@ -1,73 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
-
4
- import prompts from "prompts";
5
- import fs from 'fs'
6
- import sharp from "sharp"
7
- import path from "path";
8
- import { logPrint } from "./ww2_builder_log.mjs";
9
- import { WW2Deploy } from "./ww2_builder_deploy.mjs";
10
-
11
-
12
- /** @typedef {import("./ww2_builder_type").ConfigWW2} ConfigWW2 */
13
-
14
- /**
15
- *
16
- * @param {string} msg
17
- * @param {string[]} list
18
- * @returns {Promise<string>}
19
- */
20
- async function askWhitList(msg, list) {
21
- let p = await prompts([
22
- {
23
- type: 'select', // Tipe pertanyaan list (menu dropdown)
24
- name: 'hasilnya',
25
- message: msg,
26
- choices: list.map((val) => {
27
- let r = {
28
- title: val,
29
- value: val
30
- }
31
- return r
32
- }), // Opsi
33
- },
34
- ]);
35
- return p.hasilnya;
36
- }
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
- async function run() {
46
- console.log("v-22");
47
-
48
- let p = await askWhitList("menu", [
49
- "init_webview2",
50
- "deploy",
51
- "back",
52
- "exit"
53
- ]);
54
-
55
- if (p == "init_webview2") {
56
-
57
- await WW2Deploy.initWW2();
58
-
59
- } else if (p == "deploy") {
60
- await WW2Deploy.startDeploy();
61
- }
62
-
63
-
64
-
65
- if (p == "exit") {
66
- return;
67
- }
68
-
69
- run();
70
- }
71
-
72
-
73
- run();
@@ -1,7 +0,0 @@
1
-
2
- export type ConfigWW2={
3
- appname : string,
4
- icon_path : string,
5
- entry_point : string,
6
- outdir : string,
7
- }