Skip to content

Commit 32a5de9

Browse files
committed
MORT 1.303 업데이트
-DeppL 웹 api가 작동하지ㅐ 않는 문제 수정
1 parent d08ccd9 commit 32a5de9

File tree

5 files changed

+125
-26
lines changed

5 files changed

+125
-26
lines changed

MORT/Properties/Settings.Designer.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MORT/Properties/Settings.settings

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
<Profiles />
44
<Settings>
55
<Setting Name="MORT_VERSION" Type="System.String" Scope="Application">
6-
<Value Profile="(Default)">1.302V</Value>
6+
<Value Profile="(Default)">1.303V</Value>
77
</Setting>
88
<Setting Name="LAYER_TEXT" Type="System.String" Scope="Application">
99
<Value Profile="(Default)">MORT {0}
1010
레이어 번역창</Value>
1111
</Setting>
1212
<Setting Name="MORT_VERSION_VALUE" Type="System.Int32" Scope="Application">
13-
<Value Profile="(Default)">1302</Value>
13+
<Value Profile="(Default)">1303</Value>
1414
</Setting>
1515
<Setting Name="TOOLTIP_LIST" Type="System.String" Scope="Application">
1616
<Value Profile="(Default)">MORT를 처음 쓰시면 그 외-&gt; MORT 사용법을 확인해 주세요,
@@ -45,7 +45,7 @@ OCR 영역을 빠르게 추가하고 싶을 땐 빠른 OCR 영역을 사용하
4545
구글 OCR의 사용량은 실제 사용량과 다를 수 있습니다. 수시로 구글 콘솔에서 확인하셔야 합니다</Value>
4646
</Setting>
4747
<Setting Name="MORT_RELEASE" Type="System.String" Scope="Application">
48-
<Value Profile="(Default)">2025 12 03</Value>
48+
<Value Profile="(Default)">2025 12 07</Value>
4949
</Setting>
5050
<Setting Name="BASIC_TEXT" Type="System.String" Scope="Application">
5151
<Value Profile="(Default)">Monkeyhead's OCR Realtime TransLate {0}

MORT/TransAPI/DeeplWebView.cs

Lines changed: 98 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using Microsoft.Web.WebView2.WinForms;
22
using System;
33
using System.ComponentModel;
4+
using System.Reflection.Metadata;
45
using System.Threading.Tasks;
6+
using System.Windows.Controls;
57
using System.Windows.Forms;
68

79
namespace MORT.TransAPI
@@ -55,7 +57,7 @@ public void PrepareTranslate(DateTime dateTimeout)
5557

