Skip to content

Commit

Permalink
Doc updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Aug 29, 2024
1 parent 945a4a4 commit 0fb5c7f
Show file tree
Hide file tree
Showing 11 changed files with 436 additions and 215 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"neurospeech"
]
}
18 changes: 18 additions & 0 deletions Positron/Controls/PositronWebView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ static PositronWebView() {
OnStaticPlatformInit();
}

/// <summary>
/// Return false to deny execution of native script.
/// </summary>
public Func<string, bool> ShouldInvokeScript { get; set; }

private DisposableList disposables = new DisposableList();

public IJSContext Context { get;set; }
Expand All @@ -26,6 +31,8 @@ static PositronWebView() {

public GlobalClr Clr { get; }

private string currentUrl;

public PositronWebView()
{
Context = JSContextFactory.Instance.Create();
Expand Down Expand Up @@ -64,6 +71,8 @@ public PositronWebView()
Positron.Instance.OnUrlRequested += Instance_OnUrlRequested;
Positron.Instance.OnDeviceTokenUpdated+= Instance_OnDeviceTokenUpdated;

this.Navigating += (s, e) => this.currentUrl = e.Url;

}


Expand Down Expand Up @@ -97,6 +106,15 @@ public void RunMainThreadJavaScript(string script)
Dispatcher.DispatchTask( async () => {
try
{
var s = this.ShouldInvokeScript;
if (s != null)
{
var url = this.currentUrl;
if (!s(url))
{
throw new UnauthorizedAccessException($"Cannot access nativeShell from {url}");
}
}
var result = await this.Clr.SerializeAsync(Context.Evaluate(script));
} catch (Exception ex) {
System.Diagnostics.Debug.WriteLine(ex.ToString());
Expand Down
8 changes: 7 additions & 1 deletion Positron/Engine/ClrClassInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,15 @@ private IJSValue Invoke(
for (int i = 0; i < l; i++)
{
var pm = argTypes[i];
var vi = args[i];
if (i < args.Count)
{
p[i] = c.Deserialize(args[i], pm.ParameterType);
if (vi.CanConvertTo(pm.ParameterType, out var cv))
{
p[i] = cv;
continue;
}
p[i] = c.Deserialize(vi, pm.ParameterType);
continue;
}
if(pm.HasDefaultValue)
Expand Down
Loading

0 comments on commit 0fb5c7f

Please sign in to comment.