From 2643c03e77fb9e3b604c88d2d5e977a58295e831 Mon Sep 17 00:00:00 2001 From: SashegDev Date: Wed, 17 Jun 2026 19:28:12 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B8=D0=BB?= =?UTF-8?q?=D1=8F=D1=86=D0=B8=D1=8F=20=D0=BF=D0=BE=D0=B4=20Windows=20?= =?UTF-8?q?=D1=81=20Linux?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - добавил EnableWindowsTargeting для кросс-компиляции - добавил ImplicitUsings, убрал конфликтующие глобальные using - добавил недостающие using во всех файлах - пофиксил ambiguous references (Application, MessageBox, Button, KeyEventArgs, FontStyle) - пофиксил null-conditional assignment --- src/JustABlocker/App.xaml.cs | 27 +++++++++++-------- src/JustABlocker/JustABlocker.csproj | 5 ++++ src/JustABlocker/MainWindow.xaml.cs | 4 ++- src/JustABlocker/Models/BlacklistEntry.cs | 1 + src/JustABlocker/Native/WfpNative.cs | 1 + src/JustABlocker/Services/BlacklistManager.cs | 3 +++ src/JustABlocker/Services/DnsResolver.cs | 2 ++ src/JustABlocker/Services/WfpFilterService.cs | 2 ++ 8 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/JustABlocker/App.xaml.cs b/src/JustABlocker/App.xaml.cs index 121b287..c7ce19c 100644 --- a/src/JustABlocker/App.xaml.cs +++ b/src/JustABlocker/App.xaml.cs @@ -1,17 +1,18 @@ using System.Diagnostics; using System.Drawing; +using System.Threading; using System.Windows; -using System.Windows.Forms; using JustABlocker.Services; +using Forms = System.Windows.Forms; namespace JustABlocker; -public partial class App : Application +public partial class App : System.Windows.Application { private Mutex? _mutex; private WfpFilterService? _wfpService; private BlacklistManager? _blacklistManager; - private NotifyIcon? _trayIcon; + private Forms.NotifyIcon? _trayIcon; private MainWindow? _mainWindow; protected override void OnStartup(StartupEventArgs e) @@ -64,18 +65,18 @@ public partial class App : Application private void SetupTray() { - _trayIcon = new NotifyIcon + _trayIcon = new Forms.NotifyIcon { Icon = CreateTrayIcon(), Text = "Just a Blocker", Visible = true, }; - var menu = new ContextMenuStrip(); + var menu = new Forms.ContextMenuStrip(); menu.Items.Add("Show / Hide", null, (_, _) => ToggleWindow()); - menu.Items.Add(new ToolStripSeparator()); + menu.Items.Add(new Forms.ToolStripSeparator()); menu.Items.Add("Pause", null, (_, _) => TogglePause()); - menu.Items.Add(new ToolStripSeparator()); + menu.Items.Add(new Forms.ToolStripSeparator()); menu.Items.Add("Exit", null, (_, _) => ExitApp()); _trayIcon.ContextMenuStrip = menu; @@ -90,8 +91,8 @@ public partial class App : Application using var brush = new SolidBrush(Color.Red); g.FillRectangle(brush, 3, 3, 10, 10); using var whiteBrush = new SolidBrush(Color.White); - var font = new Font("Segoe UI", 8, FontStyle.Bold); - g.DrawString("!", font, whiteBrush, 4, 2); + using var font = new System.Drawing.Font("Segoe UI", 8, System.Drawing.FontStyle.Bold); + g.DrawString("!", font, whiteBrush, 4.0f, 2.0f); var hicon = bitmap.GetHicon(); return Icon.FromHandle(hicon); } @@ -162,8 +163,12 @@ public partial class App : Application private void ExitApp() { - _trayIcon?.Visible = false; - _trayIcon?.Dispose(); + if (_trayIcon != null) + { + _trayIcon.Visible = false; + _trayIcon.Dispose(); + _trayIcon = null; + } Current.Shutdown(); } diff --git a/src/JustABlocker/JustABlocker.csproj b/src/JustABlocker/JustABlocker.csproj index 197981c..a9d43cc 100644 --- a/src/JustABlocker/JustABlocker.csproj +++ b/src/JustABlocker/JustABlocker.csproj @@ -8,6 +8,11 @@ JustABlocker JustABlocker app.manifest + enable true + + + + diff --git a/src/JustABlocker/MainWindow.xaml.cs b/src/JustABlocker/MainWindow.xaml.cs index 18bda2f..b6ed653 100644 --- a/src/JustABlocker/MainWindow.xaml.cs +++ b/src/JustABlocker/MainWindow.xaml.cs @@ -1,3 +1,5 @@ +using System; +using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -93,7 +95,7 @@ public partial class MainWindow : Window InputBox.Focus(); } - private void InputBox_OnKeyDown(object sender, KeyEventArgs e) + private void InputBox_OnKeyDown(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key == Key.Enter) { diff --git a/src/JustABlocker/Models/BlacklistEntry.cs b/src/JustABlocker/Models/BlacklistEntry.cs index 2bda73a..3a39b5b 100644 --- a/src/JustABlocker/Models/BlacklistEntry.cs +++ b/src/JustABlocker/Models/BlacklistEntry.cs @@ -1,3 +1,4 @@ +using System; using System.Text.Json.Serialization; namespace JustABlocker.Models; diff --git a/src/JustABlocker/Native/WfpNative.cs b/src/JustABlocker/Native/WfpNative.cs index 79df899..fb2a7cd 100644 --- a/src/JustABlocker/Native/WfpNative.cs +++ b/src/JustABlocker/Native/WfpNative.cs @@ -1,3 +1,4 @@ +using System; using System.Net; using System.Net.Sockets; using System.Runtime.InteropServices; diff --git a/src/JustABlocker/Services/BlacklistManager.cs b/src/JustABlocker/Services/BlacklistManager.cs index 1528674..1c0104f 100644 --- a/src/JustABlocker/Services/BlacklistManager.cs +++ b/src/JustABlocker/Services/BlacklistManager.cs @@ -1,4 +1,7 @@ +using System; +using System.Collections.Generic; using System.Collections.ObjectModel; +using System.IO; using System.Text.Json; using JustABlocker.Models; diff --git a/src/JustABlocker/Services/DnsResolver.cs b/src/JustABlocker/Services/DnsResolver.cs index c8b15a7..66ee6ed 100644 --- a/src/JustABlocker/Services/DnsResolver.cs +++ b/src/JustABlocker/Services/DnsResolver.cs @@ -1,3 +1,5 @@ +using System; +using System.Collections.Generic; using System.Net; using JustABlocker.Models; diff --git a/src/JustABlocker/Services/WfpFilterService.cs b/src/JustABlocker/Services/WfpFilterService.cs index 40d0bc4..6968810 100644 --- a/src/JustABlocker/Services/WfpFilterService.cs +++ b/src/JustABlocker/Services/WfpFilterService.cs @@ -1,3 +1,5 @@ +using System; +using System.Collections.Generic; using System.Diagnostics; using System.Net; using System.Net.Sockets;