From b28fa9465aa85c8abc7d7838e3144c1e8fb69aef Mon Sep 17 00:00:00 2001 From: Gregor Biswanger Date: Tue, 17 Oct 2017 05:12:35 +0200 Subject: [PATCH] implement enum for types, implement OpenDialog from Dialog-API --- ElectronNET.API/BrowserWindow.cs | 12 +- ElectronNET.API/Dialog.cs | 27 ++++ .../Entities/BrowserWindowOptions.cs | 12 +- ElectronNET.API/Entities/DefaultFontFamily.cs | 35 +++++ ElectronNET.API/Entities/FileFilter.cs | 8 ++ ElectronNET.API/Entities/JumpListCategory.cs | 9 +- .../Entities/JumpListCategoryType.cs | 10 ++ ElectronNET.API/Entities/JumpListItem.cs | 22 +-- ElectronNET.API/Entities/JumpListItemType.cs | 9 ++ ElectronNET.API/Entities/MenuItem.cs | 7 +- ElectronNET.API/Entities/MenuRole.cs | 129 ++++++++++++++++++ ElectronNET.API/Entities/MenuType.cs | 11 ++ ElectronNET.API/Entities/MessageBoxOptions.cs | 10 +- ElectronNET.API/Entities/MessageBoxType.cs | 11 ++ ElectronNET.API/Entities/OnTopLevel.cs | 21 +++ ElectronNET.API/Entities/OpenDialogOptions.cs | 45 ++++++ .../Entities/OpenDialogProperty.cs | 14 ++ ElectronNET.API/Entities/ProgressBarMode.cs | 11 ++ .../Entities/ProgressBarOptions.cs | 8 +- ElectronNET.API/Entities/ThumbarButton.cs | 4 +- ElectronNET.API/Entities/ThumbarButtonFlag.cs | 35 +++++ ElectronNET.API/Entities/TitleBarStyle.cs | 13 ++ ElectronNET.API/Entities/Vibrancy.cs | 21 +++ ElectronNET.API/Entities/WebPreferences.cs | 10 +- ElectronNET.API/Extensions/EnumExtensions.cs | 34 +++++ .../Extensions/MenuItemExtensions.cs | 3 +- ElectronNET.Host/api/dialog.js | 6 + ElectronNET.Host/api/dialog.js.map | 2 +- ElectronNET.Host/api/dialog.ts | 7 + .../Controllers/HomeController.cs | 17 ++- ElectronNET.WebApp/Startup.cs | 2 +- 31 files changed, 527 insertions(+), 38 deletions(-) create mode 100644 ElectronNET.API/Entities/DefaultFontFamily.cs create mode 100644 ElectronNET.API/Entities/FileFilter.cs create mode 100644 ElectronNET.API/Entities/JumpListCategoryType.cs create mode 100644 ElectronNET.API/Entities/JumpListItemType.cs create mode 100644 ElectronNET.API/Entities/MenuRole.cs create mode 100644 ElectronNET.API/Entities/MenuType.cs create mode 100644 ElectronNET.API/Entities/MessageBoxType.cs create mode 100644 ElectronNET.API/Entities/OnTopLevel.cs create mode 100644 ElectronNET.API/Entities/OpenDialogOptions.cs create mode 100644 ElectronNET.API/Entities/OpenDialogProperty.cs create mode 100644 ElectronNET.API/Entities/ProgressBarMode.cs create mode 100644 ElectronNET.API/Entities/ThumbarButtonFlag.cs create mode 100644 ElectronNET.API/Entities/TitleBarStyle.cs create mode 100644 ElectronNET.API/Entities/Vibrancy.cs create mode 100644 ElectronNET.API/Extensions/EnumExtensions.cs diff --git a/ElectronNET.API/BrowserWindow.cs b/ElectronNET.API/BrowserWindow.cs index 9c3dd9a..3517450 100644 --- a/ElectronNET.API/BrowserWindow.cs +++ b/ElectronNET.API/BrowserWindow.cs @@ -1496,9 +1496,9 @@ namespace ElectronNET.API /// Values include normal, floating, torn-off-menu, modal-panel, main-menu, /// status, pop-up-menu and screen-saver. The default is floating. /// See the macOS docs - public void SetAlwaysOnTop(bool flag, string level) + public void SetAlwaysOnTop(bool flag, OnTopLevel level) { - BridgeConnector.Socket.Emit("browserWindowSetAlwaysOnTop", Id, flag, level); + BridgeConnector.Socket.Emit("browserWindowSetAlwaysOnTop", Id, flag, level.GetDescription()); } /// @@ -1512,9 +1512,9 @@ namespace ElectronNET.API /// See the macOS docs /// The number of layers higher to set this window relative to the given level. /// The default is 0. Note that Apple discourages setting levels higher than 1 above screen-saver. - public void SetAlwaysOnTop(bool flag, string level, int relativeLevel) + public void SetAlwaysOnTop(bool flag, OnTopLevel level, int relativeLevel) { - BridgeConnector.Socket.Emit("browserWindowSetAlwaysOnTop", Id, flag, level, relativeLevel); + BridgeConnector.Socket.Emit("browserWindowSetAlwaysOnTop", Id, flag, level.GetDescription(), relativeLevel); } /// @@ -2143,9 +2143,9 @@ namespace ElectronNET.API /// Can be appearance-based, light, dark, titlebar, selection, /// menu, popover, sidebar, medium-light or ultra-dark. /// See the macOS documentation for more details. - public void SetVibrancy(string type) + public void SetVibrancy(Vibrancy type) { - BridgeConnector.Socket.Emit("browserWindowSetVibrancy", Id, type); + BridgeConnector.Socket.Emit("browserWindowSetVibrancy", Id, type.GetDescription()); } private JsonSerializer _jsonSerializer = new JsonSerializer() diff --git a/ElectronNET.API/Dialog.cs b/ElectronNET.API/Dialog.cs index f47afac..d30eab9 100644 --- a/ElectronNET.API/Dialog.cs +++ b/ElectronNET.API/Dialog.cs @@ -26,6 +26,33 @@ namespace ElectronNET.API } } + /// + /// Note: On Windows and Linux an open dialog can not be both a file selector + /// and a directory selector, so if you set properties to ['openFile', 'openDirectory'] + /// on these platforms, a directory selector will be shown. + /// + /// + /// + /// An array of file paths chosen by the user + public Task ShowOpenDialogAsync(BrowserWindow browserWindow, OpenDialogOptions options) + { + var taskCompletionSource = new TaskCompletionSource(); + + BridgeConnector.Socket.On("showOpenDialogComplete", (filePaths) => + { + BridgeConnector.Socket.Off("showOpenDialogComplete"); + + var result = ((JArray)filePaths).ToObject(); + taskCompletionSource.SetResult(result); + }); + + BridgeConnector.Socket.Emit("showOpenDialog", + JObject.FromObject(browserWindow, _jsonSerializer), + JObject.FromObject(options, _jsonSerializer)); + + return taskCompletionSource.Task; + } + /// /// 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 diff --git a/ElectronNET.API/Entities/BrowserWindowOptions.cs b/ElectronNET.API/Entities/BrowserWindowOptions.cs index 975f767..3a7e15d 100644 --- a/ElectronNET.API/Entities/BrowserWindowOptions.cs +++ b/ElectronNET.API/Entities/BrowserWindowOptions.cs @@ -1,4 +1,6 @@ -using System.ComponentModel; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using System.ComponentModel; namespace ElectronNET.API.Entities { @@ -205,9 +207,10 @@ namespace ElectronNET.API.Entities /// /// The style of window title bar. Default is default. Possible values are: - /// 'default' | 'hidden' | 'hidden-inset' | 'hiddenInset' | 'customButtonsOnHover' + /// 'default' | 'hidden' | 'hiddenInset' | 'customButtonsOnHover' /// - public string TitleBarStyle { get; set; } + [JsonConverter(typeof(StringEnumConverter))] + public TitleBarStyle TitleBarStyle { get; set; } /// /// Shows the title in the tile bar in full screen mode on macOS for all @@ -228,7 +231,8 @@ namespace ElectronNET.API.Entities /// appearance-based, light, dark, titlebar, selection, menu, popover, sidebar, /// medium-light or ultra-dark. /// - public string Vibrancy { get; set; } + [JsonConverter(typeof(StringEnumConverter))] + public Vibrancy Vibrancy { get; set; } /// /// Controls the behavior on macOS when option-clicking the green stoplight button diff --git a/ElectronNET.API/Entities/DefaultFontFamily.cs b/ElectronNET.API/Entities/DefaultFontFamily.cs new file mode 100644 index 0000000..d178a9d --- /dev/null +++ b/ElectronNET.API/Entities/DefaultFontFamily.cs @@ -0,0 +1,35 @@ +namespace ElectronNET.API.Entities +{ + public class DefaultFontFamily + { + /// + /// Defaults to Times New Roman. + /// + public string Standard { get; set; } + + /// + /// Defaults to Times New Roman. + /// + public string Serif { get; set; } + + /// + /// Defaults to Arial. + /// + public string SansSerif { get; set; } + + /// + /// Defaults to Courier New. + /// + public string Monospace { get; set; } + + /// + /// Defaults to Script. + /// + public string Cursive { get; set; } + + /// + /// Defaults to Impact. + /// + public string Fantasy { get; set; } + } +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/FileFilter.cs b/ElectronNET.API/Entities/FileFilter.cs new file mode 100644 index 0000000..fa15bbf --- /dev/null +++ b/ElectronNET.API/Entities/FileFilter.cs @@ -0,0 +1,8 @@ +namespace ElectronNET.API.Entities +{ + public class FileFilter + { + public string[] Extensions { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/JumpListCategory.cs b/ElectronNET.API/Entities/JumpListCategory.cs index e7ca486..e52e5f8 100644 --- a/ElectronNET.API/Entities/JumpListCategory.cs +++ b/ElectronNET.API/Entities/JumpListCategory.cs @@ -1,4 +1,6 @@ using ElectronNET.API.Entities; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace ElectronNET.API { @@ -7,16 +9,17 @@ namespace ElectronNET.API /// /// Must be set if type is custom, otherwise it should be omitted. /// - public string Name { get; set; } = string.Empty; + public string Name { get; set; } /// /// Array of objects if type is tasks or custom, otherwise it should be omitted. /// - public JumpListItem[] Items { get; set; } = new JumpListItem[0]; + public JumpListItem[] Items { get; set; } /// /// One of the following: "tasks" | "frequent" | "recent" | "custom" /// - public string Type { get; set; } = "tasks"; + [JsonConverter(typeof(StringEnumConverter))] + public JumpListCategoryType Type { get; set; } } } diff --git a/ElectronNET.API/Entities/JumpListCategoryType.cs b/ElectronNET.API/Entities/JumpListCategoryType.cs new file mode 100644 index 0000000..9c00bf8 --- /dev/null +++ b/ElectronNET.API/Entities/JumpListCategoryType.cs @@ -0,0 +1,10 @@ +namespace ElectronNET.API +{ + public enum JumpListCategoryType + { + tasks, + frequent, + recent, + custom + } +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/JumpListItem.cs b/ElectronNET.API/Entities/JumpListItem.cs index 8d1ac63..d9258b3 100644 --- a/ElectronNET.API/Entities/JumpListItem.cs +++ b/ElectronNET.API/Entities/JumpListItem.cs @@ -1,16 +1,19 @@ -namespace ElectronNET.API.Entities +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace ElectronNET.API.Entities { public class JumpListItem { /// /// The command line arguments when program is executed. Should only be set if type is task. /// - public string Args { get; set; } = string.Empty; + public string Args { get; set; } /// /// Description of the task (displayed in a tooltip). Should only be set if type is task. /// - public string Description { get; set; } = string.Empty; + public string Description { get; set; } /// /// The index of the icon in the resource file. If a resource file contains multiple @@ -18,34 +21,35 @@ /// should be displayed for this task.If a resource file contains only one icon, /// this property should be set to zero. /// - public int IconIndex { get; set; } = 0; + public int IconIndex { get; set; } /// /// The absolute path to an icon to be displayed in a Jump List, which can be an /// arbitrary resource file that contains an icon(e.g. .ico, .exe, .dll). You can /// usually specify process.execPath to show the program icon. /// - public string IconPath { get; set; } = string.Empty; + public string IconPath { get; set; } /// /// Path of the file to open, should only be set if type is file. /// - public string Path { get; set; } = string.Empty; + public string Path { get; set; } /// /// Path of the program to execute, usually you should specify process.execPath /// which opens the current program.Should only be set if type is task. /// - public string Program { get; set; } = string.Empty; + public string Program { get; set; } /// /// The text to be displayed for the item in the Jump List. Should only be set if type is task. /// - public string Title { get; set; } = string.Empty; + public string Title { get; set; } /// /// One of the following: "task" | "separator" | "file" /// - public string Type {get; set; } = string.Empty; + [JsonConverter(typeof(StringEnumConverter))] + public JumpListItemType Type { get; set; } } } diff --git a/ElectronNET.API/Entities/JumpListItemType.cs b/ElectronNET.API/Entities/JumpListItemType.cs new file mode 100644 index 0000000..049834c --- /dev/null +++ b/ElectronNET.API/Entities/JumpListItemType.cs @@ -0,0 +1,9 @@ +namespace ElectronNET.API.Entities +{ + public enum JumpListItemType + { + task, + separator, + file + } +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/MenuItem.cs b/ElectronNET.API/Entities/MenuItem.cs index 667993b..983dcff 100644 --- a/ElectronNET.API/Entities/MenuItem.cs +++ b/ElectronNET.API/Entities/MenuItem.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using Newtonsoft.Json.Converters; using System; namespace ElectronNET.API.Entities @@ -16,12 +17,14 @@ namespace ElectronNET.API.Entities /// Define the action of the menu item, when specified the click property will be /// ignored. /// - public string Role { get; set; } + [JsonConverter(typeof(StringEnumConverter))] + public MenuRole Role { get; set; } /// /// Can be normal, separator, submenu, checkbox or radio. /// - public string Type { get; set; } + [JsonConverter(typeof(StringEnumConverter))] + public MenuType Type { get; set; } public string Label { get; set; } diff --git a/ElectronNET.API/Entities/MenuRole.cs b/ElectronNET.API/Entities/MenuRole.cs new file mode 100644 index 0000000..a1f8962 --- /dev/null +++ b/ElectronNET.API/Entities/MenuRole.cs @@ -0,0 +1,129 @@ +namespace ElectronNET.API.Entities +{ + public enum MenuRole + { + undo, + redo, + cut, + copy, + paste, + pasteandmatchstyle, + selectall, + delete, + + /// + /// Minimize current window + /// + minimize, + + /// + /// Close current window + /// + close, + + /// + /// Quit the application + /// + quit, + + /// + /// Reload the current window + /// + reload, + + /// + /// Reload the current window ignoring the cache. + /// + forcereload, + + /// + /// Toggle developer tools in the current window + /// + toggledevtools, + + /// + /// Toggle full screen mode on the current window + /// + togglefullscreen, + + /// + /// Reset the focused page’s zoom level to the original size + /// + resetzoom, + + /// + /// Zoom in the focused page by 10% + /// + zoomin, + + /// + /// Zoom out the focused page by 10% + /// + zoomout, + + /// + /// Whole default “Edit” menu (Undo, Copy, etc.) + /// + editMenu, + + /// + /// Whole default “Window” menu (Minimize, Close, etc.) + /// + windowMenu, + + /// + /// Only macOS: Map to the orderFrontStandardAboutPanel action + /// + about, + + /// + /// Only macOS: Map to the hide action + /// + hide, + + /// + /// Only macOS: Map to the hideOtherApplications action + /// + hideothers, + + /// + /// Only macOS: Map to the unhideAllApplications action + /// + unhide, + + /// + /// Only macOS: Map to the startSpeaking action + /// + startspeaking, + + /// + /// Only macOS: Map to the stopSpeaking action + /// + stopspeaking, + + /// + /// Only macOS: Map to the arrangeInFront action + /// + front, + + /// + /// Only macOS: Map to the performZoom action + /// + zoom, + + /// + /// Only macOS: The submenu is a “Window” menu + /// + window, + + /// + /// Only macOS: The submenu is a “Help” menu + /// + help, + + /// + /// Only macOS: The submenu is a “Services” menu + /// + services + } +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/MenuType.cs b/ElectronNET.API/Entities/MenuType.cs new file mode 100644 index 0000000..704f888 --- /dev/null +++ b/ElectronNET.API/Entities/MenuType.cs @@ -0,0 +1,11 @@ +namespace ElectronNET.API.Entities +{ + public enum MenuType + { + normal, + separator, + submenu, + checkbox, + radio + } +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/MessageBoxOptions.cs b/ElectronNET.API/Entities/MessageBoxOptions.cs index 960471c..ba652d7 100644 --- a/ElectronNET.API/Entities/MessageBoxOptions.cs +++ b/ElectronNET.API/Entities/MessageBoxOptions.cs @@ -1,13 +1,17 @@ -namespace ElectronNET.API.Entities +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace ElectronNET.API.Entities { public class MessageBoxOptions { /// /// 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. + /// option. On macOS, both "warning" and "error" display the same warning icon. /// - public string Type { get; set; } + [JsonConverter(typeof(StringEnumConverter))] + public MessageBoxType Type { get; set; } /// /// Array of texts for buttons. On Windows, an empty array will result in one button diff --git a/ElectronNET.API/Entities/MessageBoxType.cs b/ElectronNET.API/Entities/MessageBoxType.cs new file mode 100644 index 0000000..877a793 --- /dev/null +++ b/ElectronNET.API/Entities/MessageBoxType.cs @@ -0,0 +1,11 @@ +namespace ElectronNET.API.Entities +{ + public enum MessageBoxType + { + none, + info, + error, + question, + warning + } +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/OnTopLevel.cs b/ElectronNET.API/Entities/OnTopLevel.cs new file mode 100644 index 0000000..e57a283 --- /dev/null +++ b/ElectronNET.API/Entities/OnTopLevel.cs @@ -0,0 +1,21 @@ +using System.ComponentModel; + +namespace ElectronNET.API.Entities +{ + public enum OnTopLevel + { + normal, + floating, + [Description("torn-off-menu")] + tornOffMenu, + [Description("modal-panel")] + modalPanel, + [Description("main-menu")] + mainMenu, + status, + [Description("pop-up-menu")] + popUpMenu, + [Description("screen-saver")] + screenSaver + } +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/OpenDialogOptions.cs b/ElectronNET.API/Entities/OpenDialogOptions.cs new file mode 100644 index 0000000..85b81f9 --- /dev/null +++ b/ElectronNET.API/Entities/OpenDialogOptions.cs @@ -0,0 +1,45 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace ElectronNET.API.Entities +{ + public class OpenDialogOptions + { + public string Title { get; set; } + public string DefaultPath { get; set; } + + /// + /// Custom label for the confirmation button, when left empty the default label will be used. + /// + public string ButtonLabel { get; set; } + + /// + /// Contains which features the dialog should use. The following values are supported: + /// 'openFile' | 'openDirectory' | 'multiSelections' | 'showHiddenFiles' | 'createDirectory' | 'promptToCreate' | 'noResolveAliases' | 'treatPackageAsDirectory' + /// + [JsonProperty("properties", ItemConverterType = typeof(StringEnumConverter))] + public OpenDialogProperty[] Properties { get; set; } + + /// + /// Message to display above input boxes. + /// + public string Message { get; set; } + + /// + /// 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: + /// + /// + /// + /// 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[] { "*" } } + /// } + /// + /// + public FileFilter[] Filters { get; set; } + } +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/OpenDialogProperty.cs b/ElectronNET.API/Entities/OpenDialogProperty.cs new file mode 100644 index 0000000..a1b7723 --- /dev/null +++ b/ElectronNET.API/Entities/OpenDialogProperty.cs @@ -0,0 +1,14 @@ +namespace ElectronNET.API.Entities +{ + public enum OpenDialogProperty + { + openFile, + openDirectory, + multiSelections, + showHiddenFiles, + createDirectory, + promptToCreate, + noResolveAliases, + treatPackageAsDirectory + } +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/ProgressBarMode.cs b/ElectronNET.API/Entities/ProgressBarMode.cs new file mode 100644 index 0000000..dc47445 --- /dev/null +++ b/ElectronNET.API/Entities/ProgressBarMode.cs @@ -0,0 +1,11 @@ +namespace ElectronNET.API.Entities +{ + public enum ProgressBarMode + { + none, + normal, + indeterminate, + error, + paused + } +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/ProgressBarOptions.cs b/ElectronNET.API/Entities/ProgressBarOptions.cs index af2023c..ffcc25e 100644 --- a/ElectronNET.API/Entities/ProgressBarOptions.cs +++ b/ElectronNET.API/Entities/ProgressBarOptions.cs @@ -1,10 +1,14 @@ -namespace ElectronNET.API.Entities +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace ElectronNET.API.Entities { public class ProgressBarOptions { /// /// Mode for the progress bar. Can be 'none' | 'normal' | 'indeterminate' | 'error' | 'paused'. /// - public string Mode { get; set; } + [JsonConverter(typeof(StringEnumConverter))] + public ProgressBarMode Mode { get; set; } } } \ No newline at end of file diff --git a/ElectronNET.API/Entities/ThumbarButton.cs b/ElectronNET.API/Entities/ThumbarButton.cs index 219592f..ce2e0be 100644 --- a/ElectronNET.API/Entities/ThumbarButton.cs +++ b/ElectronNET.API/Entities/ThumbarButton.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using Newtonsoft.Json.Converters; using System; namespace ElectronNET.API.Entities @@ -20,7 +21,8 @@ namespace ElectronNET.API.Entities /// hidden - The button is not shown to the user. /// noninteractive - The button is enabled but not interactive; no pressed button state is drawn.This value is intended for instances where the button is used in a notification. /// - public string[] Flags { get; set; } + [JsonProperty("flags", ItemConverterType = typeof(StringEnumConverter))] + public ThumbarButtonFlag[] Flags { get; set; } /// /// The icon showing in thumbnail toolbar. diff --git a/ElectronNET.API/Entities/ThumbarButtonFlag.cs b/ElectronNET.API/Entities/ThumbarButtonFlag.cs new file mode 100644 index 0000000..869a283 --- /dev/null +++ b/ElectronNET.API/Entities/ThumbarButtonFlag.cs @@ -0,0 +1,35 @@ +namespace ElectronNET.API.Entities +{ + public enum ThumbarButtonFlag + { + /// + /// The button is active and available to the user. + /// + enabled, + + /// + /// The button is disabled.It is present, but has a visual state indicating it will not respond to user action. + /// + disabled, + + /// + /// When the button is clicked, the thumbnail window closes immediately. + /// + dismissonclick, + + /// + /// Do not draw a button border, use only the image. + /// + nobackground, + + /// + /// The button is not shown to the user. + /// + hidden, + + /// + /// The button is enabled but not interactive; no pressed button state is drawn.This value is intended for instances where the button is used in a notification. + /// + noninteractive + } +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/TitleBarStyle.cs b/ElectronNET.API/Entities/TitleBarStyle.cs new file mode 100644 index 0000000..99c923c --- /dev/null +++ b/ElectronNET.API/Entities/TitleBarStyle.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace ElectronNET.API.Entities +{ + public enum TitleBarStyle + { + [JsonProperty("default")] + defaultStyle, + hidden, + hiddenInset, + customButtonsOnHover + } +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/Vibrancy.cs b/ElectronNET.API/Entities/Vibrancy.cs new file mode 100644 index 0000000..d4fe52a --- /dev/null +++ b/ElectronNET.API/Entities/Vibrancy.cs @@ -0,0 +1,21 @@ +using Newtonsoft.Json; + +namespace ElectronNET.API.Entities +{ + public enum Vibrancy + { + [JsonProperty("appearance-based")] + appearanceBased, + light, + dark, + titlebar, + selection, + menu, + popover, + sidebar, + [JsonProperty("medium-light")] + mediumLight, + [JsonProperty("ultra-dark")] + ultraDark + } +} \ No newline at end of file diff --git a/ElectronNET.API/Entities/WebPreferences.cs b/ElectronNET.API/Entities/WebPreferences.cs index 8f4e738..6e12ea4 100644 --- a/ElectronNET.API/Entities/WebPreferences.cs +++ b/ElectronNET.API/Entities/WebPreferences.cs @@ -1,4 +1,7 @@ -namespace ElectronNET.API.Entities +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace ElectronNET.API.Entities { public class WebPreferences { @@ -121,6 +124,11 @@ /// public string DisableBlinkFeatures { get; set; } + /// + /// Sets the default font for the font-family. + /// + public DefaultFontFamily DefaultFontFamily { get; set; } + /// /// Defaults to 16. /// diff --git a/ElectronNET.API/Extensions/EnumExtensions.cs b/ElectronNET.API/Extensions/EnumExtensions.cs new file mode 100644 index 0000000..4424310 --- /dev/null +++ b/ElectronNET.API/Extensions/EnumExtensions.cs @@ -0,0 +1,34 @@ +using System; +using System.ComponentModel; +using System.Reflection; + +namespace ElectronNET.API.Extensions +{ + internal static class EnumExtensions + { + public static string GetDescription(this T enumerationValue) where T : struct + { + Type type = enumerationValue.GetType(); + if (!type.IsEnum) + { + throw new ArgumentException("EnumerationValue must be of Enum type", "enumerationValue"); + } + + //Tries to find a DescriptionAttribute for a potential friendly name + //for the enum + MemberInfo[] memberInfo = type.GetMember(enumerationValue.ToString()); + if (memberInfo != null && memberInfo.Length > 0) + { + object[] attrs = memberInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false); + + if (attrs != null && attrs.Length > 0) + { + //Pull out the description value + return ((DescriptionAttribute)attrs[0]).Description; + } + } + //If we have no description attribute, just return the ToString of the enum + return enumerationValue.ToString(); + } + } +} diff --git a/ElectronNET.API/Extensions/MenuItemExtensions.cs b/ElectronNET.API/Extensions/MenuItemExtensions.cs index ba5f8b5..0ca7282 100644 --- a/ElectronNET.API/Extensions/MenuItemExtensions.cs +++ b/ElectronNET.API/Extensions/MenuItemExtensions.cs @@ -17,8 +17,7 @@ namespace ElectronNET.API.Extensions AddMenuItemsId(menuItem.Submenu); } - if (string.IsNullOrEmpty(menuItem.Role) && - string.IsNullOrEmpty(menuItem.Id)) + if (string.IsNullOrEmpty(menuItem.Id)) { menuItem.Id = Guid.NewGuid().ToString(); } diff --git a/ElectronNET.Host/api/dialog.js b/ElectronNET.Host/api/dialog.js index 7d0a88a..67c9945 100644 --- a/ElectronNET.Host/api/dialog.js +++ b/ElectronNET.Host/api/dialog.js @@ -15,5 +15,11 @@ module.exports = function (socket) { }); } }); + socket.on('showOpenDialog', function (browserWindow, options) { + var window = electron_1.BrowserWindow.fromId(browserWindow.id); + electron_1.dialog.showOpenDialog(window, options, function (filePaths) { + socket.emit('showOpenDialogComplete', filePaths || []); + }); + }); }; //# sourceMappingURL=dialog.js.map \ No newline at end of file diff --git a/ElectronNET.Host/api/dialog.js.map b/ElectronNET.Host/api/dialog.js.map index 672e716..489341c 100644 --- a/ElectronNET.Host/api/dialog.js.map +++ b/ElectronNET.Host/api/dialog.js.map @@ -1 +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,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC;YACvE,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,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC;YACvE,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAA"} \ No newline at end of file +{"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,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC;YACvE,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,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC;YACvE,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,gBAAgB,EAAE,UAAC,aAAa,EAAE,OAAO;QAC3C,IAAI,MAAM,GAAG,wBAAa,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;QACpD,iBAAM,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,UAAC,SAAS;YAC7C,MAAM,CAAC,IAAI,CAAC,wBAAwB,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACX,CAAC,CAAC,CAAC;AACP,CAAC,CAAA"} \ No newline at end of file diff --git a/ElectronNET.Host/api/dialog.ts b/ElectronNET.Host/api/dialog.ts index 24a03c2..ac108ef 100644 --- a/ElectronNET.Host/api/dialog.ts +++ b/ElectronNET.Host/api/dialog.ts @@ -14,4 +14,11 @@ module.exports = (socket: SocketIO.Server) => { }); } }); + + socket.on('showOpenDialog', (browserWindow, options) => { + var window = BrowserWindow.fromId(browserWindow.id); + dialog.showOpenDialog(window, options, (filePaths) => { + socket.emit('showOpenDialogComplete', filePaths || []); + }); + }); } \ No newline at end of file diff --git a/ElectronNET.WebApp/Controllers/HomeController.cs b/ElectronNET.WebApp/Controllers/HomeController.cs index 2690c75..12792a1 100644 --- a/ElectronNET.WebApp/Controllers/HomeController.cs +++ b/ElectronNET.WebApp/Controllers/HomeController.cs @@ -9,10 +9,21 @@ namespace ElectronNET.WebApp.Controllers { public IActionResult Index() { - Electron.IpcMain.On("SayHello", (args) => { - Electron.Notification.Show(new NotificationOptions("Hallo Robert","Nachricht von ASP.NET Core App")); - + Electron.IpcMain.On("SayHello", async (args) => + { + Electron.Notification.Show(new NotificationOptions("Hallo Robert", "Nachricht von ASP.NET Core App")); Electron.IpcMain.Send(Electron.WindowManager.BrowserWindows.First(), "Goodbye", "Elephant!"); + + var currentBrowserWindow = Electron.WindowManager.BrowserWindows.First(); + var openDialogOptions = new OpenDialogOptions + { + Title = "Wuhuuu", + ButtonLabel = "Mhh Okay", + DefaultPath = await Electron.App.GetPathAsync(PathName.pictures), + Message = "Hello World", + Properties = new OpenDialogProperty[] { OpenDialogProperty.openDirectory } + }; + var filePaths = await Electron.Dialog.ShowOpenDialogAsync(currentBrowserWindow, openDialogOptions); }); Electron.IpcMain.On("GetPath", async (args) => diff --git a/ElectronNET.WebApp/Startup.cs b/ElectronNET.WebApp/Startup.cs index 017d9a7..2df074f 100644 --- a/ElectronNET.WebApp/Startup.cs +++ b/ElectronNET.WebApp/Startup.cs @@ -62,7 +62,7 @@ namespace ElectronNET.WebApp Click = async () => { await Electron.Dialog.ShowMessageBoxAsync(new MessageBoxOptions("(c) 2017 Gregor Biswanger & Robert Muehsig") { Title = "About us...", - Type = "info" + Type = MessageBoxType.info }); } }