win_webview2 1.1.15 → 1.1.17

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,3 +1,4 @@
1
+ import { WwvPlatFrom } from "./ww2_config";
1
2
  interface Ww2WebConfig {
2
3
  callback: (err: any, data: any) => void;
3
4
  wclassname: string;
@@ -28,5 +29,6 @@ interface Ww2Module {
28
29
  openFolderDialog: (arg: WW2FileDialogArg) => void;
29
30
  controlWindow: (arg: WW2ControlWindowsArg) => void;
30
31
  }
32
+ export declare function downloadModuleAndExtract(platform: WwvPlatFrom): Promise<void>;
31
33
  export declare function getModule(): Promise<Ww2Module>;
32
34
  export {};
@@ -3,22 +3,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.downloadModuleAndExtract = downloadModuleAndExtract;
6
7
  exports.getModule = getModule;
7
8
  const node_path_1 = __importDefault(require("node:path"));
8
9
  const dirnameTool_1 = require("./dirnameTool");
9
- const ww2_config_1 = require("./ww2_config");
10
10
  const node_fs_1 = require("node:fs");
11
11
  const downloader_1 = require("./downloader");
12
12
  const promises_1 = require("node:fs/promises");
13
- function getLibFilePath(libName, platform) {
14
- let modulePath = (0, dirnameTool_1.getWWVNodeModuleFolder)();
15
- modulePath = node_path_1.default.join(modulePath, "win_lib", platform, libName);
16
- return modulePath;
13
+ const adm_zip_1 = __importDefault(require("adm-zip"));
14
+ function extractZip(zipPath, targetDir) {
15
+ try {
16
+ const zip = new adm_zip_1.default(zipPath);
17
+ zip.extractAllTo(targetDir, true);
18
+ console.log(`✅ Extract done to: ${targetDir}`);
19
+ }
20
+ catch (err) {
21
+ console.error("❌ Error extract:", err);
22
+ }
17
23
  }
18
- const binFileVersion = "1.1.14";
19
- async function downloadModuleFile(libname, platform) {
20
- let filePath = getLibFilePath(libname, platform);
21
- let url = `https://github.com/nnttoo/win_webview2/releases/download/${binFileVersion}_${platform}/${libname}`;
24
+ ;
25
+ const binFileVersion = "1.1.16";
26
+ async function downloadModuleFile(platform) {
27
+ let modulePath = (0, dirnameTool_1.getWWVNodeModuleFolder)();
28
+ let winlibPath = node_path_1.default.join(modulePath, "win_lib");
29
+ let fileName = platform + ".zip";
30
+ let filePath = node_path_1.default.join(winlibPath, fileName);
31
+ let url = `https://github.com/nnttoo/win_webview2/releases/download/${binFileVersion}/${fileName}`;
22
32
  console.log("Bin File Version : " + binFileVersion);
23
33
  console.log("downloading :\n", url);
24
34
  try {
@@ -29,17 +39,25 @@ async function downloadModuleFile(libname, platform) {
29
39
  }
30
40
  await (0, downloader_1.downloadFile)(url, filePath);
31
41
  }
32
- async function downloadModule(platform) {
33
- await downloadModuleFile("ww2_addon.node", platform);
34
- await downloadModuleFile("WebView2Loader.dll", platform);
35
- await downloadModuleFile("exeOpenner.exe", platform);
36
- await downloadModuleFile("splash.png", platform);
42
+ async function downloadModuleAndExtract(platform) {
43
+ await downloadModuleFile(platform);
44
+ let modulePath = (0, dirnameTool_1.getWWVNodeModuleFolder)();
45
+ let winlibPath = node_path_1.default.join(modulePath, "win_lib");
46
+ let fileName = platform + ".zip";
47
+ let filePath = node_path_1.default.join(winlibPath, fileName);
48
+ extractZip(filePath, node_path_1.default.join(winlibPath, platform));
49
+ await (0, promises_1.unlink)(filePath);
50
+ }
51
+ function getCurrentPlatform() {
52
+ let result = "x64";
53
+ if (process.arch != 'x64') {
54
+ result = "x86";
55
+ }
56
+ return result;
37
57
  }
38
58
  async function getModule() {
39
59
  let addOnName = "ww2_addon.node";
40
- let config = await (0, ww2_config_1.readConfig)();
41
- if (config == null)
42
- throw "cannot read config";
60
+ let platform = getCurrentPlatform();
43
61
  let filepath = (() => {
44
62
  let userFolder = (0, dirnameTool_1.findUserProjectRoot)();
45
63
  if (userFolder == null)
@@ -53,13 +71,13 @@ async function getModule() {
53
71
  if (filepath != null)
54
72
  return filepath;
55
73
  let wwvModulePath = (0, dirnameTool_1.getWWVNodeModuleFolder)();
56
- let r = node_path_1.default.join(wwvModulePath, `win_lib/${config.platform}/ww2_addon.node`);
74
+ let r = node_path_1.default.join(wwvModulePath, `win_lib/${platform}/ww2_addon.node`);
57
75
  return r;
58
76
  })();
59
77
  if (filepath == null)
60
78
  throw "file path is null";
61
79
  if (!(0, node_fs_1.existsSync)(filepath)) {
62
- await downloadModule(config.platform);
80
+ await downloadModuleAndExtract(platform);
63
81
  }
64
82
  let myAddon = require(filepath);
65
83
  return myAddon;
@@ -1,8 +1,9 @@
1
1
  import { getWWVNodeModuleFolder } from "./dirnameTool";
2
2
  import { readConfig } from "./ww2_config";
3
+ import { downloadModuleAndExtract } from "./downloadModule";
3
4
  export declare function closeSplash(): Promise<void>;
4
5
  export * from "./downloadModule";
5
6
  export * from "./ww2_server";
6
7
  export { findUserProjectRoot } from "./dirnameTool";
7
8
  export { readConfig };
8
- export { getWWVNodeModuleFolder };
9
+ export { getWWVNodeModuleFolder, downloadModuleAndExtract };
@@ -14,13 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.getWWVNodeModuleFolder = exports.readConfig = exports.findUserProjectRoot = void 0;
17
+ exports.downloadModuleAndExtract = exports.getWWVNodeModuleFolder = exports.readConfig = exports.findUserProjectRoot = void 0;
18
18
  exports.closeSplash = closeSplash;
19
19
  const dirnameTool_1 = require("./dirnameTool");
20
20
  Object.defineProperty(exports, "getWWVNodeModuleFolder", { enumerable: true, get: function () { return dirnameTool_1.getWWVNodeModuleFolder; } });
21
21
  const ww2_config_1 = require("./ww2_config");
22
22
  Object.defineProperty(exports, "readConfig", { enumerable: true, get: function () { return ww2_config_1.readConfig; } });
23
23
  const downloadModule_1 = require("./downloadModule");
24
+ Object.defineProperty(exports, "downloadModuleAndExtract", { enumerable: true, get: function () { return downloadModule_1.downloadModuleAndExtract; } });
24
25
  function closeSplash() {
25
26
  return (0, downloadModule_1.getModule)().then((module) => {
26
27
  module.controlWindow({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "win_webview2",
3
- "version": "1.1.15",
3
+ "version": "1.1.17",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/nnttoo/win_webview2"
@@ -28,12 +28,14 @@
28
28
  "build_node_watch": "npm run build_node -- --watch",
29
29
  "build_browser": "tsc -p ./src/srcBrowser/tsconfig.json",
30
30
  "build_browser_watch": "npm run build_browser -- --watch",
31
- "build_all" : "npm run build_node && npm run build_browser",
32
- "copy_dll": "tsx ./srcInternal/copyDll.ts"
31
+ "build_all": "npm run build_node && npm run build_browser",
32
+ "copy_dll": "tsx ./srcInternal/copyDll.ts",
33
+ "Clean_WinLib": "rm -rf ./win_lib"
33
34
  },
34
35
  "author": "",
35
36
  "license": "ISC",
36
37
  "dependencies": {
38
+ "adm-zip": "^0.5.17",
37
39
  "comment-json": "^4.6.2",
38
40
  "degit": "^2.8.4",
39
41
  "express": "^5.2.1",
@@ -41,6 +43,7 @@
41
43
  "tsx": "^4.21.0"
42
44
  },
43
45
  "devDependencies": {
46
+ "@types/adm-zip": "^0.5.8",
44
47
  "@types/express": "^5.0.6",
45
48
  "@types/node": "^25.5.2",
46
49
  "@types/prompts": "^2.4.9",
@@ -1,13 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "esnext",
5
- "declaration": true,
6
- "rootDir": "./",
7
- "outDir": "../../dist/browser",
8
- "strict": true,
9
- "esModuleInterop": true,
10
- "skipLibCheck": true
11
- },
12
- "include": ["./**/*"]
13
- }
@@ -1,47 +0,0 @@
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
- }
@@ -1,105 +0,0 @@
1
-
2
- import { exec, execSync } from "child_process";
3
- import prompts from "prompts";
4
-
5
-
6
- function runCommand(command: string) {
7
- try {
8
- const currentShell = process.platform === 'win32' ? 'cmd.exe' : '/bin/sh';
9
- execSync(command, { stdio: 'inherit', shell: currentShell, killSignal: "SIGINT" });
10
- } catch (error) {
11
- console.error(`Command Error: ${command}`);
12
- process.exit();
13
- }
14
- }
15
-
16
- const jsonConfigFilePath = "./win_webview2.json";
17
-
18
-
19
- interface ChoiseItem {
20
- fun: () => any;
21
- description: string;
22
- }
23
-
24
- export type WW2Choise = { [key: string]: ChoiseItem }
25
-
26
- let ww2Choise: WW2Choise = {
27
-
28
- "ww2_typescript": {
29
- description: "init win_webview2",
30
- fun: async () => {
31
- runCommand('npx degit nnttoo/win_webview2/example/ww2_typescript#master ww2_typescript')
32
- }
33
- }
34
- }
35
-
36
-
37
- type promChoise = {
38
- title: string,
39
- value: () => any,
40
- description: string,
41
- disable?: boolean
42
- }
43
-
44
- interface ListFromGithub {
45
- path: string,
46
- desctiption: string
47
- }
48
-
49
- async function fetchFromList() {
50
- try {
51
- console.log("get list example")
52
- let url = "https://raw.githubusercontent.com/nnttoo/win_webview2/refs/heads/master/example/listexample.json";
53
- let txt = await fetch(url);
54
- let content = await txt.text();
55
- let obj = JSON.parse(content) as ListFromGithub[];
56
-
57
- for (let item of obj) {
58
-
59
- ww2Choise[item.path] = {
60
- description: item.desctiption,
61
- fun: () => {
62
- runCommand(`npx degit nnttoo/win_webview2/example/${item.path}#master ${item.path}`);
63
- }
64
- }
65
-
66
- }
67
- } catch (error) {
68
-
69
- }
70
-
71
-
72
- }
73
-
74
- export async function ww2Init() {
75
- await fetchFromList();
76
-
77
- const response = await prompts({
78
- type: 'select',
79
- name: 'menu',
80
- message: 'Pick one example',
81
- instructions: '(Use arrow keys to navigate, press enter to select)',
82
- choices: (() => {
83
- let result: promChoise[] = [];
84
-
85
- for (let item in ww2Choise) {
86
- let val = ww2Choise[item];
87
-
88
- result.push({
89
- title: item,
90
- value: val.fun,
91
- description: val.description,
92
- });
93
- }
94
- return result;
95
-
96
-
97
- })(),
98
- });
99
- if (response && response.menu) {
100
-
101
- await response.menu();
102
- }
103
-
104
-
105
- }
@@ -1,96 +0,0 @@
1
-
2
- import prompts from 'prompts';
3
- import { ww2Init } from './builder_init';
4
- import { readUserScripts } from './userExec';
5
- import { getWWvVersion } from './versiontool';
6
-
7
- interface ChoiseItem {
8
- fun: () => any;
9
- description: string;
10
- }
11
-
12
- export type WW2Choise = { [key: string]: ChoiseItem }
13
-
14
- let ww2Choise: WW2Choise = {
15
-
16
- "init_win_webview2": {
17
- description: "init win_webview2",
18
- fun: async () => {
19
- await ww2Init();
20
- }
21
- }
22
- }
23
-
24
- type promChoise = {
25
- title: string,
26
- value: () => any,
27
- description: string,
28
- disable? :boolean
29
- }
30
-
31
- export async function buildForServer() {
32
- let version = await getWWvVersion();
33
- console.log("win_webview2 : " + version);
34
-
35
- let userChoise = await readUserScripts();
36
- if(userChoise != null){
37
- ww2Choise = {
38
- ...ww2Choise,
39
- ...userChoise
40
- }
41
- }
42
-
43
- const response = await prompts({
44
- type: 'select',
45
- name: 'menu',
46
- message: 'Pick one',
47
- instructions: '(Use arrow keys to navigate, press enter to select)',
48
- choices: (() => {
49
- let result: promChoise[] = [];
50
-
51
- for (let item in ww2Choise) {
52
- let val = ww2Choise[item];
53
-
54
- result.push({
55
- title: item,
56
- value: val.fun,
57
- description : val.description,
58
- });
59
- }
60
- return result;
61
-
62
-
63
- })(),
64
- });
65
- if (response && response.menu) {
66
-
67
- await response.menu();
68
- }
69
- }
70
- const args = process.argv.slice(2);
71
-
72
-
73
- if (args.length > 0) {
74
-
75
- let argument = args[0] as string;
76
- if (argument.startsWith("--")) {
77
- argument = argument.substring(2);
78
- }
79
-
80
- console.log(argument);
81
- if (ww2Choise[argument]) {
82
- ww2Choise[argument].fun();
83
- }
84
-
85
- } else {
86
-
87
- buildForServer();
88
- }
89
-
90
- process.on('SIGINT', () => {
91
- console.log('\n[Sinyal SIGINT Terdeteksi]');
92
- console.log('User menekan Ctrl+C. Membersihkan data...');
93
-
94
- // Anda harus memanggil exit secara manual jika menggunakan listener ini
95
- process.exit(0);
96
- });
@@ -1,54 +0,0 @@
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
- }
@@ -1,26 +0,0 @@
1
- import path from "node:path";
2
- import { getWWVNodeModuleFolder } from "../tsExport/dirnameTool";
3
- import { readFile } from "node:fs/promises";
4
-
5
-
6
- /** Ini hanya bisa dipakai dengan cara tidak bundle
7
- karena package json mungkin gak ada
8
- */
9
- export async function getWWvVersion(){
10
- let result = "";
11
-
12
- try {
13
- let wwvModulePath = getWWVNodeModuleFolder();
14
- let jsonPath = path.join(wwvModulePath,"package.json");
15
- let jsontxt = await readFile(jsonPath,"utf-8");
16
- let jsonObj = JSON.parse(jsontxt) as { version : string};
17
-
18
- result = jsonObj.version;
19
-
20
- } catch (error) {
21
- console.log(error);
22
- }
23
-
24
- return result;
25
- }
26
-
@@ -1,45 +0,0 @@
1
- import path from 'node:path';
2
- import { existsSync } from 'node:fs';
3
-
4
-
5
-
6
- function findUserProjectRootRecrusive(currentDir : string = process.cwd()) {
7
-
8
- const packagePath = path.join(currentDir, 'package.json');
9
- if (existsSync(packagePath)) {
10
- return currentDir;
11
- }
12
- const parentDir = path.dirname(currentDir);
13
- if (parentDir === currentDir) {
14
- return null;
15
- }
16
- return findUserProjectRootRecrusive(parentDir);
17
- }
18
-
19
- export function findUserProjectRoot() {
20
-
21
- // - Deployed Condition
22
- const packagePath = path.join(path.dirname(process.execPath), 'package.json');
23
- if (existsSync(packagePath)) {
24
- return path.dirname(packagePath);
25
- }
26
- return findUserProjectRootRecrusive(process.cwd());
27
- }
28
-
29
- export function getWWVNodeModuleFolder(){
30
- let userRootProject = findUserProjectRoot();
31
- if(userRootProject == null) throw "root project user not found";
32
-
33
- let nodeModuleFolder = path.join(userRootProject,"node_modules/win_webview2");
34
-
35
- if(!existsSync(nodeModuleFolder)){
36
- if(userRootProject.endsWith("win_webview2")){
37
- console.log("on source win_webview2folder \n\n")
38
-
39
- let npath = path.join(nodeModuleFolder,"../../");
40
- nodeModuleFolder = npath;
41
- }
42
-
43
- }
44
- return nodeModuleFolder;
45
- }
@@ -1,128 +0,0 @@
1
- import path from "node:path";
2
- import { findUserProjectRoot, getWWVNodeModuleFolder } from "./dirnameTool";
3
- import { readConfig, WwfBinFileName, WwvPlatFrom } from "./ww2_config";
4
- import { existsSync } from "node:fs";
5
- import { config } from "node:process";
6
- import { getWWvVersion } from "../builder/versiontool";
7
- import { downloadFile } from "./downloader";
8
- import { mkdir } from "node:fs/promises";
9
-
10
-
11
-
12
-
13
- interface Ww2WebConfig {
14
- callback: (err: any, data: any) => void;
15
- wclassname: string;
16
- url: string;
17
- title: string;
18
-
19
- width: number;
20
- height: number;
21
- isKiosk: boolean;
22
- isMaximize: boolean;
23
- isDebug: boolean;
24
-
25
- }
26
-
27
- interface WW2FileDialogArg {
28
- callback: (err: any, data: any) => void;
29
- filter: string;
30
- ownerClassName: string;
31
- }
32
-
33
-
34
-
35
- export interface WW2ControlWindowsArg {
36
- wndClassName: string;
37
- controlcmd: "close" | "move" | "maximize" | "minimize" | "resize" | "check",
38
- left?: number;
39
- top?: number;
40
- height?: number;
41
- width?: number;
42
- }
43
-
44
-
45
-
46
-
47
- interface Ww2Module {
48
- openWeb: (arg: Ww2WebConfig) => void;
49
- openFileDialog: (arg: WW2FileDialogArg) => void;
50
- openFolderDialog: (arg: WW2FileDialogArg) => void;
51
- controlWindow: (arg: WW2ControlWindowsArg) => void;
52
- }
53
-
54
- function getLibFilePath(libName: WwfBinFileName, platform: WwvPlatFrom) {
55
- let modulePath = getWWVNodeModuleFolder();
56
- modulePath = path.join(modulePath, "win_lib", platform, libName);
57
-
58
- return modulePath;
59
-
60
- }
61
-
62
- const binFileVersion = "1.1.14";
63
-
64
- async function downloadModuleFile(libname: WwfBinFileName, platform: WwvPlatFrom) {
65
- let filePath = getLibFilePath(libname, platform);
66
- let url = `https://github.com/nnttoo/win_webview2/releases/download/${binFileVersion}_${platform}/${libname}`;
67
- console.log("Bin File Version : " + binFileVersion);
68
- console.log("downloading :\n",url);
69
- try {
70
-
71
- let dir = path.dirname(filePath);
72
- await mkdir(dir,{recursive : true});
73
- } catch (error) {
74
-
75
- }
76
-
77
- await downloadFile(url,filePath);
78
- }
79
-
80
- async function downloadModule(platform: WwvPlatFrom) {
81
- await downloadModuleFile("ww2_addon.node", platform);
82
- await downloadModuleFile("WebView2Loader.dll", platform);
83
- await downloadModuleFile("exeOpenner.exe", platform);
84
- await downloadModuleFile("splash.png", platform);
85
- }
86
-
87
-
88
-
89
- export async function getModule() {
90
- let addOnName = "ww2_addon.node";
91
-
92
- let config = await readConfig();
93
- if (config == null) throw "cannot read config";
94
-
95
-
96
- let filepath = (() => {
97
-
98
- let userFolder = findUserProjectRoot();
99
- if (userFolder == null) return null;
100
- let r = path.join(
101
- userFolder,
102
- addOnName
103
- );
104
-
105
- if (!existsSync(r)) return null;
106
-
107
- return r;
108
-
109
- })();
110
-
111
- filepath = await (async () => {
112
- if (filepath != null) return filepath;
113
- let wwvModulePath = getWWVNodeModuleFolder();
114
- let r = path.join(wwvModulePath, `win_lib/${config.platform}/ww2_addon.node`);
115
-
116
- return r;
117
-
118
-
119
- })();
120
-
121
- if (filepath == null) throw "file path is null";
122
- if (!existsSync(filepath)) {
123
- await downloadModule(config.platform);
124
- }
125
-
126
- let myAddon = require(filepath) as Ww2Module;
127
- return myAddon;
128
- }
@@ -1,51 +0,0 @@
1
- import * as http from 'http';
2
- import * as https from 'https';
3
- import * as fs from 'fs';
4
- import { URL } from 'url';
5
-
6
- /**
7
- * Fungsi download native dengan TypeScript
8
- * @param src - URL sumber file
9
- * @param filePath - Path lengkap tujuan penyimpanan
10
- */
11
- export async function downloadFile(src: string, filePath: string): Promise<string> {
12
- return new Promise((resolve, reject) => {
13
- const url = new URL(src);
14
- const protocol = url.protocol === 'https:' ? https : http;
15
-
16
- // Gunakan flags 'w' untuk memastikan file dibuka untuk ditulisi
17
- const file = fs.createWriteStream(filePath, { flags: 'w' });
18
-
19
- protocol.get(src, (response: http.IncomingMessage) => {
20
- const { statusCode } = response;
21
-
22
- if (statusCode && statusCode >= 300 && statusCode < 400 && response.headers.location) {
23
- file.destroy(); // Hancurkan stream sebelum redirect
24
- return resolve(downloadFile(response.headers.location, filePath));
25
- }
26
-
27
- if (statusCode !== 200) {
28
- file.destroy();
29
- fs.unlink(filePath, () => {});
30
- return reject(new Error(`Download gagal! Status: ${statusCode}`));
31
- }
32
-
33
- response.pipe(file);
34
-
35
- // GANTI DISINI: Gunakan event 'close' bukan 'finish'
36
- file.on('close', () => {
37
- resolve(filePath);
38
- });
39
-
40
- file.on('error', (err: Error) => {
41
- fs.unlink(filePath, () => {});
42
- reject(err);
43
- });
44
-
45
- }).on('error', (err: Error) => {
46
- file.destroy();
47
- fs.unlink(filePath, () => {});
48
- reject(err);
49
- });
50
- });
51
- }
@@ -1,22 +0,0 @@
1
- import { getWWVNodeModuleFolder } from "./dirnameTool";
2
- import { readConfig } from "./ww2_config";
3
- import { getModule } from "./downloadModule";
4
-
5
-
6
-
7
- export function closeSplash(){
8
- return getModule().then((module)=>{
9
- module.controlWindow({
10
- controlcmd : "close",
11
- wndClassName : "mysplashclassname"
12
- })
13
- });
14
- }
15
-
16
-
17
- export * from "./downloadModule"
18
-
19
- export * from "./ww2_server"
20
- export {findUserProjectRoot } from "./dirnameTool"
21
- export {readConfig} ;
22
- export {getWWVNodeModuleFolder}
@@ -1,27 +0,0 @@
1
- import { readFile } from "node:fs/promises";
2
- import { findUserProjectRoot } from "./dirnameTool";
3
- import path from "node:path";
4
- import { existsSync } from "node:fs";
5
-
6
- export type WwvPlatFrom = 'x86' | 'x64';
7
-
8
- export type WwfBinFileName = "exeOpenner.exe" | "WebView2Loader.dll" | "ww2_addon.node" | "splash.png"
9
-
10
- export type ConfigWW2 = {
11
- appname: string;
12
- entry_point: string;
13
- outdir: string;
14
- platform: WwvPlatFrom
15
- };
16
-
17
-
18
- const jsonConfigFilePath = "./win_webview2.json";
19
- export async function readConfig() {
20
- let userDir = findUserProjectRoot();
21
- if (userDir == null) throw "readConfig() => findProjectUser failed"
22
-
23
- let jsonPath = path.join(userDir, jsonConfigFilePath);
24
- let str = await readFile(jsonPath);
25
- let jsonObj = JSON.parse(str.toString());
26
- return jsonObj as ConfigWW2;
27
- }
@@ -1,157 +0,0 @@
1
-
2
- import express from 'express';
3
- import path from 'path';
4
- import { Server } from 'http';
5
- import { AddressInfo } from 'net';
6
- import { getModule, WW2ControlWindowsArg } from './winwebview2';
7
-
8
- interface WW2FileDialogArg {
9
- filter: string;
10
- ownerClassName: string;
11
- }
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 ww2_CreateServer(arg: {
32
- port: number,
33
- onExpressCreate: (app: express.Express) => void,
34
- uiConfig: {
35
-
36
- wclassname: string,
37
- title: string,
38
- width: number,
39
- height: number,
40
- isKiosk: boolean,
41
- isMaximize: boolean,
42
- isDebug: boolean,
43
- },
44
- htmlfolder : string
45
- }) {
46
- let port = arg.port ? arg.port : 0;
47
-
48
- let app = express();
49
- app.use(express.json());
50
- app.use(express.static(arg.htmlfolder));
51
- arg.onExpressCreate(app);
52
-
53
- app.post("/ww2_post", async (req, res) => {
54
-
55
- let body = req.body as PostData;
56
- console.log("ww2_post", body);
57
- let result = "";
58
- let err = "";
59
- try {
60
-
61
-
62
-
63
- if (body.openWeb) {
64
- let openWebArg = body.openWeb;
65
- ww2Module.openWeb({
66
- callback: () => {
67
-
68
- },
69
- height: openWebArg.height,
70
- wclassname: openWebArg.wclassname,
71
- isDebug: openWebArg.isDebug,
72
- isKiosk: openWebArg.isKiosk,
73
- isMaximize: openWebArg.isMaximize,
74
- title: openWebArg.title,
75
- url: openWebArg.url,
76
- width: openWebArg.width
77
- });
78
-
79
- result = openWebArg.url;
80
-
81
- } else if (body.controlWindow) {
82
- ww2Module.controlWindow(body.controlWindow);
83
- } else if (body.openFileDialog) {
84
- let openFileDialogArg = body.openFileDialog;
85
- result = await new Promise((r, x) => {
86
- ww2Module.openFileDialog({
87
- callback: (err, d) => {
88
- r(d);
89
- },
90
- filter: openFileDialogArg.filter,
91
- ownerClassName: openFileDialogArg.ownerClassName
92
- })
93
- });
94
- } else if(body.openFolderDialog){
95
-
96
- let ofArg = body.openFolderDialog;
97
- result = await new Promise((r,x)=>{
98
- ww2Module.openFolderDialog({
99
- callback : (err,data)=>{
100
- r(data);
101
- },
102
- filter : ofArg.filter,
103
- ownerClassName : ofArg.ownerClassName
104
- });
105
- });
106
-
107
- }
108
- } catch (error) {
109
- err = error + "";
110
- }
111
-
112
- res.json({
113
- error : err,
114
- result : result
115
- });
116
-
117
- });
118
-
119
- let ww2Module = await getModule();
120
-
121
- let server = app.listen(port, async (err) => {
122
- let add = server.address();
123
- if (add == null) {
124
- console.log("build server failed : " + err);
125
- process.exit();
126
- }
127
-
128
- let addr = add as AddressInfo;
129
-
130
- let resultPort = addr.port;
131
- let url = `http://localhost:${resultPort}`;
132
-
133
- console.log(url);
134
-
135
- console.log("open UI");
136
-
137
- let uiConfig = arg.uiConfig;
138
-
139
- ww2Module.openWeb({
140
- callback: (err, data) => {
141
- process.exit();
142
- },
143
- wclassname: uiConfig.wclassname,
144
- height: uiConfig.height,
145
- isDebug: uiConfig.isDebug,
146
- isKiosk: uiConfig.isKiosk,
147
- isMaximize: uiConfig.isMaximize,
148
- title: uiConfig.title,
149
- width: uiConfig.width,
150
- url: url,
151
-
152
- })
153
-
154
- })
155
-
156
-
157
- }
@@ -1,13 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "nodenext",
5
- "declaration": true,
6
- "rootDir": "./",
7
- "outDir": "../../dist/node",
8
- "strict": true,
9
- "esModuleInterop": true,
10
- "skipLibCheck": true
11
- },
12
- "include": ["./**/*" ]
13
- }
@@ -1,92 +0,0 @@
1
- import { exec } from "node:child_process";
2
- import { copyFile, mkdir } from "node:fs/promises";
3
- import path from "node:path";
4
-
5
- function debugDir(dirPath: string) {
6
- exec("cd " + dirPath + "&& dir", (s, o) => {
7
- console.log(o);
8
- })
9
- }
10
-
11
- (async () => {
12
-
13
- let result = "\n";
14
-
15
- let ww2SourcePath = path.join(__dirname,"../");
16
-
17
- let copyFromRoot = async (src: string, target: string) => {
18
- try {
19
-
20
- let rootPath = path.join(ww2SourcePath,"../");
21
- console.log("ModulePath : ", ww2SourcePath);
22
- console.log("rootPath : ", rootPath);
23
- result += "\n" + target;
24
- await copyFile(path.join(rootPath, src), path.join(rootPath, target));
25
- } catch (error) {
26
- console.log(error);
27
- }
28
- }
29
-
30
- try{
31
- await mkdir(path.join(ww2SourcePath, "win_lib"));
32
-
33
- } catch{
34
-
35
- }
36
- try{
37
- await mkdir(path.join(ww2SourcePath, "win_lib/x86"));
38
-
39
- } catch{
40
-
41
- }
42
-
43
- try {
44
-
45
- await mkdir(path.join(ww2SourcePath, "win_lib/x64"));
46
- } catch (error) {
47
-
48
- }
49
-
50
- await copyFromRoot(
51
- "exeOpener/build/x64/exeOpenner.exe",
52
- "win_webview2/win_lib/x64/exeOpenner.exe"
53
- );
54
- await copyFromRoot(
55
- "exeOpener/build/x64/splash.png",
56
- "win_webview2/win_lib/x64/splash.png"
57
- );
58
-
59
- await copyFromRoot(
60
- "exeOpener/build/x86/exeOpenner.exe",
61
- "win_webview2/win_lib/x86/exeOpenner.exe"
62
- );
63
- await copyFromRoot(
64
- "exeOpener/build/x86/splash.png",
65
- "win_webview2/win_lib/x86/splash.png"
66
- );
67
-
68
- console.log("copy webview2 32");
69
- await copyFromRoot(
70
- "nodeAddOn/build/ia32/Release/ww2_addon.node",
71
- "win_webview2/win_lib/x86/ww2_addon.node"
72
- );
73
- await copyFromRoot(
74
- "nodeAddOn/build/ia32/Release/WebView2Loader.dll",
75
- "win_webview2/win_lib/x86/WebView2Loader.dll"
76
- );
77
-
78
- console.log("copy webview2 64");
79
- await copyFromRoot(
80
- "nodeAddOn/build/x64/Release/ww2_addon.node",
81
- "win_webview2/win_lib/x64/ww2_addon.node"
82
- );
83
- await copyFromRoot(
84
- "nodeAddOn/build/x64/Release/WebView2Loader.dll",
85
- "win_webview2/win_lib/x64/WebView2Loader.dll"
86
- );
87
-
88
-
89
-
90
- console.log("copy done :" + result);
91
-
92
- })();
@@ -1,13 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "nodenext",
5
- "declaration": true,
6
- "rootDir": "./",
7
- "strict": true,
8
- "esModuleInterop": true,
9
- "skipLibCheck": true,
10
- "types": ["node"]
11
- },
12
- "include": ["./**/*"]
13
- }
Binary file
Binary file
Binary file
Binary file