mirror of
https://github.com/Jackett/Jackett
synced 2025-02-21 22:07:10 +00:00
Launch tray icon when Windows service updates
This commit is contained in:
parent
b95fbd76a7
commit
47a84775c5
4 changed files with 40 additions and 10 deletions
|
@ -7,7 +7,7 @@ namespace Jackett.Common.Services
|
|||
|
||||
public class TrayLockService : ITrayLockService
|
||||
{
|
||||
private readonly string EVENT_HANDLE_NAME = "JACKETT.TRAY";
|
||||
private readonly string EVENT_HANDLE_NAME = @"Global\JACKETT.TRAY";
|
||||
|
||||
private EventWaitHandle GetEventHandle()
|
||||
{
|
||||
|
|
|
@ -268,14 +268,14 @@ namespace Jackett.Common.Services
|
|||
return tempDir;
|
||||
}
|
||||
|
||||
private void StartUpdate(string updaterExePath, string installLocation, bool isWindows, bool NoRestart, bool trayWasRunning)
|
||||
private void StartUpdate(string updaterExePath, string installLocation, bool isWindows, bool NoRestart, bool trayIsRunning)
|
||||
{
|
||||
string appType = "Console";
|
||||
//DI once off Owin
|
||||
IProcessService processService = new ProcessService(logger);
|
||||
IServiceConfigService windowsService = new WindowsServiceConfigService(processService, logger);
|
||||
|
||||
if (isWindows && windowsService.ServiceExists())
|
||||
if (isWindows && windowsService.ServiceExists() && windowsService.ServiceRunning())
|
||||
{
|
||||
appType = "WindowsService";
|
||||
}
|
||||
|
@ -319,18 +319,25 @@ namespace Jackett.Common.Services
|
|||
startInfo.Arguments += " --NoRestart";
|
||||
}
|
||||
|
||||
if (trayWasRunning)
|
||||
if (trayIsRunning && appType == "Console")
|
||||
{
|
||||
startInfo.Arguments += " --StartTray";
|
||||
}
|
||||
|
||||
if (isWindows)
|
||||
{
|
||||
lockService.Signal();
|
||||
logger.Info("Signal sent to lock service");
|
||||
Thread.Sleep(2000);
|
||||
}
|
||||
|
||||
logger.Info($"Starting updater: {startInfo.FileName} {startInfo.Arguments}");
|
||||
var procInfo = Process.Start(startInfo);
|
||||
logger.Info($"Updater started process id: {procInfo.Id}");
|
||||
if (NoRestart == false)
|
||||
|
||||
if (!NoRestart)
|
||||
{
|
||||
logger.Info("Exiting Jackett..");
|
||||
lockService.Signal();
|
||||
//TODO: Remove once off Owin
|
||||
if (EnvironmentUtil.IsRunningLegacyOwin)
|
||||
{
|
||||
|
|
|
@ -65,6 +65,8 @@ namespace Jackett.Tray
|
|||
StartConsoleApplication();
|
||||
}
|
||||
|
||||
updatedVersion = updatedVersion.Equals("yes", StringComparison.OrdinalIgnoreCase) ? EnvironmentUtil.JackettVersion : updatedVersion;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(updatedVersion))
|
||||
{
|
||||
notifyIcon1.BalloonTipTitle = "Jackett";
|
||||
|
@ -81,6 +83,27 @@ namespace Jackett.Tray
|
|||
{
|
||||
trayLockService.WaitForSignal();
|
||||
logger.Info("Received signal from tray lock service");
|
||||
|
||||
if (windowsService.ServiceExists() && windowsService.ServiceRunning())
|
||||
{
|
||||
//We won't be able to start the tray app up again from the updater, as when running via a windows service there is no interaction with the desktop
|
||||
//Fire off a console process that will start the tray 20 seconds later
|
||||
|
||||
string trayExePath = Assembly.GetEntryAssembly().Location;
|
||||
|
||||
var startInfo = new ProcessStartInfo()
|
||||
{
|
||||
Arguments = $"/c timeout 20 > NUL & \"{trayExePath}\" --UpdatedVersion yes",
|
||||
FileName = "cmd.exe",
|
||||
UseShellExecute = true,
|
||||
CreateNoWindow = true,
|
||||
WindowStyle = ProcessWindowStyle.Hidden
|
||||
};
|
||||
|
||||
logger.Info("Starting 20 second delay tray launch as Jackett is running as a Windows service: " + startInfo.FileName + " " + startInfo.Arguments);
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
|
||||
CloseTrayApplication();
|
||||
}
|
||||
|
||||
|
|
|
@ -43,9 +43,9 @@ namespace Jackett.Updater
|
|||
{
|
||||
//The updater starts before Jackett closes
|
||||
logger.Info("Pausing for 3 seconds to give Jackett & tray time to shutdown");
|
||||
System.Threading.Tasks.Task.Delay(3000);
|
||||
System.Threading.Thread.Sleep(3000);
|
||||
}
|
||||
|
||||
|
||||
processService = new ProcessService(logger);
|
||||
windowsService = new WindowsServiceConfigService(processService, logger);
|
||||
|
||||
|
@ -256,7 +256,7 @@ namespace Jackett.Updater
|
|||
|
||||
if (options.NoRestart == false)
|
||||
{
|
||||
if (isWindows && (trayRunning || options.StartTray))
|
||||
if (isWindows && (trayRunning || options.StartTray) && !string.Equals(options.Type, "WindowsService", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var startInfo = new ProcessStartInfo()
|
||||
{
|
||||
|
@ -275,7 +275,7 @@ namespace Jackett.Updater
|
|||
}
|
||||
}
|
||||
|
||||
if (string.Equals(options.Type, "WindowsService", StringComparison.InvariantCultureIgnoreCase))
|
||||
if (string.Equals(options.Type, "WindowsService", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
logger.Info("Starting Windows service");
|
||||
|
||||
|
|
Loading…
Reference in a new issue