From 46361964484e0efb300173ac27179047dbe9dc12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B3=A0=EB=82=A8=ED=98=84?= Date: Mon, 26 Oct 2020 18:08:53 +0900 Subject: [PATCH] fix --- lib/gtk.js | 37 ++++++++++--------------------------- lib/shell.js | 15 ++++++++++----- 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/lib/gtk.js b/lib/gtk.js index 63609d3..0dc00c3 100644 --- a/lib/gtk.js +++ b/lib/gtk.js @@ -7,6 +7,9 @@ var SHELL = require("lib/shell"); // set binPath var binPath = "bin\\gtk-server.exe"; +// start GTKServer +var GTKServer = SHELL.createExecObject([binPath, "-stdin"]); + // Common (Elements) var GTKElements = []; @@ -40,23 +43,18 @@ var GTKElement = function() { GTKElements.push(this); }; -// start GTKServer -var = function() { - SHELL.run([ - binPath, - "-stdin" - ]); +// GTKServer WriteLine +var WriteLine = function(line) { + GTKServer.StdIn.WriteLine(line); + return GTKServer.StdOut.ReadLine(); }; // Window var Window = function() { GTKElement.apply(this, arguments); - + this.type = "Window"; this.title = "WelsonJS GTK GUI Application"; - this.setTitle = function(title) { - this.Title = title; - }; }; Window.prototype = new GTKElement(); Window.prototype.constructor = Window; @@ -64,7 +62,7 @@ Window.prototype.constructor = Window; // Table var Table = function() { GTKElement.apply(this, arguments); - + this.type = "Table"; this.attach = function(element, left, right, top, buttom) { // TODO: Table.attach() @@ -79,9 +77,6 @@ var Button = function() { this.type = "Button"; this.text = "New Button"; - this.setText = function(text) { - this.Text = text; - }; }; Button.prototype = new GTKElement(); Button.prototype.constructor = Button; @@ -92,9 +87,6 @@ var Label = function() { this.type = "Label"; this.text = "New Label"; - this.setText = function(text) { - this.text = text; - }; }; Label.prototype = new GTKElement(); Label.prototype.constructor = Label; @@ -105,9 +97,6 @@ var RadioBox = function() { this.type = "RadioBox"; this.text = "New RadioBox"; - this.setText = function(text) { - this.Text = text; - }; }; RadioBox.prototype = new GTKElement(); RadioBox.prototype.constructor = RadioBox; @@ -115,12 +104,9 @@ RadioBox.prototype.constructor = RadioBox; // CheckBox var CheckBox = function() { GTKElement.apply(this, arguments); - + this.type = "CheckBox"; this.text = "New CheckBox"; - this.setText = function(text) { - this.Text = text; - }; }; CheckBox.prototype = new GTKElement(); CheckBox.prototype.constructor = CheckBox; @@ -131,9 +117,6 @@ var TextBox = function() { this.type = "TextBox"; this.text = "New TextBox"; - this.setText = function(text) { - this.Text = text; - }; }; TextBox.prototype = new GTKElement(); TextBox.prototype.constructor = TextBox; diff --git a/lib/shell.js b/lib/shell.js index 03fab4d..3aeaf87 100644 --- a/lib/shell.js +++ b/lib/shell.js @@ -8,7 +8,7 @@ exports.VERSIONINFO = "Shell Lib (shell.js) version 0.1"; exports.global = global; exports.require = global.require; -exports.addslashes = function(s) { +var addslashes = function(s) { return s.toString().replace(/\\/g, '\\\\'). replace(/\u0008/g, '\\b'). replace(/\t/g, '\\t'). @@ -19,7 +19,7 @@ exports.addslashes = function(s) { replace(/"/g, '\\"'); }; -exports.makeCmdLine = function(cmd) { +var makeCommand = function(cmd) { if (typeof(cmd) === "string") { return cmd; } else if (typeof(cmd) === "object") { @@ -28,7 +28,7 @@ exports.makeCmdLine = function(cmd) { if (!regex.test(s)) { return s; } else { - return "\"" + exports.addslashes(s) + "\""; + return "\"" + addslashes(s) + "\""; } }).join(' '); } else { @@ -41,7 +41,7 @@ exports.exec = function(cmd, stdOutPath) { if (typeof(stdOutPath) === "undefined") { stdOutPath = "stdout.txt"; } - var c = "%comspec% /c (" + exports.makeCmdLine(cmd) + ") 1> " + stdOutPath; + var c = "%comspec% /c (" + makeCommand(cmd) + ") 1> " + stdOutPath; c += " 2>&1"; WSH.Run(c, 0, true); console.info("exec() -> " + c); @@ -57,11 +57,16 @@ exports.exec = function(cmd, stdOutPath) { exports.run = function(cmd, fork) { var WSH = CreateObject("WScript.Shell"); var fork = (typeof(fork) !== "undefined") ? fork : true; - var c = "%comspec% /q /c (" + exports.makeCmdLine(cmd) + ")"; + var c = "%comspec% /q /c (" + makeCommand(cmd) + ")"; console.info("run() -> " + c); WSH.Run(c, 0, !fork); }; +exports.createExecObject = function(cmd) { + var WSH = CreateObject("WScript.Shell"); + return WSH.Exec(makeCommand(cmd)); +}; + exports.elevatedRun = function(FN, args) { console.info("elevatedRun() -> " + FN + " " + args.join(' ')); var oShell = CreateObject("Shell.Application");