Skip to content

Commit 4e8e771

Browse files
Merge pull request #311 from Daddoon/master
Support of AddExtension, RemoveExtension, GetExtensions
2 parents 7f92ffa + 28be0dd commit 4e8e771

File tree

5 files changed

+353
-213
lines changed

5 files changed

+353
-213
lines changed

ElectronNET.API/BrowserWindow.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,5 +2310,58 @@ public void SetVibrancy(Vibrancy type)
23102310
ContractResolver = new CamelCasePropertyNamesContractResolver(),
23112311
NullValueHandling = NullValueHandling.Ignore
23122312
};
2313+
2314+
/// <summary>
2315+
/// Adds Chrome extension located at path, and returns extension's name.
2316+
/// The method will also not return if the extension's manifest is missing or incomplete.
2317+
/// Note: This API cannot be called before the ready event of the app module is emitted.
2318+
/// </summary>
2319+
/// <param name="path">Path to the Chrome extension</param>
2320+
/// <returns></returns>
2321+
public static Task<string> AddExtensionAsync(string path)
2322+
{
2323+
var taskCompletionSource = new TaskCompletionSource<string>();
2324+
2325+
BridgeConnector.Socket.On("browserWindow-addExtension-completed", (extensionname) => {
2326+
BridgeConnector.Socket.Off("browserWindow-addExtension-completed");
2327+
2328+
taskCompletionSource.SetResult(extensionname.ToString());
2329+
});
2330+
2331+
BridgeConnector.Socket.Emit("browserWindowAddExtension", path);
2332+
2333+
return taskCompletionSource.Task;
2334+
}
2335+
2336+
/// <summary>
2337+
/// Remove Chrome extension with the specified name.
2338+
/// Note: This API cannot be called before the ready event of the app module is emitted.
2339+
/// </summary>
2340+
/// <param name="name">Name of the Chrome extension to remove</param>
2341+
public static void RemoveExtension(string name)
2342+
{
2343+
BridgeConnector.Socket.Emit("browserWindowRemoveExtension", name);
2344+
}
2345+
2346+
/// <summary>
2347+
/// The keys are the extension names and each value is an object containing name and version properties.
2348+
/// Note: This API cannot be called before the ready event of the app module is emitted.
2349+
/// </summary>
2350+
/// <returns></returns>
2351+
public static Task<ChromeExtensionInfo[]> GetExtensionsAsync()
2352+
{
2353+
var taskCompletionSource = new TaskCompletionSource<ChromeExtensionInfo[]>();
2354+
2355+
BridgeConnector.Socket.On("browserWindow-getExtensions-completed", (extensionslist) => {
2356+
BridgeConnector.Socket.Off("browserWindow-getExtensions-completed");
2357+
var chromeExtensionInfos = ((JArray)extensionslist).ToObject<ChromeExtensionInfo[]>();
2358+
2359+
taskCompletionSource.SetResult(chromeExtensionInfos);
2360+
});
2361+
2362+
BridgeConnector.Socket.Emit("browserWindowGetExtensions");
2363+
2364+
return taskCompletionSource.Task;
2365+
}
23132366
}
23142367
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace ElectronNET.API.Entities
6+
{
7+
/// <summary>
8+
/// Provide metadata about the current loaded Chrome extension
9+
/// </summary>
10+
public class ChromeExtensionInfo
11+
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="ChromeExtensionInfo"/> class.
14+
/// </summary>
15+
/// <param name="name">The name of the Chrome extension.</param>
16+
/// <param name="version">The version of the Chrome extension.</param>
17+
public ChromeExtensionInfo(string name, string version)
18+
{
19+
Name = name;
20+
Version = version;
21+
}
22+
23+
/// <summary>
24+
/// Name of the Chrome extension
25+
/// </summary>
26+
public string Name { get; set; }
27+
28+
/// <summary>
29+
/// Version of the Chrome extension
30+
/// </summary>
31+
public string Version { get; set; }
32+
}
33+
}

0 commit comments

Comments
 (0)