From 9e5b053ba246cda894639c87a2da2a6ab3e612c2 Mon Sep 17 00:00:00 2001
From: Yair <39923744+yaira2@users.noreply.github.com>
Date: Sun, 26 Nov 2023 12:48:54 -0500
Subject: [PATCH] Feature: Added support for logging in/out of GitHub (#14085)
---
src/Files.App/Dialogs/SettingsDialog.xaml | 13 +++-
src/Files.App/Dialogs/SettingsDialog.xaml.cs | 5 +-
src/Files.App/Helpers/CredentialsHelpers.cs | 1 +
src/Files.App/Strings/en-US/Resources.resw | 12 +++
src/Files.App/Utils/Git/GitHelpers.cs | 12 +++
.../ViewModels/Settings/GitViewModel.cs | 43 +++++++++++
src/Files.App/Views/Settings/GitPage.xaml | 73 +++++++++++++++++++
src/Files.App/Views/Settings/GitPage.xaml.cs | 15 ++++
.../Tests/SettingsTests.cs | 1 +
9 files changed, 171 insertions(+), 4 deletions(-)
create mode 100644 src/Files.App/ViewModels/Settings/GitViewModel.cs
create mode 100644 src/Files.App/Views/Settings/GitPage.xaml
create mode 100644 src/Files.App/Views/Settings/GitPage.xaml.cs
diff --git a/src/Files.App/Dialogs/SettingsDialog.xaml b/src/Files.App/Dialogs/SettingsDialog.xaml
index f9055909bb76..161b3b457b41 100644
--- a/src/Files.App/Dialogs/SettingsDialog.xaml
+++ b/src/Files.App/Dialogs/SettingsDialog.xaml
@@ -120,11 +120,20 @@
+
+
+
+
+
+ Tag="5">
@@ -133,7 +142,7 @@
AccessKey="B"
AutomationProperties.AutomationId="SettingsItemAbout"
Content="{helpers:ResourceString Name=About}"
- Tag="5">
+ Tag="6">
diff --git a/src/Files.App/Dialogs/SettingsDialog.xaml.cs b/src/Files.App/Dialogs/SettingsDialog.xaml.cs
index 7d4f6d42cac2..f323bdce82dd 100644
--- a/src/Files.App/Dialogs/SettingsDialog.xaml.cs
+++ b/src/Files.App/Dialogs/SettingsDialog.xaml.cs
@@ -53,8 +53,9 @@ private void MainSettingsNavigationView_SelectionChanged(NavigationView sender,
1 => SettingsContentFrame.Navigate(typeof(AppearancePage)),
2 => SettingsContentFrame.Navigate(typeof(FoldersPage)),
3 => SettingsContentFrame.Navigate(typeof(TagsPage)),
- 4 => SettingsContentFrame.Navigate(typeof(AdvancedPage)),
- 5 => SettingsContentFrame.Navigate(typeof(AboutPage)),
+ 4 => SettingsContentFrame.Navigate(typeof(GitPage)),
+ 5 => SettingsContentFrame.Navigate(typeof(AdvancedPage)),
+ 6 => SettingsContentFrame.Navigate(typeof(AboutPage)),
_ => SettingsContentFrame.Navigate(typeof(AppearancePage))
};
}
diff --git a/src/Files.App/Helpers/CredentialsHelpers.cs b/src/Files.App/Helpers/CredentialsHelpers.cs
index 661e869cfa5d..8856589ce942 100644
--- a/src/Files.App/Helpers/CredentialsHelpers.cs
+++ b/src/Files.App/Helpers/CredentialsHelpers.cs
@@ -13,6 +13,7 @@ public static void SavePassword(string resourceName, string username, string pas
vault.Add(credential);
}
+ // Remove saved credentials from the vault
public static void DeleteSavedPassword(string resourceName, string username)
{
var vault = new PasswordVault();
diff --git a/src/Files.App/Strings/en-US/Resources.resw b/src/Files.App/Strings/en-US/Resources.resw
index 99b4d44179c0..4f54a13d5a96 100644
--- a/src/Files.App/Strings/en-US/Resources.resw
+++ b/src/Files.App/Strings/en-US/Resources.resw
@@ -3614,4 +3614,16 @@
Failed to set the background wallpaper
+
+ Connected to GitHub
+
+
+ Logout
+
+
+ Connect to GitHub
+
+
+ Login
+
\ No newline at end of file
diff --git a/src/Files.App/Utils/Git/GitHelpers.cs b/src/Files.App/Utils/Git/GitHelpers.cs
index 81e540aec21b..6f6a8ca50126 100644
--- a/src/Files.App/Utils/Git/GitHelpers.cs
+++ b/src/Files.App/Utils/Git/GitHelpers.cs
@@ -651,6 +651,18 @@ public static GitItemModel GetGitInformationForItem(Repository repository, strin
return gitItemModel;
}
+ // Remove saved credentails
+ public static void RemoveSavedCredentials()
+ {
+ CredentialsHelpers.DeleteSavedPassword(GIT_RESOURCE_NAME, GIT_RESOURCE_USERNAME);
+ }
+
+ // Get saved credentails
+ public static string GetSavedCredentials()
+ {
+ return CredentialsHelpers.GetPassword(GIT_RESOURCE_NAME, GIT_RESOURCE_USERNAME);
+ }
+
public static async Task InitializeRepositoryAsync(string? path)
{
if (string.IsNullOrWhiteSpace(path))
diff --git a/src/Files.App/ViewModels/Settings/GitViewModel.cs b/src/Files.App/ViewModels/Settings/GitViewModel.cs
new file mode 100644
index 000000000000..11eaaf90f0e5
--- /dev/null
+++ b/src/Files.App/ViewModels/Settings/GitViewModel.cs
@@ -0,0 +1,43 @@
+// Copyright (c) 2023 Files Community
+// Licensed under the MIT License. See the LICENSE.
+
+using System.Windows.Input;
+
+namespace Files.App.ViewModels.Settings
+{
+ public class GitViewModel : ObservableObject
+ {
+ protected readonly IFileTagsSettingsService FileTagsSettingsService = Ioc.Default.GetRequiredService();
+
+ public ICommand RemoveCredentialsCommand { get; }
+ public ICommand ConnectToGitHubCommand { get; }
+
+ // Enabled when there are saved credentials
+ private bool _IsLogoutEnabled;
+ public bool IsLogoutEnabled
+ {
+ get => _IsLogoutEnabled;
+ set => SetProperty(ref _IsLogoutEnabled, value);
+ }
+
+ public GitViewModel()
+ {
+ RemoveCredentialsCommand = new RelayCommand(DoRemoveCredentials);
+ ConnectToGitHubCommand = new RelayCommand(DoConnectToGitHubAsync);
+
+ IsLogoutEnabled = GitHelpers.GetSavedCredentials() != string.Empty;
+ }
+
+ public void DoRemoveCredentials()
+ {
+ GitHelpers.RemoveSavedCredentials();
+ IsLogoutEnabled = false;
+ }
+
+ public async void DoConnectToGitHubAsync()
+ {
+ UIHelpers.CloseAllDialogs();
+ await GitHelpers.RequireGitAuthenticationAsync();
+ }
+ }
+}
diff --git a/src/Files.App/Views/Settings/GitPage.xaml b/src/Files.App/Views/Settings/GitPage.xaml
new file mode 100644
index 000000000000..3fdf7c0f230e
--- /dev/null
+++ b/src/Files.App/Views/Settings/GitPage.xaml
@@ -0,0 +1,73 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Files.App/Views/Settings/GitPage.xaml.cs b/src/Files.App/Views/Settings/GitPage.xaml.cs
new file mode 100644
index 000000000000..347d553ad9c3
--- /dev/null
+++ b/src/Files.App/Views/Settings/GitPage.xaml.cs
@@ -0,0 +1,15 @@
+// Copyright (c) 2023 Files Community
+// Licensed under the MIT License. See the LICENSE.
+
+using Microsoft.UI.Xaml.Controls;
+
+namespace Files.App.Views.Settings
+{
+ public sealed partial class GitPage : Page
+ {
+ public GitPage()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/tests/Files.InteractionTests/Tests/SettingsTests.cs b/tests/Files.InteractionTests/Tests/SettingsTests.cs
index 043a862d6bb7..5d793d5e3162 100644
--- a/tests/Files.InteractionTests/Tests/SettingsTests.cs
+++ b/tests/Files.InteractionTests/Tests/SettingsTests.cs
@@ -30,6 +30,7 @@ public void VerifySettingsAreAccessible()
"SettingsItemAppearance",
"SettingsItemFolders",
"SettingsItemTags",
+ "SettingsItemGit",
"SettingsItemAdvanced",
"SettingsItemAbout"
};