mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-07-11 19:27:52 +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/ManageWindowsController.cs
Normal file
67
ElectronNET.WebApp/Controllers/ManageWindowsController.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 WindowsController : Controller
|
||||
{
|
||||
public IActionResult Index()
|
||||
{
|
||||
string viewPath = $"http://localhost:{BridgeSettings.WebPort}/windows/demowindow";
|
||||
|
||||
Electron.IpcMain.On("new-window", async (args) => {
|
||||
|
||||
await Electron.WindowManager.CreateWindowAsync(viewPath);
|
||||
|
||||
});
|
||||
|
||||
Electron.IpcMain.On("manage-window", async (args) => {
|
||||
|
||||
var browserWindow = await Electron.WindowManager.CreateWindowAsync(viewPath);
|
||||
browserWindow.OnMove += UpdateReply;
|
||||
browserWindow.OnResize += UpdateReply;
|
||||
});
|
||||
|
||||
Electron.IpcMain.On("listen-to-window", async (args) => {
|
||||
var mainBrowserWindow = Electron.WindowManager.BrowserWindows.First();
|
||||
|
||||
var browserWindow = await Electron.WindowManager.CreateWindowAsync(viewPath);
|
||||
browserWindow.OnFocus += () => Electron.IpcMain.Send(mainBrowserWindow, "listen-to-window-focus");
|
||||
browserWindow.OnBlur += () => Electron.IpcMain.Send(mainBrowserWindow, "listen-to-window-blur");
|
||||
|
||||
Electron.IpcMain.On("listen-to-window-set-focus", (x) => browserWindow.Focus());
|
||||
});
|
||||
|
||||
Electron.IpcMain.On("frameless-window", async (args) => {
|
||||
var options = new BrowserWindowOptions
|
||||
{
|
||||
Frame = false
|
||||
};
|
||||
await Electron.WindowManager.CreateWindowAsync(options, viewPath);
|
||||
});
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
private async void UpdateReply()
|
||||
{
|
||||
var browserWindow = Electron.WindowManager.BrowserWindows.Last();
|
||||
var size = await browserWindow.GetSizeAsync();
|
||||
var position = await browserWindow.GetPositionAsync();
|
||||
string message = $"Size: {size[0]},{size[1]} Position: {position[0]},{position[1]}";
|
||||
|
||||
var mainWindow = Electron.WindowManager.BrowserWindows.First();
|
||||
Electron.IpcMain.Send(mainWindow, "manage-window-reply", message);
|
||||
}
|
||||
|
||||
public IActionResult DemoWindow()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user