mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-11 20:21:03 +00:00
Fix parameter types to pass arguments to scripting engine
Since `ArrayList` is highly compatible with COM, you can use it to pass an array to `ScriptControl`.
This commit is contained in:
parent
3a890168df
commit
e4a8357715
|
@ -71,28 +71,28 @@ public class ScreenMatch
|
|||
templateImages = new List<Bitmap>();
|
||||
|
||||
// Read values from configration file
|
||||
string _mode;
|
||||
string _raw_params;
|
||||
string screen_time_mode;
|
||||
string screen_time_params;
|
||||
try
|
||||
{
|
||||
_mode = this.parent.GetSettingsFileHandler().Read("SCREEN_TIME_MODE", "Service");
|
||||
_raw_params = this.parent.GetSettingsFileHandler().Read("SCREEN_TIME_PARAMS", "Service");
|
||||
screen_time_mode = this.parent.GetSettingsFileHandler().Read("SCREEN_TIME_MODE", "Service");
|
||||
screen_time_params = this.parent.GetSettingsFileHandler().Read("SCREEN_TIME_PARAMS", "Service");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_mode = null;
|
||||
_raw_params = null;
|
||||
screen_time_mode = null;
|
||||
screen_time_params = null;
|
||||
this.parent.Log($"Failed to read from configration file: {ex.Message}");
|
||||
}
|
||||
|
||||
if (! String.IsNullOrEmpty(_raw_params))
|
||||
if (!String.IsNullOrEmpty(screen_time_params))
|
||||
{
|
||||
string[] ss = _raw_params.Split(',');
|
||||
string[] ss = screen_time_params.Split(',');
|
||||
foreach (string s in ss) {
|
||||
AddParam(s);
|
||||
}
|
||||
}
|
||||
SetMode(_mode);
|
||||
SetMode(screen_time_mode);
|
||||
LoadTemplateImages();
|
||||
}
|
||||
|
||||
|
@ -154,6 +154,7 @@ public class ScreenMatch
|
|||
return CaptureAndMatchAllWindows();
|
||||
|
||||
default:
|
||||
parent.Log($"Unknown capture mode: {mode}");
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ using MSScriptControl;
|
|||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using WelsonJS.TinyINIController;
|
||||
using System.Collections;
|
||||
|
||||
namespace WelsonJS.Service
|
||||
{
|
||||
|
@ -326,10 +327,17 @@ namespace WelsonJS.Service
|
|||
}
|
||||
}
|
||||
|
||||
private string InvokeScriptMethod(string methodName, params object[] parameters)
|
||||
private string InvokeScriptMethod(string methodName, string scriptName, string eventType, string[] args)
|
||||
{
|
||||
if (scriptControl != null)
|
||||
{
|
||||
object[] parameters = new object[] {
|
||||
scriptName,
|
||||
eventType,
|
||||
new ArrayList(args)
|
||||
};
|
||||
//scriptControl.AddObject("extern_arguments", new ArrayList(args), true);
|
||||
|
||||
return scriptControl.Run(methodName, parameters)?.ToString() ?? "void";
|
||||
}
|
||||
else
|
||||
|
@ -370,11 +378,11 @@ namespace WelsonJS.Service
|
|||
{
|
||||
if (args == null)
|
||||
{
|
||||
return InvokeScriptMethod("dispatchServiceEvent", scriptName, eventType, "");
|
||||
return InvokeScriptMethod("dispatchServiceEvent", scriptName, eventType, new string[] { });
|
||||
}
|
||||
else
|
||||
{
|
||||
return InvokeScriptMethod("dispatchServiceEvent", scriptName, eventType, String.Join("; ", args));
|
||||
return InvokeScriptMethod("dispatchServiceEvent", scriptName, eventType, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
5
app.js
5
app.js
|
@ -592,9 +592,8 @@ function initializeWindow(name, args, w, h) {
|
|||
}
|
||||
}
|
||||
|
||||
function dispatchServiceEvent(name, eventType, _args) {
|
||||
function dispatchServiceEvent(name, eventType, w_args) {
|
||||
var app = require(name);
|
||||
var args = _args.split('; ');
|
||||
|
||||
// load the service
|
||||
if (app) {
|
||||
|
@ -611,7 +610,7 @@ function dispatchServiceEvent(name, eventType, _args) {
|
|||
if (eventType in action) {
|
||||
try {
|
||||
return (function(f) {
|
||||
return (typeof f !== "function" ? null : f(args));
|
||||
return (typeof f !== "function" ? null : f(w_args));
|
||||
})(action[eventType]);
|
||||
} catch (e) {
|
||||
console.error("Exception:", e.message);
|
||||
|
|
|
@ -25,7 +25,7 @@ function onMessageReceived() {
|
|||
}
|
||||
|
||||
function onServiceScreenTime(args) {
|
||||
return "onServiceScreenTime recevied. " + args.join(', ');
|
||||
return "onServiceScreenTime recevied. " + args(0);
|
||||
}
|
||||
|
||||
function onFileCreated(args) {
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
[Default]
|
||||
JSCRIPT_ENV=development ;development or production
|
||||
; development or production
|
||||
JSCRIPT_ENV=development
|
||||
CHATGPT_APIKEY=file:data/chatgpt-apikey.txt
|
||||
WINDIVERT_CONFIG_FILE=data/windivert.config.json ;for network debugging
|
||||
NONFREE_STRICT=false ;User consent may be required when using third-party software with an EULA license.
|
||||
; for network debugging
|
||||
WINDIVERT_CONFIG_FILE=data/windivert.config.json
|
||||
; User consent may be required when using third-party software with an EULA license.
|
||||
NONFREE_STRICT=false
|
||||
|
||||
[Service]
|
||||
DISABLE_SCREEN_TIME=false
|
||||
DISABLE_FILE_MONITOR=false
|
||||
SCREEN_TIME_MODE=screen ;screen or window
|
||||
SCREEN_TIME_PARAMS= ;filename.exe
|
||||
; screen or window
|
||||
SCREEN_TIME_MODE=screen
|
||||
;filename.exe
|
||||
SCREEN_TIME_PARAMS=
|
||||
GRPC_HOST=http://localhost:50051
|
||||
ES_HOST=http://localhost:9200
|
||||
ES_USER=elastic
|
||||
|
|
Loading…
Reference in New Issue
Block a user