Skip to content

Commit

Permalink
[MWB]Work without service if service doesn't start (#26521)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimecbernardo committed May 31, 2023
1 parent f6a91dd commit 0f04180
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/modules/MouseWithoutBorders/App/Class/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,25 @@ private static void Main()

// 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();
Expand Down
24 changes: 24 additions & 0 deletions src/modules/MouseWithoutBorders/App/Class/Setting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,30 @@ internal bool ShowOriginalUI
}
}

// 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
Expand Down

0 comments on commit 0f04180

Please sign in to comment.