From 96b91b2298ba37b18fd9f8bbee15ea61ff4a5911 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Sat, 24 Aug 2024 13:44:48 +0900 Subject: [PATCH] Update the screen time feature --- .../WelsonJS.Service/ScreenMatching.cs | 34 ++++++++++++------- settings.example.ini | 3 +- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatching.cs b/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatching.cs index 101a509..72c2175 100644 --- a/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatching.cs +++ b/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatching.cs @@ -57,7 +57,7 @@ public class ScreenMatching private string templateDirectoryPath; private int templateCurrentIndex = 0; private double threshold = 0.5; - private string captureMode; + private string mode = "screen"; public ScreenMatching(ServiceBase parent, string workingDirectory) { @@ -65,18 +65,23 @@ public class ScreenMatching templateDirectoryPath = Path.Combine(workingDirectory, "app/assets/img/_templates"); templateImages = new List(); - SetCaptureMode("screen"); + SetMode("screen"); LoadTemplateImages(); } - public void SetCaptureMode(string captureMode) + public void SetMode(string mode) { - this.captureMode = captureMode; + this.mode = mode; + } + + public void SetThreshold(double threshold) + { + this.threshold = threshold; } public void LoadTemplateImages() { - string[] files; + string[] files = []; try { @@ -84,14 +89,15 @@ public class ScreenMatching } catch (Exception ex) { - files = new string[] { }; - parent.Log($"Exception (ScreenMatching): {ex.Message}"); + parent.Log($"Failed to read the directory structure: {ex.Message}"); } foreach (var file in files) { - Bitmap bitmap = new Bitmap(file); - bitmap.Tag = Path.GetFileName(file); + Bitmap bitmap = new Bitmap(file) + { + Tag = Path.GetFileName(file) + }; templateImages.Add(bitmap); } } @@ -99,13 +105,16 @@ public class ScreenMatching // 캡쳐 및 템플릿 매칭 진행 public List CaptureAndMatch() { - switch(captureMode) + switch (mode) { case "screen": // 화면 기준 return CaptureAndMatchAllScreens(); - case "windows": // 윈도우 핸들 기준 + case "window": // 윈도우 핸들 기준 return CaptureAndMatchAllWindows(); + + default: + break; } return new List(); @@ -239,7 +248,8 @@ public class ScreenMatching if (IsTemplateMatch(mainImage, templateImage, x, y, threshold)) { bestMatch = new Point(x, y); - maxCorrelation = 1; + maxCorrelation = 1.0; + return bestMatch; } } diff --git a/settings.example.ini b/settings.example.ini index bf98a9f..6caea9d 100644 --- a/settings.example.ini +++ b/settings.example.ini @@ -7,7 +7,8 @@ NONFREE_STRICT=false ;User consent may be required when using third-party soft [Service] DISABLE_SCREEN_TIME=false DISABLE_FILE_MONITOR=false +SCREEN_TIME_TARGETS=YOUR_OWN_APPLICATION.exe GRPC_HOST=http://localhost:50051 ES_HOST=http://localhost:9200 ES_USER=elastic -ES_PASSWORD=changeme \ No newline at end of file +ES_PASSWORD=changeme