Update lib/toolkit.js

This commit is contained in:
Namhyeon Go 2023-12-20 17:58:42 +09:00
parent 0d3052e659
commit 3cfc3fccf5
2 changed files with 37 additions and 9 deletions

View File

@ -1,5 +1,6 @@
var SYS = require("lib/system");
var HTTP = require("lib/http");
//var Toolkit = require("lib/toolkit");
function main(args) {
console.log("Hello world");
@ -11,8 +12,10 @@ function main(args) {
var web = HTTP.create();
console.log(web.userAgent);
} catch (e) {
console.error("Something wrong");
console.error("lib/http: Something wrong");
}
//Toolkit.create();
}
exports.main = main;

View File

@ -1,25 +1,25 @@
////////////////////////////////////////////////////////////////////////
// WelsonJS.Toolkit API
////////////////////////////////////////////////////////////////////////
// toolkit.js
// Namhyeon Go <abuse@catswords.net>
// https://github.com/gnh1201/welsonjs
var ToolkitObject = function() {
function ToolkitObject() {
this.interface = null;
this.create = function() {
try {
this.interface = CreateObject("WelsonJS.Toolkit");
return this;
} catch (e) {
console.info("WelsonJS.Toolkit not installed");
console.info("It could be download from https://github.com/gnh1201/welsonjs");
console.error(e.message);
}
return this;
};
this.getInterface = function() {
return this.interface;
};
this.create();
};
@ -47,8 +47,8 @@ function sendFnKey(wName, num) {
return getInterface().SendFnKey(wName, num);
}
// [lib/toolkit] Implementation of User prompts (alert, confirm. prompt) #21
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html
function alert(message) {
return getInterface().Alert(message);
}
@ -61,6 +61,30 @@ function prompt(message, _default) {
return getInterface().Prompt(message, _default);
}
// [Toolkit] Access to a shared memory #96
function NamedSharedMemory(name) {
var Toolkit = create().getInterface();
this.name = name;
this.isInitialized = false;
this.open = function() {
this.isInitialized = Toolkit.OpenNamedSharedMemory(this.name);
};
this.readText = function() {
return Toolkit.ReadTextFromSharedMemory(this.name);
};
this.writeText = function(text) {
Toolkit.WriteTextToSharedMemory(this.name, text);
};
this.clear = function() {
Toolkit.ClearSharedMemory(this.name);
};
}
exports.create = create;
exports.getInterface = getInterface;
exports.sendClick = sendClick;
@ -69,8 +93,9 @@ exports.sendFnKey = sendFnKey;
exports.alert = alert;
exports.confirm = confirm;
exports.prompt = prompt;
exports.NamedSharedMemory = NamedSharedMemory;
exports.VERSIONINFO = "WelsonJS.Toolkit Native API version 0.3.1";
exports.VERSIONINFO = "WelsonJS.Toolkit Native API version 0.3.2";
exports.AUTHOR = "abuse@catswords.net";
exports.global = global;
exports.require = global.require;