mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-09-22 15:04:47 +00:00
implement first dialog-, notification-, tray- and menu-api functions
This commit is contained in:
@@ -280,12 +280,6 @@ namespace ElectronNET.API
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
};
|
||||
|
||||
// TODO: Auslagern in eigenes Notification-API
|
||||
public void CreateNotification(NotificationOptions notificationOptions)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("createNotification", JObject.FromObject(notificationOptions, _jsonSerializer));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to close all windows. The before-quit event will be emitted first. If all
|
||||
/// windows are successfully closed, the will-quit event will be emitted and by
|
||||
|
||||
89
ElectronNET.API/Dialog.cs
Normal file
89
ElectronNET.API/Dialog.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
public sealed class Dialog
|
||||
{
|
||||
private static Dialog _dialog;
|
||||
|
||||
internal Dialog() { }
|
||||
|
||||
internal static Dialog Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_dialog == null)
|
||||
{
|
||||
_dialog = new Dialog();
|
||||
}
|
||||
|
||||
return _dialog;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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
|
||||
/// the dialog to attach itself to a parent window, making it modal. If a callback
|
||||
/// is passed, the dialog will not block the process.The API call will be
|
||||
/// asynchronous and the result will be passed via callback(response).
|
||||
/// </summary>
|
||||
/// <param name="messageBoxOptions"></param>
|
||||
/// <returns>The API call will be asynchronous and the result will be passed via MessageBoxResult.</returns>
|
||||
public async Task<MessageBoxResult> ShowMessageBoxAsync(MessageBoxOptions messageBoxOptions)
|
||||
{
|
||||
return await ShowMessageBoxAsync(null, messageBoxOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows a message box, it will block the process until the message box is closed.
|
||||
/// It returns the index of the clicked button. If a callback
|
||||
/// is passed, the dialog will not block the process.
|
||||
/// </summary>
|
||||
/// <param name="browserWindow">The browserWindow argument allows the dialog to attach itself to a parent window, making it modal.</param>
|
||||
/// <param name="messageBoxOptions"></param>
|
||||
/// <returns>The API call will be asynchronous and the result will be passed via MessageBoxResult.</returns>
|
||||
public Task<MessageBoxResult> ShowMessageBoxAsync(BrowserWindow browserWindow, MessageBoxOptions messageBoxOptions)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<MessageBoxResult>();
|
||||
|
||||
BridgeConnector.Socket.On("showMessageBoxComplete", (args) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off("showMessageBoxComplete");
|
||||
|
||||
var result = ((JArray)args);
|
||||
|
||||
taskCompletionSource.SetResult(new MessageBoxResult
|
||||
{
|
||||
Response = (int)result.First,
|
||||
CheckboxChecked = (bool)result.Last
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
if (browserWindow == null)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("showMessageBox", JObject.FromObject(messageBoxOptions, _jsonSerializer));
|
||||
} else
|
||||
{
|
||||
BridgeConnector.Socket.Emit("showMessageBox",
|
||||
JObject.FromObject(browserWindow, _jsonSerializer),
|
||||
JObject.FromObject(messageBoxOptions, _jsonSerializer));
|
||||
}
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -21,5 +21,20 @@
|
||||
/// Create native application menus and context menus.
|
||||
/// </summary>
|
||||
public static Menu Menu { get { return Menu.Instance; } }
|
||||
|
||||
/// <summary>
|
||||
/// Display native system dialogs for opening and saving files, alerting, etc.
|
||||
/// </summary>
|
||||
public static Dialog Dialog { get { return Dialog.Instance; } }
|
||||
|
||||
/// <summary>
|
||||
/// Create OS desktop notifications
|
||||
/// </summary>
|
||||
public static Notification Notification { get { return Notification.Instance; } }
|
||||
|
||||
/// <summary>
|
||||
/// Add icons and context menus to the system’s notification area.
|
||||
/// </summary>
|
||||
public static Tray Tray { get { return Tray.Instance; } }
|
||||
}
|
||||
}
|
||||
|
||||
84
ElectronNET.API/Entities/MessageBoxOptions.cs
Normal file
84
ElectronNET.API/Entities/MessageBoxOptions.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
public class MessageBoxOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Can be "none", "info", "error", "question" or "warning". On Windows, "question"
|
||||
/// displays the same icon as "info", unless you set an icon using the "icon"
|
||||
/// option.On macOS, both "warning" and "error" display the same warning icon.
|
||||
/// </summary>
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Array of texts for buttons. On Windows, an empty array will result in one button
|
||||
/// labeled "OK".
|
||||
/// </summary>
|
||||
public string[] Buttons { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Index of the button in the buttons array which will be selected by default when
|
||||
/// the message box opens.
|
||||
/// </summary>
|
||||
public int DefaultId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Title of the message box, some platforms will not show it.
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Content of the message box.
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Extra information of the message.
|
||||
/// </summary>
|
||||
public string Detail { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If provided, the message box will include a checkbox with the given label. The
|
||||
/// checkbox state can be inspected only when using callback.
|
||||
/// </summary>
|
||||
public string CheckboxLabel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initial checked state of the checkbox. false by default.
|
||||
/// </summary>
|
||||
public bool CheckboxChecked { get; set; }
|
||||
|
||||
public string Icon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The index of the button to be used to cancel the dialog, via the Esc key. By
|
||||
/// default this is assigned to the first button with "cancel" or "no" as the label.
|
||||
/// If no such labeled buttons exist and this option is not set, 0 will be used as
|
||||
/// the return value or callback response. This option is ignored on Windows.
|
||||
/// </summary>
|
||||
public int CancelId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// On Windows Electron will try to figure out which one of the buttons are common
|
||||
/// buttons(like "Cancel" or "Yes"), and show the others as command links in the
|
||||
/// dialog.This can make the dialog appear in the style of modern Windows apps. If
|
||||
/// you don't like this behavior, you can set noLink to true.
|
||||
/// </summary>
|
||||
public bool NoLink { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Normalize the keyboard access keys across platforms. Default is false. Enabling
|
||||
/// this assumes & is used in the button labels for the placement of the keyboard
|
||||
/// shortcut access key and labels will be converted so they work correctly on each
|
||||
/// platform, & characters are removed on macOS, converted to _ on Linux, and left
|
||||
/// untouched on Windows.For example, a button label of Vie&w will be converted to
|
||||
/// Vie_w on Linux and View on macOS and can be selected via Alt-W on Windows and
|
||||
/// Linux.
|
||||
/// </summary>
|
||||
public bool NormalizeAccessKeys { get; set; }
|
||||
|
||||
public MessageBoxOptions(string message)
|
||||
{
|
||||
Message = message;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
ElectronNET.API/Entities/MessageBoxResult.cs
Normal file
9
ElectronNET.API/Entities/MessageBoxResult.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace ElectronNET.API.Entities
|
||||
{
|
||||
public class MessageBoxResult
|
||||
{
|
||||
public int Response { get; set; }
|
||||
|
||||
public bool CheckboxChecked { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,52 @@
|
||||
{
|
||||
public class NotificationOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// A title for the notification, which will be shown at the top of the notification
|
||||
/// window when it is shown
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The body text of the notification, which will be displayed below the title or
|
||||
/// subtitle
|
||||
/// </summary>
|
||||
public string Body { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A subtitle for the notification, which will be displayed below the title.
|
||||
/// </summary>
|
||||
public string Subtitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not to emit an OS notification noise when showing the notification
|
||||
/// </summary>
|
||||
public bool Silent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// An icon to use in the notification
|
||||
/// </summary>
|
||||
public string Icon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not to add an inline reply option to the notification.
|
||||
/// </summary>
|
||||
public bool HasReply { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The placeholder to write in the inline reply input field.
|
||||
/// </summary>
|
||||
public string ReplyPlaceholder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the sound file to play when the notification is shown.
|
||||
/// </summary>
|
||||
public string Sound { get; set; }
|
||||
|
||||
public NotificationOptions(string title, string body)
|
||||
{
|
||||
Title = title;
|
||||
Body = body;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
39
ElectronNET.API/Notification.cs
Normal file
39
ElectronNET.API/Notification.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
public sealed class Notification
|
||||
{
|
||||
private static Notification _notification;
|
||||
|
||||
internal Notification() { }
|
||||
|
||||
internal static Notification Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_notification == null)
|
||||
{
|
||||
_notification = new Notification();
|
||||
}
|
||||
|
||||
return _notification;
|
||||
}
|
||||
}
|
||||
|
||||
public void Show(NotificationOptions notificationOptions)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("createNotification", JObject.FromObject(notificationOptions, _jsonSerializer));
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
}
|
||||
39
ElectronNET.API/Tray.cs
Normal file
39
ElectronNET.API/Tray.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
public sealed class Tray
|
||||
{
|
||||
private static Tray _tray;
|
||||
|
||||
internal Tray() { }
|
||||
|
||||
internal static Tray Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_tray == null)
|
||||
{
|
||||
_tray = new Tray();
|
||||
}
|
||||
|
||||
return _tray;
|
||||
}
|
||||
}
|
||||
|
||||
public void Show(string image, MenuItem[] menuItems)
|
||||
{
|
||||
BridgeConnector.Socket.Emit("create-tray", image, JArray.FromObject(menuItems, _jsonSerializer));
|
||||
}
|
||||
|
||||
private JsonSerializer _jsonSerializer = new JsonSerializer()
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,10 @@ namespace ElectronNET.CLI.Commands
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "app.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserWindows.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "dialog.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "menu.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "notification.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "tray.js", "api.");
|
||||
|
||||
Console.WriteLine("Start npm install...");
|
||||
ProcessHelper.CmdExecute("npm install", tempPath);
|
||||
|
||||
@@ -61,6 +61,10 @@ namespace ElectronNET.CLI.Commands
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "app.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserWindows.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "dialog.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "menu.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "notification.js", "api.");
|
||||
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "tray.js", "api.");
|
||||
|
||||
Console.WriteLine("Start npm install...");
|
||||
ProcessHelper.CmdExecute("npm install", tempPath);
|
||||
|
||||
@@ -39,4 +39,11 @@
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\browserWindows.js" Link="ElectronHost\api\browserWindows.js" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\dialog.js" Link="ElectronHost\api\dialog.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\menu.js" Link="ElectronHost\api\menu.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\notification.js" Link="ElectronHost\api\notification.js" />
|
||||
<EmbeddedResource Include="..\ElectronNET.Host\api\tray.js" Link="ElectronHost\api\tray.js" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -19,6 +19,7 @@ module.exports = function (socket) {
|
||||
}
|
||||
}
|
||||
});
|
||||
// TODO: IPC Lösung für mehrere Fenster finden
|
||||
if (ipc == undefined) {
|
||||
ipc = require('./ipc')(socket, window);
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"browserWindows.js","sourceRoot":"","sources":["browserWindows.ts"],"names":[],"mappings":";;AAAA,qCAAyC;AACzC,IAAI,OAAO,GAA6B,EAAE,CAAA;AAC1C,IAAI,GAAG,CAAC;AAER,MAAM,CAAC,OAAO,GAAG,UAAC,MAAuB;IACrC,MAAM,CAAC,EAAE,CAAC,qBAAqB,EAAE,UAAC,OAAO,EAAE,OAAO;QAC9C,IAAI,MAAM,GAAG,IAAI,wBAAa,CAAC,OAAO,CAAC,CAAC;QAExC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,UAAC,MAAM;YACvB,GAAG,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;gBAClD,IAAI,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;gBAChC,IAAI,CAAC;oBACD,UAAU,CAAC,EAAE,CAAC;gBAClB,CAAC;gBAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;oBACb,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,KAAK,2BAA2B,CAAC,CAAC,CAAC;wBAChD,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;oBAC7B,CAAC;gBACL,CAAC;YACL,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,CAAC,GAAG,IAAI,SAAS,CAAC,CAAC,CAAC;YACnB,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC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B,MAAM,CAAC,OAAO,CAAC;YACnB,CAAC;QACL,CAAC;IACL,CAAC;AACL,CAAC,CAAA"}
|
||||
19
ElectronNET.Host/api/dialog.js
Normal file
19
ElectronNET.Host/api/dialog.js
Normal file
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var electron_1 = require("electron");
|
||||
module.exports = function (socket) {
|
||||
socket.on('showMessageBox', function (browserWindow, options) {
|
||||
if ("id" in browserWindow) {
|
||||
var window = electron_1.BrowserWindow.fromId(browserWindow.id);
|
||||
electron_1.dialog.showMessageBox(window, options, function (response, checkboxChecked) {
|
||||
socket.emit('showMessageBoxComplete', response, checkboxChecked);
|
||||
});
|
||||
}
|
||||
else {
|
||||
electron_1.dialog.showMessageBox(browserWindow, function (response, checkboxChecked) {
|
||||
socket.emit('showMessageBoxComplete', response, checkboxChecked);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=dialog.js.map
|
||||
1
ElectronNET.Host/api/dialog.js.map
Normal file
1
ElectronNET.Host/api/dialog.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"dialog.js","sourceRoot":"","sources":["dialog.ts"],"names":[],"mappings":";;AAAA,qCAAiD;AAEjD,MAAM,CAAC,OAAO,GAAG,UAAC,MAAuB;IACrC,MAAM,CAAC,EAAE,CAAC,gBAAgB,EAAE,UAAC,aAAa,EAAE,OAAO;QAC/C,EAAE,CAAA,CAAC,IAAI,IAAI,aAAa,CAAC,CAAC,CAAC;YACvB,IAAI,MAAM,GAAG,wBAAa,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;YAEpD,iBAAM,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,UAAC,QAAQ,EAAE,eAAe;gBAC7D,MAAM,CAAC,IAAI,CAAC,wBAAwB,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;YACrE,CAAC,CAAC,CAAC;QACP,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,iBAAM,CAAC,cAAc,CAAC,aAAa,EAAE,UAAC,QAAQ,EAAE,eAAe;gBAC3D,MAAM,CAAC,IAAI,CAAC,wBAAwB,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;YACrE,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAA"}
|
||||
17
ElectronNET.Host/api/dialog.ts
Normal file
17
ElectronNET.Host/api/dialog.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { BrowserWindow, dialog } from "electron";
|
||||
|
||||
module.exports = (socket: SocketIO.Server) => {
|
||||
socket.on('showMessageBox', (browserWindow, options) => {
|
||||
if("id" in browserWindow) {
|
||||
var window = BrowserWindow.fromId(browserWindow.id);
|
||||
|
||||
dialog.showMessageBox(window, options, (response, checkboxChecked) => {
|
||||
socket.emit('showMessageBoxComplete', response, checkboxChecked);
|
||||
});
|
||||
} else {
|
||||
dialog.showMessageBox(browserWindow, (response, checkboxChecked) => {
|
||||
socket.emit('showMessageBoxComplete', response, checkboxChecked);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
23
ElectronNET.Host/api/menu.js
Normal file
23
ElectronNET.Host/api/menu.js
Normal file
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var electron_1 = require("electron");
|
||||
module.exports = function (socket) {
|
||||
socket.on('menu-setApplicationMenu', function (menuItems) {
|
||||
var menu = electron_1.Menu.buildFromTemplate(menuItems);
|
||||
addMenuItemClickConnector(menu.items, function (id) {
|
||||
socket.emit("menuItemClicked", id);
|
||||
});
|
||||
electron_1.Menu.setApplicationMenu(menu);
|
||||
});
|
||||
function addMenuItemClickConnector(menuItems, callback) {
|
||||
menuItems.forEach(function (item) {
|
||||
if (item.submenu && item.submenu.items.length > 0) {
|
||||
addMenuItemClickConnector(item.submenu.items, callback);
|
||||
}
|
||||
if ("id" in item && item.id) {
|
||||
item.click = function () { callback(item.id); };
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
//# sourceMappingURL=menu.js.map
|
||||
1
ElectronNET.Host/api/menu.js.map
Normal file
1
ElectronNET.Host/api/menu.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"menu.js","sourceRoot":"","sources":["menu.ts"],"names":[],"mappings":";;AAAA,qCAAgC;AAEhC,MAAM,CAAC,OAAO,GAAG,UAAC,MAAuB;IACrC,MAAM,CAAC,EAAE,CAAC,yBAAyB,EAAE,UAAC,SAAS;QAC3C,IAAM,IAAI,GAAG,eAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAE/C,yBAAyB,CAAC,IAAI,CAAC,KAAK,EAAE,UAAC,EAAE;YACrC,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;QAEH,eAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,mCAAmC,SAAS,EAAE,QAAQ;QAClD,SAAS,CAAC,OAAO,CAAC,UAAC,IAAI;YACnB,EAAE,CAAA,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;gBAC/C,yBAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAC5D,CAAC;YAED,EAAE,CAAA,CAAC,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;gBACzB,IAAI,CAAC,KAAK,GAAG,cAAQ,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAC9C,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;AACL,CAAC,CAAA"}
|
||||
25
ElectronNET.Host/api/menu.ts
Normal file
25
ElectronNET.Host/api/menu.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Menu } from "electron";
|
||||
|
||||
module.exports = (socket: SocketIO.Server) => {
|
||||
socket.on('menu-setApplicationMenu', (menuItems) => {
|
||||
const menu = Menu.buildFromTemplate(menuItems);
|
||||
|
||||
addMenuItemClickConnector(menu.items, (id) => {
|
||||
socket.emit("menuItemClicked", id);
|
||||
});
|
||||
|
||||
Menu.setApplicationMenu(menu);
|
||||
});
|
||||
|
||||
function addMenuItemClickConnector(menuItems, callback) {
|
||||
menuItems.forEach((item) => {
|
||||
if(item.submenu && item.submenu.items.length > 0) {
|
||||
addMenuItemClickConnector(item.submenu.items, callback);
|
||||
}
|
||||
|
||||
if("id" in item && item.id) {
|
||||
item.click = () => { callback(item.id); };
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
10
ElectronNET.Host/api/notification.js
Normal file
10
ElectronNET.Host/api/notification.js
Normal file
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var electron_1 = require("electron");
|
||||
module.exports = function (socket) {
|
||||
socket.on('createNotification', function (options) {
|
||||
var notification = new electron_1.Notification(options);
|
||||
notification.show();
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=notification.js.map
|
||||
1
ElectronNET.Host/api/notification.js.map
Normal file
1
ElectronNET.Host/api/notification.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"notification.js","sourceRoot":"","sources":["notification.ts"],"names":[],"mappings":";;AAAA,qCAAwC;AAExC,MAAM,CAAC,OAAO,GAAG,UAAC,MAAuB;IACrC,MAAM,CAAC,EAAE,CAAC,oBAAoB,EAAE,UAAC,OAAO;QACpC,IAAM,YAAY,GAAG,IAAI,uBAAY,CAAC,OAAO,CAAC,CAAC;QAC/C,YAAY,CAAC,IAAI,EAAE,CAAC;IACxB,CAAC,CAAC,CAAC;AACP,CAAC,CAAA"}
|
||||
8
ElectronNET.Host/api/notification.ts
Normal file
8
ElectronNET.Host/api/notification.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Notification } from "electron";
|
||||
|
||||
module.exports = (socket: SocketIO.Server) => {
|
||||
socket.on('createNotification', (options) => {
|
||||
const notification = new Notification(options);
|
||||
notification.show();
|
||||
});
|
||||
}
|
||||
14
ElectronNET.Host/api/tray.js
Normal file
14
ElectronNET.Host/api/tray.js
Normal file
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var electron_1 = require("electron");
|
||||
var path = require('path');
|
||||
var tray;
|
||||
module.exports = function (socket) {
|
||||
socket.on('create-tray', function (image, menuItems) {
|
||||
var menu = electron_1.Menu.buildFromTemplate(menuItems);
|
||||
var imagePath = path.join(__dirname.replace('api', ''), 'bin', image);
|
||||
tray = new electron_1.Tray(imagePath);
|
||||
tray.setContextMenu(menu);
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=tray.js.map
|
||||
1
ElectronNET.Host/api/tray.js.map
Normal file
1
ElectronNET.Host/api/tray.js.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"tray.js","sourceRoot":"","sources":["tray.ts"],"names":[],"mappings":";;AAAA,qCAAsC;AACtC,IAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,IAAI,IAAI,CAAC;AAET,MAAM,CAAC,OAAO,GAAG,UAAC,MAAuB;IACrC,MAAM,CAAC,EAAE,CAAC,aAAa,EAAE,UAAC,KAAK,EAAE,SAAS;QACtC,IAAM,IAAI,GAAG,eAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAE/C,IAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAExE,IAAI,GAAG,IAAI,eAAI,CAAC,SAAS,CAAC,CAAC;QAC3B,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;AACP,CAAC,CAAA"}
|
||||
14
ElectronNET.Host/api/tray.ts
Normal file
14
ElectronNET.Host/api/tray.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Menu, Tray } from "electron";
|
||||
const path = require('path');
|
||||
let tray;
|
||||
|
||||
module.exports = (socket: SocketIO.Server) => {
|
||||
socket.on('create-tray', (image, menuItems) => {
|
||||
const menu = Menu.buildFromTemplate(menuItems);
|
||||
|
||||
const imagePath = path.join(__dirname.replace('api', ''), 'bin', image);
|
||||
|
||||
tray = new Tray(imagePath);
|
||||
tray.setContextMenu(menu);
|
||||
});
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
const { app, Notification, Menu } = require('electron');
|
||||
const { app } = require('electron');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const process = require('child_process').spawn;
|
||||
const portfinder = require('detect-port');
|
||||
let io, browserWindows, apiProcess, loadURL, appApi;
|
||||
let io, browserWindows, apiProcess, loadURL, appApi, menu, dialog, notification, tray;
|
||||
|
||||
app.on('ready', () => {
|
||||
portfinder(8000, (error, port) => {
|
||||
@@ -17,36 +17,13 @@ function startSocketApiBridge(port) {
|
||||
|
||||
io.on('connection', (socket) => {
|
||||
console.log('ASP.NET Core Application connected...');
|
||||
|
||||
appApi = require('./api/app')(socket, app);
|
||||
browserWindows = require('./api/browserWindows')(socket);
|
||||
|
||||
socket.on('menu-setApplicationMenu', (menuItems) => {
|
||||
const menu = Menu.buildFromTemplate(menuItems);
|
||||
|
||||
addMenuItemClickConnector(menu.items, (id) => {
|
||||
socket.emit("menuItemClicked", id);
|
||||
});
|
||||
|
||||
Menu.setApplicationMenu(menu);
|
||||
});
|
||||
|
||||
socket.on('createNotification', (options) => {
|
||||
const notification = new Notification(options);
|
||||
notification.show();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function addMenuItemClickConnector(menuItems, callback) {
|
||||
menuItems.forEach((item) => {
|
||||
if(item.submenu && item.submenu.items.length > 0) {
|
||||
addMenuItemClickConnector(item.submenu.items, callback);
|
||||
}
|
||||
|
||||
if("id" in item && item.id) {
|
||||
item.click = () => { callback(item.id); };
|
||||
}
|
||||
menu = require('./api/menu')(socket);
|
||||
dialog = require('./api/dialog')(socket);
|
||||
notification = require('./api/notification')(socket);
|
||||
tray = require('./api/tray')(socket);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
BIN
ElectronNET.WebApp/Assets/electron.ico
Normal file
BIN
ElectronNET.WebApp/Assets/electron.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 273 KiB |
BIN
ElectronNET.WebApp/Assets/electron_32x32.png
Normal file
BIN
ElectronNET.WebApp/Assets/electron_32x32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
@@ -10,11 +10,7 @@ namespace ElectronNET.WebApp.Controllers
|
||||
public IActionResult Index()
|
||||
{
|
||||
Electron.IpcMain.On("SayHello", (args) => {
|
||||
Electron.App.CreateNotification(new NotificationOptions
|
||||
{
|
||||
Title = "Hallo Robert",
|
||||
Body = "Nachricht von ASP.NET Core App"
|
||||
});
|
||||
Electron.Notification.Show(new NotificationOptions("Hallo Robert","Nachricht von ASP.NET Core App"));
|
||||
|
||||
Electron.IpcMain.Send("Goodbye", "Elephant!");
|
||||
});
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Assets\" />
|
||||
<Folder Include="wwwroot\" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -24,4 +25,13 @@
|
||||
<ItemGroup>
|
||||
<DotNetCliToolReference Include="ElectronNET.CLI" Version="*" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Assets\electron.ico">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\electron_32x32.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -45,20 +45,40 @@ namespace ElectronNET.WebApp
|
||||
{
|
||||
Electron.Menu.SetApplicationMenu(new MenuItem[] {
|
||||
new MenuItem {
|
||||
Label = "Datei",
|
||||
Label = "File",
|
||||
Submenu = new MenuItem[] {
|
||||
new MenuItem {
|
||||
Label = "Beenden",
|
||||
Label = "Exit",
|
||||
Click = () =>
|
||||
{
|
||||
Electron.App.Exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new MenuItem
|
||||
{
|
||||
Label = "About",
|
||||
Click = async () => {
|
||||
await Electron.Dialog.ShowMessageBoxAsync(new MessageBoxOptions("(c) 2017 Gregor Biswanger & Robert Muehsig") {
|
||||
Title = "About us...",
|
||||
Type = "info"
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var browserWindow = await Electron.WindowManager.CreateWindowAsync();
|
||||
|
||||
Electron.Tray.Show("/Assets/electron_32x32.png", new MenuItem[] {
|
||||
new MenuItem {
|
||||
Label = "Exit",
|
||||
Click = () =>
|
||||
{
|
||||
Electron.App.Exit();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<title>Home</title>
|
||||
</head>
|
||||
<body>
|
||||
<h3>Hello from ASP.NET Core MVC!</h3>
|
||||
|
||||
Reference in New Issue
Block a user