Skip to content

Commit

Permalink
Merge pull request #12874 from Szpoti/turboCreateLaunchAgents
Browse files Browse the repository at this point in the history
[Release] Create Library and LaunchAgents folder if they don't exist
  • Loading branch information
molnard committed Apr 17, 2024
2 parents 0e95b1d + 38dce23 commit e206611
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
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 @@ public static async Task AddOrRemoveStartupItemAsync(bool runOnSystemStartup)
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))
{
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}");
}
}
}

0 comments on commit e206611

Please sign in to comment.