imeplement all Dialog-API functions

This commit is contained in:
Gregor Biswanger
2017-10-17 22:28:43 +02:00
parent 28dab9866d
commit 072a24d091
8 changed files with 273 additions and 7 deletions

View File

@@ -31,7 +31,7 @@ namespace ElectronNET.API
/// and a directory selector, so if you set properties to ['openFile', 'openDirectory']
/// on these platforms, a directory selector will be shown.
/// </summary>
/// <param name="browserWindow"></param>
/// <param name="browserWindow">The browserWindow argument allows the dialog to attach itself to a parent window, making it modal.</param>
/// <param name="options"></param>
/// <returns>An array of file paths chosen by the user</returns>
public Task<string[]> ShowOpenDialogAsync(BrowserWindow browserWindow, OpenDialogOptions options)
@@ -53,6 +53,30 @@ namespace ElectronNET.API
return taskCompletionSource.Task;
}
/// <summary>
/// Dialog for save files.
/// </summary>
/// <param name="browserWindow">The browserWindow argument allows the dialog to attach itself to a parent window, making it modal.</param>
/// <param name="options"></param>
/// <returns>Returns String, the path of the file chosen by the user, if a callback is provided it returns an empty string.</returns>
public Task<string> ShowSaveDialogAsync(BrowserWindow browserWindow, SaveDialogOptions options)
{
var taskCompletionSource = new TaskCompletionSource<string>();
BridgeConnector.Socket.On("showSaveDialogComplete", (filename) =>
{
BridgeConnector.Socket.Off("showSaveDialogComplete");
taskCompletionSource.SetResult(filename.ToString());
});
BridgeConnector.Socket.Emit("showSaveDialog",
JObject.FromObject(browserWindow, _jsonSerializer),
JObject.FromObject(options, _jsonSerializer));
return taskCompletionSource.Task;
}
/// <summary>
/// Shows a message box, it will block the process until the message box is closed.
/// It returns the index of the clicked button. The browserWindow argument allows
@@ -106,6 +130,58 @@ namespace ElectronNET.API
return taskCompletionSource.Task;
}
/// <summary>
/// Displays a modal dialog that shows an error message.
///
/// This API can be called safely before the ready event the app module emits,
/// it is usually used to report errors in early stage of startup.If called
/// before the app readyevent on Linux, the message will be emitted to stderr,
/// and no GUI dialog will appear.
/// </summary>
/// <param name="title">The title to display in the error box.</param>
/// <param name="content">The text content to display in the error box.</param>
public void ShowErrorBox(string title, string content)
{
BridgeConnector.Socket.Emit("showErrorBox", title, content);
}
/// <summary>
/// On macOS, this displays a modal dialog that shows a message and certificate information,
/// and gives the user the option of trusting/importing the certificate. If you provide a
/// browserWindow argument the dialog will be attached to the parent window, making it modal.
/// </summary>
/// <param name="options"></param>
/// <returns></returns>
public Task ShowCertificateTrustDialogAsync(CertificateTrustDialogOptions options)
{
return ShowCertificateTrustDialogAsync(null, options);
}
/// <summary>
/// On macOS, this displays a modal dialog that shows a message and certificate information,
/// and gives the user the option of trusting/importing the certificate. If you provide a
/// browserWindow argument the dialog will be attached to the parent window, making it modal.
/// </summary>
/// <param name="browserWindow"></param>
/// <param name="options"></param>
/// <returns></returns>
public Task ShowCertificateTrustDialogAsync(BrowserWindow browserWindow, CertificateTrustDialogOptions options)
{
var taskCompletionSource = new TaskCompletionSource<object>();
BridgeConnector.Socket.On("showCertificateTrustDialogComplete", () =>
{
BridgeConnector.Socket.Off("showCertificateTrustDialogComplete");
taskCompletionSource.SetResult(null);
});
BridgeConnector.Socket.Emit("showCertificateTrustDialog",
JObject.FromObject(browserWindow, _jsonSerializer),
JObject.FromObject(options, _jsonSerializer));
return taskCompletionSource.Task;
}
private JsonSerializer _jsonSerializer = new JsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),

