This commit is contained in:
backuppc
2025-07-07 17:44:59 +09:00
parent 5a0ff2e3ad
commit d537030eb3
10 changed files with 435 additions and 24 deletions

View File

@@ -3,6 +3,7 @@ using System.Windows.Forms;
using Microsoft.Web.WebView2.WinForms;
using Microsoft.Owin.Hosting;
using VNCServerList.Web;
using Microsoft.Web.WebView2.Core;
namespace VNCServerList
{
@@ -28,6 +29,10 @@ namespace VNCServerList
try
{
await webView.EnsureCoreWebView2Async(null);
// JavaScript에서 C# 메서드를 호출할 수 있도록 설정
webView.CoreWebView2.WebMessageReceived += CoreWebView2_WebMessageReceived;
webView.CoreWebView2.Navigate("http://localhost:8080");
}
catch (Exception ex)
@@ -36,6 +41,45 @@ namespace VNCServerList
}
}
private async void CoreWebView2_WebMessageReceived(object sender, CoreWebView2WebMessageReceivedEventArgs e)
{
try
{
var message = e.TryGetWebMessageAsString();
if (message == "OPEN_FILE_DIALOG")
{
var filePath = ShowOpenFileDialog();
if (!string.IsNullOrEmpty(filePath))
{
// JavaScript로 결과 전송 (ExecuteScriptAsync 사용)
var script = $"window.receiveFilePath('{filePath.Replace("\\", "\\\\")}');";
await webView.CoreWebView2.ExecuteScriptAsync(script);
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"WebView2 메시지 처리 오류: {ex.Message}");
}
}
private string ShowOpenFileDialog()
{
using (var openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "실행 파일 (*.exe)|*.exe|모든 파일 (*.*)|*.*";
openFileDialog.Title = "VNC Viewer 실행 파일 선택";
openFileDialog.InitialDirectory = @"C:\Program Files";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
return openFileDialog.FileName;
}
}
return null;
}
private void StartWebServer()
{
try