Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions ElectronNET.API/BrowserWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2310,5 +2310,58 @@ public void SetVibrancy(Vibrancy type)
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore
};

/// <summary>
/// Adds Chrome extension located at path, and returns extension's name.
/// The method will also not return if the extension's manifest is missing or incomplete.
/// Note: This API cannot be called before the ready event of the app module is emitted.
/// </summary>
/// <param name="path">Path to the Chrome extension</param>
/// <returns></returns>
public static Task<string> AddExtensionAsync(string path)
{
var taskCompletionSource = new TaskCompletionSource<string>();

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;
}

/// <summary>
/// Remove Chrome extension with the specified name.
/// Note: This API cannot be called before the ready event of the app module is emitted.
/// </summary>
/// <param name="name">Name of the Chrome extension to remove</param>
public static void RemoveExtension(string name)
{
BridgeConnector.Socket.Emit("browserWindowRemoveExtension", name);
}

/// <summary>
/// The keys are the extension names and each value is an object containing name and version properties.
/// Note: This API cannot be called before the ready event of the app module is emitted.
/// </summary>
/// <returns></returns>
public static Task<ChromeExtensionInfo[]> GetExtensionsAsync()
{
var taskCompletionSource = new TaskCompletionSource<ChromeExtensionInfo[]>();

BridgeConnector.Socket.On("browserWindow-getExtensions-completed", (extensionslist) => {
BridgeConnector.Socket.Off("browserWindow-getExtensions-completed");
var chromeExtensionInfos = ((JArray)extensionslist).ToObject<ChromeExtensionInfo[]>();

taskCompletionSource.SetResult(chromeExtensionInfos);
});

BridgeConnector.Socket.Emit("browserWindowGetExtensions");

return taskCompletionSource.Task;
}
}
}
33 changes: 33 additions & 0 deletions ElectronNET.API/Entities/ChromeExtensionInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ElectronNET.API.Entities
{
/// <summary>
/// Provide metadata about the current loaded Chrome extension
/// </summary>
public class ChromeExtensionInfo
{
/// <summary>
/// Initializes a new instance of the <see cref="ChromeExtensionInfo"/> class.
/// </summary>
/// <param name="name">The name of the Chrome extension.</param>
/// <param name="version">The version of the Chrome extension.</param>
public ChromeExtensionInfo(string name, string version)
{
Name = name;
Version = version;
}

/// <summary>
/// Name of the Chrome extension
/// </summary>
public string Name { get; set; }

/// <summary>
/// Version of the Chrome extension
/// </summary>
public string Version { get; set; }
}
}
Loading