diff --git a/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatch.cs b/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatch.cs index 258cf51..7cb265b 100644 --- a/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatch.cs +++ b/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatch.cs @@ -71,28 +71,28 @@ public class ScreenMatch templateImages = new List(); // 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; } diff --git a/WelsonJS.Toolkit/WelsonJS.Service/ServiceMain.cs b/WelsonJS.Toolkit/WelsonJS.Service/ServiceMain.cs index 628adc1..61f0385 100644 --- a/WelsonJS.Toolkit/WelsonJS.Service/ServiceMain.cs +++ b/WelsonJS.Toolkit/WelsonJS.Service/ServiceMain.cs @@ -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); } } diff --git a/app.js b/app.js index 26d19a8..daef76c 100644 --- a/app.js +++ b/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); diff --git a/defaultService.js b/defaultService.js index b77c0fb..f1558d4 100644 --- a/defaultService.js +++ b/defaultService.js @@ -25,7 +25,7 @@ function onMessageReceived() { } function onServiceScreenTime(args) { - return "onServiceScreenTime recevied. " + args.join(', '); + return "onServiceScreenTime recevied. " + args(0); } function onFileCreated(args) { diff --git a/settings.example.ini b/settings.example.ini index 5e5a8ca..336e298 100644 --- a/settings.example.ini +++ b/settings.example.ini @@ -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