implement first Electron-API Bridge functions - Add little sample in WebApp

This commit is contained in:
Gregor Biswanger
2017-10-12 02:24:27 +02:00
parent 6020369892
commit 5f0be6543b
13 changed files with 206 additions and 9 deletions

View File

@@ -4,16 +4,17 @@ using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using Quobject.SocketIoClientDotNet.Client;
using System;
using System.Threading.Tasks;
namespace ElectronNET.API
{
public static class App
{
public static IpcMain IpcMain { get; private set; }
private static Socket _socket;
private static JsonSerializer _jsonSerializer;
public static IpcMain IpcMain { get; private set; }
public static void OpenWindow(int width, int height, bool show)
{
_jsonSerializer = new JsonSerializer()
@@ -26,7 +27,8 @@ namespace ElectronNET.API
{
Console.WriteLine("Verbunden!");
var browserWindowOptions = new BrowserWindowOptions() {
var browserWindowOptions = new BrowserWindowOptions()
{
Height = height,
Width = width,
Show = show
@@ -42,5 +44,70 @@ namespace ElectronNET.API
{
_socket.Emit("createNotification", JObject.FromObject(notificationOptions, _jsonSerializer));
}
public static void Quit()
{
_socket.Emit("appQuit");
}
public static void Exit(int exitCode = 0)
{
_socket.Emit("appExit", exitCode);
}
public static void Relaunch()
{
_socket.Emit("appRelaunch");
}
public static void Relaunch(RelaunchOptions relaunchOptions)
{
_socket.Emit("appRelaunch", JObject.FromObject(relaunchOptions, _jsonSerializer));
}
public static void Focus()
{
_socket.Emit("appFocus");
}
public static void Hide()
{
_socket.Emit("appHide");
}
public static void Show()
{
_socket.Emit("appShow");
}
public async static Task<string> GetAppPathAsync()
{
var taskCompletionSource = new TaskCompletionSource<string>();
_socket.On("appGetAppPathCompleted", (path) =>
{
taskCompletionSource.SetResult(path.ToString());
});
_socket.Emit("appGetAppPath");
return await taskCompletionSource.Task;
}
public async static Task<string> GetPathAsync(PathName pathName)
{
var taskCompletionSource = new TaskCompletionSource<string>();
_socket.On("appGetPathCompleted", (path) =>
{
taskCompletionSource.SetResult(path.ToString());
});
_socket.Emit("appGetPath", pathName.ToString());
return await taskCompletionSource.Task;
}
public static void Blub2() { }
}
}

View File

@@ -12,9 +12,5 @@
<PackageReference Include="SocketIoClientDotNet" Version="1.0.3" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="$(ProjectDir)devCleanup.cmd" />
</Target>
</Project>

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace ElectronNET.API.Entities
{
public enum PathName
{
home,
appData,
userData,
temp,
exe,
module,
desktop,
documents,
downloads,
music,
pictures,
videos,
logs,
pepperFlashSystemPlugin
}
}

View File

@@ -0,0 +1,8 @@
namespace ElectronNET.API.Entities
{
public class RelaunchOptions
{
public string[] Args { get; set; }
public string ExecPath { get; set; }
}
}

View File

@@ -1 +1 @@
rd /s /q %userprofile%\.nuget\packages\electronnet.api
rd /s /q "%userprofile%\.nuget\packages\electronnet.api\"