diff --git a/ElectronNET.API/BrowserWindow.cs b/ElectronNET.API/BrowserWindow.cs index e7b18b4..f467173 100644 --- a/ElectronNET.API/BrowserWindow.cs +++ b/ElectronNET.API/BrowserWindow.cs @@ -2318,9 +2318,19 @@ namespace ElectronNET.API /// /// Path to the Chrome extension /// - public static string AddExtension(string path) + public static Task AddExtensionAsync(string path) { - throw new NotImplementedException(); + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("browserWindow-addExtension-completed", (extensionname) => { + BridgeConnector.Socket.Off("browserWindow-addExtension-completed"); + + taskCompletionSource.SetResult(extensionname.ToString()); + }); + + BridgeConnector.Socket.Emit("browserWindowAddExtension", path); + + return taskCompletionSource.Task; } /// @@ -2330,7 +2340,7 @@ namespace ElectronNET.API /// Name of the Chrome extension to remove public static void RemoveExtension(string name) { - throw new NotImplementedException(); + BridgeConnector.Socket.Emit("browserWindowRemoveExtension", name); } /// @@ -2338,9 +2348,20 @@ namespace ElectronNET.API /// Note: This API cannot be called before the ready event of the app module is emitted. /// /// - public static Dictionary GetExtensions() + public static Task GetExtensionsAsync() { - throw new NotImplementedException(); + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("browserWindow-getExtensions-completed", (extensionslist) => { + BridgeConnector.Socket.Off("browserWindow-getExtensions-completed"); + var chromeExtensionInfos = ((JArray)extensionslist).ToObject(); + + taskCompletionSource.SetResult(chromeExtensionInfos); + }); + + BridgeConnector.Socket.Emit("browserWindowGetExtensions"); + + return taskCompletionSource.Task; } } } diff --git a/ElectronNET.API/Entities/ChromeExtensionInfo.cs b/ElectronNET.API/Entities/ChromeExtensionInfo.cs index 09ec67c..87a44d5 100644 --- a/ElectronNET.API/Entities/ChromeExtensionInfo.cs +++ b/ElectronNET.API/Entities/ChromeExtensionInfo.cs @@ -9,30 +9,20 @@ namespace ElectronNET.API.Entities /// public class ChromeExtensionInfo { - private string _name; - private string _version; - - - internal ChromeExtensionInfo(string name, string version) + public ChromeExtensionInfo(string name, string version) { - _name = name; - _version = version; + Name = name; + Version = version; } /// /// Name of the Chrome extension /// - public string Name - { - get => _name; - } + public string Name { get; set; } /// /// Version of the Chrome extension /// - public string Version - { - get => _version; - } + public string Version { get; set; } } } diff --git a/ElectronNET.Host/api/browserWindows.ts b/ElectronNET.Host/api/browserWindows.ts index ae473cb..302f34a 100644 --- a/ElectronNET.Host/api/browserWindows.ts +++ b/ElectronNET.Host/api/browserWindows.ts @@ -706,6 +706,28 @@ export = (socket: SocketIO.Socket, app: Electron.App) => { getWindowById(id).setVibrancy(type); }); + socket.on('browserWindowAddExtension', (path) => { + const extensionName = Electron.BrowserWindow.addExtension(path); + + electronSocket.emit('browserWindow-addExtension-completed', extensionName); + }); + + socket.on('browserWindowRemoveExtension', (name) => { + Electron.BrowserWindow.removeExtension(name); + }); + + socket.on('browserWindowGetExtensions', (path) => { + const extensionsList = Electron.BrowserWindow.getExtensions(); + + let chromeExtensionInfo = new Array(); + + Object.keys(extensionsList).forEach(key => { + chromeExtensionInfo.push(extensionsList[key]); + }); + + electronSocket.emit('browserWindow-getExtensions-completed', chromeExtensionInfo); + }); + function getWindowById(id: number): Electron.BrowserWindow { for (let index = 0; index < windows.length; index++) { const element = windows[index];