public static async Task AddOrRemoveDesktopFileAsync(bool runOnSystemStartup) { string pathToDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config", "autostart"); string pathToDesktopFile = Path.Combine(pathToDir, "Wasabi.desktop"); IoHelpers.EnsureContainingDirectoryExists(pathToDesktopFile); if (runOnSystemStartup) { string pathToExec = EnvironmentHelpers.GetExecutablePath(); string pathToExecWithArgs = $"{pathToExec} {StartupHelper.SilentArgument}"; IoHelpers.EnsureFileExists(pathToExec); string fileContents = string.Join( "\n", "[Desktop Entry]", $"Name={Constants.AppName}", "Type=Application", $"Exec={pathToExecWithArgs}", "Hidden=false", "Terminal=false", "X-GNOME-Autostart-enabled=true"); await File.WriteAllTextAsync(pathToDesktopFile, fileContents).ConfigureAwait(false); } else { File.Delete(pathToDesktopFile); } }
public static async Task ModifyStartupSettingAsync(bool runOnSystemStartup) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { string pathToExeFile = EnvironmentHelpers.GetExecutablePath(); if (!File.Exists(pathToExeFile)) { throw new InvalidOperationException($"Path {pathToExeFile} does not exist."); } StartOnWindowsStartup(runOnSystemStartup, pathToExeFile); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { throw new NotImplementedException(); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { if (runOnSystemStartup) { await EnvironmentHelpers.ShellExecAsync(AddCmd).ConfigureAwait(false); } else { await EnvironmentHelpers.ShellExecAsync(DeleteCmd).ConfigureAwait(false); } } }
public static void AddOrRemoveRegistryKey(bool runOnSystemStartup) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { throw new InvalidOperationException("Registry modification can only be done on Windows."); } string pathToExeFile = EnvironmentHelpers.GetExecutablePath(); string pathToExecWithArgs = $"{pathToExeFile} {StartupHelper.SilentArgument}"; if (!File.Exists(pathToExeFile)) { throw new InvalidOperationException($"Path: {pathToExeFile} does not exist."); } using RegistryKey key = Registry.CurrentUser.OpenSubKey(KeyPath, writable: true) ?? throw new InvalidOperationException("Registry operation failed."); if (runOnSystemStartup) { key.SetValue(nameof(WalletWasabi), pathToExecWithArgs); } else { key.DeleteValue(nameof(WalletWasabi), false); } }