- WebView2 HostObject 기반 MachineBridge 브릿지 클래스 추가 - MachineBridge.cs (메인), Login, Dashboard, Todo, Common, Jobreport, Kuntae, Project 모듈 - WebSocketServer.cs 추가 (실시간 통신용) - fDashboardNew 다이얼로그 추가 - Jobreport/index.html, Project/index.html의 fetch API를 machine HostObject 호출로 전환 - DashBoardController.cs의 gcode null 처리 추가 - 사용하지 않는 파일 삭제 (navigation.html, common-nav.js, navigation.js, _add_to_project.py, _project_updater.js) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
120 lines
3.6 KiB
C#
120 lines
3.6 KiB
C#
using FCM0000.Mail;
|
|
using FCOMMON;
|
|
using Microsoft.Web.WebView2.Core;
|
|
using Microsoft.Web.WebView2.WinForms;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Project.Dialog
|
|
{
|
|
public partial class fDashboardNew : fBase
|
|
{
|
|
private Web.WebSocketServer _wsServer;
|
|
private WebView2 webView;
|
|
public fDashboardNew()
|
|
{
|
|
InitializeComponent();
|
|
|
|
|
|
InitializeWebView2();
|
|
|
|
try
|
|
{
|
|
_wsServer = new Web.WebSocketServer("http://localhost:8081/", this);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show("Failed to start WebSocket Server (Port 8081). Run as Admin or allow port.\n" + ex.Message);
|
|
}
|
|
}
|
|
bool loadok = false;
|
|
public void RefreshView()
|
|
{
|
|
if (loadok)
|
|
webView.Reload();
|
|
}
|
|
private void InitializeWebView2()
|
|
{
|
|
// 수동으로 WebView2 컨트롤 생성
|
|
this.webView = new WebView2();
|
|
|
|
// 기본 속성 설정
|
|
this.webView.CreationProperties = null;
|
|
this.webView.DefaultBackgroundColor = Color.White;
|
|
this.webView.Dock = DockStyle.Fill;
|
|
this.webView.Location = new Point(0, 0);
|
|
this.webView.Name = "webView21";
|
|
this.webView.Size = new Size(800, 600);
|
|
this.webView.TabIndex = 0;
|
|
this.webView.ZoomFactor = 1D;
|
|
|
|
// 폼에 추가
|
|
this.Controls.Add(this.webView);
|
|
|
|
// 비동기 초기화
|
|
InitializeAsync();
|
|
}
|
|
private async void InitializeAsync()
|
|
{
|
|
try
|
|
{
|
|
// Fixed Version 경로 설정
|
|
string runtimePath = Path.Combine(Application.StartupPath, "WebView2Runtime");
|
|
|
|
if (Directory.Exists(runtimePath))
|
|
{
|
|
var env = await CoreWebView2Environment.CreateAsync(runtimePath);
|
|
await this.webView.EnsureCoreWebView2Async(env);
|
|
}
|
|
else
|
|
{
|
|
// 시스템에 설치된 WebView2 사용
|
|
await this.webView.EnsureCoreWebView2Async();
|
|
}
|
|
|
|
var wwwroot = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Web", "wwwroot");
|
|
webView.CoreWebView2.SetVirtualHostNameToFolderMapping(
|
|
"hmi.local",
|
|
wwwroot,
|
|
CoreWebView2HostResourceAccessKind.Allow);
|
|
|
|
|
|
// 2. Inject Native Object
|
|
webView.CoreWebView2.AddHostObjectToScript("machine", new Web.MachineBridge(this));
|
|
|
|
Pub.WebServiceURL = "http://hmi.local";
|
|
|
|
// OWIN 서버의 DashBoard 페이지로 연결
|
|
if (FCOMMON.info.Login.no.isEmpty())
|
|
webView.Source = new Uri($"{Pub.WebServiceURL}/login.html");
|
|
else
|
|
webView.Source = new Uri($"{Pub.WebServiceURL}/DashBoard");
|
|
|
|
label1.Visible = false;
|
|
loadok = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"WebView2 초기화 실패: {ex.Message}");
|
|
}
|
|
}
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
base.OnLoad(e);
|
|
EnsureVisibleAndUsableSize();
|
|
}
|
|
private void label1_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|