Files
Electron.NET/ElectronNET.WebApp/Controllers/DialogsController.cs

68 lines
2.6 KiB
C#
Raw Permalink Normal View History

2017-10-23 21:24:05 +02:00
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using ElectronNET.API;
using ElectronNET.API.Entities;
namespace ElectronNET.WebApp.Controllers
{
public class DialogsController : Controller
{
public IActionResult Index()
{
2017-10-23 21:24:05 +02:00
if(HybridSupport.IsElectronActive)
{
Electron.IpcMain.On("select-directory", async (args) => {
var mainWindow = Electron.WindowManager.BrowserWindows.First();
var options = new OpenDialogOptions
{
Properties = new OpenDialogProperty[] {
OpenDialogProperty.openFile,
OpenDialogProperty.openDirectory
}
2017-10-23 21:24:05 +02:00
};
2017-10-23 21:24:05 +02:00
string[] files = await Electron.Dialog.ShowOpenDialogAsync(mainWindow, options);
Electron.IpcMain.Send(mainWindow, "select-directory-reply", files);
});
2017-10-23 21:24:05 +02:00
Electron.IpcMain.On("error-dialog", (args) =>
{
Electron.Dialog.ShowErrorBox("An Error Message", "Demonstrating an error message.");
});
2017-10-23 21:24:05 +02:00
Electron.IpcMain.On("information-dialog", async (args) =>
{
2017-10-23 21:24:05 +02:00
var options = new MessageBoxOptions("This is an information dialog. Isn't it nice?")
{
Type = MessageBoxType.info,
Title = "Information",
Buttons = new string[] { "Yes", "No" }
};
2017-10-23 21:24:05 +02:00
var result = await Electron.Dialog.ShowMessageBoxAsync(options);
2017-10-23 21:24:05 +02:00
var mainWindow = Electron.WindowManager.BrowserWindows.First();
Electron.IpcMain.Send(mainWindow, "information-dialog-reply", result.Response);
});
2017-10-23 21:24:05 +02:00
Electron.IpcMain.On("save-dialog", async (args) =>
{
2017-10-23 21:24:05 +02:00
var mainWindow = Electron.WindowManager.BrowserWindows.First();
var options = new SaveDialogOptions
{
2017-10-23 21:24:05 +02:00
Title = "Save an Image",
Filters = new FileFilter[]
{
new FileFilter { Name = "Images", Extensions = new string[] {"jpg", "png", "gif" } }
2017-10-23 21:24:05 +02:00
}
};
2017-10-23 21:24:05 +02:00
var result = await Electron.Dialog.ShowSaveDialogAsync(mainWindow, options);
Electron.IpcMain.Send(mainWindow, "save-dialog-reply", result);
});
}
return View();
}
}
}