From 946b2af81aee46d5722448e8b6c8db8007b7443d Mon Sep 17 00:00:00 2001 From: softworkz Date: Fri, 14 Nov 2025 11:46:24 +0100 Subject: [PATCH 1/2] Webb app: add platform conditions --- .../Controllers/HomeController.cs | 32 +++--------- src/ElectronNET.WebApp/Program.cs | 51 ++++++++++--------- 2 files changed, 35 insertions(+), 48 deletions(-) diff --git a/src/ElectronNET.WebApp/Controllers/HomeController.cs b/src/ElectronNET.WebApp/Controllers/HomeController.cs index e4dfa304..ca610a0f 100644 --- a/src/ElectronNET.WebApp/Controllers/HomeController.cs +++ b/src/ElectronNET.WebApp/Controllers/HomeController.cs @@ -10,36 +10,20 @@ public IActionResult Index() { if (HybridSupport.IsElectronActive) { - Electron.PowerMonitor.OnLockScreen += () => + if (OperatingSystem.IsMacOS() || OperatingSystem.IsWindows()) { - Console.WriteLine("Screen Locked detected from C#"); - }; + Electron.PowerMonitor.OnLockScreen += () => { Console.WriteLine("Screen Locked detected from C#"); }; - Electron.PowerMonitor.OnUnLockScreen += () => - { - Console.WriteLine("Screen unlocked detected from C# "); - }; - - Electron.PowerMonitor.OnSuspend += () => - { - Console.WriteLine("The system is going to sleep"); - }; + Electron.PowerMonitor.OnUnLockScreen += () => { Console.WriteLine("Screen unlocked detected from C# "); }; - Electron.PowerMonitor.OnResume += () => - { - Console.WriteLine("The system is resuming"); - }; + Electron.PowerMonitor.OnSuspend += () => { Console.WriteLine("The system is going to sleep"); }; - Electron.PowerMonitor.OnAC += () => - { - Console.WriteLine("The system changes to AC power"); - }; + Electron.PowerMonitor.OnResume += () => { Console.WriteLine("The system is resuming"); }; - Electron.PowerMonitor.OnBattery += () => - { - Console.WriteLine("The system is about to change to battery power"); - }; + Electron.PowerMonitor.OnAC += () => { Console.WriteLine("The system changes to AC power"); }; + Electron.PowerMonitor.OnBattery += () => { Console.WriteLine("The system is about to change to battery power"); }; + } } return View(); diff --git a/src/ElectronNET.WebApp/Program.cs b/src/ElectronNET.WebApp/Program.cs index 9adf2ea0..d3a36968 100644 --- a/src/ElectronNET.WebApp/Program.cs +++ b/src/ElectronNET.WebApp/Program.cs @@ -55,39 +55,42 @@ private static void AddDevelopmentTests() }); }); - Electron.Dock.SetMenu(new[] + if (System.OperatingSystem.IsMacOS()) { - new MenuItem + Electron.Dock.SetMenu(new[] { - Type = MenuType.normal, - Label = "MenuItem", - Click = () => + new MenuItem { - Electron.Notification.Show(new NotificationOptions( - "Dock MenuItem Click", - "A menu item added to the Dock was selected;")); + Type = MenuType.normal, + Label = "MenuItem", + Click = () => + { + Electron.Notification.Show(new NotificationOptions( + "Dock MenuItem Click", + "A menu item added to the Dock was selected;")); + }, }, - }, - new MenuItem - { - Type = MenuType.submenu, - Label = "SubMenu", - Submenu = new[] + new MenuItem { - new MenuItem + Type = MenuType.submenu, + Label = "SubMenu", + Submenu = new[] { - Type = MenuType.normal, - Label = "Sub MenuItem", - Click = () => + new MenuItem { - Electron.Notification.Show(new NotificationOptions( - "Dock Sub MenuItem Click", - "A menu item added to the Dock was selected;")); + Type = MenuType.normal, + Label = "Sub MenuItem", + Click = () => + { + Electron.Notification.Show(new NotificationOptions( + "Dock Sub MenuItem Click", + "A menu item added to the Dock was selected;")); + }, }, - }, + } } - } - }); + }); + } } } } From a6d67a4dfe402f3eafc2538cbd70c34031162679 Mon Sep 17 00:00:00 2001 From: softworkz Date: Fri, 14 Nov 2025 11:47:53 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Make=20CA1416=20and=20error=20(platform-dep?= =?UTF-8?q?ended=20reachab=C3=ADlitiy=20of=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/.editorconfig | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/.editorconfig diff --git a/src/.editorconfig b/src/.editorconfig new file mode 100644 index 00000000..17389dfa --- /dev/null +++ b/src/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# CA1416: Validate platform compatibility +dotnet_diagnostic.CA1416.severity = error