5658
public void Init(IDeeplAPIContract contract, string frontUrl, string urlFormat, string elementTarget)
5759
{
58-
if (_webView != null)
60+
if(_webView != null)
5961
{
6062
return;
6163
}
@@ -102,9 +104,9 @@ public void DoTrans(string original, string transCode, string resultCode)
102104

103105
private string ConvertHtmlToResult(string html)
104106
{
105-
if (html.Length > 2)
107+
if(html.Length > 2)
106108
{
107-
if (html[0] == '"' && html[html.Length - 1] == '"')
109+
if(html[0] == '"' && html[html.Length - 1] == '"')
108110
{
109111
html = html.Remove(0, 1);
110112
html = html.Remove(html.Length - 1, 1);
@@ -117,9 +119,9 @@ private string ConvertHtmlToResult(string html)
117119
html = html.TrimEnd();
118120
//html = html.Replace(GlobalDefine.SPLITE_TOEKN_DEEPL + "\\n\\n" ,GlobalDefine.SPLITE_TOEKN_DEEPL + System.Environment.NewLine);
119121

120-
if (html.IndexOf(GlobalDefine.SPLITE_TOEKN_DEEPL) == 0)
122+
if(html.IndexOf(GlobalDefine.SPLITE_TOEKN_DEEPL) == 0)
121123
{
122-
// html = html.Insert(GlobalDefine.SPLITE_TOEKN_DEEPL.Length, System.Environment.NewLine);
124+
// html = html.Insert(GlobalDefine.SPLITE_TOEKN_DEEPL.Length, System.Environment.NewLine);
123125
}
124126

125127

@@ -128,14 +130,15 @@ private string ConvertHtmlToResult(string html)
128130
return html;
129131
}
130132

133+
131134
private async Task SourceAsync(string text, string transCode, string resultCode)
132135
{
133136
while(!_start)
134137
{
135138
await Task.Delay(100);
136139
}
137140

138-
while (DateTime.Now < _dtNextAvailableTime)
141+
while(DateTime.Now < _dtNextAvailableTime)
139142
{
140143
await Task.Delay(50);
141144
Console.WriteLine("Wait : " + _dtNextAvailableTime.ToString());
@@ -150,11 +153,89 @@ private async Task SourceAsync(string text, string transCode, string resultCode)
150153
await Task.Delay((int)(random * 140));
151154
string requestText = RestSharp.Extensions.StringExtensions.UrlEncode(text);
152155

153-
if (requestText != _lastUrl)
156+
try
154157
{
155-
_webView.Source = new Uri(string.Format(_urlFormat, transCode, resultCode, requestText));
156-
Console.WriteLine("ocr : " + string.Format(_urlFormat, transCode, resultCode, requestText));
157-
await Task.Delay(50);
158+
159+
string scriptToClearText = @"
160+
(function() {
161+
// 'data-testid=""translator-target-input""'를 가진 요소의 하위에 있는 'div[contenteditable=""true""]'를 찾습니다.
162+
var editableDiv = document.querySelector('[data-testid=""translator-target-input""] div[contenteditable=""true""]');
163+
164+
if (editableDiv) {
165+
// 1. 요소의 내부 HTML을 빈 문자열로 설정하여 텍스트를 비웁니다.
166+
editableDiv.innerHTML = '';
167+
168+
// 2. 입력 포커스를 다시 설정하여 사용자가 바로 입력할 수 있도록 합니다.
169+
editableDiv.focus();
170+
171+
// 3. (추가된 핵심 부분) 'input' 이벤트를 수동으로 생성하고 발생시킵니다.
172+
// 이 이벤트는 웹 애플리케이션에게 내용이 사용자 입력처럼 '변경'되었음을 알립니다.
173+
var event = new Event('input', { bubbles: true });
174+
editableDiv.dispatchEvent(event);
175+
176+
// 4. C#으로 성공 메시지 전송
177+
if (window.chrome && window.chrome.webview) {
178+
window.chrome.webview.postMessage('TEXTBOX_CLEARED_SUCCESS');
179+
}
180+
181+
return '텍스트 박스 내용이 성공적으로 비워졌으며, 변경 이벤트도 발생시켰습니다.';
182+
} else {
183+
return '지정된 data-testid와 contenteditable 속성을 모두 가진 요소를 찾을 수 없습니다.';
184+
}
185+
})();
186+
";
187+
var test = await _webView.ExecuteScriptAsync(scriptToClearText);
188+
189+
}
190+
catch
191+
{
192+
193+
}
194+
195+
if(requestText != _lastUrl)
196+
{
197+
if(false)
198+
{
199+
//더이상 사용하지 않는다 추후에 문제가 생기면 사용한다
200+
_webView.Source = new Uri(string.Format(_urlFormat, transCode, resultCode, requestText));
201+
Console.WriteLine("ocr : " + string.Format(_urlFormat, transCode, resultCode, requestText));
202+
await Task.Delay(50);
203+
}
204+
else
205+
{
206+
string safeNewText = System.Text.Json.JsonSerializer.Serialize(text);
207+
208+
string scriptToSetText = $@"
209+
(function() {{
210+
// 소스 텍스트 박스('data-testid=""translator-source-input""')의 하위에 있는 'div[contenteditable=""true""]'를 찾습니다.
211+
var editableDiv = document.querySelector('[data-testid=""translator-source-input""] div[contenteditable=""true""]');
212+
213+
if (editableDiv) {{
214+
// 1. 요소의 내부 HTML을 지정된 새로운 텍스트로 설정하여 내용을 바꿉니다.
215+
editableDiv.innerHTML = '<p>{safeNewText.Trim('"')}</p>';
216+
217+
// 2. 입력 포커스를 다시 설정합니다.
218+
editableDiv.focus();
219+
220+
// 3. (핵심 부분) 'input' 이벤트를 수동으로 생성하고 발생시킵니다.
221+
var event = new Event('input', {{ bubbles: true }});
222+
editableDiv.dispatchEvent(event);
223+
224+
// 4. C#으로 성공 메시지 전송
225+
if (window.chrome && window.chrome.webview) {{
226+
window.chrome.webview.postMessage('SOURCE_TEXTBOX_SET_SUCCESS');
227+
}}
228+
229+
return '소스 텍스트 박스 내용이 성공적으로 설정되었으며, 변경 이벤트도 발생시켰습니다.';
230+
}} else {{
231+
return '지정된 data-testid=""translator-source-input"" 요소를 찾을 수 없습니다.';
232+
}}
233+
}})();
234+
";
235+
236+
await _webView.ExecuteScriptAsync(scriptToSetText);
237+
}
238+
158239
}
159240
else
160241
{
@@ -173,9 +254,9 @@ private async Task SourceAsync(string text, string transCode, string resultCode)
173254
await Task.Delay(50);
174255
var html = await _webView.CoreWebView2.ExecuteScriptAsync(_elementTarget);
175256
string origianl = html;
176-
if (html == null || html == "null" || html == "" || html == "\"\\n\"" || html == "\"\"")
257+
if(html == null || html == "null" || html == "" || html == "\"\\n\"" || html == "\"\"")
177258
{
178-
if (_dtTimeout < DateTime.Now)
259+
if(_dtTimeout < DateTime.Now)
179260
{
180261
Complete = true;
181262
IsError = true;
@@ -195,7 +276,7 @@ private async Task SourceAsync(string text, string transCode, string resultCode)
195276

196277
result = html;
197278

198-
if (_dtTimeout < DateTime.Now && false)
279+
if(_dtTimeout < DateTime.Now && false)
199280
{
200281
Complete = true;
201282
IsError = true;
@@ -204,10 +285,10 @@ private async Task SourceAsync(string text, string transCode, string resultCode)
204285
return;
205286
}
206287
}
207-
catch (Exception e) { IsError = true; Complete = true; _lastResult = e.Message; Console.WriteLine(e); }
288+
catch(Exception e) { IsError = true; Complete = true; _lastResult = e.Message; Console.WriteLine(e); }
208289

209290
}
210-
while (result == _lastResult || result == _defaultKey);
291+
while(result == _lastResult || result == _defaultKey);
211292

212293
//랜덤 딜레이를 준다
213294
random = _rand.NextDouble();
@@ -221,7 +302,7 @@ private async Task SourceAsync(string text, string transCode, string resultCode)
221302

222303
private void WebView_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e)
223304
{
224-
if (!_start)
305+
if(!_start)
225306
{
226307
_contract.UpdateCondition($"DeepL_Ready");
227308
_start = true;
@@ -230,7 +311,7 @@ private void WebView_NavigationCompleted(object sender, Microsoft.Web.WebView2.C
230311

231312
private void DeeplWebView_FormClosing(object sender, FormClosingEventArgs e)
232313
{
233-
if (e.CloseReason == CloseReason.UserClosing)
314+
if(e.CloseReason == CloseReason.UserClosing)
234315
{
235316
Hide();
236317
e.Cancel = true;//종료를 취소하고

MORT/TransAPI/GeminiTranslatorAPI.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ private async Task<string> InternalTranslateTextAsync(string requestText, bool s
9090
new { role = "user", parts = new[] { new { text = requestText } } }
9191
},
9292

93+
/*
9394
generationConfig = new
9495
{
9596
//추론기능 - 0은 끈 상태
@@ -99,6 +100,23 @@ private async Task<string> InternalTranslateTextAsync(string requestText, bool s
99100
},
100101
temperature = 0.2f // float 값으로 설정 (0.0f ~ 1.0f 사이)
101102
}
103+
*/
104+
105+
generationConfig = new
106+
{
107+
// 추론 기능 활성화: 웹에서 사용하는 모델의 기본 최대 추론 토큰 수 (8192)를 설정합니다.
108+
thinkingConfig = new
109+
{
110+
thinkingBudget = 8192
111+
},
112+
113+
// 추론에 최적화된 권장 온도(1.0f)를 설정합니다.
114+
temperature = 1.0f,
115+
116+
// (선택 사항) 웹 대화의 유연하고 자연스러운 응답 생성을 위한 일반적인 기본값을 추가합니다.
117+
topP = 0.95f,
118+
topK = 40
119+
}
102120
};
103121
}
104122

MORT/app.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@
7373
<applicationSettings>
7474
<MORT.Properties.Settings>
7575
<setting name="MORT_VERSION" serializeAs="String">
76-
<value>1.302V</value>
76+
<value>1.303V</value>
7777
</setting>
7878
<setting name="LAYER_TEXT" serializeAs="String">
7979
<value>MORT {0}
8080
레이어 번역창</value>
8181
</setting>
8282
<setting name="MORT_VERSION_VALUE" serializeAs="String">
83-
<value>1302</value>
83+
<value>1303</value>
8484
</setting>
8585
<setting name="TOOLTIP_LIST" serializeAs="String">
8686
<value>MORT를 처음 쓰시면 그 외-&gt; MORT 사용법을 확인해 주세요,
@@ -115,7 +115,7 @@ OCR 영역을 빠르게 추가하고 싶을 땐 빠른 OCR 영역을 사용하
115115
구글 OCR의 사용량은 실제 사용량과 다를 수 있습니다. 수시로 구글 콘솔에서 확인하셔야 합니다</value>
116116
</setting>
117117
<setting name="MORT_RELEASE" serializeAs="String">
118-
<value>2025 12 03</value>
118+
<value>2025 12 07</value>
119119
</setting>
120120
<setting name="BASIC_TEXT" serializeAs="String">
121121
<value>Monkeyhead's OCR Realtime TransLate {0}

0 commit comments

Comments
 (0)