View File

@@ -0,0 +1,55 @@
namespace ElectronNET.API.Entities
{
public class Certificate
{
/// <summary>
/// PEM encoded data
/// </summary>
public string Data { get; set; }
/// <summary>
/// Fingerprint of the certificate
/// </summary>
public string Fingerprint { get; set; }
/// <summary>
/// Issuer principal
/// </summary>
public CertificatePrincipal Issuer { get; set; }
/// <summary>
/// Issuer certificate (if not self-signed)
/// </summary>
public Certificate IssuerCert { get; set; }
/// <summary>
/// Issuer's Common Name
/// </summary>
public string IssuerName { get; set; }
/// <summary>
/// Hex value represented string
/// </summary>
public string SerialNumber { get; set; }
/// <summary>
/// Subject principal
/// </summary>
public CertificatePrincipal Subject { get; set; }
/// <summary>
/// Subject's Common Name
/// </summary>
public string SubjectName { get; set; }
/// <summary>
/// End date of the certificate being valid in seconds
/// </summary>
public int ValidExpiry { get; set; }
/// <summary>
/// Start date of the certificate being valid in seconds
/// </summary>
public int ValidStart { get; set; }
}
}

View File

@@ -0,0 +1,35 @@
namespace ElectronNET.API.Entities
{
public class CertificatePrincipal
{
/// <summary>
/// Common Name
/// </summary>
public string CommonName { get; set; }
/// <summary>
/// Country or region
/// </summary>
public string Country { get; set; }
/// <summary>
/// Locality
/// </summary>
public string Locality { get; set; }
/// <summary>
/// Organization names
/// </summary>
public string[] Organizations { get; set; }
/// <summary>
/// Organization Unit names
/// </summary>
public string[] OrganizationUnits { get; set; }
/// <summary>
/// State or province
/// </summary>
public string State { get; set; }
}
}

View File

@@ -0,0 +1,15 @@
namespace ElectronNET.API.Entities
{
public class CertificateTrustDialogOptions
{
/// <summary>
/// The certificate to trust/import.
/// </summary>
public Certificate Certificate { get; set; }
/// <summary>
/// The message to display to the user.
/// </summary>
public string Message { get; set; }
}
}

View File

@@ -0,0 +1,52 @@
using ElectronNET.API.Entities;
namespace ElectronNET.API
{
public class SaveDialogOptions
{
public string Title { get; set; }
/// <summary>
/// Absolute directory path, absolute file path, or file name to use by default.
/// </summary>
public string DefaultPath { get; set; }
/// <summary>
/// Custom label for the confirmation button, when left empty the default label will
/// be used.
/// </summary>
public string ButtonLabel { get; set; }
/// <summary>
/// The filters specifies an array of file types that can be displayed or
/// selected when you want to limit the user to a specific type. For example:
/// </summary>
/// <example>
/// <code>
/// new FileFilter[]
/// {
/// new FileFiler { Name = "Images", Extensions = new string[] { "jpg", "png", "gif" } },
/// new FileFiler { Name = "Movies", Extensions = new string[] { "mkv", "avi", "mp4" } },
/// new FileFiler { Name = "Custom File Type", Extensions= new string[] {"as" } },
/// new FileFiler { Name = "All Files", Extensions= new string[] { "*" } }
/// }
/// </code>
/// </example>
public FileFilter[] Filters { get; set; }
/// <summary>
/// Message to display above text fields.
/// </summary>
public string Message { get; set; }
/// <summary>
/// Custom label for the text displayed in front of the filename text field.
/// </summary>
public string NameFieldLabel { get; set; }
/// <summary>
/// Show the tags input box, defaults to true.
/// </summary>
public bool ShowsTagField { get; set; }
}
}