-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 836590d
Showing
9 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# VSCode | ||
.vscode | ||
Properties | ||
# Csharp output folders | ||
obj | ||
bin | ||
|
||
BinaryReceptor |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFramework>net6.0-windows</TargetFramework> | ||
<RuntimeIdentifier>win-x64</RuntimeIdentifier> | ||
<PublishSingleFile>true</PublishSingleFile> | ||
<SelfContained>false</SelfContained> | ||
<PublishTrimmed>false</PublishTrimmed> | ||
<Nullable>enable</Nullable> | ||
<UseWindowsForms>true</UseWindowsForms> | ||
<ApplicationIcon>Assets\icon.ico</ApplicationIcon> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Update="Assets\icon.png"> | ||
<CopyToOutputDirectory>Never</CopyToOutputDirectory> | ||
</None> | ||
<EmbeddedResource Include="Assets\icon.ico" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<Compile Update="Form1.cs"> | ||
<SubType>Form</SubType> | ||
</Compile> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace BinaryReceptorWindows | ||
{ | ||
public enum Mode | ||
{ | ||
BLUETOOTH = 0, | ||
HTTP = 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace BinaryReceptorWindows; | ||
|
||
static class Program | ||
{ | ||
/// <summary> | ||
/// The main entry point for the application. | ||
/// </summary> | ||
[STAThread] | ||
static void Main() | ||
{ | ||
ApplicationConfiguration.Initialize(); | ||
Application.Run(new TrayApp()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Binary Receptor Windows | ||
Tray icon for Windows. Allows simple operation of [BinaryReceptor](https://github.com/KamaleiZestri/BinaryReceptor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.Reflection; | ||
|
||
namespace BinaryReceptorWindows; | ||
|
||
public class TrayApp : ApplicationContext | ||
{ | ||
private const string TrayIconResource = "BinaryReceptorWindows.Assets.icon.ico"; | ||
private const string BinaryReceptorName = "BinaryReceptor"; | ||
private string localUrl = "http://localhost:24234"; | ||
private string exePath = "BinaryReceptor//BinaryReceptor.exe"; | ||
private Mode mode = Mode.BLUETOOTH; | ||
private NotifyIcon trayIcon; | ||
private ToolStripMenuItem menuItemMode; | ||
private ToolStripMenuItem menuItemSwitch; | ||
private ToolStripMenuItem menuItemStart; | ||
private ToolStripMenuItem menuItemStop; | ||
private ToolStripMenuItem menuItemShow; | ||
private ToolStripMenuItem menuItemExit; | ||
|
||
public TrayApp() | ||
{ | ||
CreateTrayIcon(); | ||
} | ||
|
||
private void CreateTrayIcon() | ||
{ | ||
menuItemMode = new ToolStripMenuItem("Mode: Bluetooth", null, Switch); | ||
menuItemSwitch = new ToolStripMenuItem("Switch Modes", null, Switch); | ||
menuItemStart = new ToolStripMenuItem("Start", null, Start); | ||
menuItemStop = new ToolStripMenuItem("Stop", null, Stop); | ||
menuItemShow = new ToolStripMenuItem("Show", null, Show); | ||
menuItemExit = new ToolStripMenuItem("Exit", null, Exit); | ||
|
||
ContextMenuStrip contextMenu = new ContextMenuStrip(); | ||
contextMenu.Items.Add(menuItemMode); | ||
contextMenu.Items.Add(menuItemSwitch); | ||
contextMenu.Items.Add(new ToolStripSeparator()); | ||
contextMenu.Items.Add(menuItemStart); | ||
contextMenu.Items.Add(menuItemStop); | ||
contextMenu.Items.Add(menuItemShow); | ||
contextMenu.Items.Add(menuItemExit); | ||
|
||
contextMenu.Opening += new CancelEventHandler(ContextMenuOnPopup); | ||
using var iconStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(TrayIconResource); | ||
trayIcon = new NotifyIcon() | ||
{ | ||
Icon = new Icon(iconStream), | ||
ContextMenuStrip = contextMenu, | ||
Visible = true, | ||
Text = BinaryReceptorName | ||
}; | ||
} | ||
private void Switch(object sender, EventArgs e) | ||
{ | ||
Stop(null, null); | ||
if (mode == Mode.BLUETOOTH) | ||
mode = Mode.HTTP; | ||
else | ||
mode = Mode.BLUETOOTH; | ||
} | ||
private void Start(object sender, EventArgs e) | ||
{ | ||
string modeString = "bluetooth"; | ||
if (mode == Mode.BLUETOOTH) | ||
modeString = "bluetooth"; | ||
else | ||
modeString = "http"; | ||
|
||
Process p = new Process(); | ||
p.StartInfo.FileName = exePath; | ||
p.StartInfo.CreateNoWindow = true; | ||
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; | ||
p.StartInfo.WorkingDirectory = Path.GetDirectoryName(exePath); | ||
p.StartInfo.Arguments = modeString; | ||
p.Start(); | ||
} | ||
private void Stop(object sender, EventArgs e) | ||
{ | ||
Process? process = Process.GetProcessesByName(BinaryReceptorName).FirstOrDefault(); | ||
if (process == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (!process.CloseMainWindow()) | ||
{ | ||
process.Kill(); | ||
} | ||
} | ||
private void Show(object sender, EventArgs e) | ||
{ | ||
// hack because of this: https://github.com/dotnet/corefx/issues/10361 | ||
string url = localUrl.Replace("&", "^&"); | ||
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true }); | ||
} | ||
private void Exit(object sender, EventArgs e) | ||
{ | ||
Stop(null, null); | ||
trayIcon.Visible = false; | ||
Application.Exit(); | ||
} | ||
private void ContextMenuOnPopup(object sender, EventArgs e) | ||
{ | ||
bool exeRunning = Process.GetProcessesByName(BinaryReceptorName).Length > 0; | ||
bool running = exeRunning; | ||
bool stopped = !exeRunning; | ||
|
||
menuItemStart.Enabled = stopped; | ||
menuItemShow.Enabled = running; | ||
menuItemStop.Enabled = running; | ||
|
||
if (mode == Mode.BLUETOOTH) | ||
menuItemMode.Text = "Mode: Bluetooth"; | ||
else | ||
menuItemMode.Text = "Mode: HTTP"; | ||
} | ||
} |