Skip to content

Commit

Permalink
Merge pull request #1 from SteveSandersonMS/master
Browse files Browse the repository at this point in the history
Merge upstream.
  • Loading branch information
Berrysoft authored Dec 23, 2019
2 parents 790952d + 7263328 commit bf896ae
Show file tree
Hide file tree
Showing 17 changed files with 865 additions and 188 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vs/
.vscode/
bin/
obj/
*.user
Expand Down
25 changes: 0 additions & 25 deletions .vscode/c_cpp_properties.json

This file was deleted.

16 changes: 8 additions & 8 deletions src/WebWindow.Blazor/ComponentsDesktop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public static class ComponentsDesktop
internal static string BaseUriAbsolute { get; private set; }
internal static DesktopJSRuntime DesktopJSRuntime { get; private set; }
internal static DesktopRenderer DesktopRenderer { get; private set; }

internal static WebWindow webWindow;
internal static WebWindow WebWindow { get; private set; }

public static void Run<TStartup>(string windowTitle, string hostHtmlPath)
{
Expand All @@ -30,7 +29,7 @@ public static void Run<TStartup>(string windowTitle, string hostHtmlPath)
UnhandledException(exception);
};

webWindow = new WebWindow(windowTitle, options =>
WebWindow = new WebWindow(windowTitle, options =>
{
var contentRootAbsolute = Path.GetDirectoryName(Path.GetFullPath(hostHtmlPath));

Expand All @@ -57,11 +56,11 @@ public static void Run<TStartup>(string windowTitle, string hostHtmlPath)
});

CancellationTokenSource appLifetimeCts = new CancellationTokenSource();
Task.Factory.StartNew(async() =>
Task.Factory.StartNew(async () =>
{
try
{
var ipc = new IPC(webWindow);
var ipc = new IPC(WebWindow);
await RunAsync<TStartup>(ipc, appLifetimeCts.Token);
}
catch (Exception ex)
Expand All @@ -73,8 +72,8 @@ public static void Run<TStartup>(string windowTitle, string hostHtmlPath)

try
{
webWindow.NavigateToUrl(BlazorAppScheme + "://app/");
webWindow.WaitForExit();
WebWindow.NavigateToUrl(BlazorAppScheme + "://app/");
WebWindow.WaitForExit();
}
finally
{
Expand Down Expand Up @@ -110,7 +109,7 @@ private static string BlazorAppScheme

private static void UnhandledException(Exception ex)
{
webWindow.ShowMessage("Error", $"{ex.Message}\n{ex.StackTrace}");
WebWindow.ShowMessage("Error", $"{ex.Message}\n{ex.StackTrace}");
}

private static async Task RunAsync<TStartup>(IPC ipc, CancellationToken appLifetime)
Expand All @@ -124,6 +123,7 @@ private static async Task RunAsync<TStartup>(IPC ipc, CancellationToken appLifet
serviceCollection.AddSingleton<NavigationManager>(DesktopNavigationManager.Instance);
serviceCollection.AddSingleton<IJSRuntime>(DesktopJSRuntime);
serviceCollection.AddSingleton<INavigationInterception, DesktopNavigationInterception>();
serviceCollection.AddSingleton(WebWindow);

var startup = new ConventionBasedStartup(Activator.CreateInstance(typeof(TStartup)));
startup.ConfigureServices(serviceCollection);
Expand Down
2 changes: 1 addition & 1 deletion src/WebWindow.Blazor/IPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public IPC(WebWindow webWindow)
_webWindow.OnWebMessageReceived += HandleScriptNotify;
}

public async Task Send(string eventName, params object[] args)
public void Send(string eventName, params object[] args)
{
try
{
Expand Down
76 changes: 68 additions & 8 deletions src/WebWindow.Native/Exports.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "WebWindow.h"

#ifdef _WIN32
# define EXPORTED __declspec( dllexport )
# define EXPORTED __declspec(dllexport)
#else
# define EXPORTED
#endif
Expand All @@ -25,12 +25,17 @@ extern "C"
}
#endif

EXPORTED WebWindow* WebWindow_ctor(UTF8String title, WebWindow* parent, WebMessageReceivedCallback webMessageReceivedCallback)
EXPORTED WebWindow* WebWindow_ctor(AutoString title, WebWindow* parent, WebMessageReceivedCallback webMessageReceivedCallback)
{
return new WebWindow(title, parent, webMessageReceivedCallback);
}

EXPORTED void WebWindow_SetTitle(WebWindow* instance, UTF8String title)
EXPORTED void WebWindow_dtor(WebWindow* instance)
{
delete instance;
}

EXPORTED void WebWindow_SetTitle(WebWindow* instance, AutoString title)
{
instance->SetTitle(title);
}
Expand All @@ -45,7 +50,7 @@ extern "C"
instance->WaitForExit();
}

EXPORTED void WebWindow_ShowMessage(WebWindow* instance, UTF8String title, UTF8String body, unsigned int type)
EXPORTED void WebWindow_ShowMessage(WebWindow* instance, AutoString title, AutoString body, unsigned int type)
{
instance->ShowMessage(title, body, type);
}
Expand All @@ -55,23 +60,78 @@ extern "C"
instance->Invoke(callback);
}

EXPORTED void WebWindow_NavigateToString(WebWindow* instance, UTF8String content)
EXPORTED void WebWindow_NavigateToString(WebWindow* instance, AutoString content)
{
instance->NavigateToString(content);
}

EXPORTED void WebWindow_NavigateToUrl(WebWindow* instance, UTF8String url)
EXPORTED void WebWindow_NavigateToUrl(WebWindow* instance, AutoString url)
{
instance->NavigateToUrl(url);
}

EXPORTED void WebWindow_SendMessage(WebWindow* instance, UTF8String message)
EXPORTED void WebWindow_SendMessage(WebWindow* instance, AutoString message)
{
instance->SendMessage(message);
}

EXPORTED void WebWindow_AddCustomScheme(WebWindow* instance, UTF8String scheme, WebResourceRequestedCallback requestHandler)
EXPORTED void WebWindow_AddCustomScheme(WebWindow* instance, AutoString scheme, WebResourceRequestedCallback requestHandler)
{
instance->AddCustomScheme(scheme, requestHandler);
}

EXPORTED void WebWindow_SetResizable(WebWindow* instance, int resizable)
{
instance->SetResizable(resizable);
}

EXPORTED void WebWindow_GetSize(WebWindow* instance, int* width, int* height)
{
instance->GetSize(width, height);
}

EXPORTED void WebWindow_SetSize(WebWindow* instance, int width, int height)
{
instance->SetSize(width, height);
}

EXPORTED void WebWindow_SetResizedCallback(WebWindow* instance, ResizedCallback callback)
{
instance->SetResizedCallback(callback);
}

EXPORTED void WebWindow_GetAllMonitors(WebWindow* instance, GetAllMonitorsCallback callback)
{
instance->GetAllMonitors(callback);
}

EXPORTED unsigned int WebWindow_GetScreenDpi(WebWindow* instance)
{
return instance->GetScreenDpi();
}

EXPORTED void WebWindow_GetPosition(WebWindow* instance, int* x, int* y)
{
instance->GetPosition(x, y);
}

EXPORTED void WebWindow_SetPosition(WebWindow* instance, int x, int y)
{
instance->SetPosition(x, y);
}

EXPORTED void WebWindow_SetMovedCallback(WebWindow* instance, MovedCallback callback)
{
instance->SetMovedCallback(callback);
}

EXPORTED void WebWindow_SetTopmost(WebWindow* instance, int topmost)
{
instance->SetTopmost(topmost);
}

EXPORTED void WebWindow_SetIconFile(WebWindow* instance, AutoString filename)
{
instance->SetIconFile(filename);
}
}
Loading

0 comments on commit bf896ae

Please sign in to comment.