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

[Release] Create Library and LaunchAgents folder if they don't exist #12874

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 16 additions & 5 deletions WalletWasabi.Fluent/Helpers/MacOsStartupHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using WalletWasabi.Helpers;
using WalletWasabi.Logging;
Expand Down Expand Up @@ -36,14 +34,27 @@
await DeleteLoginItemIfExistsAsync().ConfigureAwait(false);

string homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string plistPath = Path.Combine(homeDir, "Library/LaunchAgents/", Constants.SilentPlistName);
var libraryDir = Path.Combine(homeDir, "Library");
var launchAgentsDir = Path.Combine(libraryDir, "LaunchAgents");
var plistPath = Path.Combine(launchAgentsDir, Constants.SilentPlistName);

var fileExists = File.Exists(plistPath);
if (runOnSystemStartup)
{
if (!Directory.Exists(libraryDir))
{
Logger.LogInfo("Creating Library directory because it doesn't exist.");
Directory.CreateDirectory(libraryDir);
}

if (!Directory.Exists(launchAgentsDir))
{
Logger.LogInfo("Creating LaunchAgents directory because it doesn't exist.");
Directory.CreateDirectory(launchAgentsDir);
}

await File.WriteAllTextAsync(plistPath, PlistContent).ConfigureAwait(false);
}
else if (fileExists && !runOnSystemStartup)
else if (File.Exists(plistPath))

Check warning on line 57 in WalletWasabi.Fluent/Helpers/MacOsStartupHelper.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (release_v2.0.7)

❌ New issue: Bumpy Road Ahead

AddOrRemoveStartupItemAsync has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.
{
File.Delete(plistPath);
}
Expand Down
26 changes: 18 additions & 8 deletions WalletWasabi.Fluent/Helpers/StartupHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using WalletWasabi.Logging;

namespace WalletWasabi.Fluent.Helpers;

Expand All @@ -9,17 +11,25 @@ public static class StartupHelper

public static async Task ModifyStartupSettingAsync(bool runOnSystemStartup)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
try
{
WindowsStartupHelper.AddOrRemoveRegistryKey(runOnSystemStartup);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
WindowsStartupHelper.AddOrRemoveRegistryKey(runOnSystemStartup);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
await LinuxStartupHelper.AddOrRemoveDesktopFileAsync(runOnSystemStartup).ConfigureAwait(false);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
await MacOsStartupHelper.AddOrRemoveStartupItemAsync(runOnSystemStartup).ConfigureAwait(false);
}
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
catch (Exception ex)
{
await LinuxStartupHelper.AddOrRemoveDesktopFileAsync(runOnSystemStartup).ConfigureAwait(false);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
await MacOsStartupHelper.AddOrRemoveStartupItemAsync(runOnSystemStartup).ConfigureAwait(false);
// Suppress exception to avoid potential crashes.
Logger.LogError($"{ex}");
}
}
}