Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature : (1) Search FB Worker executable from PATH (2) Improve displ… #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions Source/Services/Worker/ExternalWorkerAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ private void WorkerGuardian()

private void InitializeWorker()
{
WinAPI.ShowWindow(_workerWindowPtr, WinAPI.ShowWindowCommands.SW_HIDE);
this.RemoveTrayIcon();
// WinAPI.ShowWindow(_workerWindowPtr, WinAPI.ShowWindowCommands.SW_HIDE);
// this.RemoveTrayIcon();

_workerProcessId = 1u; // must not be NULL (0)
WinAPI.GetWindowThreadProcessId(_workerWindowPtr, ref _workerProcessId);
Expand All @@ -218,18 +218,43 @@ private void StartNewWorker()
{
// If worker isn't found in working directory, try it relative to running binary.
executablePath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), WorkerExecutablePath);

if (!File.Exists(executablePath))
{
this.OnWorkerErrorOccurred($"Worker executable not found at {WorkerExecutablePath}");
return;
}
}

if (!File.Exists(executablePath))
{
// Search the path for it
string PathVariable = Environment.GetEnvironmentVariable("PATH");
if (PathVariable != null)
{
foreach (string SearchPath in PathVariable.Split(Path.PathSeparator))
{
try
{
string PotentialPath = Path.Combine(SearchPath, "FBuildWorker.exe");
if (File.Exists(PotentialPath))
{
executablePath = PotentialPath;
break;
}
}
catch (ArgumentException)
{
// PATH variable may contain illegal characters; just ignore them.
}
}
}
}

if (!File.Exists(executablePath))
{
this.OnWorkerErrorOccurred($"Worker executable not found. Try place worker executable in {WorkerExecutablePath}, or in PATH, or as env variable FASTBUILD_EXECUTABLE_PATH");
return;
}

var startInfo = new ProcessStartInfo(executablePath)
{
Arguments = "-nosubprocess",
CreateNoWindow = true
CreateNoWindow = false
};

Process process;
Expand Down Expand Up @@ -291,4 +316,4 @@ public void SetWorkerMode(WorkerMode mode)
WinAPIUtils.SetComboBoxSelectedIndex(comboBoxPtr, (int)mode);
}
}
}
}
2 changes: 1 addition & 1 deletion Source/ViewModels/Settings/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public string DisplayWorkersInPool
switch (workerCount)
{
case 0:
return "no workers in pool";
return "No workers in pool";
case 1:
return "1 worker in pool";
default:
Expand Down
17 changes: 17 additions & 0 deletions Source/Views/MainWindowView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Threading;
using Caliburn.Micro;
Expand All @@ -10,6 +11,8 @@ namespace FastBuild.Dashboard.Views
{
public partial class MainWindowView
{
public bool bCloseIgnoreCancel = false;

private DispatcherTimer _delayUpdateProfileTimer;
private readonly TrayNotifier _trayNotifier;
private bool _isWorking;
Expand All @@ -34,6 +37,20 @@ private void OnLoaded(object sender, RoutedEventArgs e)
}
}

protected override void OnClosing(CancelEventArgs e)
{
if (bCloseIgnoreCancel)
{
base.OnClosing(e);
}
else
{
// Override closing event events & hide window instead
e.Cancel = true;
this.Hide();
}
}

protected override void OnClosed(EventArgs e)
{
_trayNotifier.Close();
Expand Down
10 changes: 10 additions & 0 deletions Source/Views/TrayNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,20 @@ public TrayNotifier(MainWindowView owner)
_trayNotifier.ContextMenuStrip.Items.Add("Work Always", GetImage("/Resources/Icons/tray_working_all_16.ico"), (sender, args) => MenuChangeWorkerMode(2));
_trayNotifier.ContextMenuStrip.Items.Add("Work when Idle", GetImage("/Resources/Icons/tray_normal_16.ico"), (sender, args) => MenuChangeWorkerMode(1));
_trayNotifier.ContextMenuStrip.Items.Add("Disabled", GetImage("/Resources/Icons/tray_disabled_16.ico"), (sender, args) => MenuChangeWorkerMode(0));

// Add Exit Context Option since we override the "Window Close Button" to behavior like window minimize
_trayNotifier.ContextMenuStrip.Items.Add(new WinForms.ToolStripSeparator());
_trayNotifier.ContextMenuStrip.Items.Add("Exit", GetImage("/Resources/Icons/tray_normal_16.ico"), this.TrayNotifier_Exit);

this.UseNormalIcon();
}

private void TrayNotifier_Exit(object sender, EventArgs e)
{
_owner.bCloseIgnoreCancel = true;
_owner.Close();
}

private void TrayNotifier_DoubleClick(object sender, EventArgs e) => _owner.ShowAndActivate();

private void WorkingIconTimer_Tick(object sender, EventArgs e) => this.ShiftWorkingIcon();
Expand Down