win_webview2 1.1.14 → 1.1.16

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.
@@ -20,6 +20,7 @@ async function getWWvVersion() {
20
20
  result = jsonObj.version;
21
21
  }
22
22
  catch (error) {
23
+ console.log(error);
23
24
  }
24
25
  return result;
25
26
  }
@@ -31,5 +31,12 @@ function getWWVNodeModuleFolder() {
31
31
  if (userRootProject == null)
32
32
  throw "root project user not found";
33
33
  let nodeModuleFolder = node_path_1.default.join(userRootProject, "node_modules/win_webview2");
34
+ if (!(0, node_fs_1.existsSync)(nodeModuleFolder)) {
35
+ if (userRootProject.endsWith("win_webview2")) {
36
+ console.log("on source win_webview2folder \n\n");
37
+ let npath = node_path_1.default.join(nodeModuleFolder, "../../");
38
+ nodeModuleFolder = npath;
39
+ }
40
+ }
34
41
  return nodeModuleFolder;
35
42
  }
@@ -0,0 +1,32 @@
1
+ interface Ww2WebConfig {
2
+ callback: (err: any, data: any) => void;
3
+ wclassname: string;
4
+ url: string;
5
+ title: string;
6
+ width: number;
7
+ height: number;
8
+ isKiosk: boolean;
9
+ isMaximize: boolean;
10
+ isDebug: boolean;
11
+ }
12
+ interface WW2FileDialogArg {
13
+ callback: (err: any, data: any) => void;
14
+ filter: string;
15
+ ownerClassName: string;
16
+ }
17
+ export interface WW2ControlWindowsArg {
18
+ wndClassName: string;
19
+ controlcmd: "close" | "move" | "maximize" | "minimize" | "resize" | "check";
20
+ left?: number;
21
+ top?: number;
22
+ height?: number;
23
+ width?: number;
24
+ }
25
+ interface Ww2Module {
26
+ openWeb: (arg: Ww2WebConfig) => void;
27
+ openFileDialog: (arg: WW2FileDialogArg) => void;
28
+ openFolderDialog: (arg: WW2FileDialogArg) => void;
29
+ controlWindow: (arg: WW2ControlWindowsArg) => void;
30
+ }
31
+ export declare function getModule(): Promise<Ww2Module>;
32
+ export {};
@@ -0,0 +1,66 @@
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.getModule = getModule;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const dirnameTool_1 = require("./dirnameTool");
9
+ const ww2_config_1 = require("./ww2_config");
10
+ const node_fs_1 = require("node:fs");
11
+ const downloader_1 = require("./downloader");
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;
17
+ }
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}`;
22
+ console.log("Bin File Version : " + binFileVersion);
23
+ console.log("downloading :\n", url);
24
+ try {
25
+ let dir = node_path_1.default.dirname(filePath);
26
+ await (0, promises_1.mkdir)(dir, { recursive: true });
27
+ }
28
+ catch (error) {
29
+ }
30
+ await (0, downloader_1.downloadFile)(url, filePath);
31
+ }
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);
37
+ }
38
+ async function getModule() {
39
+ let addOnName = "ww2_addon.node";
40
+ let config = await (0, ww2_config_1.readConfig)();
41
+ if (config == null)
42
+ throw "cannot read config";
43
+ let filepath = (() => {
44
+ let userFolder = (0, dirnameTool_1.findUserProjectRoot)();
45
+ if (userFolder == null)
46
+ return null;
47
+ let r = node_path_1.default.join(userFolder, addOnName);
48
+ if (!(0, node_fs_1.existsSync)(r))
49
+ return null;
50
+ return r;
51
+ })();
52
+ filepath = await (async () => {
53
+ if (filepath != null)
54
+ return filepath;
55
+ let wwvModulePath = (0, dirnameTool_1.getWWVNodeModuleFolder)();
56
+ let r = node_path_1.default.join(wwvModulePath, `win_lib/${config.platform}/ww2_addon.node`);
57
+ return r;
58
+ })();
59
+ if (filepath == null)
60
+ throw "file path is null";
61
+ if (!(0, node_fs_1.existsSync)(filepath)) {
62
+ await downloadModule(config.platform);
63
+ }
64
+ let myAddon = require(filepath);
65
+ return myAddon;
66
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Fungsi download native dengan TypeScript
3
+ * @param src - URL sumber file
4
+ * @param filePath - Path lengkap tujuan penyimpanan
5
+ */
6
+ export declare function downloadFile(src: string, filePath: string): Promise<string>;
@@ -0,0 +1,78 @@
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.downloadFile = downloadFile;
37
+ const http = __importStar(require("http"));
38
+ const https = __importStar(require("https"));
39
+ const fs = __importStar(require("fs"));
40
+ const url_1 = require("url");
41
+ /**
42
+ * Fungsi download native dengan TypeScript
43
+ * @param src - URL sumber file
44
+ * @param filePath - Path lengkap tujuan penyimpanan
45
+ */
46
+ async function downloadFile(src, filePath) {
47
+ return new Promise((resolve, reject) => {
48
+ const url = new url_1.URL(src);
49
+ const protocol = url.protocol === 'https:' ? https : http;
50
+ // Gunakan flags 'w' untuk memastikan file dibuka untuk ditulisi
51
+ const file = fs.createWriteStream(filePath, { flags: 'w' });
52
+ protocol.get(src, (response) => {
53
+ const { statusCode } = response;
54
+ if (statusCode && statusCode >= 300 && statusCode < 400 && response.headers.location) {
55
+ file.destroy(); // Hancurkan stream sebelum redirect
56
+ return resolve(downloadFile(response.headers.location, filePath));
57
+ }
58
+ if (statusCode !== 200) {
59
+ file.destroy();
60
+ fs.unlink(filePath, () => { });
61
+ return reject(new Error(`Download gagal! Status: ${statusCode}`));
62
+ }
63
+ response.pipe(file);
64
+ // GANTI DISINI: Gunakan event 'close' bukan 'finish'
65
+ file.on('close', () => {
66
+ resolve(filePath);
67
+ });
68
+ file.on('error', (err) => {
69
+ fs.unlink(filePath, () => { });
70
+ reject(err);
71
+ });
72
+ }).on('error', (err) => {
73
+ file.destroy();
74
+ fs.unlink(filePath, () => { });
75
+ reject(err);
76
+ });
77
+ });
78
+ }
@@ -1,37 +1,7 @@
1
1
  import { getWWVNodeModuleFolder } from "./dirnameTool";
2
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
3
  export declare function closeSplash(): Promise<void>;
4
+ export * from "./downloadModule";
35
5
  export * from "./ww2_server";
36
6
  export { findUserProjectRoot } from "./dirnameTool";
37
7
  export { readConfig };
@@ -13,53 +13,23 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  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
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
16
  Object.defineProperty(exports, "__esModule", { value: true });
20
17
  exports.getWWVNodeModuleFolder = exports.readConfig = exports.findUserProjectRoot = void 0;
21
- exports.getModule = getModule;
22
18
  exports.closeSplash = closeSplash;
23
- const node_fs_1 = require("node:fs");
24
- const node_path_1 = __importDefault(require("node:path"));
25
19
  const dirnameTool_1 = require("./dirnameTool");
26
20
  Object.defineProperty(exports, "getWWVNodeModuleFolder", { enumerable: true, get: function () { return dirnameTool_1.getWWVNodeModuleFolder; } });
27
21
  const ww2_config_1 = require("./ww2_config");
28
22
  Object.defineProperty(exports, "readConfig", { enumerable: true, get: function () { return ww2_config_1.readConfig; } });
29
- async function getModule() {
30
- let addOnName = "ww2_addon.node";
31
- let filepath = (() => {
32
- let userFolder = (0, dirnameTool_1.findUserProjectRoot)();
33
- if (userFolder == null)
34
- return null;
35
- let r = node_path_1.default.join(userFolder, addOnName);
36
- if (!(0, node_fs_1.existsSync)(r))
37
- return null;
38
- return r;
39
- })();
40
- filepath = await (async () => {
41
- if (filepath != null)
42
- return filepath;
43
- let wwvModulePath = (0, dirnameTool_1.getWWVNodeModuleFolder)();
44
- let config = await (0, ww2_config_1.readConfig)();
45
- if (config == null)
46
- return null;
47
- let r = node_path_1.default.join(wwvModulePath, `win_lib/${config.platform}/ww2_addon.node`);
48
- return r;
49
- })();
50
- if (filepath == null)
51
- throw "file not found";
52
- let myAddon = require(filepath);
53
- return myAddon;
54
- }
23
+ const downloadModule_1 = require("./downloadModule");
55
24
  function closeSplash() {
56
- return getModule().then((module) => {
25
+ return (0, downloadModule_1.getModule)().then((module) => {
57
26
  module.controlWindow({
58
27
  controlcmd: "close",
59
28
  wndClassName: "mysplashclassname"
60
29
  });
61
30
  });
62
31
  }
32
+ __exportStar(require("./downloadModule"), exports);
63
33
  __exportStar(require("./ww2_server"), exports);
64
34
  var dirnameTool_2 = require("./dirnameTool");
65
35
  Object.defineProperty(exports, "findUserProjectRoot", { enumerable: true, get: function () { return dirnameTool_2.findUserProjectRoot; } });
@@ -1,7 +1,9 @@
1
+ export type WwvPlatFrom = 'x86' | 'x64';
2
+ export type WwfBinFileName = "exeOpenner.exe" | "WebView2Loader.dll" | "ww2_addon.node" | "splash.png";
1
3
  export type ConfigWW2 = {
2
4
  appname: string;
3
5
  entry_point: string;
4
6
  outdir: string;
5
- platform: 'Win32' | 'x64';
7
+ platform: WwvPlatFrom;
6
8
  };
7
9
  export declare function readConfig(): Promise<ConfigWW2>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "win_webview2",
3
- "version": "1.1.14",
3
+ "version": "1.1.16",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/nnttoo/win_webview2"
@@ -25,7 +25,7 @@
25
25
  "type": "commonjs",
26
26
  "scripts": {
27
27
  "build_node": "tsc -p ./src/srcNode/tsconfig.json",
28
- "build_node_watch": "npm run build -- --watch",
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
31
  "build_all" : "npm run build_node && npm run build_browser",
@@ -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
-
22
- }
23
-
24
- return result;
25
- }
26
-
@@ -1,36 +0,0 @@
1
- import { fileURLToPath } from 'node:url';
2
- import path, { dirname } from 'node:path';
3
- import { existsSync } from 'node:fs';
4
-
5
-
6
-
7
- function findUserProjectRootRecrusive(currentDir : string = process.cwd()) {
8
-
9
- const packagePath = path.join(currentDir, 'package.json');
10
- if (existsSync(packagePath)) {
11
- return currentDir;
12
- }
13
- const parentDir = path.dirname(currentDir);
14
- if (parentDir === currentDir) {
15
- return null;
16
- }
17
- return findUserProjectRootRecrusive(parentDir);
18
- }
19
-
20
- export function findUserProjectRoot() {
21
-
22
- // - Deployed Condition
23
- const packagePath = path.join(path.dirname(process.execPath), 'package.json');
24
- if (existsSync(packagePath)) {
25
- return path.dirname(packagePath);
26
- }
27
- return findUserProjectRootRecrusive(process.cwd());
28
- }
29
-
30
- export function getWWVNodeModuleFolder(){
31
- let userRootProject = findUserProjectRoot();
32
- if(userRootProject == null) throw "root project user not found";
33
-
34
- let nodeModuleFolder = path.join(userRootProject,"node_modules/win_webview2");
35
- return nodeModuleFolder;
36
- }
@@ -1,97 +0,0 @@
1
- import { execFile } from "node:child_process";
2
- import { existsSync } from "node:fs";
3
- import { readFile } from "node:fs/promises";
4
- import path from "node:path";
5
- import { findUserProjectRoot, getWWVNodeModuleFolder } from "./dirnameTool";
6
- import { ConfigWW2, readConfig } from "./ww2_config";
7
-
8
- interface Ww2WebConfig {
9
- callback: (err: any, data: any) => void;
10
- wclassname: string;
11
- url: string;
12
- title: string;
13
-
14
- width: number;
15
- height: number;
16
- isKiosk: boolean;
17
- isMaximize: boolean;
18
- isDebug: boolean;
19
-
20
- }
21
-
22
- interface WW2FileDialogArg {
23
- callback: (err: any, data: any) => void;
24
- filter: string;
25
- ownerClassName: string;
26
- }
27
-
28
- export interface WW2ControlWindowsArg {
29
- wndClassName: string;
30
- controlcmd: "close" | "move" | "maximize" | "minimize" | "resize" | "check",
31
- left?: number;
32
- top?: number;
33
- height?: number;
34
- width?: number;
35
- }
36
-
37
- interface Ww2Module {
38
- openWeb: (arg: Ww2WebConfig) => void;
39
- openFileDialog: (arg: WW2FileDialogArg) => void;
40
- openFolderDialog: (arg: WW2FileDialogArg) => void;
41
- controlWindow: (arg: WW2ControlWindowsArg) => void;
42
- }
43
-
44
-
45
-
46
- export async function getModule() {
47
- let addOnName = "ww2_addon.node";
48
-
49
- let filepath = (()=>{
50
-
51
- let userFolder = findUserProjectRoot();
52
- if(userFolder == null) return null;
53
- let r = path.join(
54
- userFolder,
55
- addOnName
56
- );
57
-
58
- if(!existsSync(r)) return null;
59
-
60
- return r;
61
-
62
- })();
63
-
64
- filepath = await ( async ()=>{
65
- if(filepath != null) return filepath;
66
- let wwvModulePath = getWWVNodeModuleFolder();
67
- let config = await readConfig();
68
- if(config == null) return null;
69
-
70
- let r = path.join(wwvModulePath, `win_lib/${config.platform}/ww2_addon.node`);
71
-
72
- return r;
73
-
74
-
75
- })();
76
-
77
- if(filepath == null) throw "file not found";
78
-
79
- let myAddon = require(filepath) as Ww2Module;
80
- return myAddon;
81
- }
82
-
83
- export function closeSplash(){
84
- return getModule().then((module)=>{
85
- module.controlWindow({
86
- controlcmd : "close",
87
- wndClassName : "mysplashclassname"
88
- })
89
- });
90
- }
91
-
92
-
93
-
94
- export * from "./ww2_server"
95
- export {findUserProjectRoot } from "./dirnameTool"
96
- export {readConfig} ;
97
- export {getWWVNodeModuleFolder}
@@ -1,23 +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 ConfigWW2 = {
7
- appname: string;
8
- entry_point: string;
9
- outdir: string;
10
- platform: 'Win32' | 'x64'
11
- };
12
-
13
-
14
- const jsonConfigFilePath = "./win_webview2.json";
15
- export async function readConfig() {
16
- let userDir = findUserProjectRoot();
17
- if (userDir == null) throw "readConfig() => findProjectUser failed"
18
-
19
- let jsonPath = path.join(userDir, jsonConfigFilePath);
20
- let str = await readFile(jsonPath);
21
- let jsonObj = JSON.parse(str.toString());
22
- return jsonObj as ConfigWW2;
23
- }
@@ -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/Win32"));
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/Win32/exeOpenner.exe"
62
- );
63
- await copyFromRoot(
64
- "exeOpener/build/x86/splash.png",
65
- "win_webview2/win_lib/Win32/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/Win32/ww2_addon.node"
72
- );
73
- await copyFromRoot(
74
- "nodeAddOn/build/ia32/Release/WebView2Loader.dll",
75
- "win_webview2/win_lib/Win32/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
Binary file
Binary file
Binary file
Binary file