Skip to content

Commit

Permalink
Added flatpak-specific build options
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihnea Rădulescu committed Sep 9, 2024
1 parent 52de443 commit b413d24
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<Copyright>Copyright © Mihnea Rădulescu 2024</Copyright>
<AssemblyVersion>1.2024.09.09</AssemblyVersion>
<AssemblyVersion>1.2024.09.10</AssemblyVersion>
<Version>$(AssemblyVersion)</Version>
<DebugType>embedded</DebugType>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion PasswordSecure.Test/PasswordSecure.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="FluentAssertions" Version="6.12.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
Expand Down
12 changes: 11 additions & 1 deletion PasswordSecure/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//#define FLATPAK_BUILD

using Avalonia.Markup.Xaml;
using PasswordSecure.Application.Providers;
using PasswordSecure.Application.Services;
Expand Down Expand Up @@ -34,8 +36,16 @@ public override void OnFrameworkInitializationCompleted()
IDataAccessService dataAccessServiceDecorated = new TaskDecoratorDataAccessService(
dataAccessService);

IEncryptedDataFolderProvider encryptedDataFolderProvider;
#if FLATPAK_BUILD
encryptedDataFolderProvider = new FlatpakEncryptedDataFolderProvider();
#else
encryptedDataFolderProvider = new DefaultEncryptedDataFolderProvider();
#endif

var mainWindow = new MainWindow();
var mainPresenter = new MainPresenter(dataAccessServiceDecorated, assemblyVersionProvider, mainWindow);
var mainPresenter = new MainPresenter(
dataAccessServiceDecorated, assemblyVersionProvider, encryptedDataFolderProvider, mainWindow);

mainWindow.Show();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace PasswordSecure.Application.Providers;

public interface IEncryptedDataFolderProvider
{
string GetEncryptedDataFolderPath();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;
using PasswordSecure.Application.Providers;

namespace PasswordSecure.Infrastructure.Providers;

public class DefaultEncryptedDataFolderProvider : IEncryptedDataFolderProvider
{
public string GetEncryptedDataFolderPath() => Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.IO;
using PasswordSecure.Application.Providers;

namespace PasswordSecure.Infrastructure.Providers;

public class FlatpakEncryptedDataFolderProvider : IEncryptedDataFolderProvider
{
public string GetEncryptedDataFolderPath()
{
var sandboxedApplicationPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
.Replace("/config", string.Empty);

var encryptedDataFolderPath = Path.Combine(sandboxedApplicationPath, EncryptedDataFolderName);
return encryptedDataFolderPath;
}

#region Private

private const string EncryptedDataFolderName = "EncryptedData";

#endregion
}
39 changes: 8 additions & 31 deletions PasswordSecure/Presentation/MainPresenter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Controls;
Expand All @@ -20,15 +19,13 @@ public class MainPresenter
{
static MainPresenter()
{
EncryptedDataFolderPath = GetEncryptedDataFolderPath();
CreateEncryptedDataFolderIfNecessary();

EncryptedFileTypes = GetEncryptedFileTypes();
}

public MainPresenter(
IDataAccessService dataAccessService,
IAssemblyVersionProvider assemblyVersionProvider,
IEncryptedDataFolderProvider encryptedDataFolderProvider,
MainWindow mainWindow)
{
_dataAccessService = dataAccessService;
Expand All @@ -48,21 +45,23 @@ public MainPresenter(
_mainWindow.HelpMenuClicked += OnHelpMenuClicked;

_accessParams = new AccessParams();

_encryptedDataFolderPath = encryptedDataFolderProvider.GetEncryptedDataFolderPath();
}

#region Private

private static readonly string EncryptedDataFolderPath;

private static readonly IReadOnlyList<FilePickerFileType> EncryptedFileTypes;

private const string EncryptedDataFolderName = "PasswordSecure";
private const int MinimumMasterPasswordLength = 8;

private readonly IDataAccessService _dataAccessService;
private readonly IAssemblyVersionProvider _assemblyVersionProvider;

private readonly MainWindow _mainWindow;
private readonly AccessParams _accessParams;

private readonly string _encryptedDataFolderPath;

private void OnVisualStateChanged(object? sender, EventArgs e) => _mainWindow.EnableControls();

Expand Down Expand Up @@ -320,29 +319,7 @@ private void ResetData()
}

private async Task<IStorageFolder?> GetEncryptedDataFolder()
=> await _mainWindow.StorageProvider.TryGetFolderFromPathAsync(EncryptedDataFolderPath);

private static string GetEncryptedDataFolderPath()
{
var userProfilePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var encryptedDataFolderPath = Path.Combine(userProfilePath, EncryptedDataFolderName);

return encryptedDataFolderPath;
}

private static void CreateEncryptedDataFolderIfNecessary()
{
try
{
if (!Directory.Exists(EncryptedDataFolderPath))
{
Directory.CreateDirectory(EncryptedDataFolderPath);
}
}
catch
{
}
}
=> await _mainWindow.StorageProvider.TryGetFolderFromPathAsync(_encryptedDataFolderPath);

private static IReadOnlyList<FilePickerFileType> GetEncryptedFileTypes()
{
Expand Down
Binary file modified Screenshot-Dark.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshot-Light.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b413d24

Please sign in to comment.