chore(browser): sync current working implementation
Rollback tag: pre-current-browser-sync-20260818
This commit is contained in:
@@ -78,17 +78,17 @@ namespace Lskj.Control.BrowserSetting
|
||||
string arg2 = message.Arguments.GetString(2);
|
||||
string arg3 = message.Arguments.GetString(3);
|
||||
string arg4 = message.Arguments.GetString(4);
|
||||
PostToUiThread(
|
||||
ERPInfo.Instance.MainControl,
|
||||
delegate
|
||||
if (ERPInfo.Instance.MainControl.InvokeRequired)
|
||||
{
|
||||
ERPInfo.Instance.MainControl.Invoke(new Action(() =>
|
||||
{
|
||||
BsOpenModuleHandler.OpenModule(
|
||||
arg0,
|
||||
arg1,
|
||||
arg2,
|
||||
arg3,
|
||||
arg4);
|
||||
});
|
||||
BsOpenModuleHandler.OpenModule(arg0, arg1, arg2, arg3, arg4);
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
BrowserSetting.BsOpenModuleHandler.OpenModule(arg0, arg1, arg2, arg3, arg4);
|
||||
}
|
||||
}
|
||||
else if (message.Name.Equals("OpenOnRightClick"))
|
||||
{
|
||||
@@ -96,103 +96,75 @@ namespace Lskj.Control.BrowserSetting
|
||||
string arg1 = message.Arguments.GetString(1);
|
||||
string arg2 = message.Arguments.GetString(2);
|
||||
string arg3 = message.Arguments.GetString(3);
|
||||
PostToUiThread(
|
||||
ERPInfo.Instance.MainControl,
|
||||
delegate
|
||||
if (ERPInfo.Instance.MainControl.InvokeRequired)
|
||||
{
|
||||
ERPInfo.Instance.MainControl.Invoke(new Action(() =>
|
||||
{
|
||||
BsOpenModuleHandler.OpenRightModule(
|
||||
arg0,
|
||||
arg1,
|
||||
arg2,
|
||||
arg3);
|
||||
});
|
||||
BsOpenModuleHandler.OpenRightModule(arg0, arg1, arg2, arg3);
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
BsOpenModuleHandler.OpenRightModule(arg0, arg1, arg2, arg3);
|
||||
}
|
||||
}
|
||||
else if (message.Name.Equals("CloseWin"))
|
||||
{
|
||||
var browserControl = frmWebBrowser;
|
||||
PostToUiThread(
|
||||
browserControl,
|
||||
delegate
|
||||
if (frmWebBrowser != null && frmWebBrowser.Parent != null && frmWebBrowser.Parent.Parent != null && frmWebBrowser.Parent.Parent is BaseForm baseForm)
|
||||
{
|
||||
if (baseForm.InvokeRequired)
|
||||
{
|
||||
baseForm.Invoke(new Action(() =>
|
||||
{
|
||||
baseForm.DialogResult = DialogResult.OK;
|
||||
baseForm.Close();
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Parent/Parent is a WinForms control-tree read and must
|
||||
// not run on CEF's UI thread.
|
||||
var parent = browserControl.Parent;
|
||||
var baseForm = parent == null
|
||||
? null
|
||||
: parent.Parent as BaseForm;
|
||||
if (baseForm == null || baseForm.IsDisposed)
|
||||
return;
|
||||
|
||||
baseForm.DialogResult = DialogResult.OK;
|
||||
baseForm.Close();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (message.Name.Equals("SelectPro"))
|
||||
{
|
||||
string arg0 = message.Arguments.GetString(0);
|
||||
string arg1 = message.Arguments.GetString(1);
|
||||
bool isclose = arg1!=null&&!string.IsNullOrWhiteSpace(arg1) && arg1.Equals("1") ? true : false;
|
||||
var browserControl = frmWebBrowser;
|
||||
PostToUiThread(
|
||||
browserControl,
|
||||
delegate
|
||||
if (frmWebBrowser != null && frmWebBrowser.Parent != null && frmWebBrowser.Parent.Parent != null && frmWebBrowser.Parent.Parent is BaseForm baseForm)
|
||||
{
|
||||
if (baseForm.InvokeRequired)
|
||||
{
|
||||
baseForm.Invoke(new Action(() =>
|
||||
{
|
||||
BsOpenModuleHandler.AddReturnRow(arg0);
|
||||
if (isclose)
|
||||
{
|
||||
baseForm.DialogResult = DialogResult.OK;
|
||||
baseForm.Close();
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
var parent = browserControl.Parent;
|
||||
var baseForm = parent == null
|
||||
? null
|
||||
: parent.Parent as BaseForm;
|
||||
if (baseForm == null || baseForm.IsDisposed)
|
||||
return;
|
||||
|
||||
BsOpenModuleHandler.AddReturnRow(arg0);
|
||||
if (isclose)
|
||||
if (isclose)
|
||||
{
|
||||
baseForm.DialogResult = DialogResult.OK;
|
||||
baseForm.Close();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return base.OnProcessMessageReceived(browser, frame, sourceProcess, message);
|
||||
}
|
||||
|
||||
private static void PostToUiThread(
|
||||
System.Windows.Forms.Control control,
|
||||
Action action)
|
||||
{
|
||||
if (control == null || action == null || control.IsDisposed ||
|
||||
!control.IsHandleCreated)
|
||||
return;
|
||||
|
||||
Action guardedAction = delegate
|
||||
{
|
||||
if (control.IsDisposed)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
action();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
ReportProcessMessageFailure(exception);
|
||||
}
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
// CEF invokes OnProcessMessageReceived on its UI thread. A
|
||||
// synchronous Control.Invoke can block that thread inside a
|
||||
// modal dialog while the dialog waits for CEF to create its
|
||||
// browser. Always queue the operation and return to CEF first.
|
||||
control.BeginInvoke(guardedAction);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
ReportProcessMessageFailure(exception);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ReportProcessMessageFailure(Exception exception)
|
||||
{
|
||||
try
|
||||
@@ -201,10 +173,10 @@ namespace Lskj.Control.BrowserSetting
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Never propagate logging failures into a native CEF callback.
|
||||
// Logging must never rethrow across the native CEF callback.
|
||||
}
|
||||
|
||||
Action showError = delegate
|
||||
Action showError = () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -212,14 +184,14 @@ namespace Lskj.Control.BrowserSetting
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Error reporting must never terminate the browser callback.
|
||||
}
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
System.Windows.Forms.Control mainControl = ERPInfo.Instance.MainControl;
|
||||
if (mainControl == null || mainControl.IsDisposed ||
|
||||
!mainControl.IsHandleCreated)
|
||||
if (mainControl == null || mainControl.IsDisposed || !mainControl.IsHandleCreated)
|
||||
return;
|
||||
|
||||
if (mainControl.InvokeRequired)
|
||||
@@ -229,36 +201,15 @@ namespace Lskj.Control.BrowserSetting
|
||||
}
|
||||
catch
|
||||
{
|
||||
// The main window may close while the callback is reporting.
|
||||
// The main window may close while the CEF callback is reporting.
|
||||
}
|
||||
}
|
||||
|
||||
public void Created(CefBrowser cefBrowser)
|
||||
{
|
||||
if (frmWebBrowser != null && OnCreated != null)
|
||||
if (OnCreated != null)
|
||||
{
|
||||
OnCreated(cefBrowser, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Closing(CefBrowser browser)
|
||||
{
|
||||
var control = frmWebBrowser;
|
||||
return control != null && control.BrowserClosing(browser);
|
||||
}
|
||||
|
||||
public void Closed(CefBrowser browser)
|
||||
{
|
||||
var control = frmWebBrowser;
|
||||
if (control != null)
|
||||
{
|
||||
control.BrowserClosed(browser);
|
||||
if (control.cefBrowserSettings == null)
|
||||
{
|
||||
frmWebBrowser = null;
|
||||
OnCreated = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user