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

View File

@ -1,25 +1,25 @@
//////////////////////////////////////////////////////////////////////// // toolkit.js
// WelsonJS.Toolkit API // Namhyeon Go <abuse@catswords.net>
//////////////////////////////////////////////////////////////////////// // https://github.com/gnh1201/welsonjs
var ToolkitObject = function() { function ToolkitObject() {
this.interface = null; this.interface = null;
this.create = function() { this.create = function() {
try { try {
this.interface = CreateObject("WelsonJS.Toolkit"); this.interface = CreateObject("WelsonJS.Toolkit");
return this;
} catch (e) { } catch (e) {
console.info("WelsonJS.Toolkit not installed"); console.info("WelsonJS.Toolkit not installed");
console.info("It could be download from https://github.com/gnh1201/welsonjs"); console.info("It could be download from https://github.com/gnh1201/welsonjs");
console.error(e.message); console.error(e.message);
} }
return this;
}; };
this.getInterface = function() { this.getInterface = function() {
return this.interface; return this.interface;
}; };
this.create(); this.create();
}; };
@ -47,8 +47,8 @@ function sendFnKey(wName, num) {
return getInterface().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 // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html
function alert(message) { function alert(message) {
return getInterface().Alert(message); return getInterface().Alert(message);
} }
@ -61,6 +61,30 @@ function prompt(message, _default) {
return getInterface().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.create = create;
exports.getInterface = getInterface; exports.getInterface = getInterface;
exports.sendClick = sendClick; exports.sendClick = sendClick;
@ -69,8 +93,9 @@ exports.sendFnKey = sendFnKey;
exports.alert = alert; exports.alert = alert;
exports.confirm = confirm; exports.confirm = confirm;
exports.prompt = prompt; 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.AUTHOR = "abuse@catswords.net";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;