From 613fb7db1273005d646aefa775a6154d641821e0 Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Tue, 4 Mar 2025 17:42:06 +0100 Subject: [PATCH] Refactor browser extension info to shared constants (#628) --- .../Pages/Settings/BrowserExtensions.razor | 71 +++++-------------- .../wwwroot/css/tailwind.css | 26 +++++-- .../BrowserExtensions/BrowserExtensionInfo.cs | 34 +++++++++ .../BrowserExtensions/BrowserType.cs | 44 ++++++++++++ .../BrowserExtensions/Constants.cs | 52 ++++++++++++++ 5 files changed, 170 insertions(+), 57 deletions(-) create mode 100644 src/Shared/AliasVault.Shared.Core/BrowserExtensions/BrowserExtensionInfo.cs create mode 100644 src/Shared/AliasVault.Shared.Core/BrowserExtensions/BrowserType.cs create mode 100644 src/Shared/AliasVault.Shared.Core/BrowserExtensions/Constants.cs diff --git a/src/AliasVault.Client/Main/Pages/Settings/BrowserExtensions.razor b/src/AliasVault.Client/Main/Pages/Settings/BrowserExtensions.razor index 4f4e484a5..75ce5a052 100644 --- a/src/AliasVault.Client/Main/Pages/Settings/BrowserExtensions.razor +++ b/src/AliasVault.Client/Main/Pages/Settings/BrowserExtensions.razor @@ -2,7 +2,7 @@ @inherits MainBase @inject IJSRuntime JsRuntime @inject ILogger Logger - +@using AliasVault.Shared.Core.BrowserExtensions Install Browser Extension
- @CurrentBrowser -

@GetBrowserName(CurrentBrowser)

+ @CurrentBrowserExtension?.Name +

@CurrentBrowserExtension?.Name

- @if (CurrentBrowser == BrowserType.Chrome) + @if (CurrentBrowserExtension?.IsAvailable ?? false) { - - Install for Chrome + Install for @CurrentBrowserExtension?.Name } else {

- Support for @GetBrowserName(CurrentBrowser) is coming soon! For now, you can use our Chrome extension. + Support for @CurrentBrowserExtension?.Name is coming soon!

}
@@ -57,19 +57,19 @@

Other Browsers

- @foreach (var browser in Enum.GetValues().Where(b => b != BrowserType.Unknown && b != CurrentBrowser)) + @foreach (var extension in Constants.Extensions.Where(x => x.Key != BrowserType.Unknown && x.Key != CurrentBrowser)) {
- @GetBrowserName(browser) -

@GetBrowserName(browser)

+ @extension.Value.Name +

@extension.Value.Name

- @if (browser == BrowserType.Chrome) + @if (extension.Value.IsAvailable) { - - Install for Chrome + Install for @extension.Value.Name } else @@ -85,24 +85,16 @@
@code { - /// - /// The type of browser. - /// - private enum BrowserType - { - Unknown, - Firefox, - Chrome, - Safari, - Edge, - Brave - } - /// /// The current browser of the user. /// private BrowserType CurrentBrowser { get; set; } + /// + /// Information for extension for the current browser of the user. + /// + private BrowserExtensionInfo? CurrentBrowserExtension { get; set; } = null; + /// protected override async Task OnInitializedAsync() { @@ -112,6 +104,7 @@ try { CurrentBrowser = await DetermineBrowser(); + CurrentBrowserExtension = Constants.Extensions[CurrentBrowser]; } catch (Exception ex) { @@ -149,30 +142,4 @@ _ => BrowserType.Unknown }; } - - /// - /// Gets the browser icon path. - /// - private static string GetBrowserIcon(BrowserType browser) => browser switch - { - BrowserType.Firefox => "/img/browser-icons/firefox.svg", - BrowserType.Chrome => "/img/browser-icons/chrome.svg", - BrowserType.Safari => "/img/browser-icons/safari.svg", - BrowserType.Edge => "/img/browser-icons/edge.svg", - BrowserType.Brave => "/img/browser-icons/brave.svg", - _ => string.Empty - }; - - /// - /// Gets the browser display name. - /// - private static string GetBrowserName(BrowserType browser) => browser switch - { - BrowserType.Firefox => "Firefox", - BrowserType.Chrome => "Google Chrome", - BrowserType.Safari => "Safari", - BrowserType.Edge => "Microsoft Edge", - BrowserType.Brave => "Brave", - _ => string.Empty - }; } diff --git a/src/AliasVault.Client/wwwroot/css/tailwind.css b/src/AliasVault.Client/wwwroot/css/tailwind.css index f175c3c1a..745ad2c83 100644 --- a/src/AliasVault.Client/wwwroot/css/tailwind.css +++ b/src/AliasVault.Client/wwwroot/css/tailwind.css @@ -1100,6 +1100,10 @@ video { grid-template-columns: repeat(1, minmax(0, 1fr)); } +.grid-cols-2 { + grid-template-columns: repeat(2, minmax(0, 1fr)); +} + .grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } @@ -1148,6 +1152,10 @@ video { justify-content: space-between; } +.gap-3 { + gap: 0.75rem; +} + .gap-4 { gap: 1rem; } @@ -2479,11 +2487,6 @@ video { --tw-gradient-to: #f49541 var(--tw-gradient-to-position); } -.dark\:text-blue-200:is(.dark *) { - --tw-text-opacity: 1; - color: rgb(191 219 254 / var(--tw-text-opacity)); -} - .dark\:text-blue-400:is(.dark *) { --tw-text-opacity: 1; color: rgb(96 165 250 / var(--tw-text-opacity)); @@ -2643,6 +2646,11 @@ video { color: rgb(229 231 235 / var(--tw-text-opacity)); } +.dark\:hover\:text-primary-300:hover:is(.dark *) { + --tw-text-opacity: 1; + color: rgb(248 185 99 / var(--tw-text-opacity)); +} + .dark\:hover\:text-primary-500:hover:is(.dark *) { --tw-text-opacity: 1; color: rgb(244 149 65 / var(--tw-text-opacity)); @@ -2765,6 +2773,10 @@ video { grid-template-columns: repeat(2, minmax(0, 1fr)); } + .sm\:grid-cols-3 { + grid-template-columns: repeat(3, minmax(0, 1fr)); + } + .sm\:flex-row { flex-direction: row; } @@ -2851,6 +2863,10 @@ video { grid-template-columns: repeat(4, minmax(0, 1fr)); } + .md\:grid-cols-5 { + grid-template-columns: repeat(5, minmax(0, 1fr)); + } + .md\:gap-4 { gap: 1rem; } diff --git a/src/Shared/AliasVault.Shared.Core/BrowserExtensions/BrowserExtensionInfo.cs b/src/Shared/AliasVault.Shared.Core/BrowserExtensions/BrowserExtensionInfo.cs new file mode 100644 index 000000000..3aabb7008 --- /dev/null +++ b/src/Shared/AliasVault.Shared.Core/BrowserExtensions/BrowserExtensionInfo.cs @@ -0,0 +1,34 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) lanedirt. All rights reserved. +// Licensed under the MIT license. See LICENSE.md file in the project root for full license information. +// +//----------------------------------------------------------------------- + +namespace AliasVault.Shared.Core.BrowserExtensions; + +/// +/// Provides information about a browser extension that is available for AliasVault. +/// +public class BrowserExtensionInfo +{ + /// + /// Gets or sets the name of the browser extension. + /// + public string Name { get; set; } = string.Empty; + + /// + /// Gets or sets the path to the icon of the browser extension. + /// + public string IconPath { get; set; } = string.Empty; + + /// + /// Gets or sets the URL to download the browser extension. + /// + public string? DownloadUrl { get; set; } + + /// + /// Gets or sets a value indicating whether the browser extension is available. + /// + public bool IsAvailable { get; set; } +} diff --git a/src/Shared/AliasVault.Shared.Core/BrowserExtensions/BrowserType.cs b/src/Shared/AliasVault.Shared.Core/BrowserExtensions/BrowserType.cs new file mode 100644 index 000000000..a0443e0dc --- /dev/null +++ b/src/Shared/AliasVault.Shared.Core/BrowserExtensions/BrowserType.cs @@ -0,0 +1,44 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) lanedirt. All rights reserved. +// Licensed under the MIT license. See LICENSE.md file in the project root for full license information. +// +//----------------------------------------------------------------------- + +namespace AliasVault.Shared.Core.BrowserExtensions; + +/// +/// The type of browser. +/// +public enum BrowserType +{ + /// + /// Unknown browser type. + /// + Unknown, + + /// + /// Firefox browser type. + /// + Firefox, + + /// + /// Chrome browser type. + /// + Chrome, + + /// + /// Safari browser type. + /// + Safari, + + /// + /// Edge browser type. + /// + Edge, + + /// + /// Brave browser type. + /// + Brave, +} diff --git a/src/Shared/AliasVault.Shared.Core/BrowserExtensions/Constants.cs b/src/Shared/AliasVault.Shared.Core/BrowserExtensions/Constants.cs new file mode 100644 index 000000000..78740fc69 --- /dev/null +++ b/src/Shared/AliasVault.Shared.Core/BrowserExtensions/Constants.cs @@ -0,0 +1,52 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) lanedirt. All rights reserved. +// Licensed under the MIT license. See LICENSE.md file in the project root for full license information. +// +//----------------------------------------------------------------------- + +namespace AliasVault.Shared.Core.BrowserExtensions; + +/// +/// Provides constants for browser extension information. +/// +public static class Constants +{ + /// + /// Gets the browser extensions available for AliasVault. This is used to render download links in the client. + /// + public static readonly Dictionary Extensions = new() + { + [BrowserType.Chrome] = new BrowserExtensionInfo + { + Name = "Google Chrome", + IconPath = "/img/browser-icons/chrome.svg", + DownloadUrl = "https://chromewebstore.google.com/detail/aliasvault/bmoggiinmnodjphdjnmpcnlleamkfedj", + IsAvailable = true, + }, + [BrowserType.Firefox] = new BrowserExtensionInfo + { + Name = "Firefox", + IconPath = "/img/browser-icons/firefox.svg", + IsAvailable = false, + }, + [BrowserType.Safari] = new BrowserExtensionInfo + { + Name = "Safari", + IconPath = "/img/browser-icons/safari.svg", + IsAvailable = false, + }, + [BrowserType.Edge] = new BrowserExtensionInfo + { + Name = "Microsoft Edge", + IconPath = "/img/browser-icons/edge.svg", + IsAvailable = false, + }, + [BrowserType.Brave] = new BrowserExtensionInfo + { + Name = "Brave", + IconPath = "/img/browser-icons/brave.svg", + IsAvailable = false, + }, + }; +}