mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-14 21:24:58 +00:00
implement Demo App sections: Dialogs, Menu, Tray, Shell, CrashHang, Notification, Shortcuts etc. Fix some API bugs and implement GlobalShortcut-, Shell- and WebContents-API.
This commit is contained in:
67
ElectronNET.WebApp/Controllers/DialogsController.cs
Normal file
67
ElectronNET.WebApp/Controllers/DialogsController.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ElectronNET.API;
|
||||
using ElectronNET.API.Entities;
|
||||
|
||||
namespace ElectronNET.WebApp.Controllers
|
||||
{
|
||||
public class DialogsController : Controller
|
||||
{
|
||||
public IActionResult Index()
|
||||
{
|
||||
Electron.IpcMain.On("select-directory", async (args) => {
|
||||
var mainWindow = Electron.WindowManager.BrowserWindows.First();
|
||||
var options = new OpenDialogOptions {
|
||||
Properties = new OpenDialogProperty[] {
|
||||
OpenDialogProperty.openFile,
|
||||
OpenDialogProperty.openDirectory
|
||||
}
|
||||
};
|
||||
|
||||
string[] files = await Electron.Dialog.ShowOpenDialogAsync(mainWindow, options);
|
||||
Electron.IpcMain.Send(mainWindow, "select-directory-reply", files);
|
||||
});
|
||||
|
||||
Electron.IpcMain.On("error-dialog", (args) =>
|
||||
{
|
||||
Electron.Dialog.ShowErrorBox("An Error Message", "Demonstrating an error message.");
|
||||
});
|
||||
|
||||
Electron.IpcMain.On("information-dialog", async (args) =>
|
||||
{
|
||||
var options = new MessageBoxOptions("This is an information dialog. Isn't it nice?")
|
||||
{
|
||||
Type = MessageBoxType.info,
|
||||
Title = "Information",
|
||||
Buttons = new string[] { "Yes", "No" }
|
||||
};
|
||||
|
||||
var result = await Electron.Dialog.ShowMessageBoxAsync(options);
|
||||
|
||||
var mainWindow = Electron.WindowManager.BrowserWindows.First();
|
||||
Electron.IpcMain.Send(mainWindow, "information-dialog-reply", result.Response);
|
||||
});
|
||||
|
||||
Electron.IpcMain.On("save-dialog", async (args) =>
|
||||
{
|
||||
var mainWindow = Electron.WindowManager.BrowserWindows.First();
|
||||
var options = new SaveDialogOptions
|
||||
{
|
||||
Title = "Save an Image",
|
||||
Filters = new FileFilter[]
|
||||
{
|
||||
new FileFilter { Name = "Images", Extensions = new string[] {"jpg", "png", "gif" } }
|
||||
}
|
||||
};
|
||||
|
||||
var result = await Electron.Dialog.ShowSaveDialogAsync(mainWindow, options);
|
||||
Electron.IpcMain.Send(mainWindow, "save-dialog-reply", result);
|
||||
});
|
||||
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user