[MWB]Work without service if service doesn't start (#26521)

This commit is contained in:
Jaime Bernardo
2023-05-31 15:50:48 +01:00
committed by GitHub
parent f6a91dd073
commit 0f04180912
2 changed files with 36 additions and 2 deletions

View File

@@ -86,15 +86,25 @@ namespace MouseWithoutBorders.Class
// If we're started from the .dll module or from the service process, we should
// assume the service mode.
if (serviceMode || runningAsSystem)
if (serviceMode && !runningAsSystem)
{
if (!runningAsSystem)
try
{
var sc = new ServiceController(ServiceName);
sc.Start();
return;
}
catch (Exception ex)
{
Common.Log("Couldn't start the service. Will try to continue as not a service.");
Common.Log(ex);
serviceMode = false;
Setting.Values.UseService = false;
}
}
if (serviceMode || runningAsSystem)
{
if (args.Length > 2)
{
Helper.UserLocalAppDataPath = args[2].Trim();

View File

@@ -979,6 +979,30 @@ namespace MouseWithoutBorders.Class
}
}
// If starting the service fails, work in not service mode.
internal bool UseService
{
get
{
lock (_loadingSettingsLock)
{
return _properties.UseService;
}
}
set
{
lock (_loadingSettingsLock)
{
_properties.UseService = value;
if (!PauseInstantSaving)
{
SaveSettings();
}
}
}
}
internal bool SendErrorLogV2
{
get