mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-04-27 00:20:24 +00:00
implement first Electron-API Bridge functions - Add little sample in WebApp
This commit is contained in:
@@ -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() { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,5 @@
|
||||
<PackageReference Include="SocketIoClientDotNet" Version="1.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="$(ProjectDir)devCleanup.cmd" />
|
||||
</Target>
|
||||
|
||||
|
||||
</Project>
|
||||
|
||||
24
ElectronNET.API/Entities/PathName.cs
Normal file
24
ElectronNET.API/Entities/PathName.cs
Normal 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
|
||||
}
|
||||
}
|
||||
8
ElectronNET.API/Entities/RelaunchOptions.cs
Normal file
8
ElectronNET.API/Entities/RelaunchOptions.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
public class RelaunchOptions
|
||||
{
|
||||
public string[] Args { get; set; }
|
||||
public string ExecPath { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
rd /s /q %userprofile%\.nuget\packages\electronnet.api
|
||||
rd /s /q "%userprofile%\.nuget\packages\electronnet.api\"
|
||||
|
||||
Reference in New Issue
Block a user