fix: компиляция под Windows с Linux

- добавил EnableWindowsTargeting для кросс-компиляции
- добавил ImplicitUsings, убрал конфликтующие глобальные using
- добавил недостающие using во всех файлах
- пофиксил ambiguous references (Application, MessageBox, Button, KeyEventArgs, FontStyle)
- пофиксил null-conditional assignment
This commit is contained in:
SashegDev
2026-06-17 19:28:12 +00:00
parent 8f46874aa1
commit 2643c03e77
8 changed files with 33 additions and 12 deletions
+16 -11
View File
@@ -1,17 +1,18 @@
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Forms;
using JustABlocker.Services; using JustABlocker.Services;
using Forms = System.Windows.Forms;
namespace JustABlocker; namespace JustABlocker;
public partial class App : Application public partial class App : System.Windows.Application
{ {
private Mutex? _mutex; private Mutex? _mutex;
private WfpFilterService? _wfpService; private WfpFilterService? _wfpService;
private BlacklistManager? _blacklistManager; private BlacklistManager? _blacklistManager;
private NotifyIcon? _trayIcon; private Forms.NotifyIcon? _trayIcon;
private MainWindow? _mainWindow; private MainWindow? _mainWindow;
protected override void OnStartup(StartupEventArgs e) protected override void OnStartup(StartupEventArgs e)
@@ -64,18 +65,18 @@ public partial class App : Application
private void SetupTray() private void SetupTray()
{ {
_trayIcon = new NotifyIcon _trayIcon = new Forms.NotifyIcon
{ {
Icon = CreateTrayIcon(), Icon = CreateTrayIcon(),
Text = "Just a Blocker", Text = "Just a Blocker",
Visible = true, Visible = true,
}; };
var menu = new ContextMenuStrip(); var menu = new Forms.ContextMenuStrip();
menu.Items.Add("Show / Hide", null, (_, _) => ToggleWindow()); 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("Pause", null, (_, _) => TogglePause());
menu.Items.Add(new ToolStripSeparator()); menu.Items.Add(new Forms.ToolStripSeparator());
menu.Items.Add("Exit", null, (_, _) => ExitApp()); menu.Items.Add("Exit", null, (_, _) => ExitApp());
_trayIcon.ContextMenuStrip = menu; _trayIcon.ContextMenuStrip = menu;
@@ -90,8 +91,8 @@ public partial class App : Application
using var brush = new SolidBrush(Color.Red); using var brush = new SolidBrush(Color.Red);
g.FillRectangle(brush, 3, 3, 10, 10); g.FillRectangle(brush, 3, 3, 10, 10);
using var whiteBrush = new SolidBrush(Color.White); using var whiteBrush = new SolidBrush(Color.White);
var font = new Font("Segoe UI", 8, FontStyle.Bold); using var font = new System.Drawing.Font("Segoe UI", 8, System.Drawing.FontStyle.Bold);
g.DrawString("!", font, whiteBrush, 4, 2); g.DrawString("!", font, whiteBrush, 4.0f, 2.0f);
var hicon = bitmap.GetHicon(); var hicon = bitmap.GetHicon();
return Icon.FromHandle(hicon); return Icon.FromHandle(hicon);
} }
@@ -162,8 +163,12 @@ public partial class App : Application
private void ExitApp() private void ExitApp()
{ {
_trayIcon?.Visible = false; if (_trayIcon != null)
_trayIcon?.Dispose(); {
_trayIcon.Visible = false;
_trayIcon.Dispose();
_trayIcon = null;
}
Current.Shutdown(); Current.Shutdown();
} }
+5
View File
@@ -8,6 +8,11 @@
<AssemblyName>JustABlocker</AssemblyName> <AssemblyName>JustABlocker</AssemblyName>
<RootNamespace>JustABlocker</RootNamespace> <RootNamespace>JustABlocker</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest> <ApplicationManifest>app.manifest</ApplicationManifest>
<ImplicitUsings>enable</ImplicitUsings>
<EnableWindowsTargeting>true</EnableWindowsTargeting> <EnableWindowsTargeting>true</EnableWindowsTargeting>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Using Remove="System.Windows.Forms" />
</ItemGroup>
</Project> </Project>
+3 -1
View File
@@ -1,3 +1,5 @@
using System;
using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
@@ -93,7 +95,7 @@ public partial class MainWindow : Window
InputBox.Focus(); 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) if (e.Key == Key.Enter)
{ {
@@ -1,3 +1,4 @@
using System;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace JustABlocker.Models; namespace JustABlocker.Models;
+1
View File
@@ -1,3 +1,4 @@
using System;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@@ -1,4 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.IO;
using System.Text.Json; using System.Text.Json;
using JustABlocker.Models; using JustABlocker.Models;
+2
View File
@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using System.Net; using System.Net;
using JustABlocker.Models; using JustABlocker.Models;
@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;